2014-08-25 02:58:48 +00:00
|
|
|
import logic
|
2014-07-05 22:52:40 +00:00
|
|
|
using tactic
|
|
|
|
|
|
|
|
inductive list (A : Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
nil {} : list A,
|
|
|
|
cons : A → list A → list A
|
2014-07-05 22:52:40 +00:00
|
|
|
|
2014-07-22 16:43:18 +00:00
|
|
|
definition is_nil {A : Type} (l : list A) : Prop
|
2014-07-05 22:52:40 +00:00
|
|
|
:= list_rec true (fun h t r, false) l
|
|
|
|
|
|
|
|
theorem is_nil_nil (A : Type) : is_nil (@nil A)
|
2014-08-30 03:45:57 +00:00
|
|
|
:= eq_true_elim (refl true)
|
2014-07-05 22:52:40 +00:00
|
|
|
|
|
|
|
theorem cons_ne_nil {A : Type} (a : A) (l : list A) : ¬ cons a l = nil
|
|
|
|
:= not_intro (assume H : cons a l = nil,
|
|
|
|
absurd
|
|
|
|
(calc true = is_nil (@nil A) : refl _
|
|
|
|
... = is_nil (cons a l) : { symm H }
|
|
|
|
... = false : refl _)
|
|
|
|
true_ne_false)
|
|
|
|
|
2014-07-22 16:43:18 +00:00
|
|
|
theorem T : is_nil (@nil Prop)
|
2014-07-05 22:52:40 +00:00
|
|
|
:= by apply is_nil_nil
|
|
|
|
|
|
|
|
(*
|
2014-07-22 16:43:18 +00:00
|
|
|
local list = Const("list", {1})(Prop)
|
|
|
|
local isNil = Const("is_nil", {1})(Prop)
|
|
|
|
local Nil = Const("nil", {1})(Prop)
|
2014-07-05 22:52:40 +00:00
|
|
|
local m = mk_metavar("m", list)
|
|
|
|
print(isNil(Nil))
|
|
|
|
print(isNil(m))
|
|
|
|
|
|
|
|
|
|
|
|
function test_unify(env, m, lhs, rhs, num_s)
|
|
|
|
print(tostring(lhs) .. " =?= " .. tostring(rhs) .. ", expected: " .. tostring(num_s))
|
|
|
|
local ss = unify(env, lhs, rhs, name_generator(), substitution())
|
|
|
|
local n = 0
|
|
|
|
for s in ss do
|
|
|
|
print("solution: " .. tostring(s:instantiate(m)))
|
|
|
|
n = n + 1
|
|
|
|
end
|
|
|
|
if num_s ~= n then print("n: " .. n) end
|
|
|
|
assert(num_s == n)
|
|
|
|
end
|
|
|
|
print("=====================")
|
|
|
|
test_unify(get_env(), m, isNil(Nil), isNil(m), 2)
|
2014-08-20 22:49:44 +00:00
|
|
|
*)
|