73 lines
2.2 KiB
Lua
73 lines
2.2 KiB
Lua
|
import("util.lua")
|
||
|
|
||
|
function pibody(e)
|
||
|
while (e:is_pi()) do
|
||
|
local _, _, r = e:fields()
|
||
|
e = r
|
||
|
end
|
||
|
return e
|
||
|
end
|
||
|
|
||
|
function funbody(e)
|
||
|
while (e:is_lambda()) do
|
||
|
local _, _, r = e:fields()
|
||
|
e = r
|
||
|
end
|
||
|
return e
|
||
|
end
|
||
|
|
||
|
function hoptst(rule, target, expected)
|
||
|
if expected == nil then
|
||
|
expected = true
|
||
|
end
|
||
|
local th = parse_lean(rule)
|
||
|
local p = pibody(th):arg(2)
|
||
|
local t = funbody(parse_lean(target))
|
||
|
local r = hop_match(p, t)
|
||
|
if (r and not expected) or (not r and expected) then
|
||
|
error("test failed: " .. tostring(rule) .. " === " .. tostring(target))
|
||
|
end
|
||
|
if r then
|
||
|
local s = p:instantiate(r):beta_reduce()
|
||
|
print "Solution:"
|
||
|
for i = 1, #r do
|
||
|
print("#" .. tostring(i) .. " <--- " .. tostring(r[i]))
|
||
|
end
|
||
|
print ""
|
||
|
if s ~= t then
|
||
|
print("Mismatch")
|
||
|
print(s)
|
||
|
print(t)
|
||
|
end
|
||
|
assert(s == t)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
parse_lean_cmds([[
|
||
|
variable f : Nat -> Nat -> Nat
|
||
|
variable g : Nat -> Nat
|
||
|
variable p : Nat -> Bool
|
||
|
]])
|
||
|
|
||
|
hoptst([[forall (A : TypeU) (P Q : A -> Bool), (forall x : A, P x /\ Q x) = ((forall x : A, P x) /\ (forall x : A, Q x))]],
|
||
|
[[forall x : Nat, p (f x 0) /\ f (f x x) 1 >= 0]])
|
||
|
|
||
|
hoptst([[forall (F G : Nat -> Nat), (forall x y : Nat, F x = x /\ G y = y) = (F = G)]],
|
||
|
[[(forall x y : Nat, f x (g x) = x /\ g (g (g y)) = y)]])
|
||
|
|
||
|
hoptst([[forall (F G : Nat -> Nat), (forall x y : Nat, F x = x /\ G y = y) = (F = G)]],
|
||
|
[[fun (a b c : Nat), (forall x y : Nat, f x (f (g b) c) = x /\ (f (g (g (f y c))) a) = y)]])
|
||
|
|
||
|
hoptst([[forall (a b c : Bool), ((a /\ b) /\ c) = (a /\ (b /\ c))]],
|
||
|
[[fun (p1 p2 p3 p4 p5 : Bool), (((p1 ∧ p2) ∧ p3) ∧ (p4 ∧ p2))]])
|
||
|
|
||
|
hoptst([[forall (F G : Nat -> Bool), (forall x : Nat, F x = (F x ∧ G x)) = (F = G)]],
|
||
|
[[forall x : Nat, p (f x x) = (p (f x x) ∧ p (f x 0))]])
|
||
|
|
||
|
hoptst([[forall (F G : Nat -> Bool), (forall x : Nat, F x = (F x ∧ G x)) = (F = G)]],
|
||
|
[[forall x : Nat, p (f x x) = (p (f (g x) x) ∧ p (f x 0))]], false)
|
||
|
|
||
|
hoptst([[forall (F G : Nat -> Nat), (forall x y : Nat, F x = x /\ G y = y) = (F = G)]],
|
||
|
[[fun (a b c : Nat), (forall x y : Nat, f x (f (g y) c) = x /\ (f (g (g (f y c))) a) = y)]], false)
|
||
|
|