src/HOL/Induct/QuoDataType.thy
changeset 15152 5c4d3f10ac5a
parent 15120 f0359f75682e
child 15169 2b5da07a0b89
equal deleted inserted replaced
15151:429666b09783 15152:5c4d3f10ac5a
   116 theorem msgrel_imp_eqv_freeright:
   116 theorem msgrel_imp_eqv_freeright:
   117      "U \<sim> V \<Longrightarrow> freeright U \<sim> freeright V"
   117      "U \<sim> V \<Longrightarrow> freeright U \<sim> freeright V"
   118 by (erule msgrel.induct, auto intro: msgrel.intros)
   118 by (erule msgrel.induct, auto intro: msgrel.intros)
   119 
   119 
   120 
   120 
   121 subsubsection{*The Discriminator for Nonces*}
   121 subsubsection{*The Discriminator for Constructors*}
   122 
   122 
   123 text{*A function to identify nonces*}
   123 text{*A function to distinguish nonces, mpairs and encryptions*}
   124 consts isNONCE :: "freemsg \<Rightarrow> bool"
   124 consts freediscrim :: "freemsg \<Rightarrow> int"
   125 primrec
   125 primrec
   126    "isNONCE (NONCE N) = True"
   126    "freediscrim (NONCE N) = 0"
   127    "isNONCE (MPAIR X Y) = False"
   127    "freediscrim (MPAIR X Y) = 1"
   128    "isNONCE (CRYPT K X) = isNONCE X"
   128    "freediscrim (CRYPT K X) = freediscrim X + 2"
   129    "isNONCE (DECRYPT K X) = isNONCE X"
   129    "freediscrim (DECRYPT K X) = freediscrim X - 2"
   130 
   130 
   131 text{*This theorem helps us prove @{term "Nonce N \<noteq> MPair X Y"}*}
   131 text{*This theorem helps us prove @{term "Nonce N \<noteq> MPair X Y"}*}
   132 theorem msgrel_imp_eq_isNONCE:
   132 theorem msgrel_imp_eq_freediscrim:
   133      "U \<sim> V \<Longrightarrow> isNONCE U = isNONCE V"
   133      "U \<sim> V \<Longrightarrow> freediscrim U = freediscrim V"
   134 by (erule msgrel.induct, auto)
   134 by (erule msgrel.induct, auto)
   135 
   135 
   136 
   136 
   137 subsection{*The Initial Algebra: A Quotiented Message Type*}
   137 subsection{*The Initial Algebra: A Quotiented Message Type*}
   138 
   138 
   358 
   358 
   359 theorem MPair_MPair_eq [iff]: "(MPair X Y = MPair X' Y') = (X=X' & Y=Y')" 
   359 theorem MPair_MPair_eq [iff]: "(MPair X Y = MPair X' Y') = (X=X' & Y=Y')" 
   360 by (blast dest: MPair_imp_eq_left MPair_imp_eq_right)
   360 by (blast dest: MPair_imp_eq_left MPair_imp_eq_right)
   361 
   361 
   362 lemma NONCE_neqv_MPAIR: "NONCE m \<sim> MPAIR X Y \<Longrightarrow> False"
   362 lemma NONCE_neqv_MPAIR: "NONCE m \<sim> MPAIR X Y \<Longrightarrow> False"
   363 by (drule msgrel_imp_eq_isNONCE, simp)
   363 by (drule msgrel_imp_eq_freediscrim, simp)
   364 
   364 
   365 theorem Nonce_neq_MPair [iff]: "Nonce N \<noteq> MPair X Y"
   365 theorem Nonce_neq_MPair [iff]: "Nonce N \<noteq> MPair X Y"
   366 apply (cases X, cases Y) 
   366 apply (cases X, cases Y) 
   367 apply (simp add: Nonce_def MPair) 
   367 apply (simp add: Nonce_def MPair) 
   368 apply (blast dest: NONCE_neqv_MPAIR) 
   368 apply (blast dest: NONCE_neqv_MPAIR) 
   369 done
   369 done
       
   370 
       
   371 text{*Example suggested by a referee*}
       
   372 theorem Crypt_Nonce_neq_Nonce: "Crypt K (Nonce M) \<noteq> Nonce N" 
       
   373 by (auto simp add: Nonce_def Crypt dest: msgrel_imp_eq_freediscrim)  
       
   374 
       
   375 text{*...and many similar results*}
       
   376 theorem Crypt_Nonce_neq_Nonce: "Crypt K (Crypt K' (Nonce M)) \<noteq> Nonce N" 
       
   377 by (auto simp add: Nonce_def Crypt dest: msgrel_imp_eq_freediscrim)  
   370 
   378 
   371 theorem Crypt_Crypt_eq [iff]: "(Crypt K X = Crypt K X') = (X=X')" 
   379 theorem Crypt_Crypt_eq [iff]: "(Crypt K X = Crypt K X') = (X=X')" 
   372 proof
   380 proof
   373   assume "Crypt K X = Crypt K X'"
   381   assume "Crypt K X = Crypt K X'"
   374   hence "Decrypt K (Crypt K X) = Decrypt K (Crypt K X')" by simp
   382   hence "Decrypt K (Crypt K X) = Decrypt K (Crypt K X')" by simp
   413     with D [of "Abs_Msg (msgrel `` {X})"]
   421     with D [of "Abs_Msg (msgrel `` {X})"]
   414     show ?case by (simp add: Decrypt)
   422     show ?case by (simp add: Decrypt)
   415   qed
   423   qed
   416 qed
   424 qed
   417 
   425 
       
   426 
       
   427 subsection{*The Abstract Discriminator*}
       
   428 
       
   429 text{*However, as @{text Crypt_Nonce_neq_Nonce} above illustrates, we don't
       
   430 need this function in order to prove discrimination theorems.*}
       
   431 
       
   432 constdefs
       
   433   discrim :: "msg \<Rightarrow> int"
       
   434    "discrim X == contents (\<Union>U \<in> Rep_Msg X. {freediscrim U})"
       
   435 
       
   436 lemma discrim_congruent: "congruent msgrel (\<lambda>U. {freediscrim U})"
       
   437 by (simp add: congruent_def msgrel_imp_eq_freediscrim) 
       
   438 
       
   439 text{*Now prove the four equations for @{term discrim}*}
       
   440 
       
   441 lemma discrim_Nonce [simp]: "discrim (Nonce N) = 0"
       
   442 by (simp add: discrim_def Nonce_def 
       
   443               UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
       
   444 
       
   445 lemma discrim_MPair [simp]: "discrim (MPair X Y) = 1"
       
   446 apply (cases X, cases Y) 
       
   447 apply (simp add: discrim_def MPair 
       
   448                  UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
       
   449 done
       
   450 
       
   451 lemma discrim_Crypt [simp]: "discrim (Crypt K X) = discrim X + 2"
       
   452 apply (cases X) 
       
   453 apply (simp add: discrim_def Crypt
       
   454                  UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
       
   455 done
       
   456 
       
   457 lemma discrim_Decrypt [simp]: "discrim (Decrypt K X) = discrim X - 2"
       
   458 apply (cases X) 
       
   459 apply (simp add: discrim_def Decrypt
       
   460                  UN_equiv_class [OF equiv_msgrel discrim_congruent]) 
       
   461 done
       
   462 
       
   463 
   418 end
   464 end
   419 
   465