src/FOLP/FOLP.thy
changeset 26322 eaf634e975fa
parent 22577 1a08fce38565
child 35762 af3ff2ba4c54
equal deleted inserted replaced
26321:d875e70a94de 26322:eaf634e975fa
     7 header {* Classical First-Order Logic with Proofs *}
     7 header {* Classical First-Order Logic with Proofs *}
     8 
     8 
     9 theory FOLP
     9 theory FOLP
    10 imports IFOLP
    10 imports IFOLP
    11 uses
    11 uses
    12   ("FOLP_lemmas.ML") ("hypsubst.ML") ("classical.ML")
    12   ("classical.ML") ("simp.ML") ("simpdata.ML")
    13   ("simp.ML") ("intprover.ML") ("simpdata.ML")
       
    14 begin
    13 begin
    15 
    14 
    16 consts
    15 consts
    17   cla :: "[p=>p]=>p"
    16   cla :: "[p=>p]=>p"
    18 axioms
    17 axioms
    19   classical: "(!!x. x:~P ==> f(x):P) ==> cla(f):P"
    18   classical: "(!!x. x:~P ==> f(x):P) ==> cla(f):P"
    20 
    19 
    21 ML {* use_legacy_bindings (the_context ()) *}
       
    22 
    20 
    23 use "FOLP_lemmas.ML"
    21 (*** Classical introduction rules for | and EX ***)
    24 
    22 
    25 use "hypsubst.ML"
    23 lemma disjCI:
       
    24   assumes "!!x. x:~Q ==> f(x):P"
       
    25   shows "?p : P|Q"
       
    26   apply (rule classical)
       
    27   apply (assumption | rule assms disjI1 notI)+
       
    28   apply (assumption | rule disjI2 notE)+
       
    29   done
       
    30 
       
    31 (*introduction rule involving only EX*)
       
    32 lemma ex_classical:
       
    33   assumes "!!u. u:~(EX x. P(x)) ==> f(u):P(a)"
       
    34   shows "?p : EX x. P(x)"
       
    35   apply (rule classical)
       
    36   apply (rule exI, rule assms, assumption)
       
    37   done
       
    38 
       
    39 (*version of above, simplifying ~EX to ALL~ *)
       
    40 lemma exCI:
       
    41   assumes "!!u. u:ALL x. ~P(x) ==> f(u):P(a)"
       
    42   shows "?p : EX x. P(x)"
       
    43   apply (rule ex_classical)
       
    44   apply (rule notI [THEN allI, THEN assms])
       
    45   apply (erule notE)
       
    46   apply (erule exI)
       
    47   done
       
    48 
       
    49 lemma excluded_middle: "?p : ~P | P"
       
    50   apply (rule disjCI)
       
    51   apply assumption
       
    52   done
       
    53 
       
    54 
       
    55 (*** Special elimination rules *)
       
    56 
       
    57 (*Classical implies (-->) elimination. *)
       
    58 lemma impCE:
       
    59   assumes major: "p:P-->Q"
       
    60     and r1: "!!x. x:~P ==> f(x):R"
       
    61     and r2: "!!y. y:Q ==> g(y):R"
       
    62   shows "?p : R"
       
    63   apply (rule excluded_middle [THEN disjE])
       
    64    apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE
       
    65        resolve_tac [@{thm r1}, @{thm r2}, @{thm major} RS @{thm mp}] 1) *})
       
    66   done
       
    67 
       
    68 (*Double negation law*)
       
    69 lemma notnotD: "p:~~P ==> ?p : P"
       
    70   apply (rule classical)
       
    71   apply (erule notE)
       
    72   apply assumption
       
    73   done
       
    74 
       
    75 
       
    76 (*** Tactics for implication and contradiction ***)
       
    77 
       
    78 (*Classical <-> elimination.  Proof substitutes P=Q in
       
    79     ~P ==> ~Q    and    P ==> Q  *)
       
    80 lemma iffCE:
       
    81   assumes major: "p:P<->Q"
       
    82     and r1: "!!x y.[| x:P; y:Q |] ==> f(x,y):R"
       
    83     and r2: "!!x y.[| x:~P; y:~Q |] ==> g(x,y):R"
       
    84   shows "?p : R"
       
    85   apply (insert major)
       
    86   apply (unfold iff_def)
       
    87   apply (rule conjE)
       
    88   apply (tactic {* DEPTH_SOLVE_1 (etac @{thm impCE} 1 ORELSE
       
    89       eresolve_tac [@{thm notE}, @{thm impE}] 1 THEN atac 1 ORELSE atac 1 ORELSE
       
    90       resolve_tac [@{thm r1}, @{thm r2}] 1) *})+
       
    91   done
       
    92 
       
    93 
       
    94 (*Should be used as swap since ~P becomes redundant*)
       
    95 lemma swap:
       
    96   assumes major: "p:~P"
       
    97     and r: "!!x. x:~Q ==> f(x):P"
       
    98   shows "?p : Q"
       
    99   apply (rule classical)
       
   100   apply (rule major [THEN notE])
       
   101   apply (rule r)
       
   102   apply assumption
       
   103   done
       
   104 
    26 use "classical.ML"      (* Patched 'cos matching won't instantiate proof *)
   105 use "classical.ML"      (* Patched 'cos matching won't instantiate proof *)
    27 use "simp.ML"           (* Patched 'cos matching won't instantiate proof *)
   106 use "simp.ML"           (* Patched 'cos matching won't instantiate proof *)
    28 
   107 
    29 ML {*
   108 ML {*
    30 
       
    31 (*** Applying HypsubstFun to generate hyp_subst_tac ***)
       
    32 
       
    33 structure Hypsubst_Data =
       
    34   struct
       
    35   (*Take apart an equality judgement; otherwise raise Match!*)
       
    36   fun dest_eq (Const("Proof",_) $ (Const("op =",_)  $ t $ u) $ _) = (t,u);
       
    37 
       
    38   val imp_intr = impI
       
    39 
       
    40   (*etac rev_cut_eq moves an equality to be the last premise. *)
       
    41   val rev_cut_eq = prove_goal @{theory}
       
    42                 "[| p:a=b;  !!x. x:a=b ==> f(x):R |] ==> ?p:R"
       
    43    (fn prems => [ REPEAT(resolve_tac prems 1) ]);
       
    44 
       
    45   val rev_mp = rev_mp
       
    46   val subst = subst
       
    47   val sym = sym
       
    48   val thin_refl = prove_goal @{theory} "!!X. [|p:x=x; PROP W|] ==> PROP W" (K [atac 1]);
       
    49   end;
       
    50 
       
    51 structure Hypsubst = HypsubstFun(Hypsubst_Data);
       
    52 open Hypsubst;
       
    53 *}
       
    54 
       
    55 use "intprover.ML"
       
    56 
       
    57 ML {*
       
    58 (*** Applying ClassicalFun to create a classical prover ***)
   109 (*** Applying ClassicalFun to create a classical prover ***)
    59 structure Classical_Data =
   110 structure Classical_Data =
    60   struct
   111 struct
    61   val sizef = size_of_thm
   112   val sizef = size_of_thm
    62   val mp = mp
   113   val mp = @{thm mp}
    63   val not_elim = notE
   114   val not_elim = @{thm notE}
    64   val swap = swap
   115   val swap = @{thm swap}
    65   val hyp_subst_tacs=[hyp_subst_tac]
   116   val hyp_subst_tacs = [hyp_subst_tac]
    66   end;
   117 end;
    67 
   118 
    68 structure Cla = ClassicalFun(Classical_Data);
   119 structure Cla = ClassicalFun(Classical_Data);
    69 open Cla;
   120 open Cla;
    70 
   121 
    71 (*Propositional rules
   122 (*Propositional rules
    72   -- iffCE might seem better, but in the examples in ex/cla
   123   -- iffCE might seem better, but in the examples in ex/cla
    73      run about 7% slower than with iffE*)
   124      run about 7% slower than with iffE*)
    74 val prop_cs = empty_cs addSIs [refl,TrueI,conjI,disjCI,impI,notI,iffI]
   125 val prop_cs =
    75                        addSEs [conjE,disjE,impCE,FalseE,iffE];
   126   empty_cs addSIs [@{thm refl}, @{thm TrueI}, @{thm conjI}, @{thm disjCI},
       
   127       @{thm impI}, @{thm notI}, @{thm iffI}]
       
   128     addSEs [@{thm conjE}, @{thm disjE}, @{thm impCE}, @{thm FalseE}, @{thm iffE}];
    76 
   129 
    77 (*Quantifier rules*)
   130 (*Quantifier rules*)
    78 val FOLP_cs = prop_cs addSIs [allI] addIs [exI,ex1I]
   131 val FOLP_cs =
    79                       addSEs [exE,ex1E] addEs [allE];
   132   prop_cs addSIs [@{thm allI}] addIs [@{thm exI}, @{thm ex1I}]
       
   133     addSEs [@{thm exE}, @{thm ex1E}] addEs [@{thm allE}];
    80 
   134 
    81 val FOLP_dup_cs = prop_cs addSIs [allI] addIs [exCI,ex1I]
   135 val FOLP_dup_cs =
    82                           addSEs [exE,ex1E] addEs [all_dupE];
   136   prop_cs addSIs [@{thm allI}] addIs [@{thm exCI}, @{thm ex1I}]
       
   137     addSEs [@{thm exE}, @{thm ex1E}] addEs [@{thm all_dupE}];
       
   138 *}
    83 
   139 
    84 *}
   140 lemma cla_rews:
       
   141   "?p1 : P | ~P"
       
   142   "?p2 : ~P | P"
       
   143   "?p3 : ~ ~ P <-> P"
       
   144   "?p4 : (~P --> P) <-> P"
       
   145   apply (tactic {* ALLGOALS (Cla.fast_tac FOLP_cs) *})
       
   146   done
    85 
   147 
    86 use "simpdata.ML"
   148 use "simpdata.ML"
    87 
   149 
    88 end
   150 end