doc-src/ZF/FOL-eg.txt
changeset 6121 5fe77b9b5185
equal deleted inserted replaced
6120:f40d61cd6b32 6121:5fe77b9b5185
       
     1 (**** FOL examples ****)
       
     2 
       
     3 Pretty.setmargin 72;  (*existing macros just allow this margin*)
       
     4 print_depth 0;
       
     5 
       
     6 (*** Intuitionistic examples ***)
       
     7 
       
     8 context IFOL.thy;
       
     9 
       
    10 (*Quantifier example from Logic&Computation*)
       
    11 Goal "(EX y. ALL x. Q(x,y)) -->  (ALL x. EX y. Q(x,y))";
       
    12 by (resolve_tac [impI] 1);
       
    13 by (resolve_tac [allI] 1);
       
    14 by (resolve_tac [exI] 1);
       
    15 by (eresolve_tac [exE] 1);
       
    16 choplev 2;
       
    17 by (eresolve_tac [exE] 1);
       
    18 by (resolve_tac [exI] 1);
       
    19 by (eresolve_tac [allE] 1);
       
    20 by (assume_tac 1);
       
    21 
       
    22 
       
    23 (*Example of Dyckhoff's method*)
       
    24 Goalw [not_def] "~ ~ ((P-->Q) | (Q-->P))";
       
    25 by (resolve_tac [impI] 1);
       
    26 by (eresolve_tac [disj_impE] 1);
       
    27 by (eresolve_tac [imp_impE] 1);
       
    28 by (eresolve_tac [imp_impE] 1);
       
    29 by (REPEAT (eresolve_tac [FalseE] 2));
       
    30 by (assume_tac 1);
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 
       
    36 (*** Classical examples ***)
       
    37 
       
    38 context FOL.thy;
       
    39 
       
    40 Goal "EX y. ALL x. P(y)-->P(x)";
       
    41 by (resolve_tac [exCI] 1);
       
    42 by (resolve_tac [allI] 1);
       
    43 by (resolve_tac [impI] 1);
       
    44 by (eresolve_tac [allE] 1);
       
    45 prth (allI RSN (2,swap));
       
    46 by (eresolve_tac [it] 1);
       
    47 by (resolve_tac [impI] 1);
       
    48 by (eresolve_tac [notE] 1);
       
    49 by (assume_tac 1);
       
    50 Goal "EX y. ALL x. P(y)-->P(x)";
       
    51 by (Blast_tac 1);
       
    52 
       
    53 
       
    54 
       
    55 - Goal "EX y. ALL x. P(y)-->P(x)";
       
    56 Level 0
       
    57 EX y. ALL x. P(y) --> P(x)
       
    58  1. EX y. ALL x. P(y) --> P(x)
       
    59 - by (resolve_tac [exCI] 1);
       
    60 Level 1
       
    61 EX y. ALL x. P(y) --> P(x)
       
    62  1. ALL y. ~(ALL x. P(y) --> P(x)) ==> ALL x. P(?a) --> P(x)
       
    63 - by (resolve_tac [allI] 1);
       
    64 Level 2
       
    65 EX y. ALL x. P(y) --> P(x)
       
    66  1. !!x. ALL y. ~(ALL x. P(y) --> P(x)) ==> P(?a) --> P(x)
       
    67 - by (resolve_tac [impI] 1);
       
    68 Level 3
       
    69 EX y. ALL x. P(y) --> P(x)
       
    70  1. !!x. [| ALL y. ~(ALL x. P(y) --> P(x)); P(?a) |] ==> P(x)
       
    71 - by (eresolve_tac [allE] 1);
       
    72 Level 4
       
    73 EX y. ALL x. P(y) --> P(x)
       
    74  1. !!x. [| P(?a); ~(ALL xa. P(?y3(x)) --> P(xa)) |] ==> P(x)
       
    75 - prth (allI RSN (2,swap));
       
    76 [| ~(ALL x. ?P1(x)); !!x. ~?Q ==> ?P1(x) |] ==> ?Q
       
    77 - by (eresolve_tac [it] 1);
       
    78 Level 5
       
    79 EX y. ALL x. P(y) --> P(x)
       
    80  1. !!x xa. [| P(?a); ~P(x) |] ==> P(?y3(x)) --> P(xa)
       
    81 - by (resolve_tac [impI] 1);
       
    82 Level 6
       
    83 EX y. ALL x. P(y) --> P(x)
       
    84  1. !!x xa. [| P(?a); ~P(x); P(?y3(x)) |] ==> P(xa)
       
    85 - by (eresolve_tac [notE] 1);
       
    86 Level 7
       
    87 EX y. ALL x. P(y) --> P(x)
       
    88  1. !!x xa. [| P(?a); P(?y3(x)) |] ==> P(x)
       
    89 - by (assume_tac 1);
       
    90 Level 8
       
    91 EX y. ALL x. P(y) --> P(x)
       
    92 No subgoals!
       
    93 - Goal "EX y. ALL x. P(y)-->P(x)";
       
    94 Level 0
       
    95 EX y. ALL x. P(y) --> P(x)
       
    96  1. EX y. ALL x. P(y) --> P(x)
       
    97 - by (best_tac FOL_dup_cs 1);
       
    98 Level 1
       
    99 EX y. ALL x. P(y) --> P(x)
       
   100 No subgoals!
       
   101 
       
   102 
       
   103 (**** finally, the example FOL/ex/if.ML ****)
       
   104 
       
   105 > val prems = goalw if_thy [if_def]
       
   106 #    "[| P ==> Q; ~P ==> R |] ==> if(P,Q,R)";
       
   107 Level 0
       
   108 if(P,Q,R)
       
   109  1. P & Q | ~P & R
       
   110 > by (Classical.fast_tac (FOL_cs addIs prems) 1);
       
   111 Level 1
       
   112 if(P,Q,R)
       
   113 No subgoals!
       
   114 > val ifI = result();
       
   115 
       
   116 
       
   117 > val major::prems = goalw if_thy [if_def]
       
   118 #    "[| if(P,Q,R);  [| P; Q |] ==> S; [| ~P; R |] ==> S |] ==> S";
       
   119 Level 0
       
   120 S
       
   121  1. S
       
   122 > by (cut_facts_tac [major] 1);
       
   123 Level 1
       
   124 S
       
   125  1. P & Q | ~P & R ==> S
       
   126 > by (Classical.fast_tac (FOL_cs addIs prems) 1);
       
   127 Level 2
       
   128 S
       
   129 No subgoals!
       
   130 > val ifE = result();
       
   131 
       
   132 > goal if_thy "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))";
       
   133 Level 0
       
   134 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   135  1. if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   136 > by (resolve_tac [iffI] 1);
       
   137 Level 1
       
   138 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   139  1. if(P,if(Q,A,B),if(Q,C,D)) ==> if(Q,if(P,A,C),if(P,B,D))
       
   140  2. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))
       
   141 > by (eresolve_tac [ifE] 1);
       
   142 Level 2
       
   143 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   144  1. [| P; if(Q,A,B) |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   145  2. [| ~P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   146  3. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))
       
   147 > by (eresolve_tac [ifE] 1);
       
   148 Level 3
       
   149 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   150  1. [| P; Q; A |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   151  2. [| P; ~Q; B |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   152  3. [| ~P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   153  4. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))
       
   154 > by (resolve_tac [ifI] 1);
       
   155 Level 4
       
   156 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   157  1. [| P; Q; A; Q |] ==> if(P,A,C)
       
   158  2. [| P; Q; A; ~Q |] ==> if(P,B,D)
       
   159  3. [| P; ~Q; B |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   160  4. [| ~P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   161  5. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))
       
   162 > by (resolve_tac [ifI] 1);
       
   163 Level 5
       
   164 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   165  1. [| P; Q; A; Q; P |] ==> A
       
   166  2. [| P; Q; A; Q; ~P |] ==> C
       
   167  3. [| P; Q; A; ~Q |] ==> if(P,B,D)
       
   168  4. [| P; ~Q; B |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   169  5. [| ~P; if(Q,C,D) |] ==> if(Q,if(P,A,C),if(P,B,D))
       
   170  6. if(Q,if(P,A,C),if(P,B,D)) ==> if(P,if(Q,A,B),if(Q,C,D))
       
   171 
       
   172 > choplev 0;
       
   173 Level 0
       
   174 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   175  1. if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   176 > val if_cs = FOL_cs addSIs [ifI] addSEs[ifE];
       
   177 > by (Classical.fast_tac if_cs 1);
       
   178 Level 1
       
   179 if(P,if(Q,A,B),if(Q,C,D)) <-> if(Q,if(P,A,C),if(P,B,D))
       
   180 No subgoals!
       
   181 > val if_commute = result();
       
   182 
       
   183 > goal if_thy "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))";
       
   184 Level 0
       
   185 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   186  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   187 > by (Classical.fast_tac if_cs 1);
       
   188 Level 1
       
   189 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   190 No subgoals!
       
   191 > val nested_ifs = result();
       
   192 
       
   193 
       
   194 > choplev 0;
       
   195 Level 0
       
   196 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   197  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   198 > by (rewrite_goals_tac [if_def]);
       
   199 Level 1
       
   200 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   201  1. (P & Q | ~P & R) & A | ~(P & Q | ~P & R) & B <->
       
   202     P & (Q & A | ~Q & B) | ~P & (R & A | ~R & B)
       
   203 > by (Classical.fast_tac FOL_cs 1);
       
   204 Level 2
       
   205 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,A,B))
       
   206 No subgoals!
       
   207 
       
   208 
       
   209 > goal if_thy "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))";
       
   210 Level 0
       
   211 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   212  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   213 > by (REPEAT (Classical.step_tac if_cs 1));
       
   214 Level 1
       
   215 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   216  1. [| A; ~P; R; ~P; R |] ==> B
       
   217  2. [| B; ~P; ~R; ~P; ~R |] ==> A
       
   218  3. [| ~P; R; B; ~P; R |] ==> A
       
   219  4. [| ~P; ~R; A; ~B; ~P |] ==> R
       
   220 
       
   221 > choplev 0;
       
   222 Level 0
       
   223 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   224  1. if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   225 > by (rewrite_goals_tac [if_def]);
       
   226 Level 1
       
   227 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   228  1. (P & Q | ~P & R) & A | ~(P & Q | ~P & R) & B <->
       
   229     P & (Q & A | ~Q & B) | ~P & (R & B | ~R & A)
       
   230 > by (Classical.fast_tac FOL_cs 1);
       
   231 by: tactic failed
       
   232 Exception- ERROR raised
       
   233 Exception failure raised
       
   234 
       
   235 > by (REPEAT (Classical.step_tac FOL_cs 1));
       
   236 Level 2
       
   237 if(if(P,Q,R),A,B) <-> if(P,if(Q,A,B),if(R,B,A))
       
   238  1. [| A; ~P; R; ~P; R; ~False |] ==> B
       
   239  2. [| A; ~P; R; R; ~False; ~B; ~B |] ==> Q
       
   240  3. [| B; ~P; ~R; ~P; ~A |] ==> R
       
   241  4. [| B; ~P; ~R; ~Q; ~A |] ==> R
       
   242  5. [| B; ~R; ~P; ~A; ~R; Q; ~False |] ==> A
       
   243  6. [| ~P; R; B; ~P; R; ~False |] ==> A
       
   244  7. [| ~P; ~R; A; ~B; ~R |] ==> P
       
   245  8. [| ~P; ~R; A; ~B; ~R |] ==> Q