src/CTT/CTT.thy
changeset 60770 240563fbf41d
parent 60754 02924903a6fd
child 61378 3e04c9ca001a
equal deleted inserted replaced
60769:cf7f3465eaf1 60770:240563fbf41d
     1 (*  Title:      CTT/CTT.thy
     1 (*  Title:      CTT/CTT.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   1993  University of Cambridge
     3     Copyright   1993  University of Cambridge
     4 *)
     4 *)
     5 
     5 
     6 section {* Constructive Type Theory *}
     6 section \<open>Constructive Type Theory\<close>
     7 
     7 
     8 theory CTT
     8 theory CTT
     9 imports Pure
     9 imports Pure
    10 begin
    10 begin
    11 
    11 
   312   shows "c(p`a): C(p`a)"
   312   shows "c(p`a): C(p`a)"
   313 apply (rule assms ProdE)+
   313 apply (rule assms ProdE)+
   314 done
   314 done
   315 
   315 
   316 
   316 
   317 subsection {* Tactics for type checking *}
   317 subsection \<open>Tactics for type checking\<close>
   318 
   318 
   319 ML {*
   319 ML \<open>
   320 
   320 
   321 local
   321 local
   322 
   322 
   323 fun is_rigid_elem (Const(@{const_name Elem},_) $ a $ _) = not(is_Var (head_of a))
   323 fun is_rigid_elem (Const(@{const_name Elem},_) $ a $ _) = not(is_Var (head_of a))
   324   | is_rigid_elem (Const(@{const_name Eqelem},_) $ a $ _ $ _) = not(is_Var (head_of a))
   324   | is_rigid_elem (Const(@{const_name Eqelem},_) $ a $ _ $ _) = not(is_Var (head_of a))
   334 
   334 
   335 fun ASSUME ctxt tf i = test_assume_tac ctxt i  ORELSE  tf i
   335 fun ASSUME ctxt tf i = test_assume_tac ctxt i  ORELSE  tf i
   336 
   336 
   337 end;
   337 end;
   338 
   338 
   339 *}
   339 \<close>
   340 
   340 
   341 (*For simplification: type formation and checking,
   341 (*For simplification: type formation and checking,
   342   but no equalities between terms*)
   342   but no equalities between terms*)
   343 lemmas routine_rls = form_rls formL_rls refl_type element_rls
   343 lemmas routine_rls = form_rls formL_rls refl_type element_rls
   344 
   344 
   345 ML {*
   345 ML \<open>
   346 local
   346 local
   347   val equal_rls = @{thms form_rls} @ @{thms element_rls} @ @{thms intrL_rls} @
   347   val equal_rls = @{thms form_rls} @ @{thms element_rls} @ @{thms intrL_rls} @
   348     @{thms elimL_rls} @ @{thms refl_elem}
   348     @{thms elimL_rls} @ @{thms refl_elem}
   349 in
   349 in
   350 
   350 
   376 fun equal_tac ctxt thms =
   376 fun equal_tac ctxt thms =
   377   REPEAT_FIRST
   377   REPEAT_FIRST
   378     (ASSUME ctxt (filt_resolve_from_net_tac ctxt 3 (Tactic.build_net (thms @ equal_rls))))
   378     (ASSUME ctxt (filt_resolve_from_net_tac ctxt 3 (Tactic.build_net (thms @ equal_rls))))
   379 
   379 
   380 end
   380 end
   381 *}
   381 \<close>
   382 
   382 
   383 method_setup form = {* Scan.succeed (fn ctxt => SIMPLE_METHOD (form_tac ctxt)) *}
   383 method_setup form = \<open>Scan.succeed (fn ctxt => SIMPLE_METHOD (form_tac ctxt))\<close>
   384 method_setup typechk = {* Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (typechk_tac ctxt ths)) *}
   384 method_setup typechk = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (typechk_tac ctxt ths))\<close>
   385 method_setup intr = {* Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (intr_tac ctxt ths)) *}
   385 method_setup intr = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (intr_tac ctxt ths))\<close>
   386 method_setup equal = {* Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (equal_tac ctxt ths)) *}
   386 method_setup equal = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (equal_tac ctxt ths))\<close>
   387 
   387 
   388 
   388 
   389 subsection {* Simplification *}
   389 subsection \<open>Simplification\<close>
   390 
   390 
   391 (*To simplify the type in a goal*)
   391 (*To simplify the type in a goal*)
   392 lemma replace_type: "\<lbrakk>B = A; a : A\<rbrakk> \<Longrightarrow> a : B"
   392 lemma replace_type: "\<lbrakk>B = A; a : A\<rbrakk> \<Longrightarrow> a : B"
   393 apply (rule equal_types)
   393 apply (rule equal_types)
   394 apply (rule_tac [2] sym_type)
   394 apply (rule_tac [2] sym_type)
   407 done
   407 done
   408 
   408 
   409 (*Simplification rules for Constructive Type Theory*)
   409 (*Simplification rules for Constructive Type Theory*)
   410 lemmas reduction_rls = comp_rls [THEN trans_elem]
   410 lemmas reduction_rls = comp_rls [THEN trans_elem]
   411 
   411 
   412 ML {*
   412 ML \<open>
   413 (*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification.
   413 (*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification.
   414   Uses other intro rules to avoid changing flexible goals.*)
   414   Uses other intro rules to avoid changing flexible goals.*)
   415 val eqintr_net = Tactic.build_net @{thms EqI intr_rls}
   415 val eqintr_net = Tactic.build_net @{thms EqI intr_rls}
   416 fun eqintr_tac ctxt =
   416 fun eqintr_tac ctxt =
   417   REPEAT_FIRST (ASSUME ctxt (filt_resolve_from_net_tac ctxt 1 eqintr_net))
   417   REPEAT_FIRST (ASSUME ctxt (filt_resolve_from_net_tac ctxt 1 eqintr_net))
   464 
   464 
   465 fun step_tac ctxt thms = safestep_tac ctxt thms  ORELSE'  biresolve_tac ctxt unsafe_brls
   465 fun step_tac ctxt thms = safestep_tac ctxt thms  ORELSE'  biresolve_tac ctxt unsafe_brls
   466 
   466 
   467 (*Fails unless it solves the goal!*)
   467 (*Fails unless it solves the goal!*)
   468 fun pc_tac ctxt thms = DEPTH_SOLVE_1 o (step_tac ctxt thms)
   468 fun pc_tac ctxt thms = DEPTH_SOLVE_1 o (step_tac ctxt thms)
   469 *}
   469 \<close>
   470 
   470 
   471 method_setup eqintr = {* Scan.succeed (SIMPLE_METHOD o eqintr_tac) *}
   471 method_setup eqintr = \<open>Scan.succeed (SIMPLE_METHOD o eqintr_tac)\<close>
   472 method_setup NE = {*
   472 method_setup NE = \<open>
   473   Scan.lift Args.name_inner_syntax >> (fn s => fn ctxt => SIMPLE_METHOD' (NE_tac ctxt s))
   473   Scan.lift Args.name_inner_syntax >> (fn s => fn ctxt => SIMPLE_METHOD' (NE_tac ctxt s))
   474 *}
   474 \<close>
   475 method_setup pc = {* Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (pc_tac ctxt ths)) *}
   475 method_setup pc = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (pc_tac ctxt ths))\<close>
   476 method_setup add_mp = {* Scan.succeed (SIMPLE_METHOD' o add_mp_tac) *}
   476 method_setup add_mp = \<open>Scan.succeed (SIMPLE_METHOD' o add_mp_tac)\<close>
   477 
   477 
   478 ML_file "rew.ML"
   478 ML_file "rew.ML"
   479 method_setup rew = {* Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (rew_tac ctxt ths)) *}
   479 method_setup rew = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (rew_tac ctxt ths))\<close>
   480 method_setup hyp_rew = {* Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (hyp_rew_tac ctxt ths)) *}
   480 method_setup hyp_rew = \<open>Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (hyp_rew_tac ctxt ths))\<close>
   481 
   481 
   482 
   482 
   483 subsection {* The elimination rules for fst/snd *}
   483 subsection \<open>The elimination rules for fst/snd\<close>
   484 
   484 
   485 lemma SumE_fst: "p : Sum(A,B) \<Longrightarrow> fst(p) : A"
   485 lemma SumE_fst: "p : Sum(A,B) \<Longrightarrow> fst(p) : A"
   486 apply (unfold basic_defs)
   486 apply (unfold basic_defs)
   487 apply (erule SumE)
   487 apply (erule SumE)
   488 apply assumption
   488 apply assumption