This document describes the sequence types available in PAD and how to generate them.
{fibonacci rows=10}{$fibonacci} {/fibonacci} # Fibonacci numbers
{prime rows=15}{$prime} {/prime} # Prime numbers
{sequence '1..10', name='n'}{$n} {/sequence} # Range 1-10
{random minimal=1, maximal=100, rows=5}{$random} {/random} # Random numbers
{list '5;2;8;1;9'}{$list} {/list} # Custom list
{sequence 'A..Z', name='letter'}{$letter} {/sequence} # Full alphabet
{sequence 'a..e', name='c'}{$c} {/sequence} # a, b, c, d, e
{sequence '0..9', name='digit'}{$digit} {/sequence} # Digits as strings
{sequence 10, oeis=81}{$sequence} {/sequence} # OEIS sequence A000081
{sequence 15, oeis=257360}{$sequence} {/sequence} # OEIS sequence A257360
The A-number is written without its leading zeroes. The terms come from
pad/sequence/types/oeis/oeis.sqlite, one row per A-number, read a sequence at a time - so
a request that asks for one costs a lookup rather than the whole table. An A-number the
table does not hold produces no terms. oeis/regenerate.php regenerates the table from the
stripped bulk download published by oeis.org.
{sequence loop, from=11, to=30, name='i'}{$i} {/sequence}
What from and to count depends on how the type produces its terms - values for the ones
that test candidates, positions for the ones that compute the nth term. rows always counts
terms and stop always names a value. See
PAD.md for which types are which.
A name that is not a sequence type, a stored sequence or an action is reported as an error. It used to be answered with a plain 1, 2, 3, … counter, which looked enough like a sequence to be mistaken for one, so a typo went unnoticed:
{sequence prime, rows=5}{$sequence} {/sequence} # the primes
{sequence prmie, rows=5}{$sequence} {/sequence} # error: 'prmie' is not a sequence type, a store or an action
Names are written as they are spelled, on every machine: {Keep '1..10', prime},
{Flag:even} and sequence:Prime(3) are no tag, type or sequence, as on a file system that
tells case apart.
The parameters written without a name are read in the order written, each by what it stands beside:
{sequence add, 3} is
{sequence add=3}, {sequence '1..9', first, 2} is {sequence '1..9', first=2} and
{pull:a shift, 2} is {pull:a shift=2}.{multiply 3}, {action:first 3}, {append 's'} - and
read as below when it is not: {reverse 'prime'} reverses the primes; see
ACTIONS.md for the actions.'1..10', a ';' list '5;2;8' or a list [5, 2, 8]
is the values the tag runs over, and a number how many rows - {sequence 5}. Beside a store
the tag pulls the store is the values, and a list is the values of a play over it, as a
';' list is: {keep:a [2, 3]} keeps the terms of a that are 2 or 3, as {keep:a '2;3'}
does. An action that takes stores takes the list, though - the one the tag names, or else
the first one written as an option: {a:append [7, 8]} and {pull:a append, [7, 8]} are
{pull:a append=[7, 8]} - and so the name of another store there: {pull:a intersection,
'b'} is {pull:a intersection='b'}.{sequence $type, rows=5} - and a
type or an action named while the tag runs one already is the option of that name:
{prime 'even'} is {prime even}, {sum 'reverse'} is {sum reverse}.{keep $type, '1..10'} with $type ‘prime’ is
{keep:prime '1..10'}, the primes of 1 to 10, and {pull 's', 'shift', 2} is
{pull:s shift=2}. One written after a count, a range or a list - or one what the name
runs does not take - that names a type or an action is read as the option of that name,
in the order written: {keep '1..10', $type} is {keep '1..10', prime}, {reverse '1..5',
'sum'} is {reverse '1..5', sum} and {sequence 'prime', 3, 'reverse'} is
{prime 3, reverse}.{sequence '1..5', 'x'}, {multiply 3, 4}, {pull:s 'abc'},
a second store {a:sum 'b'} beside the store a the tag pulls - is reported by the strict
check.fibonacci - Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, …)lucas - Lucas numbers (1, 3, 4, 7, 11, 18, 29, …)pell - Pell numbers (1, 2, 5, 12, 29, 70, …)tribonacci - Tribonacci numbers (0, 0, 1, 1, 2, 4, 7, …)catalan - Catalan numbers (1, 2, 5, 14, 42, 132, …)bell - Bell numbers (1, 2, 5, 15, 52, 203, …)perrin - Perrin numbers (3, 0, 2, 3, 2, 5, …)factorial - Factorials n! (1, 2, 6, 24, 120, 720, …)jacobsthal - Jacobsthal numbers, J(n) = J(n-1) + 2J(n-2) (1, 1, 3, 5, 11, 21, 43, …)leonardo - Leonardo numbers, L(n) = L(n-1) + L(n-2) + 1 (1, 1, 3, 5, 9, 15, 25, …)narayana - Narayana’s cows, a(n) = a(n-1) + a(n-3) (1, 1, 1, 2, 3, 4, 6, 9, …)motzkin - Motzkin numbers, the ways to draw chords that do not cross (1, 2, 4, 9, 21, 51, …)partition - The ways to write n as a sum of whole numbers (1, 2, 3, 5, 7, 11, 15, 22, …)derangement - The orders of n things that leave none in its place (0, 1, 2, 9, 44, 265, …)Where a sequence is conventionally listed with a leading term for n = 0, PAD starts at
n = 1 and does not produce it: lucas begins at 1 rather than 2, pell omits its leading 0,
catalan and bell their leading 1, caterer its leading 1 and moserdebruijn its leading 0,
and gould is shifted the same way - as are factorial, jacobsthal, motzkin, partition
and derangement, whose n = 0 term stands at position 0, before the first a run makes.
fibonacci, tribonacci, perrin, recaman, leonardo and narayana do include their
n = 0 term. Every value produced is a genuine member either way - only where the listing
starts differs.
prime - Prime numbers (2, 3, 5, 7, 11, 13, …)composite - Composite numbers (4, 6, 8, 9, 10, …)perfect - Perfect numbers (6, 28, 496, …)mersenne - Mersenne primes, the 2^p - 1 that are themselves prime (3, 7, 31, 127, 8191, …) - not the Mersenne numbers, which include 1, 15, 63 and the restemirp - Emirp primes (primes that are different primes when reversed)strong - Strong numbers / factorions, equal to the sum of the factorials of their own digits (1, 2, 145, 40585) - not the strong primes; 40585 lies beyond the default 10,000 candidates, try=100000 reaches itsemiprime - Semiprimes (products of exactly two primes)twinPrime - Both primes of every twin pair, two apart (3, 5, 7, 11, 13, 17, 19, 29, 31, …)sophieGermain - Primes p for which 2p + 1 is prime too (2, 3, 5, 11, 23, 29, 41, …)safePrime - Primes p for which (p - 1) / 2 is prime too (5, 7, 11, 23, 47, 59, …)primorial - Products of the first n primes (2, 6, 30, 210, 2310, …) - fifteen inside the integer rangefermat - Fermat numbers 2^(2^n) + 1 (3, 5, 17, 257, 65537, 4294967297) - all six a PHP integer holdstriangular - Triangular numbers (1, 3, 6, 10, 15, …)square - Square numbers (1, 4, 9, 16, 25, …)cubic - Cubic numbers (1, 8, 27, 64, 125, …)pentagonal - Pentagonal numbers (1, 5, 12, 22, 35, …)hexagonal - Hexagonal numbers (1, 6, 15, 28, 45, …)heptagonal - Heptagonal numbers (1, 7, 18, 34, 55, …)octagonal - Octagonal numbers (1, 8, 21, 40, 65, …)decagonal - Decagonal numbers (1, 10, 27, 52, 85, …)tetrahedral - Tetrahedral numbers (1, 4, 10, 20, 35, …)octahedral - Octahedral numbers (1, 6, 19, 44, 85, …)biquadratic - Biquadratic numbers (1, 16, 81, 256, …)gnomonic - Gnomonic numbers (1, 3, 5, 7, 9, …)pronic - Pronic/oblong numbers (n*(n+1))heptadecagonal - Heptadecagonal numbers (1, 17, 48, 94, 155, …)enneadecagonal - Enneadecagonal numbers (1, 19, 54, 106, 175, …)icosihenagonal - Icosihenagonal numbers (1, 21, 60, 118, 195, …)pentatope - Pentatope numbers, n(n+1)(n+2)(n+3)/24 (1, 5, 15, 35, 70, …)star - Star numbers, 6n(n-1) + 1 (1, 13, 37, 73, 121, …)centeredSquare - Centered square numbers, 2n(n-1) + 1 (1, 5, 13, 25, 41, …)centeredHexagonal - Centered hexagonal numbers, 3n(n-1) + 1 (1, 7, 19, 37, 61, …)even - Even numbers (2, 4, 6, 8, 10, …)odd - Odd numbers (1, 3, 5, 7, 9, …)happy - Happy numbers (1, 7, 10, 13, 19, …)lucky - Lucky numbers (1, 3, 7, 9, 13, …)harshad - Harshad/Niven numbers (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, …)palindrome - Palindromic numbers (1, 2, …, 9, 11, 22, …)powerful - Powerful numbers (1, 4, 8, 9, 16, …)polite - Polite numbers (3, 5, 6, 7, 9, …)kaprekar - Kaprekar numbers (1, 9, 45, 55, …)antiprime - Antiprime (highly composite) numbers (1, 2, 4, 6, 12, 24, 36, …) - walked from one to the next, so all 167 an integer holds are within reach; with try=, skip= or increment= every value is a candidate, as for the other typesgolomb - Golomb sequence (1, 2, 2, 3, 3, 4, 4, 4, …)gould - Gould sequence, odd entries in row n-1 of Pascal’s triangle (1, 2, 2, 4, 2, 4, 4, 8, …)kolakoski - Kolakoski sequence (1, 2, 2, 1, 1, 2, 1, 2, …)kynea - Kynea numbers (7, 23, 79, 287, 1087, …)moserdebruijn - Moser-de Bruijn sequence, sums of distinct powers of four (1, 4, 5, 16, 17, 20, 21, 64, …)newmanConway - Newman-Conway sequence (1, 1, 2, 2, 3, 4, 4, 4, …)recaman - Recaman sequence (0, 1, 3, 6, 2, 7, 13, 20, …)sylvester - Sylvester sequence (2, 3, 7, 43, 1807, …)cullen - Cullen numbers, n*2^n+1 (3, 9, 25, 65, 161, …)woodall - Woodall numbers, n*2^n-1 (1, 7, 23, 63, 159, …)thabit - Thabit numbers, 3*2^n-1 (2, 5, 11, 23, 47, 95, …)repunit - Repunits, n ones in a row (1, 11, 111, 1111, …)xpadovan - Padovan sequence (1, 1, 1, 2, 2, 3, 4, 5, …)caterer - Lazy caterer’s sequence (2, 4, 7, 11, 16, 22, …)vanEck - Van Eck’s sequence, how far back the last term was seen before (0, 0, 1, 0, 2, 0, 2, 2, 1, 6, …)stern - Stern’s diatomic sequence, a(2n) = a(n) and a(2n+1) = a(n) + a(n+1) (1, 1, 2, 1, 3, 2, 3, 1, …)thueMorse - The Thue-Morse sequence, the parity of the binary ones of n (1, 1, 0, 1, 0, 0, 1, …)collatz - The steps n takes to reach 1 by halving or 3n + 1 (0, 1, 7, 2, 5, 8, 16, …)digitSum, digitalRoot and reversal are functions of the position, from n = 1;
narcissistic and automorphic are lists - all of them a PHP integer holds, so their
membership tests are exact; evil and odious count the binary digits.
digitSum - The sum of the digits of n (1, 2, …, 9, 1, 2, …)digitalRoot - The digit sum taken again until one digit is left (1, 2, …, 9, 1, 2, …)reversal - n with its digits reversed (1, 2, …, 9, 1, 11, 21, …)narcissistic - Armstrong numbers, the sum of their digits each to the power of their length (1, …, 9, 153, 370, 371, 407, 1634, …)automorphic - Numbers whose square ends in the number itself (0, 1, 5, 6, 25, 76, 376, 625, …)evil - Numbers with an even number of ones in binary (3, 5, 6, 9, 10, 12, 15, …)odious - Numbers with an odd number of ones in binary (1, 2, 4, 7, 8, 11, 13, …)The terms of totient, divisors and sigma are a function of the position, from n = 1,
and their membership tests - {keep totient} and the rest - ask whether some n gives the
value, which for totient and sigma is searched among the divisors of the value: the n can
stand far past the value itself. The others are the numbers that have the property. The prime factors come from trial division and, past 10,000,
Pollard’s rho through gmp, so a number of 19 digits is factored in well under a second.
totient - Euler’s totient, how many numbers up to n share no factor with it (1, 1, 2, 2, 4, 2, 6, 4, …)divisors - The number of divisors of n (1, 2, 2, 3, 2, 4, 2, 4, 3, …)sigma - The sum of the divisors of n (1, 3, 4, 7, 6, 12, 8, 15, 13, …)abundant - Numbers whose proper divisors add up to more than themselves (12, 18, 20, 24, 30, …)deficient - Numbers whose proper divisors add up to less than themselves (1, 2, 3, 4, 5, 7, 8, …)squarefree - Numbers no square above 1 divides (1, 2, 3, 5, 6, 7, 10, 11, …)smith - Composite numbers whose digit sum equals that of their prime factors (4, 22, 27, 58, 85, …)sphenic - Products of three different primes (30, 42, 66, 70, 78, …)carmichael - Carmichael numbers, the composites Fermat’s test cannot tell from primes (561, 1105, 1729, …) - seven below the default 10,000 candidates, try= reaches moreamicable - Both numbers of every amicable pair, each the sum of the other’s proper divisors (220, 284, 1184, 1210, …)hamming - Regular numbers, with no prime factor above 5 (1, 2, 3, 4, 5, 6, 8, 9, 10, 12, …)perfectPower - Powers m^k with k of 2 or more (1, 4, 8, 9, 16, 25, 27, 32, …)Each takes a number as its parameter and applies it to the loop value, so they are most
often used as plays over another sequence - {make multiply=3} - rather than generated on
their own. A parameter that is not a number is reported rather than passed on, divide and
multiple will not take a zero, and chance needs 1 or more.
add=N - Addition (with N = 3: 4, 5, 6, 7, …)subtract=N - Subtractionmultiply=N - Multiplication (with N = 3: 3, 6, 9, 12, …)divide=N - Divisionmodulo=N - Modulo, of a fractional parameter too (with N = 3: 1, 2, 0, 1, 2, 0, …)power=N - N raised to the loop value (with N = 3: 3, 9, 27, 81, …)exponentiation=N - the loop value raised to N (with N = 3: 1, 8, 27, 64, …)ceil=N - Rounded up to a multiple of N (with N = 3: 3, 3, 3, 6, 6, 6, …)floor=N - Rounded down to a multiple of Nround=N - Rounded to the nearest multiple of Nmultiple=N - The multiples of N (with N = 3: 3, 6, 9, 12, …)step=N - Counts in steps of N (with N = 3: 1, 4, 7, 10, …)negation - Negation (-1, -2, -3, -4, …)These work on the bits of the loop value and the parameter, not on true and false - and=3
gives 1, 2, 3, 0, 1, 2, 3, 0, which is n AND 3 rather than a logical answer. The four that
complement their result run negative.
and=N - Bitwise AND (with N = 3: 1, 2, 3, 0, …)or=N - Bitwise OR (with N = 3: 3, 3, 3, 7, …)xor=N - Bitwise XOR (with N = 3: 2, 1, 0, 7, …)not - Bitwise NOT (-2, -3, -4, -5, …)nand=N - Bitwise NAND (with N = 3: -2, -3, -4, -1, …)nor=N - Bitwise NOR (with N = 3: -4, -4, -4, -8, …)xnor=N - Bitwise XNOR (with N = 3: -3, -2, -1, -8, …)The arithmetic and bitwise types, eval and loop make a term at every position a run gives
them, 0 and below included - {sequence add=3, from=0} is 3, 4, 5 - but their membership
tests, which keep, remove and flag ask, count the positions from 1, where a run starts
by default: a value is a member when a position of 1 or more makes it, so
{sequence '3;4', flag, add=3} flags 0 1, and the 3 that position 0 made is none. multiple
is the exception: it walks the values themselves, as step does, and its test takes every
multiple of N, 0 and the negative ones included - {sequence '-6..3', keep, multiple=3} is
-6, -3, 0, 3, where multiply=3 keeps 3 alone. A play over another sequence’s terms -
{make add=3} - is arithmetic on whatever value it is handed.
range - Range (e.g., '1..10')list - Custom list (e.g., '1;5;3;8')loop - Loop iterationrandom - Random numbersrepeat - Repeat a valueoeis - An OEIS sequence by its A-number, from the local table (oeis=81)identity - Identity sequence (returns input)step - Step sequencechance - Chance/probability sequenceIMPORTANT: Store names cannot be the same as action names (e.g., can’t use push='first' because first is an action).
Nor the name of something the page made - an array of the page, a {data}, {content}, {bool},
{define}, {macro} or a select table: push= (or a single tag’s name=) is refused under the
strict check - “the store name ‘x’ is already an array of the page” - and a pair that only names
its loop keeps no store. A value the request brought under the name (?nums[]=1) is no array the
page made, and gives way to the store; so the refusal covers a name the page made itself that the
request did not also bring - {set $primes = ['1']} before push='primes' is refused, with
?primes[]=1 in the request the same list is taken for the request’s and the store takes the name.
{sequence '1..10', push='mySeq'} # Store sequence
{pull:mySeq}{$sequence} {/pull:mySeq} # Retrieve and iterate
# Use pull: prefix to avoid naming conflicts with app tags
{sequence 5, push='nums'}
{pull:nums} {$sequence} {/pull:nums}
The sequence tags (resume, pull, keep, remove, flag, make) operate on stored sequences:
{sequence 5, push='mySeq'} # Create and store sequence
{resume add=10} # Transform: add 10 to each value
{resume reverse} # Transform: reverse order
{pull:mySeq} {$sequence} {/pull:mySeq} # Iterate stored sequence
Note: {resume} applies transformations to stored sequences. Use {continue} for skipping iterations (like PHP’s continue).
Use named sequences instead of level-based access:
{sequence 5, name='n'}
{$n} # Correct - use named variable
{/sequence}
{sequence 5}
{$sequence@-1} # Avoid - level-based access can be fragile ({$-1} is no field)
{/sequence}
Always prefer named sequences for clarity:
{sequence 5, name='i'}
{$i} # Clear, explicit
{/sequence}
{sequence '1..3', name='row'}
{sequence '1..4', name='col'}
({$row},{$col})
{/sequence}
{/sequence}
In an expression, sequence:<type>(n) is the nth term:
{echo '' | sequence:fibonacci(8)} 13 - the eighth Fibonacci number
{echo '' | sequence:prime(8)} 19
{if sequence:square(6) eq 36}... the term reads as a value
{echo '' | sequence:add(3, 10)} 13 - a second argument is the type's parameter: add=10
{echo '' | sequence:prime(3, 'abc')} error - prime takes no parameter
The action half of the same prefix - sequence:sum([1,2,3]) - answers with a list instead,
because a list is what an action produces; {echo '' | sequence:sum([1,2,3]) . ''} prints it
(6), where a pipe that ends on the list itself prints nothing. A value piped in without
arguments is the call’s argument: {echo 5 | sequence:fibonacci} is the fifth term, 3, and
([1,2,3] | sequence:sum) . '' is 6. Numbers written one after another are the values too, for
an action that takes no count and no store to act with: sequence:sum(1, 2, 3) is the sum of
the three and sequence:sort(3, 1, 2) sorts them, where sequence:first(5, 2) reads the 2 as
its count; a parameter given to an action that takes none - sequence:sum([1, 2], 3) - is an
error under the strict check.
Some sequences need sequence: prefix:
{sequence:repeat 42, rows=5}{$repeat}{/sequence:repeat}
{sequence:even rows=10}{$even}{/sequence:even}
Chance sequence needs a numeric parameter:
{chance 4, rows=15}{$chance}{/chance} # 1-in-4 chance (not {chance rows=15})