Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions aggregate-library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Ephapax Aggregate Library

The complete standard library for Ephapax = Common Library + Ephapax-Specific Library.

## Structure

```
aggregate-library/
├── common/ # Common Library (22 operations)
│ ├── arithmetic/ # add, subtract, multiply, divide, modulo
│ ├── comparison/ # equal, not_equal, less_than, greater_than, less_equal, greater_equal
│ ├── logical/ # and, or, not
│ ├── string/ # concat, length, substring
│ ├── collection/ # map, filter, fold, contains
│ └── conditional/ # if_then_else
└── ephapax/ # Ephapax-Specific Library (17 operations)
├── linear/ # move, drop, copy, borrow
├── region/ # new_region, alloc_in
├── io/ # print, println, read_line
├── conversion/ # i32_to_string, string_to_i32
├── product/ # pair, fst, snd
└── sum/ # inl, inr, case
```

## Common Library

Universal operations shared across all languages in the aggregate-library ecosystem. These 22 operations represent the intersection of functionality across radically different programming paradigms.

Source: https://github.com/hyperpolymath/aggregate-library

## Ephapax-Specific Library

Operations unique to Ephapax's linear type system and region-based memory management:

### Linear Types (4 operations)
- `move` - Transfer ownership of linear values
- `drop` - Explicitly consume linear values
- `copy` - Duplicate unrestricted values
- `borrow` - Create temporary references

### Regions (2 operations)
- `new_region` - Create scoped memory regions
- `alloc_in` - Allocate in specific regions

### I/O (3 operations)
- `print` - Output string without newline
- `println` - Output string with newline
- `read_line` - Read line from stdin

### Conversion (2 operations)
- `i32_to_string` - Integer to string
- `string_to_i32` - Parse string as integer

### Product Types (3 operations)
- `pair` - Construct pairs
- `fst` - Extract first element
- `snd` - Extract second element

### Sum Types (3 operations)
- `inl` - Inject left
- `inr` - Inject right
- `case` - Pattern match on sum

## Total: 39 Operations

Combined, the Ephapax standard library provides 39 fully-specified operations.
51 changes: 51 additions & 0 deletions aggregate-library/common/arithmetic/add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Operation: add

## Interface Signature

```
add: Number, Number -> Number
```

## Behavioral Semantics

**Purpose**: Computes the sum of two numbers.

**Parameters**:
- `a`: The first number (augend)
- `b`: The second number (addend)

**Return Value**: The arithmetic sum of `a` and `b`.

**Properties**:
- Commutative: `add(a, b) = add(b, a)`
- Associative: `add(add(a, b), c) = add(a, add(b, c))`
- Identity element: `add(a, 0) = a`

**Edge Cases**:
- Overflow/underflow behavior is implementation-defined (Standard Library concern)
- NaN and infinity handling is implementation-defined (Standard Library concern)

## Executable Test Cases

```yaml
test_cases:
- input: [2, 3]
output: 5
description: "Basic addition of positive integers"

- input: [-5, 3]
output: -2
description: "Addition with negative number"

- input: [0, 0]
output: 0
description: "Addition of zeros"

- input: [1.5, 2.5]
output: 4.0
description: "Addition of decimal numbers"

- input: [-10, -20]
output: -30
description: "Addition of two negative numbers"
```
61 changes: 61 additions & 0 deletions aggregate-library/common/arithmetic/divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Operation: divide

## Interface Signature

```
divide: Number, Number -> Number
```

## Behavioral Semantics

**Purpose**: Computes the quotient of two numbers.

**Parameters**:
- `a`: The dividend (number to be divided)
- `b`: The divisor (number by which to divide)

**Return Value**: The arithmetic quotient `a ÷ b`.

**Properties**:
- Non-commutative: `divide(a, b) ≠ divide(b, a)` (in general)
- Identity element: `divide(a, 1) = a`
- Inverse of multiplication: `divide(multiply(a, b), b) = a` (when `b ≠ 0`)

**Preconditions**:
- `b ≠ 0` (division by zero behavior is implementation-defined)

**Edge Cases**:
- Division by zero is implementation-defined (Standard Library concern)
- May return error, infinity, or NaN depending on language
- Integer vs floating-point division is implementation-defined
- Overflow/underflow behavior is implementation-defined
- NaN and infinity handling is implementation-defined

## Executable Test Cases

```yaml
test_cases:
- input: [6, 2]
output: 3
description: "Basic division with exact result"

- input: [7, 2]
output: 3.5
description: "Division with fractional result"

- input: [0, 5]
output: 0
description: "Zero divided by non-zero"

- input: [-10, 2]
output: -5
description: "Division with negative dividend"

- input: [10, -2]
output: -5
description: "Division with negative divisor"

- input: [-12, -3]
output: 4
description: "Division of two negative numbers"
```
59 changes: 59 additions & 0 deletions aggregate-library/common/arithmetic/modulo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Operation: modulo

