src/Provers/quantifier1.ML
changeset 11232 558a4feebb04
parent 11221 60c6e91f6079
child 12523 0d8d5bf549b0
equal deleted inserted replaced
11231:30d96882f915 11232:558a4feebb04
     5 
     5 
     6 Simplification procedures for turning
     6 Simplification procedures for turning
     7 
     7 
     8             ? x. ... & x = t & ...
     8             ? x. ... & x = t & ...
     9      into   ? x. x = t & ... & ...
     9      into   ? x. x = t & ... & ...
    10      where the `? x. x = t &' in the latter formula is eliminated
    10      where the `? x. x = t &' in the latter formula must be eliminated
    11            by ordinary simplification. 
    11            by ordinary simplification. 
    12 
    12 
    13      and   ! x. (... & x = t & ...) --> P x
    13      and   ! x. (... & x = t & ...) --> P x
    14      into  ! x. x = t --> (... & ...) --> P x
    14      into  ! x. x = t --> (... & ...) --> P x
    15      where the `!x. x=t -->' in the latter formula is eliminated
    15      where the `!x. x=t -->' in the latter formula is eliminated
    16            by ordinary simplification.
    16            by ordinary simplification.
    17 
    17 
       
    18      And analogously for t=x, but the eqn is not turned around!
       
    19 
    18      NB Simproc is only triggered by "!x. P(x) & P'(x) --> Q(x)";
    20      NB Simproc is only triggered by "!x. P(x) & P'(x) --> Q(x)";
    19         "!x. x=t --> P(x)" is covered by the congreunce rule for -->;
    21         "!x. x=t --> P(x)" is covered by the congreunce rule for -->;
    20         "!x. t=x --> P(x)" must be taken care of by an ordinary rewrite rule.
    22         "!x. t=x --> P(x)" must be taken care of by an ordinary rewrite rule.
       
    23         As must be "? x. t=x & P(x)".
    21 
    24 
       
    25         
    22      And similarly for the bounded quantifiers.
    26      And similarly for the bounded quantifiers.
    23 
    27 
    24 Gries etc call this the "1 point rules"
    28 Gries etc call this the "1 point rules"
    25 *)
    29 *)
    26 
    30 
    27 signature QUANTIFIER1_DATA =
    31 signature QUANTIFIER1_DATA =
    28 sig
    32 sig
    29   (*abstract syntax*)
    33   (*abstract syntax*)
    30   val dest_eq: term -> (term*term*term)option
    34   val dest_eq: term -> (term*term*term)option
    31   val dest_conj: term -> (term*term*term)option
    35   val dest_conj: term -> (term*term*term)option
       
    36   val dest_imp:  term -> (term*term*term)option
    32   val conj: term
    37   val conj: term
    33   val imp:  term
    38   val imp:  term
    34   (*rules*)
    39   (*rules*)
    35   val iff_reflection: thm (* P <-> Q ==> P == Q *)
    40   val iff_reflection: thm (* P <-> Q ==> P == Q *)
    36   val iffI:  thm
    41   val iffI:  thm
    37   val sym:   thm
       
    38   val conjI: thm
    42   val conjI: thm
    39   val conjE: thm
    43   val conjE: thm
    40   val impI:  thm
    44   val impI:  thm
    41   val impE:  thm
       
    42   val mp:    thm
    45   val mp:    thm
    43   val exI:   thm
    46   val exI:   thm
    44   val exE:   thm
    47   val exE:   thm
    45   val allI:  thm
    48   val uncurry: thm (* P --> Q --> R ==> P & Q --> R *)
    46   val allE:  thm
    49   val iff_allI: thm (* !!x. P x <-> Q x ==> (!x. P x) = (!x. Q x) *)
    47 end;
    50 end;
    48 
    51 
    49 signature QUANTIFIER1 =
    52 signature QUANTIFIER1 =
    50 sig
    53 sig
    51   val prove_one_point_all_tac: tactic
    54   val prove_one_point_all_tac: tactic
    59 functor Quantifier1Fun(Data: QUANTIFIER1_DATA): QUANTIFIER1 =
    62 functor Quantifier1Fun(Data: QUANTIFIER1_DATA): QUANTIFIER1 =
    60 struct
    63 struct
    61 
    64 
    62 open Data;
    65 open Data;
    63 
    66 
       
    67 (* FIXME: only test! *)
    64 fun def eq = case dest_eq eq of
    68 fun def eq = case dest_eq eq of
    65       Some(c,s,t) =>
    69       Some(c,s,t) =>
    66         if s = Bound 0 andalso not(loose_bvar1(t,0)) then Some eq else
    70         s = Bound 0 andalso not(loose_bvar1(t,0)) orelse
    67         if t = Bound 0 andalso not(loose_bvar1(s,0)) then Some(c$t$s)
    71         t = Bound 0 andalso not(loose_bvar1(s,0))
    68         else None
    72     | None => false;
    69     | None => None;
       
    70 
    73 
    71 fun extract conj = case dest_conj conj of
    74 fun extract_conj t = case dest_conj t of None => None
    72       Some(conj,P,Q) =>
    75     | Some(conj,P,Q) =>
    73         (case def P of
    76         (if def P then Some(P,Q) else
    74            Some eq => Some(eq,Q)
    77          if def Q then Some(Q,P) else
    75          | None =>
    78          (case extract_conj P of
    76              (case def Q of
    79             Some(eq,P') => Some(eq, conj $ P' $ Q)
    77                 Some eq => Some(eq,P)
    80           | None => (case extract_conj Q of
    78               | None =>
    81                        Some(eq,Q') => Some(eq,conj $ P $ Q')
    79                  (case extract P of
    82                      | None => None)));
    80                     Some(eq,P') => Some(eq, conj $ P' $ Q)
    83 
    81                   | None =>
    84 fun extract_imp t = case dest_imp t of None => None
    82                       (case extract Q of
    85     | Some(imp,P,Q) => if def P then Some(P,Q)
    83                          Some(eq,Q') => Some(eq,conj $ P $ Q')
    86                        else (case extract_conj P of
    84                        | None => None))))
    87                                Some(eq,P') => Some(eq, imp $ P' $ Q)
    85     | None => None;
    88                              | None => (case extract_imp Q of
       
    89                                           None => None
       
    90                                         | Some(eq,Q') => Some(eq, imp$P$Q')));
       
    91     
    86 
    92 
    87 fun prove_conv tac sg tu =
    93 fun prove_conv tac sg tu =
    88   let val meta_eq = cterm_of sg (Logic.mk_equals tu)
    94   let val meta_eq = cterm_of sg (Logic.mk_equals tu)
    89   in prove_goalw_cterm [] meta_eq (K [rtac iff_reflection 1, tac])
    95   in prove_goalw_cterm [] meta_eq (K [rtac iff_reflection 1, tac])
    90      handle ERROR =>
    96      handle ERROR =>
    95 (* Proves (? x. ... & x = t & ...) = (? x. x = t & ... & ...)
   101 (* Proves (? x. ... & x = t & ...) = (? x. x = t & ... & ...)
    96    Better: instantiate exI
   102    Better: instantiate exI
    97 *)
   103 *)
    98 val prove_one_point_ex_tac = rtac iffI 1 THEN
   104 val prove_one_point_ex_tac = rtac iffI 1 THEN
    99     ALLGOALS(EVERY'[etac exE, REPEAT_DETERM o (etac conjE), rtac exI,
   105     ALLGOALS(EVERY'[etac exE, REPEAT_DETERM o (etac conjE), rtac exI,
   100                     DEPTH_SOLVE_1 o (ares_tac [conjI] APPEND' etac sym)]);
   106                     DEPTH_SOLVE_1 o (ares_tac [conjI])]);
   101 
   107 
   102 (* Proves (! x. (... & x = t & ...) --> P x) =
   108 (* Proves (! x. (... & x = t & ...) --> P x) =
   103           (! x. x = t --> (... & ...) --> P x)
   109           (! x. x = t --> (... & ...) --> P x)
   104 *)
   110 *)
   105 val prove_one_point_all_tac = EVERY1[rtac iffI,
   111 local
   106                        rtac allI, etac allE, rtac impI, rtac impI, etac mp,
   112 val tac = SELECT_GOAL
   107                           REPEAT o (etac conjE),
   113           (EVERY1[REPEAT o (dtac uncurry), REPEAT o (rtac impI), etac mp,
   108                           REPEAT o (ares_tac [conjI] ORELSE' etac sym),
   114                   REPEAT o (etac conjE), REPEAT o (ares_tac [conjI])])
   109                        rtac allI, etac allE, rtac impI, REPEAT o (etac conjE),
   115 in
   110                           etac impE, atac ORELSE' etac sym, etac mp,
   116 val prove_one_point_all_tac = EVERY1[rtac iff_allI, rtac iffI, tac, tac]
   111                           REPEAT o (ares_tac [conjI])];
   117 end
   112 
   118 
   113 fun rearrange_all sg _ (F as all $ Abs(x,T,(* --> *)_ $ P $ Q)) =
   119 fun rearrange_all sg _ (F as all $ Abs(x,T, P)) =
   114      (case extract P of
   120      (case extract_imp P of
   115         None => None
   121         None => None
   116       | Some(eq,P') =>
   122       | Some(eq,Q) =>
   117           let val R = imp $ eq $ (imp $ P' $ Q)
   123           let val R = imp $ eq $ Q
   118           in Some(prove_conv prove_one_point_all_tac sg (F,all$Abs(x,T,R))) end)
   124           in Some(prove_conv prove_one_point_all_tac sg (F,all$Abs(x,T,R))) end)
   119   | rearrange_all _ _ _ = None;
   125   | rearrange_all _ _ _ = None;
   120 
   126 
   121 fun rearrange_ball tac sg _ (F as Ball $ A $ Abs(x,T,(* --> *)_ $ P $ Q)) =
   127 fun rearrange_ball tac sg _ (F as Ball $ A $ Abs(x,T,P)) =
   122      (case extract P of
   128      (case extract_imp P of
   123         None => None
   129         None => None
   124       | Some(eq,P') =>
   130       | Some(eq,Q) =>
   125           let val R = imp $ eq $ (imp $ P' $ Q)
   131           let val R = imp $ eq $ Q
   126           in Some(prove_conv tac sg (F,Ball $ A $ Abs(x,T,R))) end)
   132           in Some(prove_conv tac sg (F,Ball $ A $ Abs(x,T,R))) end)
   127   | rearrange_ball _ _ _ _ = None;
   133   | rearrange_ball _ _ _ _ = None;
   128 
   134 
   129 fun rearrange_ex sg _ (F as ex $ Abs(x,T,P)) =
   135 fun rearrange_ex sg _ (F as ex $ Abs(x,T,P)) =
   130      (case extract P of
   136      (case extract_conj P of
   131         None => None
   137         None => None
   132       | Some(eq,Q) =>
   138       | Some(eq,Q) =>
   133           Some(prove_conv prove_one_point_ex_tac sg (F,ex $ Abs(x,T,conj$eq$Q))))
   139           Some(prove_conv prove_one_point_ex_tac sg (F,ex $ Abs(x,T,conj$eq$Q))))
   134   | rearrange_ex _ _ _ = None;
   140   | rearrange_ex _ _ _ = None;
   135 
   141 
   136 fun rearrange_bex tac sg _ (F as Bex $ A $ Abs(x,T,P)) =
   142 fun rearrange_bex tac sg _ (F as Bex $ A $ Abs(x,T,P)) =
   137      (case extract P of
   143      (case extract_conj P of
   138         None => None
   144         None => None
   139       | Some(eq,Q) =>
   145       | Some(eq,Q) =>
   140           Some(prove_conv tac sg (F,Bex $ A $ Abs(x,T,conj$eq$Q))))
   146           Some(prove_conv tac sg (F,Bex $ A $ Abs(x,T,conj$eq$Q))))
   141   | rearrange_bex _ _ _ _ = None;
   147   | rearrange_bex _ _ _ _ = None;
   142 
   148