Skip to content

Latest commit

 

History

History
221 lines (149 loc) · 3.25 KB

Specification.org

File metadata and controls

221 lines (149 loc) · 3.25 KB

AML Specification

This document serves as an informal specification of AML (A mathematical language). It provides a high-level overview of all syntactic constructs of AML and its supported operations.

AML is an immutable, NULL-less, and dynamically typed programming language for writing concise mathematical expressions with the help of unicode.

Currently AML offers capabilities for:

  • Loads of arithmetic operations or mathematical functions
  • Set theory
  • Logical expressions

Features

Programs written in AML are evaluated from top to bottom. The last line of a program always returns the result of the whole execution.

Comments

Comments are written using a double dash:

-- I am a comment

Datatypes

AML supports the following datatypes:

-- numbers
1
1.3
100000000.1231

-- booleans
⊥ -- false
⊤ -- true

-- fractions
1/2
123/412

-- sets
{1, 2, 3, 4}
{1, 1/4}

Expressions

The foundational construct in AML is an expression. There are many different types of operations in AML (a complete list will be shown in the next section) which can be used to build expressions. Here are some examples:

-- Intersect two sets
{1, 2, 3} ∩ {3, 4, 5};

-- Add two fractions
1/2 + 4/3;

-- Predicates
(A ∧ B) ⊕ (C ∨ ¬D);
∀(x ∈ X: x ≥ 10);

Assignments

With an assignment the result of an expression is stored in a variable. The return value of an assignment is the value which was assigned.

A ← 1/2 · 1/2;

Functions

A function is an expression that can be executed with different inputs.

allEven: (S) → ∀(x ∈ S: x mod 2 = 0);
halfOfCircleArea: (r) → 1/2 · π · r ^ 2;

-- evaluate a function
allEven({1, 2, 3});

Conditionals

Functions also support conditionals.

f: (x) →
  if x = 5: x ÷ 2
  otherwise: x · 2;

List of operations

Operations for numbers/fractions

-- addition
1 + 2

-- subtraction
3 - 1

-- multiplication
2 · 4

-- division
4 ÷ 2

-- modulo
4 mod 2

-- exponentation
2 ^ 4

-- floor
⌊1.1⌋

-- ceil
⌈1.4⌉

-- factorial
5!

-- negation
-5

Comparisons

-- equal to
x = 2

-- unequal to
x ≠ 2

-- less than
x < 2

-- greater than
x > 2

-- less or equal than
x ≤ 2

-- greater or equal than
x ≥ 2

Logical symbols

-- implication
x = 2 ⇒ x ^ 2 = 4

-- equivalence
x = y ⇔ y = x

-- negation
¬(x = 5)

-- conjunction
x < 4 ∧ x > 2 ∧ x = 3

-- disjunction
n ≥ 4 ∨ n ≤ 2 ⇔ n ≠ 3

-- exclusive disjunction (XOR)
(¬B) ⊕ A

-- universal quantification (in combination with sets)
∀(n ∈ S: n ^ 2 ≥ n)

-- existential quantification (in combination with sets)
∃(n ∈ S: n mod 2 = 0)

-- uniqueness quantification (exactly one element should fulfill the condition) (in combination with sets
∃!(n ∈ S: n + 5 = 2n)

Set operations

-- union
A ∪ B

-- intersection
A ∩ B

-- set difference
U \ A 

-- subset
A ⊂ B

-- not a subset
A ⊄ B

-- subset or equal to
A ⊆ B

-- not a subset or equal to
A ⊈ B

-- superset
A ⊃ B

-- not a superset
A ⊅ B

-- superset or equal to
A ⊇ B

-- not a superset or equal to
A ⊉ B

-- cardinality
|A|