src/ZF/Integ/Int.thy
changeset 15182 5cea84e10f3e
parent 14565 c6dc17aab88a
child 16417 9bc16273c2d4
equal deleted inserted replaced
15181:8d9575d1caa7 15182:5cea84e10f3e
   200 by (simp add: zle_def)
   200 by (simp add: zle_def)
   201 
   201 
   202 
   202 
   203 subsection{*@{term zminus}: unary negation on @{term int}*}
   203 subsection{*@{term zminus}: unary negation on @{term int}*}
   204 
   204 
   205 lemma zminus_congruent: "congruent(intrel, %<x,y>. intrel``{<y,x>})"
   205 lemma zminus_congruent: "(%<x,y>. intrel``{<y,x>}) respects intrel"
   206 by (auto simp add: congruent_def add_ac)
   206 by (auto simp add: congruent_def add_ac)
   207 
   207 
   208 lemma raw_zminus_type: "z : int ==> raw_zminus(z) : int"
   208 lemma raw_zminus_type: "z : int ==> raw_zminus(z) : int"
   209 apply (simp add: int_def raw_zminus_def)
   209 apply (simp add: int_def raw_zminus_def)
   210 apply (typecheck add: UN_equiv_class_type [OF equiv_intrel zminus_congruent])
   210 apply (typecheck add: UN_equiv_class_type [OF equiv_intrel zminus_congruent])
   274 subsection{*@{term nat_of}: Coercion of an Integer to a Natural Number*}
   274 subsection{*@{term nat_of}: Coercion of an Integer to a Natural Number*}
   275 
   275 
   276 lemma nat_of_intify [simp]: "nat_of(intify(z)) = nat_of(z)"
   276 lemma nat_of_intify [simp]: "nat_of(intify(z)) = nat_of(z)"
   277 by (simp add: nat_of_def)
   277 by (simp add: nat_of_def)
   278 
   278 
   279 lemma nat_of_congruent: "congruent(intrel, \<lambda>x. (\<lambda>\<langle>x,y\<rangle>. x #- y)(x))"
   279 lemma nat_of_congruent: "(\<lambda>x. (\<lambda>\<langle>x,y\<rangle>. x #- y)(x)) respects intrel"
   280 by (auto simp add: congruent_def split add: nat_diff_split)
   280 by (auto simp add: congruent_def split add: nat_diff_split)
   281 
   281 
   282 lemma raw_nat_of: 
   282 lemma raw_nat_of: 
   283     "[| x\<in>nat;  y\<in>nat |] ==> raw_nat_of(intrel``{<x,y>}) = x#-y"
   283     "[| x\<in>nat;  y\<in>nat |] ==> raw_nat_of(intrel``{<x,y>}) = x#-y"
   284 by (simp add: raw_nat_of_def UN_equiv_class [OF equiv_intrel nat_of_congruent])
   284 by (simp add: raw_nat_of_def UN_equiv_class [OF equiv_intrel nat_of_congruent])
   367 
   367 
   368 subsection{*@{term zadd}: addition on int*}
   368 subsection{*@{term zadd}: addition on int*}
   369 
   369 
   370 text{*Congruence Property for Addition*}
   370 text{*Congruence Property for Addition*}
   371 lemma zadd_congruent2: 
   371 lemma zadd_congruent2: 
   372     "congruent2(intrel, %z1 z2.                       
   372     "(%z1 z2. let <x1,y1>=z1; <x2,y2>=z2                  
   373           let <x1,y1>=z1; <x2,y2>=z2                  
   373                             in intrel``{<x1#+x2, y1#+y2>})
   374                             in intrel``{<x1#+x2, y1#+y2>})"
   374      respects2 intrel"
   375 apply (simp add: congruent2_def)
   375 apply (simp add: congruent2_def)
   376 (*Proof via congruent2_commuteI seems longer*)
   376 (*Proof via congruent2_commuteI seems longer*)
   377 apply safe
   377 apply safe
   378 apply (simp (no_asm_simp) add: add_assoc Let_def)
   378 apply (simp (no_asm_simp) add: add_assoc Let_def)
   379 (*The rest should be trivial, but rearranging terms is hard
   379 (*The rest should be trivial, but rearranging terms is hard
   394 
   394 
   395 lemma raw_zadd: 
   395 lemma raw_zadd: 
   396   "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]               
   396   "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]               
   397    ==> raw_zadd (intrel``{<x1,y1>}, intrel``{<x2,y2>}) =   
   397    ==> raw_zadd (intrel``{<x1,y1>}, intrel``{<x2,y2>}) =   
   398        intrel `` {<x1#+x2, y1#+y2>}"
   398        intrel `` {<x1#+x2, y1#+y2>}"
   399 apply (simp add: raw_zadd_def UN_equiv_class2 [OF equiv_intrel zadd_congruent2])
   399 apply (simp add: raw_zadd_def 
       
   400              UN_equiv_class2 [OF equiv_intrel equiv_intrel zadd_congruent2])
   400 apply (simp add: Let_def)
   401 apply (simp add: Let_def)
   401 done
   402 done
   402 
   403 
   403 lemma zadd: 
   404 lemma zadd: 
   404   "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]          
   405   "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]          
   480 
   481 
   481 subsection{*@{term zmult}: Integer Multiplication*}
   482 subsection{*@{term zmult}: Integer Multiplication*}
   482 
   483 
   483 text{*Congruence property for multiplication*}
   484 text{*Congruence property for multiplication*}
   484 lemma zmult_congruent2:
   485 lemma zmult_congruent2:
   485     "congruent2(intrel, %p1 p2.                  
   486     "(%p1 p2. split(%x1 y1. split(%x2 y2.      
   486                 split(%x1 y1. split(%x2 y2.      
   487                     intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1))
   487                     intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1))"
   488      respects2 intrel"
   488 apply (rule equiv_intrel [THEN congruent2_commuteI], auto)
   489 apply (rule equiv_intrel [THEN congruent2_commuteI], auto)
   489 (*Proof that zmult is congruent in one argument*)
   490 (*Proof that zmult is congruent in one argument*)
   490 apply (rename_tac x y)
   491 apply (rename_tac x y)
   491 apply (frule_tac t = "%u. x#*u" in sym [THEN subst_context])
   492 apply (frule_tac t = "%u. x#*u" in sym [THEN subst_context])
   492 apply (drule_tac t = "%u. y#*u" in subst_context)
   493 apply (drule_tac t = "%u. y#*u" in subst_context)
   506 
   507 
   507 lemma raw_zmult: 
   508 lemma raw_zmult: 
   508      "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]     
   509      "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]     
   509       ==> raw_zmult(intrel``{<x1,y1>}, intrel``{<x2,y2>}) =      
   510       ==> raw_zmult(intrel``{<x1,y1>}, intrel``{<x2,y2>}) =      
   510           intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}"
   511           intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}"
   511 by (simp add: raw_zmult_def UN_equiv_class2 [OF equiv_intrel zmult_congruent2])
   512 by (simp add: raw_zmult_def 
       
   513            UN_equiv_class2 [OF equiv_intrel equiv_intrel zmult_congruent2])
   512 
   514 
   513 lemma zmult: 
   515 lemma zmult: 
   514      "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]     
   516      "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]     
   515       ==> (intrel``{<x1,y1>}) $* (intrel``{<x2,y2>}) =      
   517       ==> (intrel``{<x1,y1>}) $* (intrel``{<x2,y2>}) =      
   516           intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}"
   518           intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}"