(* Title: ZF/Arith.thy Author: Lawrence C Paulson, Cambridge University Computer Laboratory Copyright 1992 University of Cambridge
*)
(*"Difference" is subtraction of natural numbers. There are no negative numbers; we have m #- n = 0 iff m<=n and m #- n = succ(k) iff m>n. Also, rec(m, 0, \<lambda>z w.z) is pred(m).
*)
section\<open>Arithmetic Operators and Their Definitions\<close>
theory Arith imports Univ begin
text\<open>Proofs about elementary arithmetic: addition, multiplication, etc.\<close>
definition
pred :: "i\i" (*inverse of succ*) where "pred(y) \ nat_case(0, \x. x, y)"
definition
natify :: "i\i" (*coerces non-nats to nats*) where "natify \ Vrecursor(\f a. if a = succ(pred(a)) then succ(f`pred(a))
else 0)"
(*Must simplify BEFORE the induction: else we get a critical pair*) lemma diff_succ_succ [simp]: "succ(m) #- succ(n) = m #- n" apply (simp add: natify_succ diff_def) apply (rule_tac x1 = n in natify_in_nat [THEN nat_induct], auto) done
(*This defining property is no longer wanted*) declare raw_diff_succ [simp del]
(*Natify has weakened this law, compared with the older approach*) lemma diff_0 [simp]: "m #- 0 = natify(m)" by (simp add: diff_def)
lemma diff_le_self: "m\nat \ (m #- n) \ m" apply (subgoal_tac " (m #- natify (n)) \ m") apply (rule_tac [2] m = m and n = "natify (n) "in diff_induct) apply (erule_tac [6] leE) apply (simp_all add: le_iff) done
subsection\<open>Addition\<close>
(*Natify has weakened this law, compared with the older approach*) lemma add_0_natify [simp]: "0 #+ m = natify(m)" by (simp add: add_def)
lemma add_succ [simp]: "succ(m) #+ n = succ(m #+ n)" by (simp add: natify_succ add_def)
lemma add_0: "m \ nat \ 0 #+ m = m" by simp
(*Associative law for addition*) lemma add_assoc: "(m #+ n) #+ k = m #+ (n #+ k)" apply (subgoal_tac "(natify(m) #+ natify(n)) #+ natify(k) =
natify(m) #+ (natify(n) #+ natify(k))") apply (rule_tac [2] n = "natify(m)"in nat_induct) apply auto done
(*The following two lemmas are used for add_commute and sometimes
elsewhere, since they are safe for rewriting.*) lemma add_0_right_natify [simp]: "m #+ 0 = natify(m)" apply (subgoal_tac "natify(m) #+ 0 = natify(m)") apply (rule_tac [2] n = "natify(m)"in nat_induct) apply auto done
(*Commutative law for addition*) lemma add_commute: "m #+ n = n #+ m" apply (subgoal_tac "natify(m) #+ natify(n) = natify(n) #+ natify(m) ") apply (rule_tac [2] n = "natify(m) "in nat_induct) apply auto done
(*Addition is an AC-operator*) lemmas add_ac = add_assoc add_commute add_left_commute
(*Cancellation law on the left*) lemma raw_add_left_cancel: "\raw_add(k, m) = raw_add(k, n); k\nat\ \ m=n" apply (erule rev_mp) apply (induct_tac "k", auto) done
lemma add_left_cancel_natify: "k #+ m = k #+ n \ natify(m) = natify(n)" unfolding add_def apply (drule raw_add_left_cancel, auto) done
lemma add_left_cancel: "\i = j; i #+ m = j #+ n; m\nat; n\nat\ \ m = n" by (force dest!: add_left_cancel_natify)
(*Thanks to Sten Agerholm*) lemma add_le_elim1_natify: "k#+m \ k#+n \ natify(m) \ natify(n)" apply (rule_tac P = "natify(k) #+m \ natify(k) #+n" in rev_mp) apply (rule_tac [2] n = "natify(k) "in nat_induct) apply auto done
lemma add_le_elim1: "\k#+m \ k#+n; m \ nat; n \ nat\ \ m \ n" by (drule add_le_elim1_natify, auto)
lemma add_lt_elim1_natify: "k#+m < k#+n \ natify(m) < natify(n)" apply (rule_tac P = "natify(k) #+m < natify(k) #+n"in rev_mp) apply (rule_tac [2] n = "natify(k) "in nat_induct) apply auto done
lemma add_lt_elim1: "\k#+m < k#+n; m \ nat; n \ nat\ \ m < n" by (drule add_lt_elim1_natify, auto)
lemma zero_less_add: "\n \ nat; m \ nat\ \ 0 < m #+ n \ (0 by (induct_tac "n", auto)
subsection\<open>Monotonicity of Addition\<close>
(*strict, in 1st argument; proof is by rule induction on 'less than'. Still need j\<in>nat, for consider j = omega. Then we can have i<omega,
which is the same as i\<in>nat, but natify(j)=0, so the conclusion fails.*) lemma add_lt_mono1: "\inat\ \ i#+k < j#+k" apply (frule lt_nat_in_nat, assumption) apply (erule succ_lt_induct) apply (simp_all add: leI) done
text\<open>strict, in second argument\<close> lemma add_lt_mono2: "\inat\ \ k#+i < k#+j" by (simp add: add_commute [of k] add_lt_mono1)
text\<open>A [clumsy] way of lifting < monotonicity to \<open>\<le>\<close> monotonicity\<close> lemma Ord_lt_mono_imp_le_mono: assumes lt_mono: "\i j. \i \ f(i) < f(j)" and ford: "\i. i:k \ Ord(f(i))" and leij: "i \ j" and jink: "j:k" shows"f(i) \ f(j)" apply (insert leij jink) apply (blast intro!: leCI lt_mono ford elim!: leE) done
lemma diff_add_eq: "((u #+ m) #- (u #+ n)) = ((0 #+ m) #- n)" by (simp add: diff_cancel)
(*To tidy up the result of a simproc. Only the RHS will be simplified.*) lemma eq_cong2: "u = u' \ (t\u) \ (t\u')" by auto
lemma iff_cong2: "u \ u' \ (t\u) \ (t\u')" by auto
subsection\<open>Multiplication\<close>
lemma mult_0 [simp]: "0 #* m = 0" by (simp add: mult_def)
lemma mult_succ [simp]: "succ(m) #* n = n #+ (m #* n)" by (simp add: add_def mult_def natify_succ raw_mult_type)
(*right annihilation in product*) lemma mult_0_right [simp]: "m #* 0 = 0" unfolding mult_def apply (rule_tac n = "natify(m) "in nat_induct) apply auto done
(*right successor law for multiplication*) lemma mult_succ_right [simp]: "m #* succ(n) = m #+ (m #* n)" apply (subgoal_tac "natify(m) #* succ (natify(n)) =
natify(m) #+ (natify(m) #* natify(n))") apply (simp (no_asm_use) add: natify_succ add_def mult_def) apply (rule_tac n = "natify(m) "in nat_induct) apply (simp_all add: add_ac) done
lemma mult_1_natify [simp]: "1 #* n = natify(n)" by auto
lemma mult_1_right_natify [simp]: "n #* 1 = natify(n)" by auto
lemma mult_1: "n \ nat \ 1 #* n = n" by simp
lemma mult_1_right: "n \ nat \ n #* 1 = n" by simp
(*Commutative law for multiplication*) lemma mult_commute: "m #* n = n #* m" apply (subgoal_tac "natify(m) #* natify(n) = natify(n) #* natify(m) ") apply (rule_tac [2] n = "natify(m) "in nat_induct) apply auto done
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.16Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.