src/HOL/Import/import_rule.ML
changeset 60801 7664e0916eec
parent 60754 02924903a6fd
child 61110 6b7c2ecc6aea
equal deleted inserted replaced
60799:57dd0b45fc21 60801:7664e0916eec
    53 
    53 
    54 fun meta_eq_to_obj_eq th =
    54 fun meta_eq_to_obj_eq th =
    55   let
    55   let
    56     val (tml, tmr) = Thm.dest_binop (strip_imp_concl (Thm.cprop_of th))
    56     val (tml, tmr) = Thm.dest_binop (strip_imp_concl (Thm.cprop_of th))
    57     val cty = Thm.ctyp_of_cterm tml
    57     val cty = Thm.ctyp_of_cterm tml
    58     val i = Drule.instantiate' [SOME cty] [SOME tml, SOME tmr]
    58     val i = Thm.instantiate' [SOME cty] [SOME tml, SOME tmr]
    59       @{thm meta_eq_to_obj_eq}
    59       @{thm meta_eq_to_obj_eq}
    60   in
    60   in
    61     Thm.implies_elim i th
    61     Thm.implies_elim i th
    62   end
    62   end
    63 
    63 
    64 fun beta ct = meta_eq_to_obj_eq (Thm.beta_conversion false ct)
    64 fun beta ct = meta_eq_to_obj_eq (Thm.beta_conversion false ct)
    65 
    65 
    66 fun eq_mp th1 th2 =
    66 fun eq_mp th1 th2 =
    67   let
    67   let
    68     val (tm1l, tm1r) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1)))
    68     val (tm1l, tm1r) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1)))
    69     val i1 = Drule.instantiate' [] [SOME tm1l, SOME tm1r] @{thm iffD1}
    69     val i1 = Thm.instantiate' [] [SOME tm1l, SOME tm1r] @{thm iffD1}
    70     val i2 = meta_mp i1 th1
    70     val i2 = meta_mp i1 th1
    71   in
    71   in
    72     meta_mp i2 th2
    72     meta_mp i2 th2
    73   end
    73   end
    74 
    74 
    77     val t1c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1))
    77     val t1c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1))
    78     val t2c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th2))
    78     val t2c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th2))
    79     val (cf, cg) = Thm.dest_binop t1c
    79     val (cf, cg) = Thm.dest_binop t1c
    80     val (cx, cy) = Thm.dest_binop t2c
    80     val (cx, cy) = Thm.dest_binop t2c
    81     val [fd, fr] = Thm.dest_ctyp (Thm.ctyp_of_cterm cf)
    81     val [fd, fr] = Thm.dest_ctyp (Thm.ctyp_of_cterm cf)
    82     val i1 = Drule.instantiate' [SOME fd, SOME fr]
    82     val i1 = Thm.instantiate' [SOME fd, SOME fr]
    83       [SOME cf, SOME cg, SOME cx, SOME cy] @{thm cong}
    83       [SOME cf, SOME cg, SOME cx, SOME cy] @{thm cong}
    84     val i2 = meta_mp i1 th1
    84     val i2 = meta_mp i1 th1
    85   in
    85   in
    86     meta_mp i2 th2
    86     meta_mp i2 th2
    87   end
    87   end
    91     val t1c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1))
    91     val t1c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1))
    92     val t2c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th2))
    92     val t2c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th2))
    93     val (r, s) = Thm.dest_binop t1c
    93     val (r, s) = Thm.dest_binop t1c
    94     val (_, t) = Thm.dest_binop t2c
    94     val (_, t) = Thm.dest_binop t2c
    95     val ty = Thm.ctyp_of_cterm r
    95     val ty = Thm.ctyp_of_cterm r
    96     val i1 = Drule.instantiate' [SOME ty] [SOME r, SOME s, SOME t] @{thm trans}
    96     val i1 = Thm.instantiate' [SOME ty] [SOME r, SOME s, SOME t] @{thm trans}
    97     val i2 = meta_mp i1 th1
    97     val i2 = meta_mp i1 th1
    98   in
    98   in
    99     meta_mp i2 th2
    99     meta_mp i2 th2
   100   end
   100   end
   101 
   101 
   105     val th2c = strip_imp_concl (Thm.cprop_of th2)
   105     val th2c = strip_imp_concl (Thm.cprop_of th2)
   106     val th1a = implies_elim_all th1
   106     val th1a = implies_elim_all th1
   107     val th2a = implies_elim_all th2
   107     val th2a = implies_elim_all th2
   108     val th1b = Thm.implies_intr th2c th1a
   108     val th1b = Thm.implies_intr th2c th1a
   109     val th2b = Thm.implies_intr th1c th2a
   109     val th2b = Thm.implies_intr th1c th2a
   110     val i = Drule.instantiate' []
   110     val i = Thm.instantiate' []
   111       [SOME (Thm.dest_arg th1c), SOME (Thm.dest_arg th2c)] @{thm iffI}
   111       [SOME (Thm.dest_arg th1c), SOME (Thm.dest_arg th2c)] @{thm iffI}
   112     val i1 = Thm.implies_elim i (Thm.assume (Thm.cprop_of th2b))
   112     val i1 = Thm.implies_elim i (Thm.assume (Thm.cprop_of th2b))
   113     val i2 = Thm.implies_elim i1 th1b
   113     val i2 = Thm.implies_elim i1 th1b
   114     val i3 = Thm.implies_intr (Thm.cprop_of th2b) i2
   114     val i3 = Thm.implies_intr (Thm.cprop_of th2b) i2
   115     val i4 = Thm.implies_elim i3 th2b
   115     val i4 = Thm.implies_elim i3 th2b
   118   end
   118   end
   119 
   119 
   120 fun conj1 th =
   120 fun conj1 th =
   121   let
   121   let
   122     val (tml, tmr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th)))
   122     val (tml, tmr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th)))
   123     val i = Drule.instantiate' [] [SOME tml, SOME tmr] @{thm conjunct1}
   123     val i = Thm.instantiate' [] [SOME tml, SOME tmr] @{thm conjunct1}
   124   in
   124   in
   125     meta_mp i th
   125     meta_mp i th
   126   end
   126   end
   127 
   127 
   128 fun conj2 th =
   128 fun conj2 th =
   129   let
   129   let
   130     val (tml, tmr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th)))
   130     val (tml, tmr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th)))
   131     val i = Drule.instantiate' [] [SOME tml, SOME tmr] @{thm conjunct2}
   131     val i = Thm.instantiate' [] [SOME tml, SOME tmr] @{thm conjunct2}
   132   in
   132   in
   133     meta_mp i th
   133     meta_mp i th
   134   end
   134   end
   135 
   135 
   136 fun refl ctm =
   136 fun refl ctm =
   137   let
   137   let
   138     val cty = Thm.ctyp_of_cterm ctm
   138     val cty = Thm.ctyp_of_cterm ctm
   139   in
   139   in
   140     Drule.instantiate' [SOME cty] [SOME ctm] @{thm refl}
   140     Thm.instantiate' [SOME cty] [SOME ctm] @{thm refl}
   141   end
   141   end
   142 
   142 
   143 fun abs cv th =
   143 fun abs cv th =
   144   let
   144   let
   145     val th1 = implies_elim_all th
   145     val th1 = implies_elim_all th
   149     val bl = beta al
   149     val bl = beta al
   150     val br = meta_eq_to_obj_eq (Thm.symmetric (Thm.beta_conversion false ar))
   150     val br = meta_eq_to_obj_eq (Thm.symmetric (Thm.beta_conversion false ar))
   151     val th2 = trans (trans bl th1) br
   151     val th2 = trans (trans bl th1) br
   152     val th3 = implies_elim_all th2
   152     val th3 = implies_elim_all th2
   153     val th4 = Thm.forall_intr cv th3
   153     val th4 = Thm.forall_intr cv th3
   154     val i = Drule.instantiate' [SOME (Thm.ctyp_of_cterm cv), SOME (Thm.ctyp_of_cterm tl)]
   154     val i = Thm.instantiate' [SOME (Thm.ctyp_of_cterm cv), SOME (Thm.ctyp_of_cterm tl)]
   155       [SOME ll, SOME lr] @{thm ext2}
   155       [SOME ll, SOME lr] @{thm ext2}
   156   in
   156   in
   157     meta_mp i th4
   157     meta_mp i th4
   158   end
   158   end
   159 
   159 
   200     val (th_s, abst) = Thm.dest_comb th_s
   200     val (th_s, abst) = Thm.dest_comb th_s
   201     val rept = Thm.dest_arg th_s
   201     val rept = Thm.dest_arg th_s
   202     val P = Thm.dest_arg cn
   202     val P = Thm.dest_arg cn
   203     val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept)
   203     val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept)
   204   in
   204   in
   205     Drule.instantiate' [SOME nty, SOME oty] [SOME rept, SOME abst, SOME P,
   205     Thm.instantiate' [SOME nty, SOME oty] [SOME rept, SOME abst, SOME P,
   206       SOME (Thm.global_cterm_of thy (Free ("a", Thm.typ_of nty))),
   206       SOME (Thm.global_cterm_of thy (Free ("a", Thm.typ_of nty))),
   207       SOME (Thm.global_cterm_of thy (Free ("r", Thm.typ_of oty)))] @{thm typedef_hol2hollight}
   207       SOME (Thm.global_cterm_of thy (Free ("r", Thm.typ_of oty)))] @{thm typedef_hol2hollight}
   208   end
   208   end
   209 
   209 
   210 fun tydef' tycname abs_name rep_name cP ct td_th thy =
   210 fun tydef' tycname abs_name rep_name cP ct td_th thy =
   211   let
   211   let
   212     val ctT = Thm.ctyp_of_cterm ct
   212     val ctT = Thm.ctyp_of_cterm ct
   213     val nonempty = Drule.instantiate' [SOME ctT] [SOME cP, SOME ct] @{thm light_ex_imp_nonempty}
   213     val nonempty = Thm.instantiate' [SOME ctT] [SOME cP, SOME ct] @{thm light_ex_imp_nonempty}
   214     val th2 = meta_mp nonempty td_th
   214     val th2 = meta_mp nonempty td_th
   215     val c =
   215     val c =
   216       case Thm.concl_of th2 of
   216       case Thm.concl_of th2 of
   217         _ $ (Const(@{const_name Ex},_) $ Abs(_,_,Const(@{const_name Set.member},_) $ _ $ c)) => c
   217         _ $ (Const(@{const_name Ex},_) $ Abs(_,_,Const(@{const_name Set.member},_) $ _ $ c)) => c
   218       | _ => error "type_introduction: bad type definition theorem"
   218       | _ => error "type_introduction: bad type definition theorem"
   226     val (th_s, _) = Thm.dest_comb (Thm.dest_arg (Thm.cprop_of th))
   226     val (th_s, _) = Thm.dest_comb (Thm.dest_arg (Thm.cprop_of th))
   227     val (th_s, abst) = Thm.dest_comb th_s
   227     val (th_s, abst) = Thm.dest_comb th_s
   228     val rept = Thm.dest_arg th_s
   228     val rept = Thm.dest_arg th_s
   229     val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept)
   229     val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept)
   230     val typedef_th =
   230     val typedef_th =
   231        Drule.instantiate'
   231        Thm.instantiate'
   232           [SOME nty, SOME oty]
   232           [SOME nty, SOME oty]
   233           [SOME rept, SOME abst, SOME cP, SOME (Thm.global_cterm_of thy' (Free ("a", aty))),
   233           [SOME rept, SOME abst, SOME cP, SOME (Thm.global_cterm_of thy' (Free ("a", aty))),
   234              SOME (Thm.global_cterm_of thy' (Free ("r", Thm.typ_of ctT)))]
   234              SOME (Thm.global_cterm_of thy' (Free ("r", Thm.typ_of ctT)))]
   235           @{thm typedef_hol2hollight}
   235           @{thm typedef_hol2hollight}
   236     val th4 = typedef_th OF [#type_definition (#2 typedef_info)]
   236     val th4 = typedef_th OF [#type_definition (#2 typedef_info)]