src/HOL/Integ/IntDef.thy
changeset 14532 43e44c8b03ab
parent 14496 aba569f1b1e0
child 14658 b1293d0f8d5f
equal deleted inserted replaced
14531:716c9def5614 14532:43e44c8b03ab
    35 
    35 
    36   Zero_int_def:  "0 == int 0"
    36   Zero_int_def:  "0 == int 0"
    37   One_int_def:   "1 == int 1"
    37   One_int_def:   "1 == int 1"
    38 
    38 
    39   minus_int_def:
    39   minus_int_def:
    40     "- z == contents (\<Union>(x,y) \<in> Rep_Integ(z). { Abs_Integ(intrel``{(y,x)}) })"
    40     "- z == Abs_Integ (\<Union>(x,y) \<in> Rep_Integ z. intrel``{(y,x)})"
    41 
    41 
    42   add_int_def:
    42   add_int_def:
    43    "z + w ==
    43    "z + w ==
    44        contents (\<Union>(x,y) \<in> Rep_Integ(z). \<Union>(u,v) \<in> Rep_Integ(w).
    44        Abs_Integ (\<Union>(x,y) \<in> Rep_Integ z. \<Union>(u,v) \<in> Rep_Integ w.
    45 		 { Abs_Integ(intrel``{(x+u, y+v)}) })"
    45 		 intrel``{(x+u, y+v)})"
    46 
    46 
    47   diff_int_def:  "z - (w::int) == z + (-w)"
    47   diff_int_def:  "z - (w::int) == z + (-w)"
    48 
    48 
    49   mult_int_def:
    49   mult_int_def:
    50    "z * w ==
    50    "z * w ==
    51        contents (\<Union>(x,y) \<in> Rep_Integ(z). \<Union>(u,v) \<in> Rep_Integ(w).
    51        Abs_Integ (\<Union>(x,y) \<in> Rep_Integ z. \<Union>(u,v) \<in> Rep_Integ w.
    52 		 { Abs_Integ(intrel``{(x*u + y*v, x*v + y*u)}) })"
    52 		  intrel``{(x*u + y*v, x*v + y*u)})"
    53 
    53 
    54   le_int_def:
    54   le_int_def:
    55    "z \<le> (w::int) == 
    55    "z \<le> (w::int) == 
    56     \<exists>x y u v. x+v \<le> u+y & (x,y) \<in> Rep_Integ z & (u,v) \<in> Rep_Integ w"
    56     \<exists>x y u v. x+v \<le> u+y & (x,y) \<in> Rep_Integ z & (u,v) \<in> Rep_Integ w"
    57 
    57 
    74 
    74 
    75 declare equiv_intrel_iff [simp]
    75 declare equiv_intrel_iff [simp]
    76 
    76 
    77 
    77 
    78 text{*All equivalence classes belong to set of representatives*}
    78 text{*All equivalence classes belong to set of representatives*}
    79 lemma intrel_in_integ [simp]: "intrel``{(x,y)} \<in> Integ"
    79 lemma [simp]: "intrel``{(x,y)} \<in> Integ"
    80 by (auto simp add: Integ_def intrel_def quotient_def)
    80 by (auto simp add: Integ_def intrel_def quotient_def)
    81 
    81 
    82 lemma inj_on_Abs_Integ: "inj_on Abs_Integ Integ"
    82 lemma inj_on_Abs_Integ: "inj_on Abs_Integ Integ"
    83 apply (rule inj_on_inverseI)
    83 apply (rule inj_on_inverseI)
    84 apply (erule Abs_Integ_inverse)
    84 apply (erule Abs_Integ_inverse)
   112 
   112 
   113 subsubsection{*Integer Unary Negation*}
   113 subsubsection{*Integer Unary Negation*}
   114 
   114 
   115 lemma minus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})"
   115 lemma minus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})"
   116 proof -
   116 proof -
   117   have "congruent intrel (\<lambda>(x,y). {Abs_Integ (intrel``{(y,x)})})"
   117   have "congruent intrel (\<lambda>(x,y). intrel``{(y,x)})"
   118     by (simp add: congruent_def) 
   118     by (simp add: congruent_def) 
   119   thus ?thesis
   119   thus ?thesis
   120     by (simp add: minus_int_def UN_equiv_class [OF equiv_intrel])
   120     by (simp add: minus_int_def UN_equiv_class [OF equiv_intrel])
   121 qed
   121 qed
   122 
   122 
   132 lemma add:
   132 lemma add:
   133      "Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) =
   133      "Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) =
   134       Abs_Integ (intrel``{(x+u, y+v)})"
   134       Abs_Integ (intrel``{(x+u, y+v)})"
   135 proof -
   135 proof -
   136   have "congruent2 intrel
   136   have "congruent2 intrel
   137         (\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). {Abs_Integ (intrel `` {(x+u, y+v)})}) w) z)"
   137         (\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). intrel `` {(x+u, y+v)}) w) z)"
   138     by (simp add: congruent2_def)
   138     by (simp add: congruent2_def)
   139   thus ?thesis
   139   thus ?thesis
   140     by (simp add: add_int_def UN_UN_split_split_eq
   140     by (simp add: add_int_def UN_UN_split_split_eq
   141                   UN_equiv_class2 [OF equiv_intrel])
   141                   UN_equiv_class2 [OF equiv_intrel])
   142 qed
   142 qed
   187 
   187 
   188 text{*Congruence property for multiplication*}
   188 text{*Congruence property for multiplication*}
   189 lemma mult_congruent2:
   189 lemma mult_congruent2:
   190      "congruent2 intrel
   190      "congruent2 intrel
   191         (%p1 p2. (%(x,y). (%(u,v).
   191         (%p1 p2. (%(x,y). (%(u,v).
   192                     { Abs_Integ(intrel``{(x*u + y*v, x*v + y*u)}) }) p2) p1)"
   192                     intrel``{(x*u + y*v, x*v + y*u)}) p2) p1)"
   193 apply (rule equiv_intrel [THEN congruent2_commuteI])
   193 apply (rule equiv_intrel [THEN congruent2_commuteI])
   194 apply (auto simp add: congruent_def mult_ac)  
   194  apply (force simp add: mult_ac, clarify) 
       
   195 apply (simp add: congruent_def mult_ac)  
   195 apply (rename_tac u v w x y z)
   196 apply (rename_tac u v w x y z)
   196 apply (subgoal_tac "u*y + x*y = w*y + v*y  &  u*z + x*z = w*z + v*z")
   197 apply (subgoal_tac "u*y + x*y = w*y + v*y  &  u*z + x*z = w*z + v*z")
   197 apply (simp add: mult_ac, arith)
   198 apply (simp add: mult_ac, arith)
   198 apply (simp add: add_mult_distrib [symmetric])
   199 apply (simp add: add_mult_distrib [symmetric])
   199 done
   200 done
       
   201 
   200 
   202 
   201 lemma mult:
   203 lemma mult:
   202      "Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) =
   204      "Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) =
   203       Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})"
   205       Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})"
   204 by (simp add: mult_int_def UN_UN_split_split_eq mult_congruent2
   206 by (simp add: mult_int_def UN_UN_split_split_eq mult_congruent2
   389 
   391 
   390 subsection{*Magnitide of an Integer, as a Natural Number: @{term nat}*}
   392 subsection{*Magnitide of an Integer, as a Natural Number: @{term nat}*}
   391 
   393 
   392 constdefs
   394 constdefs
   393    nat  :: "int => nat"
   395    nat  :: "int => nat"
   394     "nat z == contents (\<Union>(x,y) \<in> Rep_Integ(z). { x-y })"
   396     "nat z == contents (\<Union>(x,y) \<in> Rep_Integ z. { x-y })"
   395 
   397 
   396 lemma nat: "nat (Abs_Integ (intrel``{(x,y)})) = x-y"
   398 lemma nat: "nat (Abs_Integ (intrel``{(x,y)})) = x-y"
   397 proof -
   399 proof -
   398   have "congruent intrel (\<lambda>(x,y). {x-y})"
   400   have "congruent intrel (\<lambda>(x,y). {x-y})"
   399     by (simp add: congruent_def, arith) 
   401     by (simp add: congruent_def, arith) 
   687 
   689 
   688 subsection{*Embedding of the Integers into any Ring: @{term of_int}*}
   690 subsection{*Embedding of the Integers into any Ring: @{term of_int}*}
   689 
   691 
   690 constdefs
   692 constdefs
   691    of_int :: "int => 'a::ring"
   693    of_int :: "int => 'a::ring"
   692    "of_int z == contents (\<Union>(i,j) \<in> Rep_Integ(z). { of_nat i - of_nat j })"
   694    "of_int z == contents (\<Union>(i,j) \<in> Rep_Integ z. { of_nat i - of_nat j })"
   693 
   695 
   694 
   696 
   695 lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j"
   697 lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j"
   696 proof -
   698 proof -
   697   have "congruent intrel (\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) })"
   699   have "congruent intrel (\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) })"