doc-src/ZF/ZF_examples.thy
author paulson
Tue, 19 Aug 2003 13:53:58 +0200
changeset 14152 12f6f18e7afc
child 14159 e2eba24c8a2a
permissions -rw-r--r--
For the Isar version of the ZF logics manual
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14152
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     1
header{*Examples of Reasoning in ZF Set Theory*}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     2
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     3
theory ZF_examples = Main_ZFC:
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     4
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     5
subsection {* Binary Trees *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     6
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     7
consts
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     8
  bt :: "i => i"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
     9
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    10
datatype "bt(A)" =
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    11
  Lf | Br ("a \<in> A", "t1 \<in> bt(A)", "t2 \<in> bt(A)")
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    12
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    13
declare bt.intros [simp]
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    14
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    15
text{*Induction via tactic emulation*}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    16
lemma Br_neq_left [rule_format]: "l \<in> bt(A) ==> \<forall>x r. Br(x, l, r) \<noteq> l"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    17
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    18
  apply (induct_tac l)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    19
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    20
  apply auto
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    21
  done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    22
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    23
(*
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    24
  apply (Inductive.case_tac l)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    25
  apply (tactic {*exhaust_tac "l" 1*})
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    26
*)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    27
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    28
text{*The new induction method, which I don't understand*}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    29
lemma Br_neq_left': "l \<in> bt(A) ==> (!!x r. Br(x, l, r) \<noteq> l)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    30
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    31
  apply (induct set: bt)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    32
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    33
  apply auto
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    34
  done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    35
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    36
lemma Br_iff: "Br(a, l, r) = Br(a', l', r') <-> a = a' & l = l' & r = r'"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    37
  -- "Proving a freeness theorem."
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    38
  by (blast elim!: bt.free_elims)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    39
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    40
inductive_cases BrE: "Br(a, l, r) \<in> bt(A)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    41
  -- "An elimination rule, for type-checking."
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    42
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    43
text {*
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    44
@{thm[display] BrE[no_vars]}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    45
\rulename{BrE}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    46
*};
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    47
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    48
subsection{*Powerset example*}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    49
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    50
lemma Pow_mono: "A<=B  ==>  Pow(A) <= Pow(B)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    51
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    52
apply (rule subsetI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    53
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    54
apply (rule PowI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    55
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    56
apply (drule PowD)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    57
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    58
apply (erule subset_trans, assumption)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    59
done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    60
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    61
lemma "Pow(A Int B) = Pow(A) Int Pow(B)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    62
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    63
apply (rule equalityI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    64
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    65
apply (rule Int_greatest)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    66
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    67
apply (rule Int_lower1 [THEN Pow_mono])
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    68
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    69
apply (rule Int_lower2 [THEN Pow_mono])
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    70
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    71
apply (rule subsetI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    72
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    73
apply (erule IntE)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    74
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    75
apply (rule PowI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    76
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    77
apply (drule PowD)+
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    78
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    79
apply (rule Int_greatest, assumption+)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    80
done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    81
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    82
text{*Trying again from the beginning in order to use @{text blast}*}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    83
lemma "Pow(A Int B) = Pow(A) Int Pow(B)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    84
by blast
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    85
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    86
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    87
lemma "C<=D ==> Union(C) <= Union(D)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    88
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    89
apply (rule subsetI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    90
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    91
apply (erule UnionE)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    92
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    93
apply (rule UnionI)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    94
apply (erule subsetD, assumption, assumption)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    95
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    96
done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    97
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    98
text{*Trying again from the beginning in order to prove from the definitions*}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
    99
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   100
lemma "C<=D ==> Union(C) <= Union(D)"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   101
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   102
apply (rule Union_least)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   103
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   104
apply (rule Union_upper)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   105
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   106
apply (erule subsetD, assumption)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   107
done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   108
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   109
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   110
lemma "[| a:A;  f: A->B;  g: C->D;  A Int C = 0 |] ==> (f Un g)`a = f`a"
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   111
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   112
apply (rule apply_equality)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   113
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   114
apply (rule UnI1)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   115
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   116
apply (rule apply_Pair, assumption+)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   117
  --{* @{subgoals[display,indent=0,margin=65]} *}
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   118
apply (rule fun_disjoint_Un, assumption+)
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   119
done
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   120
12f6f18e7afc For the Isar version of the ZF logics manual
paulson
parents:
diff changeset
   121
end