|
| 1 | +# PolyglotFormalisms.Elixir |
| 2 | + |
| 3 | +Elixir implementation of the PolyglotFormalisms Common Library specification. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This package provides Elixir implementations of fundamental operations defined in the PolyglotFormalisms specification, enabling semantic equivalence verification across multiple programming languages. |
| 8 | + |
| 9 | +## Modules |
| 10 | + |
| 11 | +### Arithmetic |
| 12 | +- `add(a, b)` - Addition |
| 13 | +- `subtract(a, b)` - Subtraction |
| 14 | +- `multiply(a, b)` - Multiplication |
| 15 | +- `divide(a, b)` - Division |
| 16 | +- `modulo(a, b)` - Modulo (integer operation) |
| 17 | + |
| 18 | +### Comparison |
| 19 | +- `less_than(a, b)` - Strict less than |
| 20 | +- `greater_than(a, b)` - Strict greater than |
| 21 | +- `equal(a, b)` - Equality |
| 22 | +- `not_equal(a, b)` - Inequality |
| 23 | +- `less_equal(a, b)` - Less than or equal |
| 24 | +- `greater_equal(a, b)` - Greater than or equal |
| 25 | + |
| 26 | +### Logical |
| 27 | +- `logical_and(a, b)` - Logical conjunction |
| 28 | +- `logical_or(a, b)` - Logical disjunction |
| 29 | +- `logical_not(a)` - Logical negation |
| 30 | + |
| 31 | +**Note:** Function names include `logical_` prefix to avoid conflicts with Elixir's Kernel reserved keywords. |
| 32 | + |
| 33 | +## Installation |
| 34 | + |
| 35 | +Add this package to your `mix.exs` dependencies: |
| 36 | + |
| 37 | +```elixir |
| 38 | +def deps do |
| 39 | + [ |
| 40 | + {:polyglot_formalisms, "~> 0.2.0"} |
| 41 | + ] |
| 42 | +end |
| 43 | +``` |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +```elixir |
| 48 | +alias PolyglotFormalisms.{Arithmetic, Comparison, Logical} |
| 49 | + |
| 50 | +# Arithmetic |
| 51 | +sum = Arithmetic.add(2.0, 3.0) |
| 52 | +product = Arithmetic.multiply(4.0, 5.0) |
| 53 | + |
| 54 | +# Comparison |
| 55 | +is_less = Comparison.less_than(2.0, 3.0) |
| 56 | +is_equal = Comparison.equal(5.0, 5.0) |
| 57 | + |
| 58 | +# Logical |
| 59 | +both_true = Logical.logical_and(true, true) |
| 60 | +either_true = Logical.logical_or(false, true) |
| 61 | +negated = Logical.logical_not(false) |
| 62 | +``` |
| 63 | + |
| 64 | +## Mathematical Properties |
| 65 | + |
| 66 | +All implementations preserve the mathematical properties defined in the PolyglotFormalisms specification: |
| 67 | + |
| 68 | +### Arithmetic Properties |
| 69 | +- Commutativity (for add, multiply) |
| 70 | +- Associativity (for add, multiply) |
| 71 | +- Identity elements |
| 72 | +- Distributivity |
| 73 | + |
| 74 | +### Comparison Properties |
| 75 | +- Transitivity |
| 76 | +- Reflexivity |
| 77 | +- Symmetry |
| 78 | +- Asymmetry |
| 79 | + |
| 80 | +### Logical Properties |
| 81 | +- Commutativity |
| 82 | +- Associativity |
| 83 | +- Distributivity |
| 84 | +- De Morgan's laws |
| 85 | +- Excluded middle |
| 86 | +- Non-contradiction |
| 87 | + |
| 88 | +## Behavioral Semantics |
| 89 | + |
| 90 | +This implementation follows BEAM/Erlang semantics: |
| 91 | + |
| 92 | +### Float Operations |
| 93 | +- Division by zero returns `Infinity` or `-Infinity` |
| 94 | +- NaN propagation follows IEEE 754 |
| 95 | +- Comparison with NaN returns `false` |
| 96 | + |
| 97 | +### Integer Operations |
| 98 | +- Modulo uses Erlang `rem` operator semantics |
| 99 | +- Modulo by zero raises `ArithmeticError` (BEAM behavior) |
| 100 | + |
| 101 | +### Boolean Operations |
| 102 | +- Short-circuit evaluation for `and` and `or` |
| 103 | +- Eager evaluation for wrapper functions |
| 104 | + |
| 105 | +## Testing |
| 106 | + |
| 107 | +Run the test suite: |
| 108 | + |
| 109 | +```bash |
| 110 | +mix test |
| 111 | +``` |
| 112 | + |
| 113 | +Run tests with documentation tests: |
| 114 | + |
| 115 | +```bash |
| 116 | +mix test --include doctest |
| 117 | +``` |
| 118 | + |
| 119 | +## Cross-Language Verification |
| 120 | + |
| 121 | +This Elixir implementation is semantically equivalent to: |
| 122 | +- Julia implementation (PolyglotFormalisms.jl) |
| 123 | +- ReScript implementation (alib-for-rescript) |
| 124 | +- Gleam implementation (polyglot_formalisms_gleam) |
| 125 | + |
| 126 | +Formal verification proofs demonstrating semantic equivalence are available in the main PolyglotFormalisms specification repository. |
| 127 | + |
| 128 | +## Documentation |
| 129 | + |
| 130 | +Generate documentation: |
| 131 | + |
| 132 | +```bash |
| 133 | +mix docs |
| 134 | +``` |
| 135 | + |
| 136 | +## License |
| 137 | + |
| 138 | +PMPL-1.0-or-later (Polymathematical Meta-Public License / Palimpsest License) |
| 139 | + |
| 140 | +## Related Projects |
| 141 | + |
| 142 | +- [PolyglotFormalisms.jl](https://github.com/hyperpolymath/PolyglotFormalisms.jl) - Julia reference implementation |
| 143 | +- [alib-for-rescript](https://github.com/hyperpolymath/alib-for-rescript) - ReScript implementation |
| 144 | +- [polyglot_formalisms_gleam](https://github.com/hyperpolymath/polyglot_formalisms_gleam) - Gleam implementation |
| 145 | + |
| 146 | + |
| 147 | +## Architecture |
| 148 | + |
| 149 | +See [TOPOLOGY.md](TOPOLOGY.md) for a visual architecture map and completion dashboard. |
0 commit comments