This module provides powerful sequence generation capabilities for the PAD framework, supporting mathematical sequences, number theory sequences, random generation, and array operations.
The sequence module (internally prefixed with pq) enables templates to generate and manipulate numeric sequences like Fibonacci, primes, ranges, and many specialized mathematical sequences. It provides a comprehensive system for building sequences with customizable parameters (from/to, increment, limits), applying transformations (sort, reverse, dedup), and extracting results (sum, average, count).
given.php - Process named sequencesparm.php - Parameter extractionstore.php - Store built sequencesvars.php - Variable managementrandomly/ - Random sequence buildingdata.php - Return sequence datareturn.php - Main return logicstore/ - Store results to variablesextra/ - Additional processing (chain, actions, etc.)parm.php - Play parametersplay/ - Different play modes (bool, function, order)122 mathematical and number theory sequences, including:
Arithmetic Sequences
Number Properties
Famous Sequences
Polygonal Numbers
3D Figurate Numbers
Other Sequences
Utilities
Logical Operations
Transform and analyze sequences:
Aggregation
Selection
Transformation
Combination
Ordering
Structure
Configure sequence generation:
Range Control
Limit Control
Behavior
Ordering
Duplicates
Actions & Storage
Special
'0..1') also counts in a step below 1rows is the page’s size, 10 when not given, a page below 1 or no number is page 1, and {pager 'sequence'} - or the name of the type, the store or the tag, {pager 'prime'}, {pager 'keep'}, or the name= given - writes the links to the other pages. The pager of a range, a list or a store counts all its terms, made only up to the page shown; of any other run - a type, or a list with a play, unique, min/max, stop, try or randomly - it knows the pages made, up to the one after the page shown, so it has a next page while there are more. In the order written, as among a data tag’s options: an action before page acts on every term and the page is cut from its result - {sequence '5;3;9;1;7;2', sort, page=1, rows=3} is 1 2 3 - one after it acts on the page. A type without an end of its own - no to or stop - has no every term: it is cut to its page first, wherever page is written - {sequence 'prime', reverse, page=2, rows=5} is 29 23 19 17 13 - unless every action before page keeps a front of the run and drops none of it (first, shift, element, prepend, without negative): {sequence 'prime', first=20, page=5, rows=5} is past the twenty, no terms. A dedup, intersection or onlyNow before page on such a run, or one of these under negative, drops terms of that front: the run is made again with twice the terms until what they leave fills the page after the one shown - {sequence 'golomb', dedup, page=2, rows=3} is 4 5 6 with a next page - or until doubling the run leaves no more terms than before ({sequence 'kolakoski', dedup} has two) - while it leaves none at all, up to a thousand times the terms that page needs - or the run reaches its candidate or time limitfirst=5, negative gives all but the first five. It applies to actions only; a play is inverted by writing remove where you would write keepfrom and to bound the loop the sequence is generated by, and what that loop counts
depends on how the type produces its terms:
to is an upper bound on the terms
themselves. {sequence prime, to=20} gives the primes up to 20, and
{sequence triangular, to=20} gives 1 3 6 10 15.to is how many are produced.
{sequence square, to=20} gives twenty squares, ending at 400, and
{sequence fibonacci, to=20} gives twenty Fibonacci numbers.perfect, mersenne, kolakoski, and any stored
sequence read back with pull - are indexed by position too, so to is a position in
that list.rows counts produced terms whichever kind is in play, so it is the parameter to reach
for when a fixed number of terms is what is wanted, and stop always names a value.
Which kind a type is follows from the files in its directory: a bool.php predicate tests
values, while function.php, order.php and fixed.php are given a position, as most
loop.php files are - the exceptions test or step through the values themselves: prime
and emirp test the loop value, multiple and step step through the values by their
parameter, so from and to bound their terms. A type that is generated by position and
also has a bool.php - golomb, gould, square and others - keeps generating by position;
the predicate is what keep, remove and flag ask.
build= picks the other kind for one run, and two of the builds serve every type:
build='bool' walks the values and keeps the ones that belong, so from and to name
values: {sequence fibonacci, build='bool', to=100} gives 1 2 3 5 8 13 21 34 55 89, each
value once. A type without a bool.php is asked through its membership check.build='function' gives the term at each position, so from and to count terms:
{sequence happy, build='function', from=5, to=8} gives the 5th to 8th happy numbers,
19 23 28 31. A type that tests values has its nth value found by walking them, kept for
the rest of the request; one that steps through them by itself - step, even, odd,
multiple - has it worked out from its first terms, at any position:
{sequence step=3, build='function', from=2, to=4} gives 4 7 10.The sequence module extends PAD’s template capabilities:
Sequences are invoked through PAD template tags. The type is named directly - there is no
type= attribute - and options follow it as a comma-separated list:
{sequence fibonacci, from=1, to=10}{$sequence} {/sequence}
{sequence prime, rows=20, sum}{$sequence}{/sequence}
{sequence range='1..100', increment=5, average}{$sequence}{/sequence}
{sequence random, minimal=1, maximal=100, rows=10, unique}{$sequence} {/sequence}
Parameters control generation, actions transform results, and outputs can be stored for later use.
{sequence fibonacci, from=1, to=10} gives ten of them,
0 1 1 2 3 5 8 13 21 34{sequence prime, rows=20, sum} gives 639{sequence random, minimal=1, maximal=100, rows=10, unique}{sequence even, to=10, reverse} gives 20 18 16 … 2.
Descending order comes from the reverse action; negative inverts an action’s
selection and does not reorder anything{sequence range='1..100', average} gives 50.5This module demonstrates PAD’s extensibility, providing a complete mathematical sequence engine within the template system.