src/ZF/ex/Integ.ML
changeset 4152 451104c223e2
parent 4091 771b1f6422a8
child 5068 fb28eaa07e01
equal deleted inserted replaced
4151:5c19cd418c33 4152:451104c223e2
    92 
    92 
    93 (**** zminus: unary negation on integ ****)
    93 (**** zminus: unary negation on integ ****)
    94 
    94 
    95 goalw Integ.thy [congruent_def]
    95 goalw Integ.thy [congruent_def]
    96     "congruent(intrel, %<x,y>. intrel``{<y,x>})";
    96     "congruent(intrel, %<x,y>. intrel``{<y,x>})";
    97 by (safe_tac (claset()));
    97 by Safe_tac;
    98 by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
    98 by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
    99 qed "zminus_congruent";
    99 qed "zminus_congruent";
   100 
   100 
   101 (*Resolve th against the corresponding facts for zminus*)
   101 (*Resolve th against the corresponding facts for zminus*)
   102 val zminus_ize = RSLIST [equiv_intrel, zminus_congruent];
   102 val zminus_ize = RSLIST [equiv_intrel, zminus_congruent];
   108 qed "zminus_type";
   108 qed "zminus_type";
   109 
   109 
   110 goalw Integ.thy [integ_def,zminus_def]
   110 goalw Integ.thy [integ_def,zminus_def]
   111     "!!z w. [| $~z = $~w;  z: integ;  w: integ |] ==> z=w";
   111     "!!z w. [| $~z = $~w;  z: integ;  w: integ |] ==> z=w";
   112 by (etac (zminus_ize UN_equiv_class_inject) 1);
   112 by (etac (zminus_ize UN_equiv_class_inject) 1);
   113 by (safe_tac (claset()));
   113 by Safe_tac;
   114 (*The setloop is only needed because assumptions are in the wrong order!*)
   114 (*The setloop is only needed because assumptions are in the wrong order!*)
   115 by (asm_full_simp_tac (simpset() addsimps add_ac
   115 by (asm_full_simp_tac (simpset() addsimps add_ac
   116                        setloop dtac eq_intrelD) 1);
   116                        setloop dtac eq_intrelD) 1);
   117 qed "zminus_inject";
   117 qed "zminus_inject";
   118 
   118 
   133 
   133 
   134 (**** znegative: the test for negative integers ****)
   134 (**** znegative: the test for negative integers ****)
   135 
   135 
   136 (*No natural number is negative!*)
   136 (*No natural number is negative!*)
   137 goalw Integ.thy [znegative_def, znat_def]  "~ znegative($# n)";
   137 goalw Integ.thy [znegative_def, znat_def]  "~ znegative($# n)";
   138 by (safe_tac (claset()));
   138 by Safe_tac;
   139 by (dres_inst_tac [("psi", "?lhs=?rhs")] asm_rl 1);
   139 by (dres_inst_tac [("psi", "?lhs=?rhs")] asm_rl 1);
   140 by (dres_inst_tac [("psi", "?lhs<?rhs")] asm_rl 1);
   140 by (dres_inst_tac [("psi", "?lhs<?rhs")] asm_rl 1);
   141 by (fast_tac (claset() addss
   141 by (fast_tac (claset() addss
   142               (simpset() addsimps [add_le_self2 RS le_imp_not_lt])) 1);
   142               (simpset() addsimps [add_le_self2 RS le_imp_not_lt])) 1);
   143 qed "not_znegative_znat";
   143 qed "not_znegative_znat";
   153 
   153 
   154 (**** zmagnitude: magnitide of an integer, as a natural number ****)
   154 (**** zmagnitude: magnitide of an integer, as a natural number ****)
   155 
   155 
   156 goalw Integ.thy [congruent_def]
   156 goalw Integ.thy [congruent_def]
   157     "congruent(intrel, %<x,y>. (y#-x) #+ (x#-y))";
   157     "congruent(intrel, %<x,y>. (y#-x) #+ (x#-y))";
   158 by (safe_tac (claset()));
   158 by Safe_tac;
   159 by (ALLGOALS Asm_simp_tac);
   159 by (ALLGOALS Asm_simp_tac);
   160 by (etac rev_mp 1);
   160 by (etac rev_mp 1);
   161 by (res_inst_tac [("m","x1"),("n","y1")] diff_induct 1 THEN 
   161 by (res_inst_tac [("m","x1"),("n","y1")] diff_induct 1 THEN 
   162     REPEAT (assume_tac 1));
   162     REPEAT (assume_tac 1));
   163 by (Asm_simp_tac 3);
   163 by (Asm_simp_tac 3);
   207 goalw Integ.thy [congruent2_def]
   207 goalw Integ.thy [congruent2_def]
   208     "congruent2(intrel, %z1 z2.                      \
   208     "congruent2(intrel, %z1 z2.                      \
   209 \         let <x1,y1>=z1; <x2,y2>=z2                 \
   209 \         let <x1,y1>=z1; <x2,y2>=z2                 \
   210 \                           in intrel``{<x1#+x2, y1#+y2>})";
   210 \                           in intrel``{<x1#+x2, y1#+y2>})";
   211 (*Proof via congruent2_commuteI seems longer*)
   211 (*Proof via congruent2_commuteI seems longer*)
   212 by (safe_tac (claset()));
   212 by Safe_tac;
   213 by (asm_simp_tac (simpset() addsimps [add_assoc, Let_def]) 1);
   213 by (asm_simp_tac (simpset() addsimps [add_assoc, Let_def]) 1);
   214 (*The rest should be trivial, but rearranging terms is hard;
   214 (*The rest should be trivial, but rearranging terms is hard;
   215   add_ac does not help rewriting with the assumptions.*)
   215   add_ac does not help rewriting with the assumptions.*)
   216 by (res_inst_tac [("m1","x1a")] (add_left_commute RS ssubst) 1);
   216 by (res_inst_tac [("m1","x1a")] (add_left_commute RS ssubst) 1);
   217 by (res_inst_tac [("m1","x2a")] (add_left_commute RS ssubst) 3);
   217 by (res_inst_tac [("m1","x2a")] (add_left_commute RS ssubst) 3);
   303 goal Integ.thy 
   303 goal Integ.thy 
   304     "congruent2(intrel, %p1 p2.                 \
   304     "congruent2(intrel, %p1 p2.                 \
   305 \               split(%x1 y1. split(%x2 y2.     \
   305 \               split(%x1 y1. split(%x2 y2.     \
   306 \                   intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1))";
   306 \                   intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1))";
   307 by (rtac (equiv_intrel RS congruent2_commuteI) 1);
   307 by (rtac (equiv_intrel RS congruent2_commuteI) 1);
   308 by (safe_tac (claset()));
   308 by Safe_tac;
   309 by (ALLGOALS Asm_simp_tac);
   309 by (ALLGOALS Asm_simp_tac);
   310 (*Proof that zmult is congruent in one argument*)
   310 (*Proof that zmult is congruent in one argument*)
   311 by (asm_simp_tac 
   311 by (asm_simp_tac 
   312     (simpset() addsimps (add_ac @ [add_mult_distrib_left RS sym])) 2);
   312     (simpset() addsimps (add_ac @ [add_mult_distrib_left RS sym])) 2);
   313 by (asm_simp_tac
   313 by (asm_simp_tac