src/Pure/Proof/proof_rewrite_rules.ML
changeset 15531 08c8dad8e399
parent 14981 e73f8140af78
child 15570 8d8c70b41bab
equal deleted inserted replaced
15530:6f43714517ee 15531:08c8dad8e399
    20 
    20 
    21 open Proofterm;
    21 open Proofterm;
    22 
    22 
    23 fun rew b =
    23 fun rew b =
    24   let
    24   let
    25     fun ? x = if b then Some x else None;
    25     fun ? x = if b then SOME x else NONE;
    26     fun ax (prf as PAxm (s, prop, _)) Ts =
    26     fun ax (prf as PAxm (s, prop, _)) Ts =
    27       if b then PAxm (s, prop, Some Ts) else prf;
    27       if b then PAxm (s, prop, SOME Ts) else prf;
    28     fun ty T = if b then
    28     fun ty T = if b then
    29         let val Type (_, [Type (_, [U, _]), _]) = T
    29         let val Type (_, [Type (_, [U, _]), _]) = T
    30         in Some U end
    30         in SOME U end
    31       else None;
    31       else NONE;
    32     val equal_intr_axm = ax equal_intr_axm [];
    32     val equal_intr_axm = ax equal_intr_axm [];
    33     val equal_elim_axm = ax equal_elim_axm [];
    33     val equal_elim_axm = ax equal_elim_axm [];
    34     val symmetric_axm = ax symmetric_axm [propT];
    34     val symmetric_axm = ax symmetric_axm [propT];
    35 
    35 
    36     fun rew' _ (PThm (("ProtoPure.rev_triv_goal", _), _, _, _) % _ %%
    36     fun rew' _ (PThm (("ProtoPure.rev_triv_goal", _), _, _, _) % _ %%
    37         (PThm (("ProtoPure.triv_goal", _), _, _, _) % _ %% prf)) = Some prf
    37         (PThm (("ProtoPure.triv_goal", _), _, _, _) % _ %% prf)) = SOME prf
    38       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
    38       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
    39         (PAxm ("ProtoPure.equal_intr", _, _) % _ % _ %% prf %% _)) = Some prf
    39         (PAxm ("ProtoPure.equal_intr", _, _) % _ % _ %% prf %% _)) = SOME prf
    40       | rew' _ (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    40       | rew' _ (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    41         (PAxm ("ProtoPure.equal_intr", _, _) % A % B %% prf1 %% prf2)) =
    41         (PAxm ("ProtoPure.equal_intr", _, _) % A % B %% prf1 %% prf2)) =
    42             Some (equal_intr_axm % B % A %% prf2 %% prf1)
    42             SOME (equal_intr_axm % B % A %% prf2 %% prf1)
    43 
    43 
    44       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A) % Some (_ $ B) %%
    44       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME (_ $ A) % SOME (_ $ B) %%
    45         (PAxm ("ProtoPure.combination", _, _) % Some (Const ("Goal", _)) %
    45         (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("Goal", _)) %
    46           _ % _ % _ %% (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %%
    46           _ % _ % _ %% (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %%
    47         ((tg as PThm (("ProtoPure.triv_goal", _), _, _, _)) % _ %% prf2)) =
    47         ((tg as PThm (("ProtoPure.triv_goal", _), _, _, _)) % _ %% prf2)) =
    48         Some (tg %> B %% (equal_elim_axm %> A %> B %% prf1 %% prf2))
    48         SOME (tg %> B %% (equal_elim_axm %> A %> B %% prf1 %% prf2))
    49 
    49 
    50       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A) % Some (_ $ B) %%
    50       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME (_ $ A) % SOME (_ $ B) %%
    51         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    51         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    52           (PAxm ("ProtoPure.combination", _, _) % Some (Const ("Goal", _)) %
    52           (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("Goal", _)) %
    53              _ % _ % _ %% (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1)) %%
    53              _ % _ % _ %% (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1)) %%
    54         ((tg as PThm (("ProtoPure.triv_goal", _), _, _, _)) % _ %% prf2)) =
    54         ((tg as PThm (("ProtoPure.triv_goal", _), _, _, _)) % _ %% prf2)) =
    55         Some (tg %> B %% (equal_elim_axm %> A %> B %%
    55         SOME (tg %> B %% (equal_elim_axm %> A %> B %%
    56           (symmetric_axm % ? B % ? A %% prf1) %% prf2))
    56           (symmetric_axm % ? B % ? A %% prf1) %% prf2))
    57 
    57 
    58       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    58       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME X % SOME Y %%
    59         (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
    59         (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
    60           (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==>", _)) % _ % _ % _ %%
    60           (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("==>", _)) % _ % _ % _ %%
    61              (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) =
    61              (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) =
    62         let
    62         let
    63           val _ $ A $ C = Envir.beta_norm X;
    63           val _ $ A $ C = Envir.beta_norm X;
    64           val _ $ B $ D = Envir.beta_norm Y
    64           val _ $ B $ D = Envir.beta_norm Y
    65         in Some (AbsP ("H1", ? X, AbsP ("H2", ? B,
    65         in SOME (AbsP ("H1", ? X, AbsP ("H2", ? B,
    66           equal_elim_axm %> C %> D %% incr_pboundvars 2 0 prf2 %%
    66           equal_elim_axm %> C %> D %% incr_pboundvars 2 0 prf2 %%
    67             (PBound 1 %% (equal_elim_axm %> B %> A %%
    67             (PBound 1 %% (equal_elim_axm %> B %> A %%
    68               (symmetric_axm % ? A % ? B %% incr_pboundvars 2 0 prf1) %% PBound 0)))))
    68               (symmetric_axm % ? A % ? B %% incr_pboundvars 2 0 prf1) %% PBound 0)))))
    69         end
    69         end
    70 
    70 
    71       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    71       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME X % SOME Y %%
    72         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    72         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    73           (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
    73           (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
    74             (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==>", _)) % _ % _ % _ %%
    74             (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("==>", _)) % _ % _ % _ %%
    75                (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2))) =
    75                (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2))) =
    76         let
    76         let
    77           val _ $ A $ C = Envir.beta_norm Y;
    77           val _ $ A $ C = Envir.beta_norm Y;
    78           val _ $ B $ D = Envir.beta_norm X
    78           val _ $ B $ D = Envir.beta_norm X
    79         in Some (AbsP ("H1", ? X, AbsP ("H2", ? A,
    79         in SOME (AbsP ("H1", ? X, AbsP ("H2", ? A,
    80           equal_elim_axm %> D %> C %%
    80           equal_elim_axm %> D %> C %%
    81             (symmetric_axm % ? C % ? D %% incr_pboundvars 2 0 prf2)
    81             (symmetric_axm % ? C % ? D %% incr_pboundvars 2 0 prf2)
    82               %% (PBound 1 %% (equal_elim_axm %> A %> B %% incr_pboundvars 2 0 prf1 %% PBound 0)))))
    82               %% (PBound 1 %% (equal_elim_axm %> A %> B %% incr_pboundvars 2 0 prf1 %% PBound 0)))))
    83         end
    83         end
    84 
    84 
    85       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    85       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME X % SOME Y %%
    86         (PAxm ("ProtoPure.combination", _, _) % Some (Const ("all", _)) % _ % _ % _ %%
    86         (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("all", _)) % _ % _ % _ %%
    87           (PAxm ("ProtoPure.reflexive", _, _) % _) %%
    87           (PAxm ("ProtoPure.reflexive", _, _) % _) %%
    88             (PAxm ("ProtoPure.abstract_rule", _, _) % _ % _ %% prf))) =
    88             (PAxm ("ProtoPure.abstract_rule", _, _) % _ % _ %% prf))) =
    89         let
    89         let
    90           val Const (_, T) $ P = Envir.beta_norm X;
    90           val Const (_, T) $ P = Envir.beta_norm X;
    91           val _ $ Q = Envir.beta_norm Y;
    91           val _ $ Q = Envir.beta_norm Y;
    92         in Some (AbsP ("H", ? X, Abst ("x", ty T,
    92         in SOME (AbsP ("H", ? X, Abst ("x", ty T,
    93             equal_elim_axm %> incr_boundvars 1 P $ Bound 0 %> incr_boundvars 1 Q $ Bound 0 %%
    93             equal_elim_axm %> incr_boundvars 1 P $ Bound 0 %> incr_boundvars 1 Q $ Bound 0 %%
    94               (incr_pboundvars 1 1 prf %> Bound 0) %% (PBound 0 %> Bound 0))))
    94               (incr_pboundvars 1 1 prf %> Bound 0) %% (PBound 0 %> Bound 0))))
    95         end
    95         end
    96 
    96 
    97       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    97       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME X % SOME Y %%
    98         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%        
    98         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%        
    99           (PAxm ("ProtoPure.combination", _, _) % Some (Const ("all", _)) % _ % _ % _ %%
    99           (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("all", _)) % _ % _ % _ %%
   100             (PAxm ("ProtoPure.reflexive", _, _) % _) %%
   100             (PAxm ("ProtoPure.reflexive", _, _) % _) %%
   101               (PAxm ("ProtoPure.abstract_rule", _, _) % _ % _ %% prf)))) =
   101               (PAxm ("ProtoPure.abstract_rule", _, _) % _ % _ %% prf)))) =
   102         let
   102         let
   103           val Const (_, T) $ P = Envir.beta_norm X;
   103           val Const (_, T) $ P = Envir.beta_norm X;
   104           val _ $ Q = Envir.beta_norm Y;
   104           val _ $ Q = Envir.beta_norm Y;
   105           val t = incr_boundvars 1 P $ Bound 0;
   105           val t = incr_boundvars 1 P $ Bound 0;
   106           val u = incr_boundvars 1 Q $ Bound 0
   106           val u = incr_boundvars 1 Q $ Bound 0
   107         in Some (AbsP ("H", ? X, Abst ("x", ty T,
   107         in SOME (AbsP ("H", ? X, Abst ("x", ty T,
   108           equal_elim_axm %> t %> u %%
   108           equal_elim_axm %> t %> u %%
   109             (symmetric_axm % ? u % ? t %% (incr_pboundvars 1 1 prf %> Bound 0))
   109             (symmetric_axm % ? u % ? t %% (incr_pboundvars 1 1 prf %> Bound 0))
   110               %% (PBound 0 %> Bound 0))))
   110               %% (PBound 0 %> Bound 0))))
   111         end
   111         end
   112 
   112 
   113       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some A % Some C %%
   113       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME A % SOME C %%
   114         (PAxm ("ProtoPure.transitive", _, _) % _ % Some B % _ %% prf1 %% prf2) %% prf3) =
   114         (PAxm ("ProtoPure.transitive", _, _) % _ % SOME B % _ %% prf1 %% prf2) %% prf3) =
   115            Some (equal_elim_axm %> B %> C %% prf2 %%
   115            SOME (equal_elim_axm %> B %> C %% prf2 %%
   116              (equal_elim_axm %> A %> B %% prf1 %% prf3))
   116              (equal_elim_axm %> A %> B %% prf1 %% prf3))
   117       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some A % Some C %%
   117       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % SOME A % SOME C %%
   118         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   118         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   119           (PAxm ("ProtoPure.transitive", _, _) % _ % Some B % _ %% prf1 %% prf2)) %% prf3) =
   119           (PAxm ("ProtoPure.transitive", _, _) % _ % SOME B % _ %% prf1 %% prf2)) %% prf3) =
   120            Some (equal_elim_axm %> B %> C %% (symmetric_axm % ? C % ? B %% prf1) %%
   120            SOME (equal_elim_axm %> B %> C %% (symmetric_axm % ? C % ? B %% prf1) %%
   121              (equal_elim_axm %> A %> B %% (symmetric_axm % ? B % ? A %% prf2) %% prf3))
   121              (equal_elim_axm %> A %> B %% (symmetric_axm % ? B % ? A %% prf2) %% prf3))
   122 
   122 
   123       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   123       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   124         (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf) = Some prf
   124         (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf) = SOME prf
   125       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   125       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   126         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   126         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   127           (PAxm ("ProtoPure.reflexive", _, _) % _)) %% prf) = Some prf
   127           (PAxm ("ProtoPure.reflexive", _, _) % _)) %% prf) = SOME prf
   128 
   128 
   129       | rew' _ (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   129       | rew' _ (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   130         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %% prf)) = Some prf
   130         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %% prf)) = SOME prf
   131 
   131 
   132       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   132       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   133         (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A $ C) % Some (_ $ B $ D) %%
   133         (PAxm ("ProtoPure.equal_elim", _, _) % SOME (_ $ A $ C) % SOME (_ $ B $ D) %%
   134           (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   134           (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   135             (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   135             (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
   136               (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3) %% prf4) =
   136               (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3) %% prf4) =
   137           Some (equal_elim_axm %> C %> D %% prf2 %%
   137           SOME (equal_elim_axm %> C %> D %% prf2 %%
   138             (equal_elim_axm %> A %> C %% prf3 %%
   138             (equal_elim_axm %> A %> C %% prf3 %%
   139               (equal_elim_axm %> B %> A %% (symmetric_axm % ? A % ? B %% prf1) %% prf4)))
   139               (equal_elim_axm %> B %> A %% (symmetric_axm % ? A % ? B %% prf1) %% prf4)))
   140 
   140 
   141       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   141       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   142         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   142         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   143           (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A $ C) % Some (_ $ B $ D) %%
   143           (PAxm ("ProtoPure.equal_elim", _, _) % SOME (_ $ A $ C) % SOME (_ $ B $ D) %%
   144             (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   144             (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   145               (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   145               (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
   146                 (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3)) %% prf4) =
   146                 (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3)) %% prf4) =
   147           Some (equal_elim_axm %> A %> B %% prf1 %%
   147           SOME (equal_elim_axm %> A %> B %% prf1 %%
   148             (equal_elim_axm %> C %> A %% (symmetric_axm % ? A % ? C %% prf3) %%
   148             (equal_elim_axm %> C %> A %% (symmetric_axm % ? A % ? C %% prf3) %%
   149               (equal_elim_axm %> D %> C %% (symmetric_axm % ? C % ? D %% prf2) %% prf4)))
   149               (equal_elim_axm %> D %> C %% (symmetric_axm % ? C % ? D %% prf2) %% prf4)))
   150 
   150 
   151       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   151       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   152         (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ B $ D) % Some (_ $ A $ C) %%
   152         (PAxm ("ProtoPure.equal_elim", _, _) % SOME (_ $ B $ D) % SOME (_ $ A $ C) %%
   153           (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   153           (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   154             (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   154             (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   155               (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   155               (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
   156                 (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3) %% prf4) =
   156                 (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3) %% prf4) =
   157           Some (equal_elim_axm %> D %> C %% (symmetric_axm % ? C % ? D %% prf2) %%
   157           SOME (equal_elim_axm %> D %> C %% (symmetric_axm % ? C % ? D %% prf2) %%
   158             (equal_elim_axm %> B %> D %% prf3 %%
   158             (equal_elim_axm %> B %> D %% prf3 %%
   159               (equal_elim_axm %> A %> B %% prf1 %% prf4)))
   159               (equal_elim_axm %> A %> B %% prf1 %% prf4)))
   160 
   160 
   161       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   161       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   162         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   162         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   163           (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ B $ D) % Some (_ $ A $ C) %%
   163           (PAxm ("ProtoPure.equal_elim", _, _) % SOME (_ $ B $ D) % SOME (_ $ A $ C) %%
   164             (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   164             (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   165               (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   165               (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   166                 (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   166                 (PAxm ("ProtoPure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
   167                   (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3)) %% prf4) =
   167                   (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3)) %% prf4) =
   168           Some (equal_elim_axm %> B %> A %% (symmetric_axm % ? A % ? B %% prf1) %%
   168           SOME (equal_elim_axm %> B %> A %% (symmetric_axm % ? A % ? B %% prf1) %%
   169             (equal_elim_axm %> D %> B %% (symmetric_axm % ? B % ? D %% prf3) %%
   169             (equal_elim_axm %> D %> B %% (symmetric_axm % ? B % ? D %% prf3) %%
   170               (equal_elim_axm %> C %> D %% prf2 %% prf4)))
   170               (equal_elim_axm %> C %> D %% prf2 %% prf4)))
   171 
   171 
   172       | rew' _ ((prf as PAxm ("ProtoPure.combination", _, _) %
   172       | rew' _ ((prf as PAxm ("ProtoPure.combination", _, _) %
   173         Some ((eq as Const ("==", T)) $ t) % _ % _ % _) %%
   173         SOME ((eq as Const ("==", T)) $ t) % _ % _ % _) %%
   174           (PAxm ("ProtoPure.reflexive", _, _) % _)) =
   174           (PAxm ("ProtoPure.reflexive", _, _) % _)) =
   175         let val (U, V) = (case T of
   175         let val (U, V) = (case T of
   176           Type (_, [U, V]) => (U, V) | _ => (dummyT, dummyT))
   176           Type (_, [U, V]) => (U, V) | _ => (dummyT, dummyT))
   177         in Some (prf %% (ax combination_axm [V, U] %> eq % ? eq % ? t % ? t %%
   177         in SOME (prf %% (ax combination_axm [V, U] %> eq % ? eq % ? t % ? t %%
   178           (ax reflexive_axm [T] % ? eq) %% (ax reflexive_axm [U] % ? t)))
   178           (ax reflexive_axm [T] % ? eq) %% (ax reflexive_axm [U] % ? t)))
   179         end
   179         end
   180 
   180 
   181       | rew' _ _ = None;
   181       | rew' _ _ = NONE;
   182   in rew' end;
   182   in rew' end;
   183 
   183 
   184 fun rprocs b = [("Pure/meta_equality", rew b)];
   184 fun rprocs b = [("Pure/meta_equality", rew b)];
   185 val setup = [Proofterm.add_prf_rprocs (rprocs false)];
   185 val setup = [Proofterm.add_prf_rprocs (rprocs false)];
   186 
   186 
   199       in
   199       in
   200         strip Ts (foldl (uncurry lambda o Library.swap) (t', frees))
   200         strip Ts (foldl (uncurry lambda o Library.swap) (t', frees))
   201       end;
   201       end;
   202 
   202 
   203     fun rew Ts (prf1 %% prf2) = rew Ts prf1 %% rew Ts prf2
   203     fun rew Ts (prf1 %% prf2) = rew Ts prf1 %% rew Ts prf2
   204       | rew Ts (prf % Some t) = rew Ts prf % Some (rew_term Ts t)
   204       | rew Ts (prf % SOME t) = rew Ts prf % SOME (rew_term Ts t)
   205       | rew Ts (Abst (s, Some T, prf)) = Abst (s, Some T, rew (T :: Ts) prf)
   205       | rew Ts (Abst (s, SOME T, prf)) = Abst (s, SOME T, rew (T :: Ts) prf)
   206       | rew Ts (AbsP (s, Some t, prf)) = AbsP (s, Some (rew_term Ts t), rew Ts prf)
   206       | rew Ts (AbsP (s, SOME t, prf)) = AbsP (s, SOME (rew_term Ts t), rew Ts prf)
   207       | rew _ prf = prf
   207       | rew _ prf = prf
   208 
   208 
   209   in rew [] end;
   209   in rew [] end;
   210 
   210 
   211 
   211 
   214 fun vars_of t = rev (foldl_aterms
   214 fun vars_of t = rev (foldl_aterms
   215   (fn (vs, v as Var _) => v ins vs | (vs, _) => vs) ([], t));
   215   (fn (vs, v as Var _) => v ins vs | (vs, _) => vs) ([], t));
   216 
   216 
   217 fun insert_refl defs Ts (prf1 %% prf2) =
   217 fun insert_refl defs Ts (prf1 %% prf2) =
   218       insert_refl defs Ts prf1 %% insert_refl defs Ts prf2
   218       insert_refl defs Ts prf1 %% insert_refl defs Ts prf2
   219   | insert_refl defs Ts (Abst (s, Some T, prf)) =
   219   | insert_refl defs Ts (Abst (s, SOME T, prf)) =
   220       Abst (s, Some T, insert_refl defs (T :: Ts) prf)
   220       Abst (s, SOME T, insert_refl defs (T :: Ts) prf)
   221   | insert_refl defs Ts (AbsP (s, t, prf)) =
   221   | insert_refl defs Ts (AbsP (s, t, prf)) =
   222       AbsP (s, t, insert_refl defs Ts prf)
   222       AbsP (s, t, insert_refl defs Ts prf)
   223   | insert_refl defs Ts prf = (case strip_combt prf of
   223   | insert_refl defs Ts prf = (case strip_combt prf of
   224         (PThm ((s, _), _, prop, Some Ts), ts) =>
   224         (PThm ((s, _), _, prop, SOME Ts), ts) =>
   225           if s mem defs then
   225           if s mem defs then
   226             let
   226             let
   227               val vs = vars_of prop;
   227               val vs = vars_of prop;
   228               val tvars = term_tvars prop;
   228               val tvars = term_tvars prop;
   229               val (_, rhs) = Logic.dest_equals prop;
   229               val (_, rhs) = Logic.dest_equals prop;
   230               val rhs' = foldl betapply (subst_TVars (map fst tvars ~~ Ts)
   230               val rhs' = foldl betapply (subst_TVars (map fst tvars ~~ Ts)
   231                 (foldr (fn p => Abs ("", dummyT, abstract_over p)) (vs, rhs)),
   231                 (foldr (fn p => Abs ("", dummyT, abstract_over p)) (vs, rhs)),
   232                 map the ts);
   232                 map the ts);
   233             in
   233             in
   234               change_type (Some [fastype_of1 (Ts, rhs')]) reflexive_axm %> rhs'
   234               change_type (SOME [fastype_of1 (Ts, rhs')]) reflexive_axm %> rhs'
   235             end
   235             end
   236           else prf
   236           else prf
   237       | (_, []) => prf
   237       | (_, []) => prf
   238       | (prf', ts) => proof_combt' (insert_refl defs Ts prf', ts));
   238       | (prf', ts) => proof_combt' (insert_refl defs Ts prf', ts));
   239 
   239 
   245     val f = if not r then I else
   245     val f = if not r then I else
   246       let
   246       let
   247         val cnames = map (fst o dest_Const o fst) defs';
   247         val cnames = map (fst o dest_Const o fst) defs';
   248         val thms = flat (map (fn (s, ps) =>
   248         val thms = flat (map (fn (s, ps) =>
   249             if s mem defnames then []
   249             if s mem defnames then []
   250             else map (pair s o Some o fst) (filter_out (fn (p, _) =>
   250             else map (pair s o SOME o fst) (filter_out (fn (p, _) =>
   251               null (term_consts p inter cnames)) ps))
   251               null (term_consts p inter cnames)) ps))
   252           (Symtab.dest (thms_of_proof Symtab.empty prf)))
   252           (Symtab.dest (thms_of_proof Symtab.empty prf)))
   253       in Reconstruct.expand_proof sign thms end
   253       in Reconstruct.expand_proof sign thms end
   254   in
   254   in
   255     rewrite_terms (Pattern.rewrite_term tsig defs' [])
   255     rewrite_terms (Pattern.rewrite_term tsig defs' [])