## Interface Signature

```
modulo: Number, Number -> Number
```

## Behavioral Semantics

**Purpose**: Computes the remainder of division of two numbers.

**Parameters**:
- `a`: The dividend (number to be divided)
- `b`: The divisor (number by which to divide)

**Return Value**: The remainder when `a` is divided by `b`.

**Properties**:
- Non-commutative: `modulo(a, b) ≠ modulo(b, a)` (in general)
- `modulo(a, b)` has the same sign as the divisor in most implementations
- For positive integers: `0 ≤ modulo(a, b) < b` when `b > 0`

**Preconditions**:
- `b ≠ 0` (modulo by zero behavior is implementation-defined)

**Edge Cases**:
- Modulo by zero is implementation-defined (Standard Library concern)
- Sign of result with negative operands is implementation-defined
- Some languages use truncated division (result has sign of dividend)
- Others use floored division (result has sign of divisor)
- Behavior with floating-point numbers is implementation-defined

## Executable Test Cases

```yaml
test_cases:
- input: [7, 3]
output: 1
description: "Basic modulo with positive integers"

- input: [10, 5]
output: 0
description: "Modulo with no remainder"

- input: [15, 4]
output: 3
description: "Modulo returning non-zero remainder"

- input: [0, 5]
output: 0
description: "Zero modulo non-zero"

- input: [100, 7]
output: 2
description: "Modulo with larger numbers"
```

**Note**: Test cases with negative numbers are omitted due to implementation-defined behavior across languages.
57 changes: 57 additions & 0 deletions aggregate-library/common/arithmetic/multiply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Operation: multiply

## Interface Signature

```
multiply: Number, Number -> Number
```

## Behavioral Semantics

**Purpose**: Computes the product of two numbers.

**Parameters**:
- `a`: The multiplicand (first factor)
- `b`: The multiplier (second factor)

**Return Value**: The arithmetic product `a × b`.

**Properties**:
- Commutative: `multiply(a, b) = multiply(b, a)`
- Associative: `multiply(multiply(a, b), c) = multiply(a, multiply(b, c))`
- Identity element: `multiply(a, 1) = a`
- Zero property: `multiply(a, 0) = 0`
- Distributive over addition: `multiply(a, add(b, c)) = add(multiply(a, b), multiply(a, c))`

**Edge Cases**:
- Overflow/underflow behavior is implementation-defined (Standard Library concern)
- NaN and infinity handling is implementation-defined (Standard Library concern)

## Executable Test Cases

```yaml
test_cases:
- input: [2, 3]
output: 6
description: "Basic multiplication of positive integers"

- input: [-5, 3]
output: -15
description: "Multiplication with negative number"

- input: [0, 42]
output: 0
description: "Multiplication by zero"

- input: [7, 1]
output: 7
description: "Multiplication by one (identity)"

- input: [2.5, 4]
output: 10.0
description: "Multiplication with decimal number"

- input: [-3, -4]
output: 12
description: "Multiplication of two negative numbers"
```
55 changes: 55 additions & 0 deletions aggregate-library/common/arithmetic/subtract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Operation: subtract

## Interface Signature

```
subtract: Number, Number -> Number
```

## Behavioral Semantics

**Purpose**: Computes the difference between two numbers.

**Parameters**:
- `a`: The minuend (number from which another is subtracted)
- `b`: The subtrahend (number to be subtracted)

**Return Value**: The arithmetic difference `a - b`.

**Properties**:
- Non-commutative: `subtract(a, b) ≠ subtract(b, a)` (in general)
- Identity element: `subtract(a, 0) = a`
- Inverse of addition: `subtract(add(a, b), b) = a`

**Edge Cases**:
- Overflow/underflow behavior is implementation-defined (Standard Library concern)
- NaN and infinity handling is implementation-defined (Standard Library concern)

## Executable Test Cases

```yaml
test_cases:
- input: [5, 3]
output: 2
description: "Basic subtraction of positive integers"

- input: [3, 5]
output: -2
description: "Subtraction resulting in negative number"

- input: [0, 0]
output: 0
description: "Subtraction of zeros"

- input: [-5, 3]
output: -8
description: "Subtracting positive from negative"

- input: [10.5, 2.5]
output: 8.0
description: "Subtraction of decimal numbers"

- input: [-10, -20]
output: 10
description: "Subtracting negative from negative"
```
Loading
Loading