abbreviation Arrow :: "[t,t]==>t" (infixr‹⟶›30) where"A ⟶ B ≡∏_:A. B"
abbreviation Times :: "[t,t]==>t" (infixr‹×›50) where"A × B ≡∑_:A. B"
text‹
Reduction: a weaker notion than equality; a hack for simplification. ‹Reduce[a,b]› means either that ‹a = b : A› for some ‹A› or else
that ‹a› and ‹b› are textually identical.
Does not verify ‹a:A›! Sound because only ‹trans_red› uses a ‹Reduce›
premise. No new theorems can be proved about the standard judgments. › axiomatization where
refl_red: "∧a. Reduce[a,a]"and
red_if_equal: "∧a b A. a = b : A ==> Reduce[a,b]"and
trans_red: "∧a b c A. [a = b : A; Reduce[b,c]]==> a = c : A"and
― ‹Reflexivity›
refl_type: "∧A. A type ==> A = A"and
refl_elem: "∧a A. a : A ==> a = a : A"and
― ‹Symmetry›
sym_type: "∧A B. A = B ==> B = A"and
sym_elem: "∧a b A. a = b : A ==> b = a : A"and
― ‹Transitivity›
trans_type: "∧A B C. [A = B; B = C]==> A = C"and
trans_elem: "∧a b c A. [a = b : A; b = c : A]==> a = c : A"and
equal_types: "∧a A B. [a : A; A = B]==> a : B"and
equal_typesL: "∧a b A B. [a = b : A; A = B]==> a = b : B"and
― ‹Substitution›
subst_type: "∧a A B. [a : A; ∧z. z:A ==> B(z) type]==> B(a) type"and
subst_typeL: "∧a c A B D. [a = c : A; ∧z. z:A ==> B(z) = D(z)]==> B(a) = D(c)"and
subst_elem: "∧a b A B. [a : A; ∧z. z:A ==> b(z):B(z)]==> b(a):B(a)"and
subst_elemL: "∧a b c d A B. [a = c : A; ∧z. z:A ==> b(z)=d(z) : B(z)]==> b(a)=d(c) : B(a)"and
― ‹The type ‹N› -- natural numbers›
NF: "N type"and
NI0: "0 : N"and
NI_succ: "∧a. a : N ==> succ(a) : N"and
NI_succL: "∧a b. a = b : N ==> succ(a) = succ(b) : N"and
NE: "∧p a b C. [p: N; a: C(0); ∧u v. [u: N; v: C(u)]==> b(u,v): C(succ(u))] ==> rec(p, a, λu v. b(u,v)) : C(p)"and
NEL: "∧p q a b c d C. [p = q : N; a = c : C(0); ∧u v. [u: N; v: C(u)]==> b(u,v) = d(u,v): C(succ(u))] ==> rec(p, a, λu v. b(u,v)) = rec(q,c,d) : C(p)"and
NC0: "∧a b C. [a: C(0); ∧u v. [u: N; v: C(u)]==> b(u,v): C(succ(u))] ==> rec(0, a, λu v. b(u,v)) = a : C(0)"and
NC_succ: "∧p a b C. [p: N; a: C(0); ∧u v. [u: N; v: C(u)]==> b(u,v): C(succ(u))]==> rec(succ(p), a, λu v. b(u,v)) = b(p, rec(p, a, λu v. b(u,v))) : C(succ(p))"and
ProdFL: "∧A B C D. [A = C; ∧x. x:A ==> B(x) = D(x)]==>∏x:A. B(x) = ∏x:C. D(x)"and
ProdI: "∧b A B. [A type; ∧x. x:A ==> b(x):B(x)]==>\<lambda>x. b(x) : ∏x:A. B(x)"and
ProdIL: "∧b c A B. [A type; ∧x. x:A ==> b(x) = c(x) : B(x)]==> \<lambda>x. b(x) = \<lambda>x. c(x) : ∏x:A. B(x)"and
ProdE: "∧p a A B. [p : ∏x:A. B(x); a : A]==> p`a : B(a)"and
ProdEL: "∧p q a b A B. [p = q: ∏x:A. B(x); a = b : A]==> p`a = q`b : B(a)"and
ProdC: "∧a b A B. [a : A; ∧x. x:A ==> b(x) : B(x)]==> (\<lambda>x. b(x)) ` a = b(a) : B(a)"and
ProdC2: "∧p A B. p : ∏x:A. B(x) ==> (\<lambda>x. p`x) = p : ∏x:A. B(x)"and
― ‹The Sum of a family of types›
SumF: "∧A B. [A type; ∧x. x:A ==> B(x) type]==>∑x:A. B(x) type"and
SumFL: "∧A B C D. [A = C; ∧x. x:A ==> B(x) = D(x)]==>∑x:A. B(x) = ∑x:C. D(x)"and
SumI: "∧a b A B. [a : A; b : B(a)]==> <a,b> : ∑x:A. B(x)"and
SumIL: "∧a b c d A B. [ a = c : A; b = d : B(a)]==> <a,b> = <c,d> : ∑x:A. B(x)"and
SumE: "∧p c A B C. [p: ∑x:A. B(x); ∧x y. [x:A; y:B(x)]==> c(x,y): C(<x,y>)] ==> split(p, λx y. c(x,y)) : C(p)"and
SumEL: "∧p q c d A B C. [p = q : ∑x:A. B(x); ∧x y. [x:A; y:B(x)]==> c(x,y)=d(x,y): C(<x,y>)] ==> split(p, λx y. c(x,y)) = split(q, λx y. d(x,y)) : C(p)"and
SumC: "∧a b c A B C. [a: A; b: B(a); ∧x y. [x:A; y:B(x)]==> c(x,y): C(<x,y>)] ==> split(<a,b>, λx y. c(x,y)) = c(a,b) : C(<a,b>)"and
fst_def: "∧a. fst(a) ≡ split(a, λx y. x)"and
snd_def: "∧a. snd(a) ≡ split(a, λx y. y)"and
― ‹The sum of two types›
PlusF: "∧A B. [A type; B type]==> A+B type"and
PlusFL: "∧A B C D. [A = C; B = D]==> A+B = C+D"and
PlusI_inl: "∧a A B. [a : A; B type]==> inl(a) : A+B"and
PlusI_inlL: "∧a c A B. [a = c : A; B type]==> inl(a) = inl(c) : A+B"and
PlusI_inr: "∧b A B. [A type; b : B]==> inr(b) : A+B"and
PlusI_inrL: "∧b d A B. [A type; b = d : B]==> inr(b) = inr(d) : A+B"and
PlusE: "∧p c d A B C. [p: A+B; ∧x. x:A ==> c(x): C(inl(x)); ∧y. y:B ==> d(y): C(inr(y)) ]==> when(p, λx. c(x), λy. d(y)) : C(p)"and
PlusEL: "∧p q c d e f A B C. [p = q : A+B; ∧x. x: A ==> c(x) = e(x) : C(inl(x)); ∧y. y: B ==> d(y) = f(y) : C(inr(y))] ==> when(p, λx. c(x), λy. d(y)) = when(q, λx. e(x), λy. f(y)) : C(p)"and
PlusC_inl: "∧a c d A B C. [a: A; ∧x. x:A ==> c(x): C(inl(x)); ∧y. y:B ==> d(y): C(inr(y)) ] ==> when(inl(a), λx. c(x), λy. d(y)) = c(a) : C(inl(a))"and
PlusC_inr: "∧b c d A B C. [b: B; ∧x. x:A ==> c(x): C(inl(x)); ∧y. y:B ==> d(y): C(inr(y))] ==> when(inr(b), λx. c(x), λy. d(y)) = d(b) : C(inr(b))"and
― ‹The type ‹Eq››
EqF: "∧a b A. [A type; a : A; b : A]==> Eq(A,a,b) type"and
EqFL: "∧a b c d A B. [A = B; a = c : A; b = d : A]==> Eq(A,a,b) = Eq(B,c,d)"and
EqI: "∧a b A. a = b : A ==> eq : Eq(A,a,b)"and
EqE: "∧p a b A. p : Eq(A,a,b) ==> a = b : A"and
― ‹By equality of types, can prove ‹C(p)› from ‹C(eq)›, an elimination rule›
EqC: "∧p a b A. p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)"and
― ‹The type ‹F››
FF: "F type"and
FE: "∧p C. [p: F; C type]==> contr(p) : C"and
FEL: "∧p q C. [p = q : F; C type]==> contr(p) = contr(q) : C"and
― ‹The type T›
― ‹Martin-Löf's book (page 68) discusses elimination and computation.
Elimination can be derived by computation and equality of types,
but with an extra premise ‹C(x)› type ‹x:T›.
Also computation can be derived from elimination.›
TF: "T type"and
TI: "tt : T"and
TE: "∧p c C. [p : T; c : C(tt)]==> c : C(p)"and
TEL: "∧p q c d C. [p = q : T; c = d : C(tt)]==> c = d : C(p)"and
TC: "∧p. p : T ==> p = tt : T"
subsection"Tactics and derived rules for Constructive Type Theory"
text‹
Introduction rules. OMITTED:
▪ ‹EqI›, because its premise is an ‹eqelem›, not an ‹elem›. › lemmas intr_rls = NI0 NI_succ ProdI SumI PlusI_inl PlusI_inr TI and intrL_rls = NI_succL ProdIL SumIL PlusI_inlL PlusI_inrL
text‹
Elimination rules. OMITTED:
▪ ‹EqE›, because its conclusion is an ‹eqelem›, not an ‹elem›
▪ ‹TE›, because it does not involve a constructor. › lemmas elim_rls = NE ProdE SumE PlusE FE and elimL_rls = NEL ProdEL SumEL PlusEL FEL
text‹OMITTED: ‹eqC› are ‹TC› because they make rewriting loop: ‹p = un = un = …›› lemmas comp_rls = NC0 NC_succ ProdC SumC PlusC_inl PlusC_inr
text‹Rules with conclusion ‹a:A›, an elem judgment.› lemmas element_rls = intr_rls elim_rls
text‹Definitions are (meta)equality axioms.› lemmas basic_defs = fst_def snd_def
text‹Compare with standard version: ‹B› is applied to UNSIMPLIFIED expression!› lemma SumIL2: "[c = a : A; d = b : B(a)]==> <c,d> = <a,b> : Sum(A,B)" by (rule sym_elem) (rule SumIL; rule sym_elem)
text‹
Exploit ‹p:Prod(A,B)› to create the assumption ‹z:B(a)›.
A more natural form of product elimination. › lemma subst_prodE: assumes"p: Prod(A,B)" and"a: A" and"∧z. z: B(a) ==> c(z): C(z)" shows"c(p`a): C(p`a)" by (rule assms ProdE)+
subsection‹Tactics for type checking›
ML ‹
is_rigid_elem 🍋‹Elem for a _› = not(is_Var (head_of a))
| is_rigid_elem 🍋‹Eqelem for a _ _› = not(is_Var (head_of a))
| is_rigid_elem 🍋‹Type for a› = not(is_Var (head_of a))
| is_rigid_elem _ = false
(*Try solving a:A or a=b:A by assumption provided a is rigid!*) fun test_assume_tac ctxt = SUBGOAL (fn (prem, i) => if is_rigid_elem (Logic.strip_assums_concl prem) then assume_tac ctxt i else no_tac)
funASSUME ctxt tf i = test_assume_tac ctxt i ORELSE tf i
(*Solve all subgoals "A type" using formation rules. *)
val form_net = Bires.build_net @{thms form_rls}; fun form_tac ctxt =
REPEAT_FIRST (ASSUME ctxt (Bires.filt_resolve_from_net_tac ctxt 1 form_net));
(*Type checking: solve a:A (a rigid, A flexible) by intro and elim rules. *) fun typechk_tac ctxt thms = let val tac =
Bires.filt_resolve_from_net_tac ctxt 3
(Bires.build_net (thms @ @{thms form_rls} @ @{thms element_rls})) in REPEAT_FIRST (ASSUME ctxt tac) end
(*Solve a:A (a flexible, A rigid) by introduction rules. Cannotusestringtrees(filt_resolve_tac)since
goals like ?a:SUM(A,B) have a trivial head-string *) fun intr_tac ctxt thms = let val tac =
Bires.filt_resolve_from_net_tac ctxt 1
(Bires.build_net (thms @ @{thms form_rls} @ @{thms intr_rls})) in REPEAT_FIRST (ASSUME ctxt tac) end
(*Equality proving: solve a=b:A (where a is rigid) by long rules. *) fun equal_tac ctxt thms =
REPEAT_FIRST
(ASSUME ctxt
(Bires.filt_resolve_from_net_tac ctxt 3
(Bires.build_net (thms @ @{thms form_rls element_rls intrL_rls elimL_rls refl_elem})))) ›
ML\<open> (*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification.
Uses other intro rules to avoid changing flexible goals.*)
val eqintr_net = Bires.build_net @{thms EqI intr_rls} fun eqintr_tac ctxt =
REPEAT_FIRST (ASSUME ctxt (Bires.filt_resolve_from_net_tac ctxt 1 eqintr_net))
(** Tactics that instantiate CTT-rules. Varsinthegiventermswillbeincremented!
The (rtac EqE i) lets them apply to equality judgments. **)
fun NE_tac ctxt sp i =
TRY (resolve_tac ctxt @{thms EqE} i) THEN
Rule_Insts.res_inst_tac ctxt [((("p", 0), Position.none), sp)] [] @{thm NE} i
fun SumE_tac ctxt sp i =
TRY (resolve_tac ctxt @{thms EqE} i) THEN
Rule_Insts.res_inst_tac ctxt [((("p", 0), Position.none), sp)] [] @{thm SumE} i
fun PlusE_tac ctxt sp i =
TRY (resolve_tac ctxt @{thms EqE} i) THEN
Rule_Insts.res_inst_tac ctxt [((("p", 0), Position.none), sp)] [] @{thm PlusE} i
(** Predicate logic reasoning, WITH THINNING!! Procedures adapted from NJ. **)
(*Finds f:Prod(A,B) and a:A in the assumptions, concludes there is z:B(a) *) fun add_mp_tac ctxt i =
resolve_tac ctxt @{thms subst_prodE} i THEN assume_tac ctxt i THEN assume_tac ctxt i
(*Finds P\<longrightarrow>Q and P in the assumptions, replaces implication by Q *) fun mp_tac ctxt i = eresolve_tac ctxt @{thms subst_prodE} i THEN assume_tac ctxt i
(*"safe" when regarded as predicate calculus rules*)
val safe_brls = sort Bires.subgoals_ord
[ (true, @{thm FE}), (true,asm_rl),
(false, @{thm ProdI}), (true, @{thm SumE}), (true, @{thm PlusE}) ]
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.