src/Pure/Proof/proof_rewrite_rules.ML
author berghofe
Sat Feb 02 13:26:51 2002 +0100 (2002-02-02 ago)
changeset 12866 c00df7765656
parent 12237 39aeccee9e1c
child 12906 165f4e1937f4
permissions -rw-r--r--
Rewrite procedure now works for both compact and full proof objects.
     1 (*  Title:      Pure/Proof/proof_rewrite_rules.ML
     2     ID:         $Id$
     3     Author:     Stefan Berghofer, TU Muenchen
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 
     6 Simplification function for partial proof terms involving
     7 meta level rules.
     8 *)
     9 
    10 signature PROOF_REWRITE_RULES =
    11 sig
    12   val rew : bool -> typ list -> Proofterm.proof -> Proofterm.proof option
    13   val rprocs : bool -> (string * (typ list -> Proofterm.proof -> Proofterm.proof option)) list
    14   val setup : (theory -> theory) list
    15 end;
    16 
    17 structure ProofRewriteRules : PROOF_REWRITE_RULES =
    18 struct
    19 
    20 open Proofterm;
    21 
    22 fun rew b =
    23   let
    24     fun ? x = if b then Some x else None;
    25     fun ax (prf as PAxm (s, prop, _)) Ts =
    26       if b then PAxm (s, prop, Some Ts) else prf;
    27     fun ty T = if b then
    28         let val Type (_, [Type (_, [U, _]), _]) = T
    29         in Some T end
    30       else None;
    31     val equal_intr_axm = ax equal_intr_axm [];
    32     val equal_elim_axm = ax equal_elim_axm [];
    33     val symmetric_axm = ax symmetric_axm [propT];
    34 
    35     fun rew' _ (PThm (("ProtoPure.rev_triv_goal", _), _, _, _) % _ %%
    36         (PThm (("ProtoPure.triv_goal", _), _, _, _) % _ %% prf)) = Some prf
    37       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
    38         (PAxm ("ProtoPure.equal_intr", _, _) % _ % _ %% prf %% _)) = Some prf
    39       | rew' _ (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    40         (PAxm ("ProtoPure.equal_intr", _, _) % A % B %% prf1 %% prf2)) =
    41             Some (equal_intr_axm % B % A %% prf2 %% prf1)
    42 
    43       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A) % Some (_ $ B) %%
    44         (PAxm ("ProtoPure.combination", _, _) % Some (Const ("Goal", _)) %
    45           _ % _ % _ %% (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %%
    46         ((tg as PThm (("ProtoPure.triv_goal", _), _, _, _)) % _ %% prf2)) =
    47         Some (tg %> B %% (equal_elim_axm %> A %> B %% prf1 %% prf2))
    48 
    49       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A) % Some (_ $ B) %%
    50         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    51           (PAxm ("ProtoPure.combination", _, _) % Some (Const ("Goal", _)) %
    52              _ % _ % _ %% (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1)) %%
    53         ((tg as PThm (("ProtoPure.triv_goal", _), _, _, _)) % _ %% prf2)) =
    54         Some (tg %> B %% (equal_elim_axm %> A %> B %%
    55           (symmetric_axm % ? B % ? A %% prf1) %% prf2))
    56 
    57       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    58         (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
    59           (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==>", _)) % _ % _ % _ %%
    60              (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) =
    61         let
    62           val _ $ A $ C = Envir.beta_norm X;
    63           val _ $ B $ D = Envir.beta_norm Y
    64         in Some (AbsP ("H1", ? X, AbsP ("H2", ? B,
    65           equal_elim_axm %> C %> D %% incr_pboundvars 2 0 prf2 %%
    66             (PBound 1 %% (equal_elim_axm %> B %> A %%
    67               (symmetric_axm % ? A % ? B %% incr_pboundvars 2 0 prf1) %% PBound 0)))))
    68         end
    69 
    70       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    71         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
    72           (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
    73             (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==>", _)) % _ % _ % _ %%
    74                (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2))) =
    75         let
    76           val _ $ A $ C = Envir.beta_norm Y;
    77           val _ $ B $ D = Envir.beta_norm X
    78         in Some (AbsP ("H1", ? X, AbsP ("H2", ? A,
    79           equal_elim_axm %> D %> C %%
    80             (symmetric_axm % ? C % ? D %% incr_pboundvars 2 0 prf2)
    81               %% (PBound 1 %% (equal_elim_axm %> A %> B %% incr_pboundvars 2 0 prf1 %% PBound 0)))))
    82         end
    83 
    84       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    85         (PAxm ("ProtoPure.combination", _, _) % Some (Const ("all", _)) % _ % _ % _ %%
    86           (PAxm ("ProtoPure.reflexive", _, _) % _) %%
    87             (PAxm ("ProtoPure.abstract_rule", _, _) % _ % _ %% prf))) =
    88         let
    89           val Const (_, T) $ P = Envir.beta_norm X;
    90           val _ $ Q = Envir.beta_norm Y;
    91         in Some (AbsP ("H", ? X, Abst ("x", ty T,
    92             equal_elim_axm %> incr_boundvars 1 P $ Bound 0 %> incr_boundvars 1 Q $ Bound 0 %%
    93               (incr_pboundvars 1 1 prf %> Bound 0) %% (PBound 0 %> Bound 0))))
    94         end
    95 
    96       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some X % Some Y %%
    97         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%        
    98           (PAxm ("ProtoPure.combination", _, _) % Some (Const ("all", _)) % _ % _ % _ %%
    99             (PAxm ("ProtoPure.reflexive", _, _) % _) %%
   100               (PAxm ("ProtoPure.abstract_rule", _, _) % _ % _ %% prf)))) =
   101         let
   102           val Const (_, T) $ P = Envir.beta_norm X;
   103           val _ $ Q = Envir.beta_norm Y;
   104           val t = incr_boundvars 1 P $ Bound 0;
   105           val u = incr_boundvars 1 Q $ Bound 0
   106         in Some (AbsP ("H", ? X, Abst ("x", ty T,
   107           equal_elim_axm %> t %> u %%
   108             (symmetric_axm % ? u % ? t %% (incr_pboundvars 1 1 prf %> Bound 0))
   109               %% (PBound 0 %> Bound 0))))
   110         end
   111 
   112       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some A % Some C %%
   113         (PAxm ("ProtoPure.transitive", _, _) % _ % Some B % _ %% prf1 %% prf2) %% prf3) =
   114            Some (equal_elim_axm %> B %> C %% prf2 %%
   115              (equal_elim_axm %> A %> B %% prf1 %% prf3))
   116       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % Some A % Some C %%
   117         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   118           (PAxm ("ProtoPure.transitive", _, _) % _ % Some B % _ %% prf1 %% prf2)) %% prf3) =
   119            Some (equal_elim_axm %> B %> C %% (symmetric_axm % ? C % ? B %% prf1) %%
   120              (equal_elim_axm %> A %> B %% (symmetric_axm % ? B % ? A %% prf2) %% prf3))
   121 
   122       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   123         (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf) = Some prf
   124       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   125         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   126           (PAxm ("ProtoPure.reflexive", _, _) % _)) %% prf) = Some prf
   127 
   128       | rew' _ (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   129         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %% prf)) = Some prf
   130 
   131       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   132         (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A $ C) % Some (_ $ B $ D) %%
   133           (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   134             (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   135               (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3) %% prf4) =
   136           Some (equal_elim_axm %> C %> D %% prf2 %%
   137             (equal_elim_axm %> A %> C %% prf3 %%
   138               (equal_elim_axm %> B %> A %% (symmetric_axm % ? A % ? B %% prf1) %% prf4)))
   139 
   140       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   141         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   142           (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ A $ C) % Some (_ $ B $ D) %%
   143             (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   144               (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   145                 (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3)) %% prf4) =
   146           Some (equal_elim_axm %> A %> B %% prf1 %%
   147             (equal_elim_axm %> C %> A %% (symmetric_axm % ? A % ? C %% prf3) %%
   148               (equal_elim_axm %> D %> C %% (symmetric_axm % ? C % ? D %% prf2) %% prf4)))
   149 
   150       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   151         (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ B $ D) % Some (_ $ A $ C) %%
   152           (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   153             (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   154               (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   155                 (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3) %% prf4) =
   156           Some (equal_elim_axm %> D %> C %% (symmetric_axm % ? C % ? D %% prf2) %%
   157             (equal_elim_axm %> B %> D %% prf3 %%
   158               (equal_elim_axm %> A %> B %% prf1 %% prf4)))
   159 
   160       | rew' _ (PAxm ("ProtoPure.equal_elim", _, _) % _ % _ %%
   161         (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   162           (PAxm ("ProtoPure.equal_elim", _, _) % Some (_ $ B $ D) % Some (_ $ A $ C) %%
   163             (PAxm ("ProtoPure.symmetric", _, _) % _ % _ %%
   164               (PAxm ("ProtoPure.combination", _, _) % _ % _ % _ % _ %%
   165                 (PAxm ("ProtoPure.combination", _, _) % Some (Const ("==", _)) % _ % _ % _ %%
   166                   (PAxm ("ProtoPure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3)) %% prf4) =
   167           Some (equal_elim_axm %> B %> A %% (symmetric_axm % ? A % ? B %% prf1) %%
   168             (equal_elim_axm %> D %> B %% (symmetric_axm % ? B % ? D %% prf3) %%
   169               (equal_elim_axm %> C %> D %% prf2 %% prf4)))
   170 
   171       | rew' _ _ = None;
   172   in rew' end;
   173 
   174 fun rprocs b = [("Pure/meta_equality", rew b)];
   175 val setup = [Proofterm.add_prf_rprocs (rprocs false)];
   176 
   177 end;