pad

Sequence/Iteration Support

This module provides powerful sequence generation capabilities for the PAD framework, supporting mathematical sequences, number theory sequences, random generation, and array operations.

Overview

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).

Directory Structure

Core Components

Sequence Types (types/)

122 mathematical and number theory sequences, including:

Arithmetic Sequences

Number Properties

Famous Sequences

Polygonal Numbers

3D Figurate Numbers

Other Sequences

Utilities

Logical Operations

Actions (actions/)

Transform and analyze sequences:

Aggregation

Selection

Transformation

Combination

Ordering

Structure

Options (options/types/)

Configure sequence generation:

Range Control

Limit Control

Behavior

Ordering

Duplicates

Actions & Storage

Special

Key Features

Flexible Sequence Generation

Powerful Transformations

Advanced Parameters

What from and to count

from and to bound the loop the sequence is generated by, and what that loop counts depends on how the type produces its terms:

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:

Storage and Reuse

Integration with PAD Framework

The sequence module extends PAD’s template capabilities:

  1. Template Tags: Sequences accessible via template tags with parameters
  2. Data Generation: Generate data arrays for iteration
  3. Calculations: Perform mathematical operations in templates
  4. Random Data: Generate random datasets for testing/demos
  5. Number Theory: Access mathematical sequences for specialized applications

Usage Pattern

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.

Example Workflows

  1. Generate Fibonacci numbers - {sequence fibonacci, from=1, to=10} gives ten of them, 0 1 1 2 3 5 8 13 21 34
  2. Sum the first 20 primes - {sequence prime, rows=20, sum} gives 639
  3. Random unique numbers - {sequence random, minimal=1, maximal=100, rows=10, unique}
  4. Even numbers descending - {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
  5. Average of a range - {sequence range='1..100', average} gives 50.5

This module demonstrates PAD’s extensibility, providing a complete mathematical sequence engine within the template system.