e3dc552c39
The example tests/lua/simp1.lua demonstrates the issue. The higher-order matcher matches closed terms that are definitionally equal. So, given a definition definition a := 1 it will match 'a' with '1' since they are definitionally equal. Then, if we have a theorem theorem a_eq_1 : a = 1 as a rewrite rule, it was triggering the following infinite loop when simplifying the expression "a" a --> 1 --> 1 --> 1 ... The first simplification is expected. The other ones are not. The problem is that "1" is definitionally equal to "a", and they match. The rewrite_rule_set manager accepts the rule a --> 1 since the left-hand-side does not occur in the right-hand-side. To avoid this loop, we test if the new expression is not equal to the previous one. Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
44 lines
1 KiB
Lua
44 lines
1 KiB
Lua
add_rewrite_rules({"Nat", "add_zerol"})
|
|
add_rewrite_rules({"Nat", "add_zeror"})
|
|
parse_lean_cmds([[
|
|
variable f : Nat -> Nat -> Nat
|
|
variable g : Nat -> Nat
|
|
variable b : Nat
|
|
definition a := 1
|
|
theorem a_eq_1 : a = 1
|
|
:= refl a
|
|
definition c := 1
|
|
set_opaque a true
|
|
|
|
axiom f_id (x : Nat) : f x 1 = 2*x
|
|
|
|
axiom g_g_x (x : Nat) : (not (x = 0)) -> g (g x) = 0
|
|
]])
|
|
add_rewrite_rules("a_eq_1")
|
|
add_rewrite_rules("f_id")
|
|
add_rewrite_rules("eq_id")
|
|
|
|
-- set_option({"lean", "pp", "implicit"}, true)
|
|
e, pr = simplify(parse_lean('fun x, f (f x (0 + a)) (g (b + 0))'))
|
|
print(e)
|
|
print(pr)
|
|
local env = get_environment()
|
|
print(env:type_check(pr))
|
|
|
|
e, pr = simplify(parse_lean('forall x, let d := a + 1 in f x a >= d'))
|
|
print(e)
|
|
print(pr)
|
|
local env = get_environment()
|
|
print(env:type_check(pr))
|
|
|
|
e, pr = simplify(parse_lean('(fun x, f (f x (0 + a)) (g (b + 0))) b'))
|
|
print(e)
|
|
print(pr)
|
|
local env = get_environment()
|
|
print(env:type_check(pr))
|
|
|
|
e, pr = simplify(parse_lean('(fun x y, f x y) = f'))
|
|
print(e)
|
|
print(pr)
|
|
local env = get_environment()
|
|
print(env:type_check(pr))
|