src/HOL/Induct/QuoDataType.thy
author blanchet
Thu, 11 Sep 2014 19:32:36 +0200
changeset 58310 91ea607a34d8
parent 58305 57752a91eec4
child 58889 5b7a9633cfa8
permissions -rw-r--r--
updated news
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 40825
diff changeset
     1
(*  Title:      HOL/Induct/QuoDataType.thy
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     3
    Copyright   2004  University of Cambridge
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     4
*)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     5
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     6
header{*Defining an Initial Algebra by Quotienting a Free Algebra*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     7
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15172
diff changeset
     8
theory QuoDataType imports Main begin
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
     9
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    10
subsection{*Defining the Free Algebra*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    11
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    12
text{*Messages with encryption and decryption as free constructors.*}
58310
91ea607a34d8 updated news
blanchet
parents: 58305
diff changeset
    13
datatype
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    14
     freemsg = NONCE  nat
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 30198
diff changeset
    15
             | MPAIR  freemsg freemsg
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 30198
diff changeset
    16
             | CRYPT  nat freemsg  
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 30198
diff changeset
    17
             | DECRYPT  nat freemsg
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    18
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    19
text{*The equivalence relation, which makes encryption and decryption inverses
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    20
provided the keys are the same.
19736
wenzelm
parents: 18460
diff changeset
    21
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    22
The first two rules are the desired equations. The next four rules
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    23
make the equations applicable to subterms. The last two rules are symmetry
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    24
and transitivity.*}
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    25
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    26
inductive_set
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    27
  msgrel :: "(freemsg * freemsg) set"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    28
  and msg_rel :: "[freemsg, freemsg] => bool"  (infixl "\<sim>" 50)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    29
  where
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    30
    "X \<sim> Y == (X,Y) \<in> msgrel"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    31
  | CD:    "CRYPT K (DECRYPT K X) \<sim> X"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    32
  | DC:    "DECRYPT K (CRYPT K X) \<sim> X"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    33
  | NONCE: "NONCE N \<sim> NONCE N"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    34
  | MPAIR: "\<lbrakk>X \<sim> X'; Y \<sim> Y'\<rbrakk> \<Longrightarrow> MPAIR X Y \<sim> MPAIR X' Y'"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    35
  | CRYPT: "X \<sim> X' \<Longrightarrow> CRYPT K X \<sim> CRYPT K X'"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    36
  | DECRYPT: "X \<sim> X' \<Longrightarrow> DECRYPT K X \<sim> DECRYPT K X'"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    37
  | SYM:   "X \<sim> Y \<Longrightarrow> Y \<sim> X"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    38
  | TRANS: "\<lbrakk>X \<sim> Y; Y \<sim> Z\<rbrakk> \<Longrightarrow> X \<sim> Z"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    39
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    40
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    41
text{*Proving that it is an equivalence relation*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    42
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    43
lemma msgrel_refl: "X \<sim> X"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    44
  by (induct X) (blast intro: msgrel.intros)+
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    45
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    46
theorem equiv_msgrel: "equiv UNIV msgrel"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    47
proof -
30198
922f944f03b2 name changes
nipkow
parents: 23746
diff changeset
    48
  have "refl msgrel" by (simp add: refl_on_def msgrel_refl)
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    49
  moreover have "sym msgrel" by (simp add: sym_def, blast intro: msgrel.SYM)
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    50
  moreover have "trans msgrel" by (simp add: trans_def, blast intro: msgrel.TRANS)
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    51
  ultimately show ?thesis by (simp add: equiv_def)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    52
qed
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    53
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    54
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    55
subsection{*Some Functions on the Free Algebra*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    56
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    57
subsubsection{*The Set of Nonces*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    58
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    59
text{*A function to return the set of nonces present in a message.  It will
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    60
be lifted to the initial algrebra, to serve as an example of that process.*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    61
primrec freenonces :: "freemsg \<Rightarrow> nat set" where
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    62
  "freenonces (NONCE N) = {N}"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    63
| "freenonces (MPAIR X Y) = freenonces X \<union> freenonces Y"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    64
| "freenonces (CRYPT K X) = freenonces X"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    65
| "freenonces (DECRYPT K X) = freenonces X"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    66
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    67
text{*This theorem lets us prove that the nonces function respects the
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    68
equivalence relation.  It also helps us prove that Nonce
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    69
  (the abstract constructor) is injective*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    70
theorem msgrel_imp_eq_freenonces: "U \<sim> V \<Longrightarrow> freenonces U = freenonces V"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    71
  by (induct set: msgrel) auto
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    72
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    73
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    74
subsubsection{*The Left Projection*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    75
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    76
text{*A function to return the left part of the top pair in a message.  It will
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    77
be lifted to the initial algrebra, to serve as an example of that process.*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    78
primrec freeleft :: "freemsg \<Rightarrow> freemsg" where
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    79
  "freeleft (NONCE N) = NONCE N"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    80
| "freeleft (MPAIR X Y) = X"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    81
| "freeleft (CRYPT K X) = freeleft X"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    82
| "freeleft (DECRYPT K X) = freeleft X"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    83
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    84
text{*This theorem lets us prove that the left function respects the
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    85
equivalence relation.  It also helps us prove that MPair
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    86
  (the abstract constructor) is injective*}
14658
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
    87
theorem msgrel_imp_eqv_freeleft:
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
    88
     "U \<sim> V \<Longrightarrow> freeleft U \<sim> freeleft V"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    89
  by (induct set: msgrel) (auto intro: msgrel.intros)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    90
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    91
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    92
subsubsection{*The Right Projection*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    93
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
    94
text{*A function to return the right part of the top pair in a message.*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    95
primrec freeright :: "freemsg \<Rightarrow> freemsg" where
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    96
  "freeright (NONCE N) = NONCE N"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    97
| "freeright (MPAIR X Y) = Y"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    98
| "freeright (CRYPT K X) = freeright X"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
    99
| "freeright (DECRYPT K X) = freeright X"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   100
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   101
text{*This theorem lets us prove that the right function respects the
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   102
equivalence relation.  It also helps us prove that MPair
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   103
  (the abstract constructor) is injective*}
14658
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
   104
theorem msgrel_imp_eqv_freeright:
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
   105
     "U \<sim> V \<Longrightarrow> freeright U \<sim> freeright V"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   106
  by (induct set: msgrel) (auto intro: msgrel.intros)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   107
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   108
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   109
subsubsection{*The Discriminator for Constructors*}
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   110
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   111
text{*A function to distinguish nonces, mpairs and encryptions*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
   112
primrec freediscrim :: "freemsg \<Rightarrow> int" where
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
   113
  "freediscrim (NONCE N) = 0"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
   114
| "freediscrim (MPAIR X Y) = 1"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
   115
| "freediscrim (CRYPT K X) = freediscrim X + 2"
9e58f0499f57 modernized primrec
haftmann
parents: 32960
diff changeset
   116
| "freediscrim (DECRYPT K X) = freediscrim X - 2"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   117
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   118
text{*This theorem helps us prove @{term "Nonce N \<noteq> MPair X Y"}*}
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   119
theorem msgrel_imp_eq_freediscrim:
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   120
     "U \<sim> V \<Longrightarrow> freediscrim U = freediscrim V"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   121
  by (induct set: msgrel) auto
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   122
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   123
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   124
subsection{*The Initial Algebra: A Quotiented Message Type*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   125
45694
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 41959
diff changeset
   126
definition "Msg = UNIV//msgrel"
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 41959
diff changeset
   127
49834
b27bbb021df1 discontinued obsolete typedef (open) syntax;
wenzelm
parents: 45694
diff changeset
   128
typedef msg = Msg
45694
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 41959
diff changeset
   129
  morphisms Rep_Msg Abs_Msg
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 41959
diff changeset
   130
  unfolding Msg_def by (auto simp add: quotient_def)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   131
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   132
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   133
text{*The abstract message constructors*}
19736
wenzelm
parents: 18460
diff changeset
   134
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   135
  Nonce :: "nat \<Rightarrow> msg" where
19736
wenzelm
parents: 18460
diff changeset
   136
  "Nonce N = Abs_Msg(msgrel``{NONCE N})"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   137
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   138
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   139
  MPair :: "[msg,msg] \<Rightarrow> msg" where
19736
wenzelm
parents: 18460
diff changeset
   140
   "MPair X Y =
15120
f0359f75682e undid UN/INT syntax
nipkow
parents: 14658
diff changeset
   141
       Abs_Msg (\<Union>U \<in> Rep_Msg X. \<Union>V \<in> Rep_Msg Y. msgrel``{MPAIR U V})"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   142
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   143
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   144
  Crypt :: "[nat,msg] \<Rightarrow> msg" where
19736
wenzelm
parents: 18460
diff changeset
   145
   "Crypt K X =
15120
f0359f75682e undid UN/INT syntax
nipkow
parents: 14658
diff changeset
   146
       Abs_Msg (\<Union>U \<in> Rep_Msg X. msgrel``{CRYPT K U})"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   147
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   148
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   149
  Decrypt :: "[nat,msg] \<Rightarrow> msg" where
19736
wenzelm
parents: 18460
diff changeset
   150
   "Decrypt K X =
15120
f0359f75682e undid UN/INT syntax
nipkow
parents: 14658
diff changeset
   151
       Abs_Msg (\<Union>U \<in> Rep_Msg X. msgrel``{DECRYPT K U})"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   152
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   153
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   154
text{*Reduces equality of equivalence classes to the @{term msgrel} relation:
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   155
  @{term "(msgrel `` {x} = msgrel `` {y}) = ((x,y) \<in> msgrel)"} *}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   156
lemmas equiv_msgrel_iff = eq_equiv_class_iff [OF equiv_msgrel UNIV_I UNIV_I]
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   157
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   158
declare equiv_msgrel_iff [simp]
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   159
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   160
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   161
text{*All equivalence classes belong to set of representatives*}
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   162
lemma [simp]: "msgrel``{U} \<in> Msg"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   163
by (auto simp add: Msg_def quotient_def intro: msgrel_refl)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   164
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   165
lemma inj_on_Abs_Msg: "inj_on Abs_Msg Msg"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   166
apply (rule inj_on_inverseI)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   167
apply (erule Abs_Msg_inverse)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   168
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   169
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   170
text{*Reduces equality on abstractions to equality on representatives*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   171
declare inj_on_Abs_Msg [THEN inj_on_iff, simp]
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   172
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   173
declare Abs_Msg_inverse [simp]
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   174
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   175
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   176
subsubsection{*Characteristic Equations for the Abstract Constructors*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   177
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   178
lemma MPair: "MPair (Abs_Msg(msgrel``{U})) (Abs_Msg(msgrel``{V})) = 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   179
              Abs_Msg (msgrel``{MPAIR U V})"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   180
proof -
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   181
  have "(\<lambda>U V. msgrel `` {MPAIR U V}) respects2 msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   182
    by (auto simp add: congruent2_def msgrel.MPAIR)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   183
  thus ?thesis
14658
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
   184
    by (simp add: MPair_def UN_equiv_class2 [OF equiv_msgrel equiv_msgrel])
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   185
qed
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   186
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   187
lemma Crypt: "Crypt K (Abs_Msg(msgrel``{U})) = Abs_Msg (msgrel``{CRYPT K U})"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   188
proof -
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   189
  have "(\<lambda>U. msgrel `` {CRYPT K U}) respects msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   190
    by (auto simp add: congruent_def msgrel.CRYPT)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   191
  thus ?thesis
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   192
    by (simp add: Crypt_def UN_equiv_class [OF equiv_msgrel])
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   193
qed
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   194
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   195
lemma Decrypt:
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   196
     "Decrypt K (Abs_Msg(msgrel``{U})) = Abs_Msg (msgrel``{DECRYPT K U})"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   197
proof -
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   198
  have "(\<lambda>U. msgrel `` {DECRYPT K U}) respects msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   199
    by (auto simp add: congruent_def msgrel.DECRYPT)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   200
  thus ?thesis
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   201
    by (simp add: Decrypt_def UN_equiv_class [OF equiv_msgrel])
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   202
qed
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   203
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   204
text{*Case analysis on the representation of a msg as an equivalence class.*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   205
lemma eq_Abs_Msg [case_names Abs_Msg, cases type: msg]:
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   206
     "(!!U. z = Abs_Msg(msgrel``{U}) ==> P) ==> P"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   207
apply (rule Rep_Msg [of z, unfolded Msg_def, THEN quotientE])
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   208
apply (drule arg_cong [where f=Abs_Msg])
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   209
apply (auto simp add: Rep_Msg_inverse intro: msgrel_refl)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   210
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   211
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   212
text{*Establishing these two equations is the point of the whole exercise*}
14533
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   213
theorem CD_eq [simp]: "Crypt K (Decrypt K X) = X"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   214
by (cases X, simp add: Crypt Decrypt CD)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   215
14533
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   216
theorem DC_eq [simp]: "Decrypt K (Crypt K X) = X"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   217
by (cases X, simp add: Crypt Decrypt DC)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   218
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   219
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   220
subsection{*The Abstract Function to Return the Set of Nonces*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   221
19736
wenzelm
parents: 18460
diff changeset
   222
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   223
  nonces :: "msg \<Rightarrow> nat set" where
19736
wenzelm
parents: 18460
diff changeset
   224
   "nonces X = (\<Union>U \<in> Rep_Msg X. freenonces U)"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   225
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   226
lemma nonces_congruent: "freenonces respects msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   227
by (auto simp add: congruent_def msgrel_imp_eq_freenonces) 
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   228
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   229
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   230
text{*Now prove the four equations for @{term nonces}*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   231
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   232
lemma nonces_Nonce [simp]: "nonces (Nonce N) = {N}"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   233
by (simp add: nonces_def Nonce_def 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   234
              UN_equiv_class [OF equiv_msgrel nonces_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   235
 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   236
lemma nonces_MPair [simp]: "nonces (MPair X Y) = nonces X \<union> nonces Y"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   237
apply (cases X, cases Y) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   238
apply (simp add: nonces_def MPair 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   239
                 UN_equiv_class [OF equiv_msgrel nonces_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   240
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   241
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   242
lemma nonces_Crypt [simp]: "nonces (Crypt K X) = nonces X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   243
apply (cases X) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   244
apply (simp add: nonces_def Crypt
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   245
                 UN_equiv_class [OF equiv_msgrel nonces_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   246
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   247
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   248
lemma nonces_Decrypt [simp]: "nonces (Decrypt K X) = nonces X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   249
apply (cases X) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   250
apply (simp add: nonces_def Decrypt
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   251
                 UN_equiv_class [OF equiv_msgrel nonces_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   252
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   253
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   254
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   255
subsection{*The Abstract Function to Return the Left Part*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   256
19736
wenzelm
parents: 18460
diff changeset
   257
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   258
  left :: "msg \<Rightarrow> msg" where
19736
wenzelm
parents: 18460
diff changeset
   259
   "left X = Abs_Msg (\<Union>U \<in> Rep_Msg X. msgrel``{freeleft U})"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   260
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   261
lemma left_congruent: "(\<lambda>U. msgrel `` {freeleft U}) respects msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   262
by (auto simp add: congruent_def msgrel_imp_eqv_freeleft) 
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   263
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   264
text{*Now prove the four equations for @{term left}*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   265
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   266
lemma left_Nonce [simp]: "left (Nonce N) = Nonce N"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   267
by (simp add: left_def Nonce_def 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   268
              UN_equiv_class [OF equiv_msgrel left_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   269
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   270
lemma left_MPair [simp]: "left (MPair X Y) = X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   271
apply (cases X, cases Y) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   272
apply (simp add: left_def MPair 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   273
                 UN_equiv_class [OF equiv_msgrel left_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   274
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   275
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   276
lemma left_Crypt [simp]: "left (Crypt K X) = left X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   277
apply (cases X) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   278
apply (simp add: left_def Crypt
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   279
                 UN_equiv_class [OF equiv_msgrel left_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   280
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   281
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   282
lemma left_Decrypt [simp]: "left (Decrypt K X) = left X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   283
apply (cases X) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   284
apply (simp add: left_def Decrypt
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   285
                 UN_equiv_class [OF equiv_msgrel left_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   286
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   287
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   288
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   289
subsection{*The Abstract Function to Return the Right Part*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   290
19736
wenzelm
parents: 18460
diff changeset
   291
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   292
  right :: "msg \<Rightarrow> msg" where
19736
wenzelm
parents: 18460
diff changeset
   293
   "right X = Abs_Msg (\<Union>U \<in> Rep_Msg X. msgrel``{freeright U})"
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   294
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   295
lemma right_congruent: "(\<lambda>U. msgrel `` {freeright U}) respects msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   296
by (auto simp add: congruent_def msgrel_imp_eqv_freeright) 
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   297
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   298
text{*Now prove the four equations for @{term right}*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   299
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   300
lemma right_Nonce [simp]: "right (Nonce N) = Nonce N"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   301
by (simp add: right_def Nonce_def 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   302
              UN_equiv_class [OF equiv_msgrel right_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   303
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   304
lemma right_MPair [simp]: "right (MPair X Y) = Y"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   305
apply (cases X, cases Y) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   306
apply (simp add: right_def MPair 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   307
                 UN_equiv_class [OF equiv_msgrel right_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   308
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   309
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   310
lemma right_Crypt [simp]: "right (Crypt K X) = right X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   311
apply (cases X) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   312
apply (simp add: right_def Crypt
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   313
                 UN_equiv_class [OF equiv_msgrel right_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   314
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   315
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   316
lemma right_Decrypt [simp]: "right (Decrypt K X) = right X"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   317
apply (cases X) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   318
apply (simp add: right_def Decrypt
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   319
                 UN_equiv_class [OF equiv_msgrel right_congruent]) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   320
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   321
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   322
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   323
subsection{*Injectivity Properties of Some Constructors*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   324
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   325
lemma NONCE_imp_eq: "NONCE m \<sim> NONCE n \<Longrightarrow> m = n"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   326
by (drule msgrel_imp_eq_freenonces, simp)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   327
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   328
text{*Can also be proved using the function @{term nonces}*}
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   329
lemma Nonce_Nonce_eq [iff]: "(Nonce m = Nonce n) = (m = n)"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   330
by (auto simp add: Nonce_def msgrel_refl dest: NONCE_imp_eq)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   331
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   332
lemma MPAIR_imp_eqv_left: "MPAIR X Y \<sim> MPAIR X' Y' \<Longrightarrow> X \<sim> X'"
14658
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
   333
by (drule msgrel_imp_eqv_freeleft, simp)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   334
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   335
lemma MPair_imp_eq_left: 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   336
  assumes eq: "MPair X Y = MPair X' Y'" shows "X = X'"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   337
proof -
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   338
  from eq
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   339
  have "left (MPair X Y) = left (MPair X' Y')" by simp
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   340
  thus ?thesis by simp
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   341
qed
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   342
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   343
lemma MPAIR_imp_eqv_right: "MPAIR X Y \<sim> MPAIR X' Y' \<Longrightarrow> Y \<sim> Y'"
14658
b1293d0f8d5f congruent2 now allows different equiv relations
paulson
parents: 14565
diff changeset
   344
by (drule msgrel_imp_eqv_freeright, simp)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   345
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   346
lemma MPair_imp_eq_right: "MPair X Y = MPair X' Y' \<Longrightarrow> Y = Y'" 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   347
apply (cases X, cases X', cases Y, cases Y') 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   348
apply (simp add: MPair)
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   349
apply (erule MPAIR_imp_eqv_right)  
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   350
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   351
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   352
theorem MPair_MPair_eq [iff]: "(MPair X Y = MPair X' Y') = (X=X' & Y=Y')" 
14533
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   353
by (blast dest: MPair_imp_eq_left MPair_imp_eq_right)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   354
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   355
lemma NONCE_neqv_MPAIR: "NONCE m \<sim> MPAIR X Y \<Longrightarrow> False"
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   356
by (drule msgrel_imp_eq_freediscrim, simp)
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   357
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   358
theorem Nonce_neq_MPair [iff]: "Nonce N \<noteq> MPair X Y"
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   359
apply (cases X, cases Y) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   360
apply (simp add: Nonce_def MPair) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   361
apply (blast dest: NONCE_neqv_MPAIR) 
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   362
done
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   363
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   364
text{*Example suggested by a referee*}
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   365
theorem Crypt_Nonce_neq_Nonce: "Crypt K (Nonce M) \<noteq> Nonce N" 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   366
by (auto simp add: Nonce_def Crypt dest: msgrel_imp_eq_freediscrim)  
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   367
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   368
text{*...and many similar results*}
15172
73069e033a0b new example of a quotiented nested data type
paulson
parents: 15169
diff changeset
   369
theorem Crypt2_Nonce_neq_Nonce: "Crypt K (Crypt K' (Nonce M)) \<noteq> Nonce N" 
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   370
by (auto simp add: Nonce_def Crypt dest: msgrel_imp_eq_freediscrim)  
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   371
14533
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   372
theorem Crypt_Crypt_eq [iff]: "(Crypt K X = Crypt K X') = (X=X')" 
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   373
proof
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   374
  assume "Crypt K X = Crypt K X'"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   375
  hence "Decrypt K (Crypt K X) = Decrypt K (Crypt K X')" by simp
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   376
  thus "X = X'" by simp
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   377
next
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   378
  assume "X = X'"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   379
  thus "Crypt K X = Crypt K X'" by simp
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   380
qed
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   381
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   382
theorem Decrypt_Decrypt_eq [iff]: "(Decrypt K X = Decrypt K X') = (X=X')" 
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   383
proof
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   384
  assume "Decrypt K X = Decrypt K X'"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   385
  hence "Crypt K (Decrypt K X) = Crypt K (Decrypt K X')" by simp
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   386
  thus "X = X'" by simp
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   387
next
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   388
  assume "X = X'"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   389
  thus "Decrypt K X = Decrypt K X'" by simp
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   390
qed
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   391
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   392
lemma msg_induct [case_names Nonce MPair Crypt Decrypt, cases type: msg]:
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   393
  assumes N: "\<And>N. P (Nonce N)"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   394
      and M: "\<And>X Y. \<lbrakk>P X; P Y\<rbrakk> \<Longrightarrow> P (MPair X Y)"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   395
      and C: "\<And>K X. P X \<Longrightarrow> P (Crypt K X)"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   396
      and D: "\<And>K X. P X \<Longrightarrow> P (Decrypt K X)"
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   397
  shows "P msg"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   398
proof (cases msg)
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   399
  case (Abs_Msg U)
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   400
  have "P (Abs_Msg (msgrel `` {U}))"
14533
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   401
  proof (induct U)
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   402
    case (NONCE N) 
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   403
    with N show ?case by (simp add: Nonce_def) 
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   404
  next
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   405
    case (MPAIR X Y)
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   406
    with M [of "Abs_Msg (msgrel `` {X})" "Abs_Msg (msgrel `` {Y})"]
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   407
    show ?case by (simp add: MPair) 
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   408
  next
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   409
    case (CRYPT K X)
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   410
    with C [of "Abs_Msg (msgrel `` {X})"]
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   411
    show ?case by (simp add: Crypt) 
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   412
  next
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   413
    case (DECRYPT K X)
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   414
    with D [of "Abs_Msg (msgrel `` {X})"]
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   415
    show ?case by (simp add: Decrypt)
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   416
  qed
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   417
  with Abs_Msg show ?thesis by (simp only:)
14533
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   418
qed
32806c0afebf freeness theorems and induction rule
paulson
parents: 14527
diff changeset
   419
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   420
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   421
subsection{*The Abstract Discriminator*}
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   422
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   423
text{*However, as @{text Crypt_Nonce_neq_Nonce} above illustrates, we don't
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   424
need this function in order to prove discrimination theorems.*}
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   425
19736
wenzelm
parents: 18460
diff changeset
   426
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
   427
  discrim :: "msg \<Rightarrow> int" where
39910
10097e0a9dbd constant `contents` renamed to `the_elem`
haftmann
parents: 39246
diff changeset
   428
   "discrim X = the_elem (\<Union>U \<in> Rep_Msg X. {freediscrim U})"
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   429
15169
2b5da07a0b89 new "respects" syntax for quotienting
paulson
parents: 15152
diff changeset
   430
lemma discrim_congruent: "(\<lambda>U. {freediscrim U}) respects msgrel"
40825
c55ee3793712 adaptions to changes in Equiv_Relation.thy
haftmann
parents: 39910
diff changeset
   431
by (auto simp add: congruent_def msgrel_imp_eq_freediscrim) 
15152
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   432
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   433
text{*Now prove the four equations for @{term discrim}*}
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   434
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   435
lemma discrim_Nonce [simp]: "discrim (Nonce N) = 0"
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   436
by (simp add: discrim_def Nonce_def 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   437
              UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   438
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   439
lemma discrim_MPair [simp]: "discrim (MPair X Y) = 1"
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   440
apply (cases X, cases Y) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   441
apply (simp add: discrim_def MPair 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   442
                 UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   443
done
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   444
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   445
lemma discrim_Crypt [simp]: "discrim (Crypt K X) = discrim X + 2"
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   446
apply (cases X) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   447
apply (simp add: discrim_def Crypt
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   448
                 UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   449
done
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   450
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   451
lemma discrim_Decrypt [simp]: "discrim (Decrypt K X) = discrim X - 2"
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   452
apply (cases X) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   453
apply (simp add: discrim_def Decrypt
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   454
                 UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   455
done
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   456
5c4d3f10ac5a new examples
paulson
parents: 15120
diff changeset
   457
14527
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   458
end
bc9e5587d05a IsaMakefile
paulson
parents:
diff changeset
   459