-
Notifications
You must be signed in to change notification settings - Fork 7
/
default.lua
89 lines (87 loc) · 1.99 KB
/
default.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local function unequal(literal)
return function(s, v)
if v then
return nil
else
local x = literal[1]
local y = literal[2]
if x:is_const() and y:is_const() then
if x.id == y.id then
return nil
else
return {x.id,y.id}
end
else
return nil
end
end
end
end
datalog.add_iter_prim("unequal", 2, unequal)
local function larger(literal)
return function(s, v)
if v then
return nil
else
local x = literal[1]
local y = literal[2]
if x:is_const() and y:is_const() then
local j = tonumber(x.id)
local k = tonumber(y.id)
if j > k then
return {j, k}
else
return nil
end
elseif x:is_const() then
local k = tonumber(x.id)
return {k, k-1}
elseif y:is_const() then
local j = tonumber(y.id)
return {j+1, j}
else
return nil
end
end
end
end
datalog.add_iter_prim("larger", 2, larger)
local function add(literal)
return function(s, v)
if v then
return nil
else
local x = literal[1]
local y = literal[2]
local z = literal[3]
if y:is_const() and z:is_const() then
local j = tonumber(y.id)
local k = tonumber(z.id)
if j and k then
return {j + k, j, k}
else
return nil
end
elseif x:is_const() and z:is_const() then
local i = tonumber(x.id)
local k = tonumber(z.id)
if i and k then
return {i, i - k, k}
else
return nil
end
elseif x:is_const() and y:is_const() then
local i = tonumber(x.id)
local j = tonumber(y.id)
if i and j then
return {i, j, i - j}
else
return nil
end
else
return nil
end
end
end
end
datalog.add_iter_prim("add", 3, add)