diff -r 0c18df79b1c8 -r a642599ffdea src/ZF/IntDiv.thy --- a/src/ZF/IntDiv.thy Tue Sep 27 17:03:23 2022 +0100 +++ b/src/ZF/IntDiv.thy Tue Sep 27 17:46:52 2022 +0100 @@ -34,65 +34,65 @@ begin definition - quorem :: "[i,i] => o" where - "quorem \ % . + quorem :: "[i,i] \ o" where + "quorem \ \\a,b\ \q,r\. a = b$*q $+ r \ (#0$ #0$\r \ r$(#0$ b$ r $\ #0)" definition - adjust :: "[i,i] => i" where - "adjust(b) \ %. if #0 $\ r$-b then <#2$*q $+ #1,r$-b> + adjust :: "[i,i] \ i" where + "adjust(b) \ \\q,r\. if #0 $\ r$-b then <#2$*q $+ #1,r$-b> else <#2$*q,r>" (** the division algorithm **) definition - posDivAlg :: "i => i" where + posDivAlg :: "i \ i" where (*for the case a>=0, b>0*) -(*recdef posDivAlg "inv_image less_than (%(a,b). nat_of(a $- b $+ #1))"*) +(*recdef posDivAlg "inv_image less_than (\\a,b\. nat_of(a $- b $+ #1))"*) "posDivAlg(ab) \ - wfrec(measure(int*int, %. nat_of (a $- b $+ #1)), + wfrec(measure(int*int, \\a,b\. nat_of (a $- b $+ #1)), ab, - % f. if (a$#0) then <#0,a> + \\a,b\ f. if (a$#0) then <#0,a> else adjust(b, f ` ))" -(*for the case a<0, b>0*) +(*for the case a\0, b\0*) definition - negDivAlg :: "i => i" where -(*recdef negDivAlg "inv_image less_than (%(a,b). nat_of(- a $- b))"*) + negDivAlg :: "i \ i" where +(*recdef negDivAlg "inv_image less_than (\\a,b\. nat_of(- a $- b))"*) "negDivAlg(ab) \ - wfrec(measure(int*int, %. nat_of ($- a $- b)), + wfrec(measure(int*int, \\a,b\. nat_of ($- a $- b)), ab, - % f. if (#0 $\ a$+b | b$\#0) then <#-1,a$+b> + \\a,b\ f. if (#0 $\ a$+b | b$\#0) then <#-1,a$+b> else adjust(b, f ` ))" (*for the general case @{term"b\0"}*) definition - negateSnd :: "i => i" where - "negateSnd \ %. " + negateSnd :: "i \ i" where + "negateSnd \ \\q,r\. " (*The full division algorithm considers all possible signs for a, b including the special case a=0, b<0, because negDivAlg requires a<0*) definition - divAlg :: "i => i" where + divAlg :: "i \ i" where "divAlg \ - %. if #0 $\ a then - if #0 $\ b then posDivAlg () + \\a,b\. if #0 $\ a then + if #0 $\ b then posDivAlg (\a,b\) else if a=#0 then <#0,#0> else negateSnd (negDivAlg (<$-a,$-b>)) else - if #0$) + if #0$a,b\) else negateSnd (posDivAlg (<$-a,$-b>))" definition - zdiv :: "[i,i]=>i" (infixl \zdiv\ 70) where + zdiv :: "[i,i]\i" (infixl \zdiv\ 70) where "a zdiv b \ fst (divAlg ())" definition - zmod :: "[i,i]=>i" (infixl \zmod\ 70) where + zmod :: "[i,i]\i" (infixl \zmod\ 70) where "a zmod b \ snd (divAlg ())" @@ -380,7 +380,7 @@ lemma unique_quotient: - "\quorem (, ); quorem (, ); b \ int; b \ #0; + "\quorem (\a,b\, \q,r\); quorem (\a,b\, ); b \ int; b \ #0; q \ int; q' \ int\ \ q = q'" apply (simp add: split_ifs quorem_def neq_iff_zless) apply safe @@ -391,7 +391,7 @@ done lemma unique_remainder: - "\quorem (, ); quorem (, ); b \ int; b \ #0; + "\quorem (\a,b\, \q,r\); quorem (\a,b\, ); b \ int; b \ #0; q \ int; q' \ int; r \ int; r' \ int\ \ r = r'" apply (subgoal_tac "q = q'") @@ -404,7 +404,7 @@ the Division Algorithm for \a\0\ and \b>0\\ lemma adjust_eq [simp]: - "adjust(b, ) = (let diff = r$-b in + "adjust(b, \q,r\) = (let diff = r$-b in if #0 $\ diff then <#2$*q $+ #1,diff> else <#2$*q,r>)" by (simp add: Let_def adjust_def) @@ -421,7 +421,7 @@ lemma posDivAlg_eqn: "\#0 $< b; a \ int; b \ int\ \ - posDivAlg() = + posDivAlg(\a,b\) = (if a$ else adjust(b, posDivAlg ()))" apply (rule posDivAlg_unfold [THEN trans]) apply (simp add: vimage_iff not_zless_iff_zle [THEN iff_sym]) @@ -431,10 +431,10 @@ lemma posDivAlg_induct_lemma [rule_format]: assumes prem: "\a b. \a \ int; b \ int; - \ (a $< b | b $\ #0) \ P()\ \ P()" - shows " \ int*int \ P()" -using wf_measure [where A = "int*int" and f = "%.nat_of (a $- b $+ #1)"] -proof (induct "" arbitrary: u v rule: wf_induct) + \ (a $< b | b $\ #0) \ P()\ \ P(\a,b\)" + shows "\u,v\ \ int*int \ P(\u,v\)" +using wf_measure [where A = "int*int" and f = "\\a,b\.nat_of (a $- b $+ #1)"] +proof (induct "\u,v\" arbitrary: u v rule: wf_induct) case (step x) hence uv: "u \ int" "v \ int" by auto thus ?case @@ -452,7 +452,7 @@ and ih: "\a b. \a \ int; b \ int; \ (a $< b | b $\ #0) \ P(a, #2 $* b)\ \ P(a,b)" shows "P(u,v)" -apply (subgoal_tac "(%. P (x,y)) ()") +apply (subgoal_tac "(\\x,y\. P (x,y)) (\u,v\)") apply simp apply (rule posDivAlg_induct_lemma) apply (simp (no_asm_use)) @@ -526,7 +526,7 @@ (*Typechecking for posDivAlg*) lemma posDivAlg_type [rule_format]: - "\a \ int; b \ int\ \ posDivAlg() \ int * int" + "\a \ int; b \ int\ \ posDivAlg(\a,b\) \ int * int" apply (rule_tac u = "a" and v = "b" in posDivAlg_induct) apply assumption+ apply (case_tac "#0 $< ba") @@ -542,7 +542,7 @@ (*Correctness of posDivAlg: it computes quotients correctly*) lemma posDivAlg_correct [rule_format]: "\a \ int; b \ int\ - \ #0 $\ a \ #0 $< b \ quorem (, posDivAlg())" + \ #0 $\ a \ #0 $< b \ quorem (\a,b\, posDivAlg(\a,b\))" apply (rule_tac u = "a" and v = "b" in posDivAlg_induct) apply auto apply (simp_all add: quorem_def) @@ -576,7 +576,7 @@ lemma negDivAlg_eqn: "\#0 $< b; a \ int; b \ int\ \ - negDivAlg() = + negDivAlg(\a,b\) = (if #0 $\ a$+b then <#-1,a$+b> else adjust(b, negDivAlg ()))" apply (rule negDivAlg_unfold [THEN trans]) @@ -588,10 +588,10 @@ assumes prem: "\a b. \a \ int; b \ int; \ (#0 $\ a $+ b | b $\ #0) \ P()\ - \ P()" - shows " \ int*int \ P()" -using wf_measure [where A = "int*int" and f = "%.nat_of ($- a $- b)"] -proof (induct "" arbitrary: u v rule: wf_induct) + \ P(\a,b\)" + shows "\u,v\ \ int*int \ P(\u,v\)" +using wf_measure [where A = "int*int" and f = "\\a,b\.nat_of ($- a $- b)"] +proof (induct "\u,v\" arbitrary: u v rule: wf_induct) case (step x) hence uv: "u \ int" "v \ int" by auto thus ?case @@ -609,7 +609,7 @@ \ (#0 $\ a $+ b | b $\ #0) \ P(a, #2 $* b)\ \ P(a,b)" shows "P(u,v)" -apply (subgoal_tac " (%. P (x,y)) ()") +apply (subgoal_tac " (\\x,y\. P (x,y)) (\u,v\)") apply simp apply (rule negDivAlg_induct_lemma) apply (simp (no_asm_use)) @@ -620,7 +620,7 @@ (*Typechecking for negDivAlg*) lemma negDivAlg_type: - "\a \ int; b \ int\ \ negDivAlg() \ int * int" + "\a \ int; b \ int\ \ negDivAlg(\a,b\) \ int * int" apply (rule_tac u = "a" and v = "b" in negDivAlg_induct) apply assumption+ apply (case_tac "#0 $< ba") @@ -638,7 +638,7 @@ It doesn't work if a=0 because the 0/b=0 rather than -1*) lemma negDivAlg_correct [rule_format]: "\a \ int; b \ int\ - \ a $< #0 \ #0 $< b \ quorem (, negDivAlg())" + \ a $< #0 \ #0 $< b \ quorem (\a,b\, negDivAlg(\a,b\))" apply (rule_tac u = "a" and v = "b" in negDivAlg_induct) apply auto apply (simp_all add: quorem_def) @@ -687,7 +687,7 @@ apply (simp add: linear_arith_lemma integ_of_type vimage_iff) done -lemma negateSnd_eq [simp]: "negateSnd () = " +lemma negateSnd_eq [simp]: "negateSnd (\q,r\) = " apply (unfold negateSnd_def) apply auto done @@ -699,7 +699,7 @@ lemma quorem_neg: "\quorem (<$-a,$-b>, qr); a \ int; b \ int; qr \ int * int\ - \ quorem (, negateSnd(qr))" + \ quorem (\a,b\, negateSnd(qr))" apply clarify apply (auto elim: zless_asym simp add: quorem_def zless_zminus) txt\linear arithmetic from here on\ @@ -711,7 +711,7 @@ done lemma divAlg_correct: - "\b \ #0; a \ int; b \ int\ \ quorem (, divAlg())" + "\b \ #0; a \ int; b \ int\ \ quorem (\a,b\, divAlg(\a,b\))" apply (auto simp add: quorem_0 divAlg_def) apply (safe intro!: quorem_neg posDivAlg_correct negDivAlg_correct posDivAlg_type negDivAlg_type) @@ -720,7 +720,7 @@ apply (auto simp add: zle_def) done -lemma divAlg_type: "\a \ int; b \ int\ \ divAlg() \ int * int" +lemma divAlg_type: "\a \ int; b \ int\ \ divAlg(\a,b\) \ int * int" apply (auto simp add: divAlg_def) apply (auto simp add: posDivAlg_type negDivAlg_type negateSnd_type) done @@ -802,20 +802,20 @@ lemma quorem_div_mod: "\b \ #0; a \ int; b \ int\ - \ quorem (, )" + \ quorem (\a,b\, )" apply (cut_tac a = "a" and b = "b" in zmod_zdiv_equality) apply (auto simp add: quorem_def neq_iff_zless pos_mod_sign pos_mod_bound neg_mod_sign neg_mod_bound) done -(*Surely quorem(,) implies @{term"a \ int"}, but it doesn't matter*) +(*Surely quorem(\a,b\,\q,r\) implies @{term"a \ int"}, but it doesn't matter*) lemma quorem_div: - "\quorem(,); b \ #0; a \ int; b \ int; q \ int\ + "\quorem(\a,b\,\q,r\); b \ #0; a \ int; b \ int; q \ int\ \ a zdiv b = q" by (blast intro: quorem_div_mod [THEN unique_quotient]) lemma quorem_mod: - "\quorem(,); b \ #0; a \ int; b \ int; q \ int; r \ int\ + "\quorem(\a,b\,\q,r\); b \ #0; a \ int; b \ int; q \ int; r \ int\ \ a zmod b = r" by (blast intro: quorem_div_mod [THEN unique_remainder]) @@ -953,7 +953,7 @@ apply (simp add: int_0_less_mult_iff) apply (blast dest: zless_trans) (*linear arithmetic...*) -apply (drule_tac t = "%x. x $- r" in subst_context) +apply (drule_tac t = "\x. x $- r" in subst_context) apply (drule sym) apply (simp add: zcompare_rls) done @@ -963,12 +963,12 @@ apply (simp add: int_0_le_mult_iff zcompare_rls) apply (blast dest: zle_zless_trans) apply (simp add: zdiff_zmult_distrib2) -apply (drule_tac t = "%x. x $- a $* q" in subst_context) +apply (drule_tac t = "\x. x $- a $* q" in subst_context) apply (simp add: zcompare_rls) done lemma self_quotient: - "\quorem(,); a \ int; q \ int; a \ #0\ \ q = #1" + "\quorem(\a,a\,\q,r\); a \ int; q \ int; a \ #0\ \ q = #1" apply (simp add: split_ifs quorem_def neq_iff_zless) apply (rule zle_anti_sym) apply safe @@ -984,7 +984,7 @@ done lemma self_remainder: - "\quorem(,); a \ int; q \ int; r \ int; a \ #0\ \ r = #0" + "\quorem(\a,a\,\q,r\); a \ int; q \ int; r \ int; a \ #0\ \ r = #0" apply (frule self_quotient) apply (auto simp add: quorem_def) done @@ -1291,7 +1291,7 @@ (** proving (a*b) zdiv c = a $* (b zdiv c) $+ a * (b zmod c) **) lemma zmult1_lemma: - "\quorem(, ); c \ int; c \ #0\ + "\quorem(\b,c\, \q,r\); c \ int; c \ #0\ \ quorem (, )" apply (auto simp add: split_ifs quorem_def neq_iff_zless zadd_zmult_distrib2 pos_mod_sign pos_mod_bound neg_mod_sign neg_mod_bound) @@ -1354,7 +1354,7 @@ a zdiv c $+ b zdiv c $+ ((a zmod c $+ b zmod c) zdiv c) **) lemma zadd1_lemma: - "\quorem(, ); quorem(, ); + "\quorem(\a,c\, \aq,ar\); quorem(\b,c\, \bq,br\); c \ int; c \ #0\ \ quorem (, )" apply (auto simp add: split_ifs quorem_def neq_iff_zless zadd_zmult_distrib2 @@ -1511,7 +1511,7 @@ done lemma zdiv_zmult2_lemma: - "\quorem (, ); a \ int; b \ int; b \ #0; #0 $< c\ + "\quorem (\a,b\, \q,r\); a \ int; b \ int; b \ #0; #0 $< c\ \ quorem (, )" apply (auto simp add: zmult_ac zmod_zdiv_equality [symmetric] quorem_def neq_iff_zless int_0_less_mult_iff