src/Doc/Logics_ZF/If.thy
author wenzelm
Thu, 14 Jun 2018 17:50:23 +0200
changeset 68449 6d0f1a5a16ea
parent 67443 3abf6a722518
child 69505 cc2d676d5395
permissions -rw-r--r--
auto update;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59720
f893472fff31 proper headers;
wenzelm
parents: 56451
diff changeset
     1
(*  Title:      Doc/Logics_ZF/If.thy
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     3
    Copyright   1991  University of Cambridge
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     4
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     5
First-Order Logic: the 'if' example.
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     6
*)
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     7
66453
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 59720
diff changeset
     8
theory If imports FOL begin
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
     9
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 19792
diff changeset
    10
definition "if" :: "[o,o,o]=>o" where
19792
e8e3da6d3ff7 quoted "if";
wenzelm
parents: 16417
diff changeset
    11
  "if(P,Q,R) == P&Q | ~P&R"
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    12
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    13
lemma ifI:
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    14
    "[| P ==> Q; ~P ==> R |] ==> if(P,Q,R)"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    15
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    16
apply (simp add: if_def)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    17
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    18
apply blast
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    19
done
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    20
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    21
lemma ifE:
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    22
   "[| if(P,Q,R);  [| P; Q |] ==> S; [| ~P; R |] ==> S |] ==> S"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    23
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    24
apply (simp add: if_def)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    25
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    26
apply blast
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    27
done
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    28
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    29
lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    30
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    31
apply (rule iffI)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    32
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    33
apply (erule ifE)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    34
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    35
apply (erule ifE)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    36
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    37
apply (rule ifI)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    38
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    39
apply (rule ifI)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    40
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    41
oops
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    42
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 66453
diff changeset
    43
text\<open>Trying again from the beginning in order to use @{text blast}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    44
declare ifI [intro!]
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    45
declare ifE [elim!]
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    46
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    47
lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    48
by blast
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    49
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    50
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    51
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    52
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    53
by blast
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    54
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 66453
diff changeset
    55
text\<open>Trying again from the beginning in order to prove from the definitions\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    56
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    57
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    58
apply (simp add: if_def)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    59
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    60
apply blast
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    61
done
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    62
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    63
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 66453
diff changeset
    64
text\<open>An invalid formula.  High-level rules permit a simpler diagnosis\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    65
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    66
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    67
apply auto
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    68
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    69
(*The next step will fail unless subgoals remain*)
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    70
apply (tactic all_tac)
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    71
oops
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    72
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 66453
diff changeset
    73
text\<open>Trying again from the beginning in order to prove from the definitions\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    74
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    75
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    76
apply (simp add: if_def)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    77
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    78
apply (auto) 
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67406
diff changeset
    79
  \<comment> \<open>@{subgoals[display,indent=0,margin=65]}\<close>
14205
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    80
(*The next step will fail unless subgoals remain*)
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    81
apply (tactic all_tac)
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    82
oops
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    83
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    84
4ae8d65bc97c new example for the Isar version of the ZF manual
paulson
parents:
diff changeset
    85
end