Skip to content

Latest commit

 

History

History
197 lines (172 loc) · 15.2 KB

README.org

File metadata and controls

197 lines (172 loc) · 15.2 KB

The AIDDL Core Library

The AIDDL Core Library contains everything needed to use AIDDL in a specific programming language. Here we document the functionality expected from every Core implementation.

Containers, Modules & Entries

AIDDL files (modules) are parsed into containers. Containers are essentially sets of modules with some additional functionality, e.g., to resolve references. An AIDDL module is a collection of entries. Each entry is composed of a type, a name, and a value.

Function Registry

Contains URIs and implementations of default evaluator functions, defined functions, and loaded functions. Used by evaluator and request handler to call functions given their URI.

Evaluator

Tuples whose first element is a function URI may be evaluated. This is often used as part of a condition or type definition. The following is a complete list of all implemented evaluator functions that should be supported by every implementation of the AIDDL Core Library.

Most lower case symbols ($a,b,e,f,m,t,x$) refer to terms that may also be evaluated. The symbol $σ$ is a substitution. A substitution is a non-cyclic mapping from terms to terms. Applying a substitution $σ = \{k_1:v_1, \ldots \}$ to a term $x$ is written as $xσ$ and results in a new term that recursively replaces all appearances of $k_i$ in $x$ by $v_i$. Another important concept is matching. A term $a$ can be matched to a term $b$ iff there exists a substitution $σ$ such that $aσ = b$. Upper case letters represent collections, which can be either collection terms $C$, sets $S$, or lists $L$. In some cases we use set notation on collections (which may be lists) for simplicity. }

Name Arguments Description
org.aiddl.eval
call $f, x$ Call function referred to by $f$ with argument $x$
lambda $a$ Create reference to anonymous function defined by $a$
quote $x$ $x$
type $x$, $t$ Check if $x$ has type $t$
signature $X=(x_1 \ldots) , S=[s_1 \ldots]$ $\mathit{true}$ iff all $x_i$ have type $smin{i,| S| }$
equals $a$, $b$ $a = b$
not-equals $a$, $b$ $a ≠ b$
matches $a$, $b$ $∃_σ : aσ = b$
first $L$ first element of $L$ ($L$ may be a tuple)
last $L$ last element of $L$ ($L$ may be a tuple)
size $C$ $| C| $
get-key $C,k$ $v$ s.t. $k:v ∈ C$ ($C$ may be a tuple)
get-idx $L,n$ $n$th element of $L$ ($L$ may be a tuple)
let $σ,a$ $a σ$
if $c,a,b$ if $c$ then $a$ else $b$
cond $L$ $e_i$ s.t. $min_i : (c_i:e_i) ∈ L ∧ c_i$
map $f,m,C$ $\{ fσ | e ∈ C, mσ=e \}$
filter $f,m,C$ $\{ e | e ∈ C, mσ=e,fσ = true \}$
reduce $f,m,C$
match $f,m,C$
zip $f,m,C$
key $k:v$ $k$
value $k:v$ $v$
.logic
not $x$ true if $x$ is false
and $x_1 \ldots x_n$ true if all $x_i$ are true
or $x_1 \ldots x_n$ true if any $x_i$ is true
forall $m, C, x$ $∀e ∈ C ∃_σ : e_i = m σ ∧ x σ = true$
exists $m, C, x$ $∃e ∈ C ∃_σ : e_i = m σ ∧ x σ = true$
.collection
in $e, C$ $e ∈ C$
contains $C, e$ $e ∈ C$
contains-all $C_1, C_2$ $C_2 \subseteq C_1$
contains-any $C_1, C_2$ $C_1 ∩ C_2 ≠ \varnothing$
contains-match $C, m$ $∃e ∈ C, σ : mσ = e$
add-element $e, C$ $C’ ~ \text{s.t.} ~ e ∈ C’$
add-all $C_1, C_2$ $C’ = C_1 ∪ C_2$
remove $e, C$ $C-\{e\}$
remove-all $C_1, C_2$ $C_2-C_1$
sum $C$ $∑e ∈ C e$
.collection.list
concat $L_1, L_2$ $L’ = L_1 \dot L_2$
% head $L$ first element of $L$
% tail $L$ last element of $L$
% cut-head $L$ $L$ without first element
% cut-tail $L$ $L$ without last element
.collection.set
union $\{S_1, \ldots, S_n \}$ $S’ = \bigcup_i S_i$
.numerical
add $a,b$ $a+b$
sub $a,b$ $a-b$
mult $a,b$ $ab$
div $a,b$ $a/b$
modulo $a,b$ $a \mod b$
greater-than $a,b$ $a > b$
greater-than-eq $a,b$ $a \geq b$
less-than $a,b$ $a < b$
less-than-eq $a,b$ $a \leq b$
.term
term $a$ true
numerical $a$ $a$ is numerical
integer $a$ $a$ is integer
rational $a$ $a$ is rational
real $a$ $a$ is real
infinity $a$ $a$ is infinity
symbolic $a$ $a$ is symbolic
boolean $a$ $a$ is boolean
string $a$ $a$ is string
variable $a$ $a$ is variable
reference $a$ $a$ is reference
fun-ref $a$ $a$ is function reference
collection $a$ $a$ is collection
list $a$ $a$ is list
set $a$ $a$ is set
tuple $a$ $a$ is tuple
key-value $a$ $a$ is key-value pair

Request Handler

The request handler allows to compose function calls with common imperative control structures.

The following list provides a short overview of requests with examples.

Call functionality on input and write result to output:

(call plan (s0 g O) pi)

Execute requests in a sequence:

[R1 R2 R3]

Execute request while condition is true:

(while (< acc 0.95) plan-and-learn)

For each combination of variable-value pairs, create a substitution and call R substituted.

(forall [?x:[a b] ?y:[1 2]] (call f (?x ?y) o))

Loop indefinitely:

(loop [sense plan act])

Match two terms and execute request on the resulting substitution if possible:

(match (?x ?y) ((1 2) (3 4))(call dist (?x ?y) d))

If condition holds execute first request, otherwise execute second (optional) request:

(if (x < 10) R1 R2)

Write evaluated expression to entry:

(if (+ 10 12) n)

Create entry:

(create (#integer n 10))

Print message:

(print Source (x $x))

Measure time between two points:

(stopwatch start A1)
(call Plan $Pi pi)
(stopwatch stop A1)