## Definitions:

set(a) | K(a) contains keys(T(a))
cp(a) | Union all I(e) for all e in C(a)
magic(a) | K(a) + {for k in K(a): k - cp(a)}
jk(a, b) | {for ka in K(a), for kb in K(b): ka + kb}
const(a) | there is no (v, lvl) in V(a) where lvl = 0
ext-V(a) | {for (v, lvl) in V(a) where lvl != 0: (v, lvl - 1)}
ext-C(a) | {for (e, v) in C(a) where min({for (x, lvl) in V(v): lvl}) > depth(v) - depth(a)}

## Rules

Class | Expression | T | V | I | C | K
--- | --- | --- | --- | --- | --- | ---
Variable | a | T(env(a).a) | {(a, level(env(a)))} | env(a).a | {} | {if collection(env(a).a): K(T) else {}}
Get | a.b | T(T(a).b) | V(a) | {if (set(a) && (unique(T(a).b) || reference(~(T(a).b)))): I(a)} | C(a) | {if (set(a) && unique(T(a).b)): K(T), if (K(a) contains {}): {}}
Define | name = expr | T(expr)[1..1] name; | V(expr) | I(expr) | C(expr) | {if (set(expr)): {name} else {}}
Filter | filter(expr, cond) | T(expr) | V(expr) + ext-V(cond) | I(expr) | C(expr) + ext-C(cond) | magic(expr)
AbstractJoin | join(left, right, cond) | T(left) + T(right) | V(left) + V(right) + ext-V(cond) | I(left) + I(right) | {if inner || cross: C(left) + C(right) + ext-C(cond), if left outer: C(left), if right outer: C(right)} | magic(jk(left, right))
And | a and b | Boolean | V(a) + V(b) | N/A | C(a) + C(b) | N/A
Or | a or b | Boolean | V(a) + V(b) | N/A | C(a) * C(b) | N/A
Equals | a == b | Boolean | V(a) + V(b) | N/A | {if const(a): b, if const(b): a} | N/A
Not | not a | Boolean | V(a) | N/A | {} | N/A
Exists | exists(expr) | Boolean | V(expr) | N/A | C(expr) | N/A