src/ZF/Integ/Int.ML
changeset 9576 3df14e0a3a51
parent 9570 e16e168984e1
child 9578 ab26d6c8ebfe
equal deleted inserted replaced
9575:af71f5f4ca6b 9576:3df14e0a3a51
     6 The integers as equivalence classes over nat*nat.
     6 The integers as equivalence classes over nat*nat.
     7 
     7 
     8 Could also prove...
     8 Could also prove...
     9 "znegative(z) ==> $# zmagnitude(z) = $- z"
     9 "znegative(z) ==> $# zmagnitude(z) = $- z"
    10 "~ znegative(z) ==> $# zmagnitude(z) = z"
    10 "~ znegative(z) ==> $# zmagnitude(z) = z"
    11 $+ and $* are monotonic wrt $<
       
    12 *)
    11 *)
    13 
    12 
    14 AddSEs [quotientE];
    13 AddSEs [quotientE];
    15 
    14 
    16 (*** Proving that intrel is an equivalence relation ***)
    15 (*** Proving that intrel is an equivalence relation ***)
   239 	                          raw_zminus_zminus]) 1);
   238 	                          raw_zminus_zminus]) 1);
   240 qed "zminus_zminus_intify"; 
   239 qed "zminus_zminus_intify"; 
   241 
   240 
   242 Goalw [int_of_def] "$- ($#0) = $#0";
   241 Goalw [int_of_def] "$- ($#0) = $#0";
   243 by (simp_tac (simpset() addsimps [zminus]) 1);
   242 by (simp_tac (simpset() addsimps [zminus]) 1);
   244 qed "zminus_0";
   243 qed "zminus_int0";
   245 
   244 
   246 Addsimps [zminus_zminus_intify, zminus_0];
   245 Addsimps [zminus_zminus_intify, zminus_int0];
   247 
   246 
   248 Goal "z : int ==> $- ($- z) = z";
   247 Goal "z : int ==> $- ($- z) = z";
   249 by (Asm_simp_tac 1);
   248 by (Asm_simp_tac 1);
   250 qed "zminus_zminus";
   249 qed "zminus_zminus";
   251 
   250 
   325 qed "not_zneg_mag"; 
   324 qed "not_zneg_mag"; 
   326 
   325 
   327 Addsimps [not_zneg_mag];
   326 Addsimps [not_zneg_mag];
   328 
   327 
   329 Goalw [int_def, znegative_def, int_of_def]
   328 Goalw [int_def, znegative_def, int_of_def]
   330      "[| z: int; znegative(z) |] ==> EX n:nat. z = $- ($# succ(n))"; 
   329      "[| znegative(z); z: int |] ==> EX n:nat. z = $- ($# succ(n))"; 
   331 by (auto_tac(claset() addSDs [less_imp_succ_add], 
   330 by (auto_tac(claset() addSDs [less_imp_succ_add], 
   332 	     simpset() addsimps [zminus, image_singleton_iff]));
   331 	     simpset() addsimps [zminus, image_singleton_iff]));
   333 qed "zneg_int_of";
   332 qed "zneg_int_of";
   334 
   333 
   335 Goal "[| z: int; znegative(z) |] ==> $# (zmagnitude(z)) = $- z"; 
   334 Goal "[| znegative(z); z: int |] ==> $# (zmagnitude(z)) = $- z"; 
   336 by (dtac zneg_int_of 1);
   335 by (dtac zneg_int_of 1);
   337 by Auto_tac;
   336 by Auto_tac;
   338 qed "zneg_mag"; 
   337 qed "zneg_mag"; 
   339 
   338 
   340 Addsimps [zneg_mag];
   339 Addsimps [zneg_mag];
   616 qed "zadd_zmult_distrib";
   615 qed "zadd_zmult_distrib";
   617 
   616 
   618 Goal "w $* (z1 $+ z2) = (w $* z1) $+ (w $* z2)";
   617 Goal "w $* (z1 $+ z2) = (w $* z1) $+ (w $* z2)";
   619 by (simp_tac (simpset() addsimps [inst "z" "w" zmult_commute,
   618 by (simp_tac (simpset() addsimps [inst "z" "w" zmult_commute,
   620                                   zadd_zmult_distrib]) 1);
   619                                   zadd_zmult_distrib]) 1);
   621 qed "zadd_zmult_distrib_left";
   620 qed "zadd_zmult_distrib2";
   622 
   621 
   623 val int_typechecks =
   622 val int_typechecks =
   624     [int_of_type, zminus_type, zmagnitude_type, zadd_type, zmult_type];
   623     [int_of_type, zminus_type, zmagnitude_type, zadd_type, zmult_type];
   625 
   624 
   626 
   625 
   628 
   627 
   629 Goal "z $- w : int";
   628 Goal "z $- w : int";
   630 by (simp_tac (simpset() addsimps [zdiff_def]) 1);
   629 by (simp_tac (simpset() addsimps [zdiff_def]) 1);
   631 qed "zdiff_type";
   630 qed "zdiff_type";
   632 AddIffs [zdiff_type];  AddTCs [zdiff_type];
   631 AddIffs [zdiff_type];  AddTCs [zdiff_type];
   633 
       
   634 Goal "$#0 $- x = $-x";
       
   635 by (simp_tac (simpset() addsimps [zdiff_def]) 1);
       
   636 qed "zdiff_int0";
       
   637 
       
   638 Goal "x $- $#0 = intify(x)";
       
   639 by (simp_tac (simpset() addsimps [zdiff_def]) 1);
       
   640 qed "zdiff_int0_right";
       
   641 
       
   642 Goal "x $- x = $#0";
       
   643 by (simp_tac (simpset() addsimps [zdiff_def]) 1);
       
   644 qed "zdiff_self";
       
   645 
       
   646 Addsimps [zdiff_int0, zdiff_int0_right, zdiff_self];
       
   647 
   632 
   648 Goal "$- (z $- y) = y $- z";
   633 Goal "$- (z $- y) = y $- z";
   649 by (simp_tac (simpset() addsimps [zdiff_def, zadd_commute])1);
   634 by (simp_tac (simpset() addsimps [zdiff_def, zadd_commute])1);
   650 qed "zminus_zdiff_eq";
   635 qed "zminus_zdiff_eq";
   651 Addsimps [zminus_zdiff_eq];
   636 Addsimps [zminus_zdiff_eq];
   693 by Auto_tac;  
   678 by Auto_tac;  
   694 qed "zless_linear";
   679 qed "zless_linear";
   695 
   680 
   696 Goal "~ (z$<z)";
   681 Goal "~ (z$<z)";
   697 by (auto_tac (claset(), 
   682 by (auto_tac (claset(), 
   698               simpset() addsimps  [zless_def, znegative_def, int_of_def]));  
   683               simpset() addsimps  [zless_def, znegative_def, int_of_def,
       
   684                                    zdiff_def]));  
   699 by (rotate_tac 2 1);
   685 by (rotate_tac 2 1);
   700 by Auto_tac;  
   686 by Auto_tac;  
   701 qed "zless_not_refl";
   687 qed "zless_not_refl";
   702 AddIffs [zless_not_refl];
   688 AddIffs [zless_not_refl];
       
   689 
       
   690 Goal "[| x: int; y: int |] ==> (x ~= y) <-> (x $< y | y $< x)";
       
   691 by (cut_inst_tac [("z","x"),("w","y")] zless_linear 1);
       
   692 by Auto_tac;  
       
   693 qed "neq_iff_zless";
       
   694 
       
   695 Goal "w $< z ==> intify(w) ~= intify(z)";
       
   696 by Auto_tac;  
       
   697 by (subgoal_tac "~ (intify(w) $< intify(z))" 1);
       
   698 by (etac ssubst 2);
       
   699 by (Full_simp_tac 1);
       
   700 by Auto_tac;  
       
   701 qed "zless_imp_intify_neq";
   703 
   702 
   704 (*This lemma allows direct proofs of other <-properties*)
   703 (*This lemma allows direct proofs of other <-properties*)
   705 Goalw [zless_def, znegative_def, zdiff_def, int_def] 
   704 Goalw [zless_def, znegative_def, zdiff_def, int_def] 
   706     "[| w $< z; w: int; z: int |] ==> (EX n. z = w $+ $#(succ(n)))";
   705     "[| w $< z; w: int; z: int |] ==> (EX n. z = w $+ $#(succ(n)))";
   707 by (auto_tac (claset() addSDs [less_imp_succ_add], 
   706 by (auto_tac (claset() addSDs [less_imp_succ_add], 
   708               simpset() addsimps [zadd, zminus, int_of_def]));  
   707               simpset() addsimps [zadd, zminus, int_of_def]));  
   709 by (res_inst_tac [("x","k")] exI 1);
   708 by (res_inst_tac [("x","k")] exI 1);
   710 by (etac add_left_cancel 1);
   709 by (etac add_left_cancel 1);
   711 by Auto_tac;  
   710 by Auto_tac;  
   712 qed "zless_imp_succ_zadd_lemma";
   711 val lemma = result();
   713 
   712 
   714 Goal "w $< z ==> (EX n. w $+ $#(succ(n)) = intify(z))";
   713 Goal "w $< z ==> (EX n. w $+ $#(succ(n)) = intify(z))";
   715 by (subgoal_tac "intify(w) $< intify(z)" 1);
   714 by (subgoal_tac "intify(w) $< intify(z)" 1);
   716 by (dres_inst_tac [("w","intify(w)")] zless_imp_succ_zadd_lemma 1);
   715 by (dres_inst_tac [("w","intify(w)")] lemma 1);
   717 by Auto_tac;  
   716 by Auto_tac;  
   718 qed "zless_imp_succ_zadd";
   717 qed "zless_imp_succ_zadd";
   719 
   718 
   720 Goalw [zless_def, znegative_def, zdiff_def, int_def] 
   719 Goalw [zless_def, znegative_def, zdiff_def, int_def] 
   721     "w : int ==> w $< w $+ $# succ(n)";
   720     "w : int ==> w $< w $+ $# succ(n)";
   722 by (auto_tac (claset(), 
   721 by (auto_tac (claset(), 
   723               simpset() addsimps [zadd, zminus, int_of_def, image_iff]));  
   722               simpset() addsimps [zadd, zminus, int_of_def, image_iff]));  
   724 by (res_inst_tac [("x","0")] exI 1);
   723 by (res_inst_tac [("x","0")] exI 1);
   725 by Auto_tac;  
   724 by Auto_tac;  
   726 qed "zless_succ_zadd_lemma";
   725 val lemma = result();
   727 
   726 
   728 Goal "w $< w $+ $# succ(n)";
   727 Goal "w $< w $+ $# succ(n)";
   729 by (cut_facts_tac [intify_in_int RS zless_succ_zadd_lemma] 1);
   728 by (cut_facts_tac [intify_in_int RS lemma] 1);
   730 by Auto_tac;  
   729 by Auto_tac;  
   731 qed "zless_succ_zadd";
   730 qed "zless_succ_zadd";
   732 
   731 
   733 Goal "w $< z <-> (EX n. w $+ $#(succ(n)) = intify(z))";
   732 Goal "w $< z <-> (EX n. w $+ $#(succ(n)) = intify(z))";
   734 by (rtac iffI 1);
   733 by (rtac iffI 1);
   755 by (subgoal_tac "intify(x) $< intify(z)" 1);
   754 by (subgoal_tac "intify(x) $< intify(z)" 1);
   756 by (res_inst_tac [("y", "intify(y)")] zless_trans_lemma 2);
   755 by (res_inst_tac [("y", "intify(y)")] zless_trans_lemma 2);
   757 by Auto_tac;  
   756 by Auto_tac;  
   758 qed "zless_trans";
   757 qed "zless_trans";
   759 
   758 
       
   759 Goal "z $< w ==> ~ (w $< z)";
       
   760 by (blast_tac (claset() addDs [zless_trans]) 1);
       
   761 qed "zless_not_sym";
       
   762 
       
   763 (* [| z $< w; ~ P ==> w $< z |] ==> P *)
       
   764 bind_thm ("zless_asym", zless_not_sym RS swap);
       
   765 
       
   766 
   760 (*** "Less Than or Equals", $<= ***)
   767 (*** "Less Than or Equals", $<= ***)
   761 
   768 
   762 Goalw [zle_def] "z $<= z";
   769 Goalw [zle_def] "z $<= z";
   763 by Auto_tac;  
   770 by Auto_tac;  
   764 qed "zle_refl";
   771 qed "zle_refl";
   793 qed "zless_zle_trans";
   800 qed "zless_zle_trans";
   794 
   801 
   795 Goal "~ (z $< w) <-> (w $<= z)";
   802 Goal "~ (z $< w) <-> (w $<= z)";
   796 by (cut_inst_tac [("z","z"),("w","w")] zless_linear 1);
   803 by (cut_inst_tac [("z","z"),("w","w")] zless_linear 1);
   797 by (auto_tac (claset() addDs [zless_trans], simpset() addsimps [zle_def]));  
   804 by (auto_tac (claset() addDs [zless_trans], simpset() addsimps [zle_def]));  
   798 by (auto_tac (claset(), 
   805 by (auto_tac (claset() addSDs [zless_imp_intify_neq],  simpset()));
   799             simpset() addsimps [zless_def, zdiff_def, zadd_def, zminus_def]));
       
   800 by (fold_tac [zless_def, zdiff_def, zadd_def, zminus_def]);
       
   801 by Auto_tac;  
       
   802 qed "not_zless_iff_zle";
   806 qed "not_zless_iff_zle";
   803 
   807 
   804 Goal "~ (z $<= w) <-> (w $< z)";
   808 Goal "~ (z $<= w) <-> (w $< z)";
   805 by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1);
   809 by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1);
   806 qed "not_zle_iff_zless";
   810 qed "not_zle_iff_zless";
   807 
       
   808 
   811 
   809 
   812 
   810 (*** More subtraction laws (for zcompare_rls) ***)
   813 (*** More subtraction laws (for zcompare_rls) ***)
   811 
   814 
   812 Goal "(x $- y) $- z = x $- (y $+ z)";
   815 Goal "(x $- y) $- z = x $- (y $+ z)";
   917 qed "zadd_left_cancel_zle";
   920 qed "zadd_left_cancel_zle";
   918 
   921 
   919 Addsimps [zadd_right_cancel_zle, zadd_left_cancel_zle];
   922 Addsimps [zadd_right_cancel_zle, zadd_left_cancel_zle];
   920 
   923 
   921 
   924 
       
   925 (*** Comparison laws ***)
       
   926 
       
   927 Goal "($- x $< $- y) <-> (y $< x)";
       
   928 by (simp_tac (simpset() addsimps [zless_def, zdiff_def] @ zadd_ac) 1);
       
   929 qed "zminus_zless_zminus"; 
       
   930 Addsimps [zminus_zless_zminus];
       
   931 
       
   932 Goal "($- x $<= $- y) <-> (y $<= x)";
       
   933 by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1);
       
   934 qed "zminus_zle_zminus"; 
       
   935 Addsimps [zminus_zle_zminus];
       
   936 
       
   937 
   922 (*** More inequality lemmas ***)
   938 (*** More inequality lemmas ***)
   923 
   939 
   924 Goal "[| x: int;  y: int |] ==> (x = $- y) <-> (y = $- x)";
   940 Goal "[| x: int;  y: int |] ==> (x = $- y) <-> (y = $- x)";
   925 by Auto_tac;
   941 by Auto_tac;
   926 qed "equation_zminus";
   942 qed "equation_zminus";
   927 
   943 
   928 Goal "[| x: int;  y: int |] ==> ($- x = y) <-> ($- y = x)";
   944 Goal "[| x: int;  y: int |] ==> ($- x = y) <-> ($- y = x)";
   929 by Auto_tac;
   945 by Auto_tac;
   930 qed "zminus_equation";
   946 qed "zminus_equation";
       
   947 
       
   948 Goal "(intify(x) = $- y) <-> (intify(y) = $- x)";
       
   949 by (cut_inst_tac [("x","intify(x)"), ("y","intify(y)")] equation_zminus 1);
       
   950 by Auto_tac;
       
   951 qed "equation_zminus_intify";
       
   952 
       
   953 Goal "($- x = intify(y)) <-> ($- y = intify(x))";
       
   954 by (cut_inst_tac [("x","intify(x)"), ("y","intify(y)")] zminus_equation 1);
       
   955 by Auto_tac;
       
   956 qed "zminus_equation_intify";
       
   957 
       
   958 
       
   959 (** The next several equations are permutative: watch out! **)
       
   960 
       
   961 Goal "(x $< $- y) <-> (y $< $- x)";
       
   962 by (simp_tac (simpset() addsimps [zless_def, zdiff_def] @ zadd_ac) 1);
       
   963 qed "zless_zminus"; 
       
   964 
       
   965 Goal "($- x $< y) <-> ($- y $< x)";
       
   966 by (simp_tac (simpset() addsimps [zless_def, zdiff_def] @ zadd_ac) 1);
       
   967 qed "zminus_zless"; 
       
   968 
       
   969 Goal "(x $<= $- y) <-> (y $<= $- x)";
       
   970 by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym, 
       
   971                                   zminus_zless]) 1);
       
   972 qed "zle_zminus"; 
       
   973 
       
   974 Goal "($- x $<= y) <-> ($- y $<= x)";
       
   975 by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym, 
       
   976                                   zless_zminus]) 1);
       
   977 qed "zminus_zle";