# Mathematical Programming Languages: Complete Appendices ## Appendix A: Complete Symbol Reference ### A.1 Core Mathematical Operators #### Greek Letters (Variables) All 24 Greek letters serve as single-character identifiers, following mathematical convention: | Symbol | ASCII Escape | Unicode | Mathematical Usage | MPL Usage | |--------|-------------|---------|-------------------|-----------| | α | `\alpha` | U+03B1 | Angle, coefficient | General variable | | β | `\beta` | U+03B2 | Angle, coefficient | General variable | | γ | `\gamma` | U+03B3 | Euler constant | General variable | | δ | `\delta` | U+03B4 | Small change | General variable | | ε | `\epsilon` | U+03B5 | Small positive | General variable | | ζ | `\zeta` | U+03B6 | Zeta function | General variable | | η | `\eta` | U+03B7 | Efficiency | General variable | | θ | `\theta` | U+03B8 | Angle | General variable | | ι | `\iota` | U+03B9 | Imaginary unit | General variable | | κ | `\kappa` | U+03BA | Curvature | General variable | | λ | `\lambda`, `\lam` | U+03BB | Eigenvalue | Lambda/function | | μ | `\mu` | U+03BC | Mean, measure | General variable | | ν | `\nu` | U+03BD | Frequency | General variable | | ξ | `\xi` | U+03BE | Random variable | General variable | | ο | `\omicron` | U+03BF | - | General variable | | π | `\pi` | U+03C0 | Pi constant | Variable/constant | | ρ | `\rho` | U+03C1 | Density | General variable | | σ | `\sigma` | U+03C3 | Standard deviation | General variable | | τ | `\tau` | U+03C4 | Time constant | General variable | | υ | `\upsilon` | U+03C5 | - | General variable | | φ | `\phi` | U+03C6 | Golden ratio | General variable | | χ | `\chi` | U+03C7 | Chi distribution | General variable | | ψ | `\psi` | U+03C8 | Wave function | General variable | | ω | `\omega` | U+03C9 | Angular velocity | General variable | #### Logical Operators | Symbol | ASCII Escape | Unicode | Precedence | Associativity | Description | |--------|-------------|---------|------------|---------------|-------------| | ∧ | `\and`, `\wedge` | U+2227 | 3 | Left | Logical AND | | ∨ | `\or`, `\vee` | U+2228 | 2 | Left | Logical OR | | ¬ | `\not`, `\neg` | U+00AC | 8 | Prefix | Logical NOT | | ⟹ | `\implies`, `\Rightarrow` | U+27F9 | 1 | Right | Implication | | ⟺ | `\iff`, `\Leftrightarrow` | U+27FA | 1 | Right | If and only if | | ∀ | `\forall` | U+2200 | - | - | Universal quantifier | | ∃ | `\exists` | U+2203 | - | - | Existential quantifier | #### Arithmetic Operators | Symbol | ASCII Escape | Unicode | Precedence | Associativity | Description | |--------|-------------|---------|------------|---------------|-------------| | + | - | U+002B | 5 | Left | Addition | | - | - | U+002D | 5 | Left | Subtraction | | × | `\times` | U+00D7 | 6 | Left | Multiplication | | ÷ | `\div` | U+00F7 | 6 | Left | Division | | ^ | - | U+005E | 7 | Right | Exponentiation | | √ | `\sqrt` | U+221A | 8 | Prefix | Square root | | Σ | `\sum` | U+2211 | - | - | Summation | #### Set Theory Operators | Symbol | ASCII Escape | Unicode | Description | |--------|-------------|---------|-------------| | ∅ | `\emptyset` | U+2205 | Empty set | | ∈ | `\in` | U+2208 | Element of | | ∉ | `\notin` | U+2209 | Not element of | | ⊂ | `\subset` | U+2282 | Proper subset | | ⊆ | `\subseteq` | U+2286 | Subset or equal | | ∪ | `\union`, `\cup` | U+222A | Set union | | ∩ | `\intersect`, `\cap` | U+2229 | Set intersection | | \| | - | U+007C | Set size/cardinality | #### Comparison Operators | Symbol | ASCII Escape | Unicode | Precedence | Description | |--------|-------------|---------|------------|-------------| | = | - | U+003D | 4 | Equality | | ≠ | `\neq`, `\ne` | U+2260 | 4 | Not equal | | < | - | U+003C | 4 | Less than | | > | - | U+003E | 4 | Greater than | | ≤ | `\leq`, `\le` | U+2264 | 4 | Less or equal | | ≥ | `\geq`, `\ge` | U+2265 | 4 | Greater or equal | | ≈ | `\approx` | U+2248 | 4 | Approximately | ### A.2 Programming Extensions #### I/O and Assignment | Symbol | ASCII Escape | Unicode | Usage | Example | |--------|-------------|---------|-------|---------| | ✎ | `\pencil` | U+270E | Output/print | `✎ "Hello"` | | ← | `\leftarrow`, `\gets` | U+2190 | Assignment | `x ← 42` | | → | `\rightarrow`, `\to` | U+2192 | Function type | `ℕ → ℕ` | | ≜ | `\coloneq` | U+225C | Definition | `fact ≜ λn: ...` | #### Exception Handling | Symbol | ASCII Escape | Unicode | Usage | Example | |--------|-------------|---------|-------|---------| | ↯ | `\lightning` | U+21AF | Raise exception | `↯"Error!"` | | ↴ | `\downarrow` | U+21B4 | Handle exception | `expr ↴ {handler}` | #### Concurrency | Symbol | ASCII Escape | Unicode | Usage | Example | |--------|-------------|---------|-------|---------| | ‖ | `\parallel` | U+2016 | Parallel composition | `task1 ‖ task2` | | ⇀ | `\send` | U+21C0 | Channel send | `value ⇀ channel` | | ↽ | `\receive` | U+21BD | Channel receive | `↽ channel` | #### Resource Management | Symbol | ASCII Escape | Unicode | Usage | Example | |--------|-------------|---------|-------|---------| | ⊕ | `\oplus` | U+2295 | Resource acquire | `file ← ⊕open(path)` | | ⊖ | `\ominus` | U+2296 | Resource release | `⊖file` | | 〔〕 | `\lbracket`, `\rbracket` | U+3014/5 | RAII scope | `〔resource ops〕` | #### Type Symbols | Symbol | ASCII Escape | Unicode | Type | Set Definition | |--------|-------------|---------|------|----------------| | ℕ | `\nat`, `\N` | U+2115 | Natural numbers | {0, 1, 2, ...} | | ℤ | `\int`, `\Z` | U+2124 | Integers | {..., -2, -1, 0, 1, 2, ...} | | ℚ | `\rat`, `\Q` | U+211A | Rational numbers | {p/q : p,q ∈ ℤ, q ≠ 0} | | ℝ | `\real`, `\R` | U+211D | Real numbers | Complete ordered field | | ℂ | `\complex`, `\C` | U+2102 | Complex numbers | {a + bi : a,b ∈ ℝ} | | 𝔹 | `\bool`, `\B` | U+1D539 | Booleans | {true, false} | ## Appendix B: Annotated Example Programs ### B.1 Hypothetical Student Journey - Progressive Examples #### Month 1: First Program ```mpl ✎ "Jambo!" ``` **Annotations:** - `✎` (pencil): Output operator - intuitively "write this out" - No semicolon needed for single expressions - String literals use standard double quotes - **Passes Fatima Test**: A child would see a pencil and know it means "write" #### Month 3: Variables and Arithmetic ```mpl -- Calculate rectangle area ℓ ← 5 -- length w ← 3 -- width A ← ℓ × w -- area formula ✎ A -- output: 15 ``` **Annotations:** - `←` (left arrow): Assignment matches math notation - Variables can be single letters or Greek symbols - `×` for multiplication (not `*`) - Comments use `--` (double dash) #### Month 6: Loops and Summation ```mpl -- Sum numbers 1 to 10 Σ ← 0 ∀ n ∈ [1..10]: Σ ← Σ + n ✎ "Sum: " + Σ ``` **Annotations:** - `∀` (for all): Universal quantifier for iteration - `∈` (element of): Natural set membership - `[1..10]`: Range notation - String concatenation with `+` #### Month 6: Conditional Logic ```mpl -- Classify a number x ← -5 x < 0 ⟹ ✎ "Negative" x = 0 ⟹ ✎ "Zero" x > 0 ⟹ ✎ "Positive" ``` **Annotations:** - `⟹` (implies): If-then as logical implication - No explicit "if" keyword needed - Conditions evaluated in order #### Month 6: Recursion (Factorial) ```mpl -- Factorial function fact ≜ λn: n ≤ 1 ⟹ 1 ∣ n × fact(n - 1) ✎ fact(5) -- Output: 120 ``` **Annotations:** - `≜` (define as): Function definition - `λ` (lambda): Function notation - `∣` (pipe): Else separator in conditionals - Recursion mirrors mathematical definition ### B.2 Advanced Examples #### Quadratic Solver ```mpl -- Solve ax² + bx + c = 0 quadratic ≜ λa,b,c: Δ ← b² - 4×a×c Δ < 0 ⟹ ✎ "No real solutions" Δ = 0 ⟹ ✎ "One solution: " + (-b÷(2×a)) Δ > 0 ⟹ r₁ ← (-b + √Δ) ÷ (2×a) r₂ ← (-b - √Δ) ÷ (2×a) ✎ "Two solutions: " + r₁ + ", " + r₂ ``` #### List Processing ```mpl -- Filter and map numbers ← [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -- Get even numbers evens ← {n ∈ numbers | n mod 2 = 0} -- Square them squares ← {n² | n ∈ evens} ✎ squares -- Output: [4, 16, 36, 64, 100] ``` #### Error Handling ```mpl -- Safe division with exceptions safeDivide ≜ λx,y: y = 0 ⟹ ↯"Division by zero!" x ÷ y -- Using with handler result ← safeDivide(10, 0) ↴ { ↯"Division by zero!" ⟹ ✎ "Error caught" ↯e ⟹ ↯e -- Re-raise other errors } ``` #### Concurrent Downloads ```mpl -- Download multiple URLs in parallel urls ← ["http://a.com", "http://b.com", "http://c.com"] -- Launch parallel downloads ∀ url ∈ urls: fetch(url) ⇀ results ‖ -- Collect results ∀ i ∈ [1..|urls|]: data ← ↽results ✎ "Downloaded: " + |data| + " bytes" ``` #### File Processing with RAII ```mpl -- Process file with automatic cleanup processFile ≜ λpath: 〔 file ← ⊕open(path) -- Acquire lines ← readLines(file) ∀ line ∈ lines: words ← split(line, " ") ✎ "Word count: " + |words| -- file automatically released here 〕 ``` ### B.3 Real-World Application Examples #### Data Analysis ```mpl -- Statistical analysis analyze ≜ λdata: n ← |data| μ ← (Σ x ∈ data: x) ÷ n -- mean σ² ← (Σ x ∈ data: (x-μ)²) ÷ n -- variance σ ← √σ² -- std dev ✎ "n=" + n + ", μ=" + μ + ", σ=" + σ ``` #### Simple Web Server ```mpl -- HTTP server server ≜ λport: ∀ req ∈ listen(port): -- Handle request in parallel handleRequest(req) ‖ handleRequest ≜ λreq: req.path = "/" ⟹ respond(200, "