lean2/tests/lua/env6.lua
Leonardo de Moura 20947de2f1 test(lua): add replace method test
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2014-05-12 15:51:22 -07:00

21 lines
929 B
Lua

local env = empty_environment()
env = add_decl(env, mk_var_decl("A", Bool))
local A = Const("A")
local x = Const("x")
env = add_decl(env, mk_axiom("magic", Pi(x, Bool, x)))
local saved_env = env
env = add_decl(env, mk_axiom("Ax", A))
env = add_decl(env, mk_definition("T1", A, Const("Ax")))
-- The check mk_theorem("Ax", A, Const("T1")) failes because env
-- contains the axiom named Ax.
-- So, we cannot transform Ax into a theorem that depends on itself.
-- (This is good)
assert(not pcall(function() env:replace(check(env, mk_theorem("Ax", A, Const("T1")))) end))
assert(env:find("Ax"):is_axiom())
local magic = Const("magic")
-- Replace axiom Ax with the theorem Ax that is checked in the old
-- environment saved_env. Everything works because env is a descendant
-- of saved_env
env = env:replace(check(saved_env, mk_theorem("Ax", A, magic(A))))
assert(not env:find("Ax"):is_axiom())
assert(env:find("Ax"):is_theorem())