Up to index of Isabelle/HOL/HOL-Complex/HOL-Complex-Matrix
theory ComputeNumeraltheory ComputeNumeral imports ComputeHOL Float begin (* normalization of bit strings *) lemmas bitnorm = Pls_0_eq Min_1_eq (* neg for bit strings *) lemma neg1: "neg Numeral.Pls = False" by (simp add: Numeral.Pls_def) lemma neg2: "neg Numeral.Min = True" apply (subst Numeral.Min_def) by auto lemma neg3: "neg (x BIT Numeral.B0) = neg x" apply (simp add: neg_def) apply (subst Bit_def) by auto lemma neg4: "neg (x BIT Numeral.B1) = neg x" apply (simp add: neg_def) apply (subst Bit_def) by auto lemmas bitneg = neg1 neg2 neg3 neg4 (* iszero for bit strings *) lemma iszero1: "iszero Numeral.Pls = True" by (simp add: Numeral.Pls_def iszero_def) lemma iszero2: "iszero Numeral.Min = False" apply (subst Numeral.Min_def) apply (subst iszero_def) by simp lemma iszero3: "iszero (x BIT Numeral.B0) = iszero x" apply (subst Numeral.Bit_def) apply (subst iszero_def)+ by auto lemma iszero4: "iszero (x BIT Numeral.B1) = False" apply (subst Numeral.Bit_def) apply (subst iszero_def)+ apply simp by arith lemmas bitiszero = iszero1 iszero2 iszero3 iszero4 (* lezero for bit strings *) constdefs "lezero x == (x ≤ 0)" lemma lezero1: "lezero Numeral.Pls = True" unfolding Numeral.Pls_def lezero_def by auto lemma lezero2: "lezero Numeral.Min = True" unfolding Numeral.Min_def lezero_def by auto lemma lezero3: "lezero (x BIT Numeral.B0) = lezero x" unfolding Numeral.Bit_def lezero_def by auto lemma lezero4: "lezero (x BIT Numeral.B1) = neg x" unfolding Numeral.Bit_def lezero_def neg_def by auto lemmas bitlezero = lezero1 lezero2 lezero3 lezero4 (* equality for bit strings *) lemma biteq1: "(Numeral.Pls = Numeral.Pls) = True" by auto lemma biteq2: "(Numeral.Min = Numeral.Min) = True" by auto lemma biteq3: "(Numeral.Pls = Numeral.Min) = False" unfolding Pls_def Min_def by auto lemma biteq4: "(Numeral.Min = Numeral.Pls) = False" unfolding Pls_def Min_def by auto lemma biteq5: "(x BIT Numeral.B0 = y BIT Numeral.B0) = (x = y)" unfolding Bit_def by auto lemma biteq6: "(x BIT Numeral.B1 = y BIT Numeral.B1) = (x = y)" unfolding Bit_def by auto lemma biteq7: "(x BIT Numeral.B0 = y BIT Numeral.B1) = False" unfolding Bit_def by (simp, arith) lemma biteq8: "(x BIT Numeral.B1 = y BIT Numeral.B0) = False" unfolding Bit_def by (simp, arith) lemma biteq9: "(Numeral.Pls = x BIT Numeral.B0) = (Numeral.Pls = x)" unfolding Bit_def Pls_def by auto lemma biteq10: "(Numeral.Pls = x BIT Numeral.B1) = False" unfolding Bit_def Pls_def by (simp, arith) lemma biteq11: "(Numeral.Min = x BIT Numeral.B0) = False" unfolding Bit_def Min_def by (simp, arith) lemma biteq12: "(Numeral.Min = x BIT Numeral.B1) = (Numeral.Min = x)" unfolding Bit_def Min_def by auto lemma biteq13: "(x BIT Numeral.B0 = Numeral.Pls) = (x = Numeral.Pls)" unfolding Bit_def Pls_def by auto lemma biteq14: "(x BIT Numeral.B1 = Numeral.Pls) = False" unfolding Bit_def Pls_def by (simp, arith) lemma biteq15: "(x BIT Numeral.B0 = Numeral.Min) = False" unfolding Bit_def Pls_def Min_def by (simp, arith) lemma biteq16: "(x BIT Numeral.B1 = Numeral.Min) = (x = Numeral.Min)" unfolding Bit_def Min_def by (simp, arith) lemmas biteq = biteq1 biteq2 biteq3 biteq4 biteq5 biteq6 biteq7 biteq8 biteq9 biteq10 biteq11 biteq12 biteq13 biteq14 biteq15 biteq16 (* x < y for bit strings *) lemma bitless1: "(Numeral.Pls < Numeral.Min) = False" unfolding Pls_def Min_def by auto lemma bitless2: "(Numeral.Pls < Numeral.Pls) = False" by auto lemma bitless3: "(Numeral.Min < Numeral.Pls) = True" unfolding Pls_def Min_def by auto lemma bitless4: "(Numeral.Min < Numeral.Min) = False" unfolding Pls_def Min_def by auto lemma bitless5: "(x BIT Numeral.B0 < y BIT Numeral.B0) = (x < y)" unfolding Bit_def by auto lemma bitless6: "(x BIT Numeral.B1 < y BIT Numeral.B1) = (x < y)" unfolding Bit_def by auto lemma bitless7: "(x BIT Numeral.B0 < y BIT Numeral.B1) = (x ≤ y)" unfolding Bit_def by auto lemma bitless8: "(x BIT Numeral.B1 < y BIT Numeral.B0) = (x < y)" unfolding Bit_def by auto lemma bitless9: "(Numeral.Pls < x BIT Numeral.B0) = (Numeral.Pls < x)" unfolding Bit_def Pls_def by auto lemma bitless10: "(Numeral.Pls < x BIT Numeral.B1) = (Numeral.Pls ≤ x)" unfolding Bit_def Pls_def by auto lemma bitless11: "(Numeral.Min < x BIT Numeral.B0) = (Numeral.Pls ≤ x)" unfolding Bit_def Pls_def Min_def by auto lemma bitless12: "(Numeral.Min < x BIT Numeral.B1) = (Numeral.Min < x)" unfolding Bit_def Min_def by auto lemma bitless13: "(x BIT Numeral.B0 < Numeral.Pls) = (x < Numeral.Pls)" unfolding Bit_def Pls_def by auto lemma bitless14: "(x BIT Numeral.B1 < Numeral.Pls) = (x < Numeral.Pls)" unfolding Bit_def Pls_def by auto lemma bitless15: "(x BIT Numeral.B0 < Numeral.Min) = (x < Numeral.Pls)" unfolding Bit_def Pls_def Min_def by auto lemma bitless16: "(x BIT Numeral.B1 < Numeral.Min) = (x < Numeral.Min)" unfolding Bit_def Min_def by auto lemmas bitless = bitless1 bitless2 bitless3 bitless4 bitless5 bitless6 bitless7 bitless8 bitless9 bitless10 bitless11 bitless12 bitless13 bitless14 bitless15 bitless16 (* x ≤ y for bit strings *) lemma bitle1: "(Numeral.Pls ≤ Numeral.Min) = False" unfolding Pls_def Min_def by auto lemma bitle2: "(Numeral.Pls ≤ Numeral.Pls) = True" by auto lemma bitle3: "(Numeral.Min ≤ Numeral.Pls) = True" unfolding Pls_def Min_def by auto lemma bitle4: "(Numeral.Min ≤ Numeral.Min) = True" unfolding Pls_def Min_def by auto lemma bitle5: "(x BIT Numeral.B0 ≤ y BIT Numeral.B0) = (x ≤ y)" unfolding Bit_def by auto lemma bitle6: "(x BIT Numeral.B1 ≤ y BIT Numeral.B1) = (x ≤ y)" unfolding Bit_def by auto lemma bitle7: "(x BIT Numeral.B0 ≤ y BIT Numeral.B1) = (x ≤ y)" unfolding Bit_def by auto lemma bitle8: "(x BIT Numeral.B1 ≤ y BIT Numeral.B0) = (x < y)" unfolding Bit_def by auto lemma bitle9: "(Numeral.Pls ≤ x BIT Numeral.B0) = (Numeral.Pls ≤ x)" unfolding Bit_def Pls_def by auto lemma bitle10: "(Numeral.Pls ≤ x BIT Numeral.B1) = (Numeral.Pls ≤ x)" unfolding Bit_def Pls_def by auto lemma bitle11: "(Numeral.Min ≤ x BIT Numeral.B0) = (Numeral.Pls ≤ x)" unfolding Bit_def Pls_def Min_def by auto lemma bitle12: "(Numeral.Min ≤ x BIT Numeral.B1) = (Numeral.Min ≤ x)" unfolding Bit_def Min_def by auto lemma bitle13: "(x BIT Numeral.B0 ≤ Numeral.Pls) = (x ≤ Numeral.Pls)" unfolding Bit_def Pls_def by auto lemma bitle14: "(x BIT Numeral.B1 ≤ Numeral.Pls) = (x < Numeral.Pls)" unfolding Bit_def Pls_def by auto lemma bitle15: "(x BIT Numeral.B0 ≤ Numeral.Min) = (x < Numeral.Pls)" unfolding Bit_def Pls_def Min_def by auto lemma bitle16: "(x BIT Numeral.B1 ≤ Numeral.Min) = (x ≤ Numeral.Min)" unfolding Bit_def Min_def by auto lemmas bitle = bitle1 bitle2 bitle3 bitle4 bitle5 bitle6 bitle7 bitle8 bitle9 bitle10 bitle11 bitle12 bitle13 bitle14 bitle15 bitle16 (* succ for bit strings *) lemmas bitsucc = succ_Pls succ_Min succ_1 succ_0 (* pred for bit strings *) lemmas bitpred = pred_Pls pred_Min pred_1 pred_0 (* unary minus for bit strings *) lemmas bituminus = minus_Pls minus_Min minus_1 minus_0 (* addition for bit strings *) lemmas bitadd = add_Pls add_Pls_right add_Min add_Min_right add_BIT_11 add_BIT_10 add_BIT_0[where b="Numeral.B0"] add_BIT_0[where b="Numeral.B1"] (* multiplication for bit strings *) lemma mult_Pls_right: "x * Numeral.Pls = Numeral.Pls" by (simp add: Pls_def) lemma mult_Min_right: "x * Numeral.Min = - x" by (subst mult_commute, simp add: mult_Min) lemma multb0x: "(x BIT Numeral.B0) * y = (x * y) BIT Numeral.B0" unfolding Bit_def by simp lemma multxb0: "x * (y BIT Numeral.B0) = (x * y) BIT Numeral.B0" unfolding Bit_def by simp lemma multb1: "(x BIT Numeral.B1) * (y BIT Numeral.B1) = (((x * y) BIT Numeral.B0) + x + y) BIT Numeral.B1" unfolding Bit_def by (simp add: ring_simps) lemmas bitmul = mult_Pls mult_Min mult_Pls_right mult_Min_right multb0x multxb0 multb1 lemmas bitarith = bitnorm bitiszero bitneg bitlezero biteq bitless bitle bitsucc bitpred bituminus bitadd bitmul constdefs "nat_norm_number_of (x::nat) == x" lemma nat_norm_number_of: "nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)" apply (simp add: nat_norm_number_of_def) unfolding lezero_def iszero_def neg_def apply (simp add: number_of_is_id) done (* Normalization of nat literals *) lemma natnorm0: "(0::nat) = number_of (Numeral.Pls)" by auto lemma natnorm1: "(1 :: nat) = number_of (Numeral.Pls BIT Numeral.B1)" by auto lemmas natnorm = natnorm0 natnorm1 nat_norm_number_of (* Suc *) lemma natsuc: "Suc (number_of x) = (if neg x then 1 else number_of (Numeral.succ x))" by (auto simp add: number_of_is_id) (* Addition for nat *) lemma natadd: "number_of x + ((number_of y)::nat) = (if neg x then (number_of y) else (if neg y then number_of x else (number_of (x + y))))" by (auto simp add: number_of_is_id) (* Subtraction for nat *) lemma natsub: "(number_of x) - ((number_of y)::nat) = (if neg x then 0 else (if neg y then number_of x else (nat_norm_number_of (number_of (x + (- y))))))" unfolding nat_norm_number_of by (auto simp add: number_of_is_id neg_def lezero_def iszero_def Let_def nat_number_of_def) (* Multiplication for nat *) lemma natmul: "(number_of x) * ((number_of y)::nat) = (if neg x then 0 else (if neg y then 0 else number_of (x * y)))" apply (auto simp add: number_of_is_id neg_def iszero_def) apply (case_tac "x > 0") apply auto apply (simp add: mult_strict_left_mono[where a=y and b=0 and c=x, simplified]) done lemma nateq: "(((number_of x)::nat) = (number_of y)) = ((lezero x ∧ lezero y) ∨ (x = y))" by (auto simp add: iszero_def lezero_def neg_def number_of_is_id) lemma natless: "(((number_of x)::nat) < (number_of y)) = ((x < y) ∧ (¬ (lezero y)))" by (auto simp add: number_of_is_id neg_def lezero_def) lemma natle: "(((number_of x)::nat) ≤ (number_of y)) = (y < x --> lezero x)" by (auto simp add: number_of_is_id lezero_def nat_number_of_def) fun natfac :: "nat => nat" where "natfac n = (if n = 0 then 1 else n * (natfac (n - 1)))" lemmas compute_natarith = bitarith natnorm natsuc natadd natsub natmul nateq natless natle natfac.simps lemma number_eq: "(((number_of x)::'a::{number_ring, ordered_idom}) = (number_of y)) = (x = y)" unfolding number_of_eq apply simp done lemma number_le: "(((number_of x)::'a::{number_ring, ordered_idom}) ≤ (number_of y)) = (x ≤ y)" unfolding number_of_eq apply simp done lemma number_less: "(((number_of x)::'a::{number_ring, ordered_idom}) < (number_of y)) = (x < y)" unfolding number_of_eq apply simp done lemma number_diff: "((number_of x)::'a::{number_ring, ordered_idom}) - number_of y = number_of (x + (- y))" apply (subst diff_number_of_eq) apply simp done lemmas number_norm = number_of_Pls[symmetric] numeral_1_eq_1[symmetric] lemmas compute_numberarith = number_of_minus[symmetric] number_of_add[symmetric] number_diff number_of_mult[symmetric] number_norm number_eq number_le number_less lemma compute_real_of_nat_number_of: "real ((number_of v)::nat) = (if neg v then 0 else number_of v)" by (simp only: real_of_nat_number_of number_of_is_id) lemma compute_nat_of_int_number_of: "nat ((number_of v)::int) = (number_of v)" by simp lemmas compute_num_conversions = compute_real_of_nat_number_of compute_nat_of_int_number_of real_number_of lemmas zpowerarith = zpower_number_of_even zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring] zpower_Pls zpower_Min (* div, mod *) lemma adjust: "adjust b (q, r) = (if 0 ≤ r - b then (2 * q + 1, r - b) else (2 * q, r))" by (auto simp only: adjust_def) lemma negateSnd: "negateSnd (q, r) = (q, -r)" by (auto simp only: negateSnd_def) lemma divAlg: "divAlg (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<b then negDivAlg a b else negateSnd (posDivAlg (-a) (-b)))" by (auto simp only: divAlg_def) lemmas compute_div_mod = div_def mod_def divAlg adjust negateSnd posDivAlg.simps negDivAlg.simps (* collecting all the theorems *) lemma even_Pls: "even (Numeral.Pls) = True" apply (unfold Pls_def even_def) by simp lemma even_Min: "even (Numeral.Min) = False" apply (unfold Min_def even_def) by simp lemma even_B0: "even (x BIT Numeral.B0) = True" apply (unfold Bit_def) by simp lemma even_B1: "even (x BIT Numeral.B1) = False" apply (unfold Bit_def) by simp lemma even_number_of: "even ((number_of w)::int) = even w" by (simp only: number_of_is_id) lemmas compute_even = even_Pls even_Min even_B0 even_B1 even_number_of lemmas compute_numeral = compute_if compute_let compute_pair compute_bool compute_natarith compute_numberarith max_def min_def compute_num_conversions zpowerarith compute_div_mod compute_even end
lemma bitnorm:
Numeral.Pls BIT bit.B0 = Numeral.Pls
Numeral.Min BIT bit.B1 = Numeral.Min
lemma neg1:
neg Numeral.Pls = False
lemma neg2:
neg Numeral.Min = True
lemma neg3:
neg (x BIT bit.B0) = neg x
lemma neg4:
neg (x BIT bit.B1) = neg x
lemma bitneg:
neg Numeral.Pls = False
neg Numeral.Min = True
neg (x BIT bit.B0) = neg x
neg (x BIT bit.B1) = neg x
lemma iszero1:
iszero Numeral.Pls = True
lemma iszero2:
iszero Numeral.Min = False
lemma iszero3:
iszero (x BIT bit.B0) = iszero x
lemma iszero4:
iszero (x BIT bit.B1) = False
lemma bitiszero:
iszero Numeral.Pls = True
iszero Numeral.Min = False
iszero (x BIT bit.B0) = iszero x
iszero (x BIT bit.B1) = False
lemma lezero1:
lezero Numeral.Pls = True
lemma lezero2:
lezero Numeral.Min = True
lemma lezero3:
lezero (x BIT bit.B0) = lezero x
lemma lezero4:
lezero (x BIT bit.B1) = neg x
lemma bitlezero:
lezero Numeral.Pls = True
lezero Numeral.Min = True
lezero (x BIT bit.B0) = lezero x
lezero (x BIT bit.B1) = neg x
lemma biteq1:
(Numeral.Pls = Numeral.Pls) = True
lemma biteq2:
(Numeral.Min = Numeral.Min) = True
lemma biteq3:
(Numeral.Pls = Numeral.Min) = False
lemma biteq4:
(Numeral.Min = Numeral.Pls) = False
lemma biteq5:
(x BIT bit.B0 = y BIT bit.B0) = (x = y)
lemma biteq6:
(x BIT bit.B1 = y BIT bit.B1) = (x = y)
lemma biteq7:
(x BIT bit.B0 = y BIT bit.B1) = False
lemma biteq8:
(x BIT bit.B1 = y BIT bit.B0) = False
lemma biteq9:
(Numeral.Pls = x BIT bit.B0) = (Numeral.Pls = x)
lemma biteq10:
(Numeral.Pls = x BIT bit.B1) = False
lemma biteq11:
(Numeral.Min = x BIT bit.B0) = False
lemma biteq12:
(Numeral.Min = x BIT bit.B1) = (Numeral.Min = x)
lemma biteq13:
(x BIT bit.B0 = Numeral.Pls) = (x = Numeral.Pls)
lemma biteq14:
(x BIT bit.B1 = Numeral.Pls) = False
lemma biteq15:
(x BIT bit.B0 = Numeral.Min) = False
lemma biteq16:
(x BIT bit.B1 = Numeral.Min) = (x = Numeral.Min)
lemma biteq:
(Numeral.Pls = Numeral.Pls) = True
(Numeral.Min = Numeral.Min) = True
(Numeral.Pls = Numeral.Min) = False
(Numeral.Min = Numeral.Pls) = False
(x BIT bit.B0 = y BIT bit.B0) = (x = y)
(x BIT bit.B1 = y BIT bit.B1) = (x = y)
(x BIT bit.B0 = y BIT bit.B1) = False
(x BIT bit.B1 = y BIT bit.B0) = False
(Numeral.Pls = x BIT bit.B0) = (Numeral.Pls = x)
(Numeral.Pls = x BIT bit.B1) = False
(Numeral.Min = x BIT bit.B0) = False
(Numeral.Min = x BIT bit.B1) = (Numeral.Min = x)
(x BIT bit.B0 = Numeral.Pls) = (x = Numeral.Pls)
(x BIT bit.B1 = Numeral.Pls) = False
(x BIT bit.B0 = Numeral.Min) = False
(x BIT bit.B1 = Numeral.Min) = (x = Numeral.Min)
lemma bitless1:
(Numeral.Pls < Numeral.Min) = False
lemma bitless2:
(Numeral.Pls < Numeral.Pls) = False
lemma bitless3:
(Numeral.Min < Numeral.Pls) = True
lemma bitless4:
(Numeral.Min < Numeral.Min) = False
lemma bitless5:
(x BIT bit.B0 < y BIT bit.B0) = (x < y)
lemma bitless6:
(x BIT bit.B1 < y BIT bit.B1) = (x < y)
lemma bitless7:
(x BIT bit.B0 < y BIT bit.B1) = (x ≤ y)
lemma bitless8:
(x BIT bit.B1 < y BIT bit.B0) = (x < y)
lemma bitless9:
(Numeral.Pls < x BIT bit.B0) = (Numeral.Pls < x)
lemma bitless10:
(Numeral.Pls < x BIT bit.B1) = (Numeral.Pls ≤ x)
lemma bitless11:
(Numeral.Min < x BIT bit.B0) = (Numeral.Pls ≤ x)
lemma bitless12:
(Numeral.Min < x BIT bit.B1) = (Numeral.Min < x)
lemma bitless13:
(x BIT bit.B0 < Numeral.Pls) = (x < Numeral.Pls)
lemma bitless14:
(x BIT bit.B1 < Numeral.Pls) = (x < Numeral.Pls)
lemma bitless15:
(x BIT bit.B0 < Numeral.Min) = (x < Numeral.Pls)
lemma bitless16:
(x BIT bit.B1 < Numeral.Min) = (x < Numeral.Min)
lemma bitless:
(Numeral.Pls < Numeral.Min) = False
(Numeral.Pls < Numeral.Pls) = False
(Numeral.Min < Numeral.Pls) = True
(Numeral.Min < Numeral.Min) = False
(x BIT bit.B0 < y BIT bit.B0) = (x < y)
(x BIT bit.B1 < y BIT bit.B1) = (x < y)
(x BIT bit.B0 < y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 < y BIT bit.B0) = (x < y)
(Numeral.Pls < x BIT bit.B0) = (Numeral.Pls < x)
(Numeral.Pls < x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B1) = (Numeral.Min < x)
(x BIT bit.B0 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 < Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Min) = (x < Numeral.Min)
lemma bitle1:
(Numeral.Pls ≤ Numeral.Min) = False
lemma bitle2:
(Numeral.Pls ≤ Numeral.Pls) = True
lemma bitle3:
(Numeral.Min ≤ Numeral.Pls) = True
lemma bitle4:
(Numeral.Min ≤ Numeral.Min) = True
lemma bitle5:
(x BIT bit.B0 ≤ y BIT bit.B0) = (x ≤ y)
lemma bitle6:
(x BIT bit.B1 ≤ y BIT bit.B1) = (x ≤ y)
lemma bitle7:
(x BIT bit.B0 ≤ y BIT bit.B1) = (x ≤ y)
lemma bitle8:
(x BIT bit.B1 ≤ y BIT bit.B0) = (x < y)
lemma bitle9:
(Numeral.Pls ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
lemma bitle10:
(Numeral.Pls ≤ x BIT bit.B1) = (Numeral.Pls ≤ x)
lemma bitle11:
(Numeral.Min ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
lemma bitle12:
(Numeral.Min ≤ x BIT bit.B1) = (Numeral.Min ≤ x)
lemma bitle13:
(x BIT bit.B0 ≤ Numeral.Pls) = (x ≤ Numeral.Pls)
lemma bitle14:
(x BIT bit.B1 ≤ Numeral.Pls) = (x < Numeral.Pls)
lemma bitle15:
(x BIT bit.B0 ≤ Numeral.Min) = (x < Numeral.Pls)
lemma bitle16:
(x BIT bit.B1 ≤ Numeral.Min) = (x ≤ Numeral.Min)
lemma bitle:
(Numeral.Pls ≤ Numeral.Min) = False
(Numeral.Pls ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Min) = True
(x BIT bit.B0 ≤ y BIT bit.B0) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B0 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B0) = (x < y)
(Numeral.Pls ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Pls ≤ x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B1) = (Numeral.Min ≤ x)
(x BIT bit.B0 ≤ Numeral.Pls) = (x ≤ Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 ≤ Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Min) = (x ≤ Numeral.Min)
lemma bitsucc:
Numeral.succ Numeral.Pls = Numeral.Pls BIT bit.B1
Numeral.succ Numeral.Min = Numeral.Pls
Numeral.succ (k BIT bit.B1) = Numeral.succ k BIT bit.B0
Numeral.succ (k BIT bit.B0) = k BIT bit.B1
lemma bitpred:
Numeral.pred Numeral.Pls = Numeral.Min
Numeral.pred Numeral.Min = Numeral.Min BIT bit.B0
Numeral.pred (k BIT bit.B1) = k BIT bit.B0
Numeral.pred (k BIT bit.B0) = Numeral.pred k BIT bit.B1
lemma bituminus:
- Numeral.Pls = Numeral.Pls
- Numeral.Min = Numeral.Pls BIT bit.B1
- k BIT bit.B1 = Numeral.pred (- k) BIT bit.B1
- k BIT bit.B0 = (- k) BIT bit.B0
lemma bitadd:
Numeral.Pls + k = k
k + Numeral.Pls = k
Numeral.Min + k = Numeral.pred k
k + Numeral.Min = Numeral.pred k
k BIT bit.B1 + l BIT bit.B1 = (k + Numeral.succ l) BIT bit.B0
k BIT bit.B1 + l BIT bit.B0 = (k + l) BIT bit.B1
k BIT bit.B0 + l BIT bit.B0 = (k + l) BIT bit.B0
k BIT bit.B0 + l BIT bit.B1 = (k + l) BIT bit.B1
lemma mult_Pls_right:
x * Numeral.Pls = Numeral.Pls
lemma mult_Min_right:
x * Numeral.Min = - x
lemma multb0x:
x BIT bit.B0 * y = (x * y) BIT bit.B0
lemma multxb0:
x * y BIT bit.B0 = (x * y) BIT bit.B0
lemma multb1:
x BIT bit.B1 * y BIT bit.B1 = ((x * y) BIT bit.B0 + x + y) BIT bit.B1
lemma bitmul:
Numeral.Pls * w = Numeral.Pls
Numeral.Min * k = - k
x * Numeral.Pls = Numeral.Pls
x * Numeral.Min = - x
x BIT bit.B0 * y = (x * y) BIT bit.B0
x * y BIT bit.B0 = (x * y) BIT bit.B0
x BIT bit.B1 * y BIT bit.B1 = ((x * y) BIT bit.B0 + x + y) BIT bit.B1
lemma bitarith:
Numeral.Pls BIT bit.B0 = Numeral.Pls
Numeral.Min BIT bit.B1 = Numeral.Min
iszero Numeral.Pls = True
iszero Numeral.Min = False
iszero (x BIT bit.B0) = iszero x
iszero (x BIT bit.B1) = False
neg Numeral.Pls = False
neg Numeral.Min = True
neg (x BIT bit.B0) = neg x
neg (x BIT bit.B1) = neg x
lezero Numeral.Pls = True
lezero Numeral.Min = True
lezero (x BIT bit.B0) = lezero x
lezero (x BIT bit.B1) = neg x
(Numeral.Pls = Numeral.Pls) = True
(Numeral.Min = Numeral.Min) = True
(Numeral.Pls = Numeral.Min) = False
(Numeral.Min = Numeral.Pls) = False
(x BIT bit.B0 = y BIT bit.B0) = (x = y)
(x BIT bit.B1 = y BIT bit.B1) = (x = y)
(x BIT bit.B0 = y BIT bit.B1) = False
(x BIT bit.B1 = y BIT bit.B0) = False
(Numeral.Pls = x BIT bit.B0) = (Numeral.Pls = x)
(Numeral.Pls = x BIT bit.B1) = False
(Numeral.Min = x BIT bit.B0) = False
(Numeral.Min = x BIT bit.B1) = (Numeral.Min = x)
(x BIT bit.B0 = Numeral.Pls) = (x = Numeral.Pls)
(x BIT bit.B1 = Numeral.Pls) = False
(x BIT bit.B0 = Numeral.Min) = False
(x BIT bit.B1 = Numeral.Min) = (x = Numeral.Min)
(Numeral.Pls < Numeral.Min) = False
(Numeral.Pls < Numeral.Pls) = False
(Numeral.Min < Numeral.Pls) = True
(Numeral.Min < Numeral.Min) = False
(x BIT bit.B0 < y BIT bit.B0) = (x < y)
(x BIT bit.B1 < y BIT bit.B1) = (x < y)
(x BIT bit.B0 < y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 < y BIT bit.B0) = (x < y)
(Numeral.Pls < x BIT bit.B0) = (Numeral.Pls < x)
(Numeral.Pls < x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B1) = (Numeral.Min < x)
(x BIT bit.B0 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 < Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Min) = (x < Numeral.Min)
(Numeral.Pls ≤ Numeral.Min) = False
(Numeral.Pls ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Min) = True
(x BIT bit.B0 ≤ y BIT bit.B0) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B0 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B0) = (x < y)
(Numeral.Pls ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Pls ≤ x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B1) = (Numeral.Min ≤ x)
(x BIT bit.B0 ≤ Numeral.Pls) = (x ≤ Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 ≤ Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Min) = (x ≤ Numeral.Min)
Numeral.succ Numeral.Pls = Numeral.Pls BIT bit.B1
Numeral.succ Numeral.Min = Numeral.Pls
Numeral.succ (k BIT bit.B1) = Numeral.succ k BIT bit.B0
Numeral.succ (k BIT bit.B0) = k BIT bit.B1
Numeral.pred Numeral.Pls = Numeral.Min
Numeral.pred Numeral.Min = Numeral.Min BIT bit.B0
Numeral.pred (k BIT bit.B1) = k BIT bit.B0
Numeral.pred (k BIT bit.B0) = Numeral.pred k BIT bit.B1
- Numeral.Pls = Numeral.Pls
- Numeral.Min = Numeral.Pls BIT bit.B1
- k BIT bit.B1 = Numeral.pred (- k) BIT bit.B1
- k BIT bit.B0 = (- k) BIT bit.B0
Numeral.Pls + k = k
k + Numeral.Pls = k
Numeral.Min + k = Numeral.pred k
k + Numeral.Min = Numeral.pred k
k BIT bit.B1 + l BIT bit.B1 = (k + Numeral.succ l) BIT bit.B0
k BIT bit.B1 + l BIT bit.B0 = (k + l) BIT bit.B1
k BIT bit.B0 + l BIT bit.B0 = (k + l) BIT bit.B0
k BIT bit.B0 + l BIT bit.B1 = (k + l) BIT bit.B1
Numeral.Pls * w = Numeral.Pls
Numeral.Min * k = - k
x * Numeral.Pls = Numeral.Pls
x * Numeral.Min = - x
x BIT bit.B0 * y = (x * y) BIT bit.B0
x * y BIT bit.B0 = (x * y) BIT bit.B0
x BIT bit.B1 * y BIT bit.B1 = ((x * y) BIT bit.B0 + x + y) BIT bit.B1
lemma nat_norm_number_of:
nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)
lemma natnorm0:
0 = Numeral0
lemma natnorm1:
1 = Numeral1
lemma natnorm:
0 = Numeral0
1 = Numeral1
nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)
lemma natsuc:
Suc (number_of x) = (if neg x then 1 else number_of (Numeral.succ x))
lemma natadd:
number_of x + number_of y =
(if neg x then number_of y
else if neg y then number_of x else number_of (x + y))
lemma natsub:
number_of x - number_of y =
(if neg x then 0
else if neg y then number_of x else nat_norm_number_of (number_of (x + - y)))
lemma natmul:
number_of x * number_of y =
(if neg x then 0 else if neg y then 0 else number_of (x * y))
lemma nateq:
(number_of x = number_of y) = (lezero x ∧ lezero y ∨ x = y)
lemma natless:
(number_of x < number_of y) = (x < y ∧ ¬ lezero y)
lemma natle:
(number_of x ≤ number_of y) = (y < x --> lezero x)
lemma compute_natarith:
Numeral.Pls BIT bit.B0 = Numeral.Pls
Numeral.Min BIT bit.B1 = Numeral.Min
iszero Numeral.Pls = True
iszero Numeral.Min = False
iszero (x BIT bit.B0) = iszero x
iszero (x BIT bit.B1) = False
neg Numeral.Pls = False
neg Numeral.Min = True
neg (x BIT bit.B0) = neg x
neg (x BIT bit.B1) = neg x
lezero Numeral.Pls = True
lezero Numeral.Min = True
lezero (x BIT bit.B0) = lezero x
lezero (x BIT bit.B1) = neg x
(Numeral.Pls = Numeral.Pls) = True
(Numeral.Min = Numeral.Min) = True
(Numeral.Pls = Numeral.Min) = False
(Numeral.Min = Numeral.Pls) = False
(x BIT bit.B0 = y BIT bit.B0) = (x = y)
(x BIT bit.B1 = y BIT bit.B1) = (x = y)
(x BIT bit.B0 = y BIT bit.B1) = False
(x BIT bit.B1 = y BIT bit.B0) = False
(Numeral.Pls = x BIT bit.B0) = (Numeral.Pls = x)
(Numeral.Pls = x BIT bit.B1) = False
(Numeral.Min = x BIT bit.B0) = False
(Numeral.Min = x BIT bit.B1) = (Numeral.Min = x)
(x BIT bit.B0 = Numeral.Pls) = (x = Numeral.Pls)
(x BIT bit.B1 = Numeral.Pls) = False
(x BIT bit.B0 = Numeral.Min) = False
(x BIT bit.B1 = Numeral.Min) = (x = Numeral.Min)
(Numeral.Pls < Numeral.Min) = False
(Numeral.Pls < Numeral.Pls) = False
(Numeral.Min < Numeral.Pls) = True
(Numeral.Min < Numeral.Min) = False
(x BIT bit.B0 < y BIT bit.B0) = (x < y)
(x BIT bit.B1 < y BIT bit.B1) = (x < y)
(x BIT bit.B0 < y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 < y BIT bit.B0) = (x < y)
(Numeral.Pls < x BIT bit.B0) = (Numeral.Pls < x)
(Numeral.Pls < x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B1) = (Numeral.Min < x)
(x BIT bit.B0 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 < Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Min) = (x < Numeral.Min)
(Numeral.Pls ≤ Numeral.Min) = False
(Numeral.Pls ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Min) = True
(x BIT bit.B0 ≤ y BIT bit.B0) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B0 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B0) = (x < y)
(Numeral.Pls ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Pls ≤ x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B1) = (Numeral.Min ≤ x)
(x BIT bit.B0 ≤ Numeral.Pls) = (x ≤ Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 ≤ Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Min) = (x ≤ Numeral.Min)
Numeral.succ Numeral.Pls = Numeral.Pls BIT bit.B1
Numeral.succ Numeral.Min = Numeral.Pls
Numeral.succ (k BIT bit.B1) = Numeral.succ k BIT bit.B0
Numeral.succ (k BIT bit.B0) = k BIT bit.B1
Numeral.pred Numeral.Pls = Numeral.Min
Numeral.pred Numeral.Min = Numeral.Min BIT bit.B0
Numeral.pred (k BIT bit.B1) = k BIT bit.B0
Numeral.pred (k BIT bit.B0) = Numeral.pred k BIT bit.B1
- Numeral.Pls = Numeral.Pls
- Numeral.Min = Numeral.Pls BIT bit.B1
- k BIT bit.B1 = Numeral.pred (- k) BIT bit.B1
- k BIT bit.B0 = (- k) BIT bit.B0
Numeral.Pls + k = k
k + Numeral.Pls = k
Numeral.Min + k = Numeral.pred k
k + Numeral.Min = Numeral.pred k
k BIT bit.B1 + l BIT bit.B1 = (k + Numeral.succ l) BIT bit.B0
k BIT bit.B1 + l BIT bit.B0 = (k + l) BIT bit.B1
k BIT bit.B0 + l BIT bit.B0 = (k + l) BIT bit.B0
k BIT bit.B0 + l BIT bit.B1 = (k + l) BIT bit.B1
Numeral.Pls * w = Numeral.Pls
Numeral.Min * k = - k
x * Numeral.Pls = Numeral.Pls
x * Numeral.Min = - x
x BIT bit.B0 * y = (x * y) BIT bit.B0
x * y BIT bit.B0 = (x * y) BIT bit.B0
x BIT bit.B1 * y BIT bit.B1 = ((x * y) BIT bit.B0 + x + y) BIT bit.B1
0 = Numeral0
1 = Numeral1
nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)
Suc (number_of x) = (if neg x then 1 else number_of (Numeral.succ x))
number_of x + number_of y =
(if neg x then number_of y
else if neg y then number_of x else number_of (x + y))
number_of x - number_of y =
(if neg x then 0
else if neg y then number_of x else nat_norm_number_of (number_of (x + - y)))
number_of x * number_of y =
(if neg x then 0 else if neg y then 0 else number_of (x * y))
(number_of x = number_of y) = (lezero x ∧ lezero y ∨ x = y)
(number_of x < number_of y) = (x < y ∧ ¬ lezero y)
(number_of x ≤ number_of y) = (y < x --> lezero x)
natfac n = (if n = 0 then 1 else n * natfac (n - 1))
lemma number_eq:
(number_of x = number_of y) = (x = y)
lemma number_le:
(number_of x ≤ number_of y) = (x ≤ y)
lemma number_less:
(number_of x < number_of y) = (x < y)
lemma number_diff:
number_of x - number_of y = number_of (x + - y)
lemma number_norm:
(0::'a) = Numeral0
(1::'a) = Numeral1
lemma compute_numberarith:
- number_of w = number_of (- w)
number_of v + number_of w = number_of (v + w)
number_of x - number_of y = number_of (x + - y)
number_of v * number_of w = number_of (v * w)
(0::'a) = Numeral0
(1::'a) = Numeral1
(number_of x = number_of y) = (x = y)
(number_of x ≤ number_of y) = (x ≤ y)
(number_of x < number_of y) = (x < y)
lemma compute_real_of_nat_number_of:
real (number_of v) = (if neg v then 0 else number_of v)
lemma compute_nat_of_int_number_of:
nat (number_of v) = number_of v
lemma compute_num_conversions:
real (number_of v) = (if neg v then 0 else number_of v)
nat (number_of v) = number_of v
real (number_of v) = number_of v
lemma zpowerarith:
z ^ number_of (w BIT bit.B0) = (let w = z ^ number_of w in w * w)
z ^ number_of (w BIT bit.B1) =
(if Numeral0 ≤ number_of w then let w = z ^ number_of w in z * w * w
else Numeral1)
z ^ Numeral0 = Numeral1
z ^ -1 = Numeral1
lemma adjust:
adjust b (q, r) = (if 0 ≤ r - b then (2 * q + 1, r - b) else (2 * q, r))
lemma negateSnd:
negateSnd (q, r) = (q, - r)
lemma divAlg:
divAlg (a, b) =
(if 0 ≤ a
then if 0 ≤ b then posDivAlg a b
else if a = 0 then 0N else negateSnd (negDivAlg (- a) (- b))
else if 0 < b then negDivAlg a b else negateSnd (posDivAlg (- a) (- b)))
lemma compute_div_mod:
a div b == fst (divAlg (a, b))
a mod b == snd (divAlg (a, b))
divAlg (a, b) =
(if 0 ≤ a
then if 0 ≤ b then posDivAlg a b
else if a = 0 then 0N else negateSnd (negDivAlg (- a) (- b))
else if 0 < b then negDivAlg a b else negateSnd (posDivAlg (- a) (- b)))
adjust b (q, r) = (if 0 ≤ r - b then (2 * q + 1, r - b) else (2 * q, r))
negateSnd (q, r) = (q, - r)
posDivAlg a b =
(if a < b ∨ b ≤ 0 then (0, a) else adjust b (posDivAlg a (2 * b)))
negDivAlg a b =
(if 0 ≤ a + b ∨ b ≤ 0 then (-1, a + b) else adjust b (negDivAlg a (2 * b)))
lemma even_Pls:
even Numeral.Pls = True
lemma even_Min:
even Numeral.Min = False
lemma even_B0:
even (x BIT bit.B0) = True
lemma even_B1:
even (x BIT bit.B1) = False
lemma even_number_of:
even (number_of w) = even w
lemma compute_even:
even Numeral.Pls = True
even Numeral.Min = False
even (x BIT bit.B0) = True
even (x BIT bit.B1) = False
even (number_of w) = even w
lemma compute_numeral:
If True = (λx y. x)
If False = (λx y. y)
Let s f == f s
fst (x, y) = x
snd (x, y) = y
((a, b) = (c, d)) = (a = c ∧ b = d)
prod_case f (x, y) = f x y
(¬ True) = False
(¬ False) = True
(P ∧ True) = P
(True ∧ P) = P
(P ∧ False) = False
(False ∧ P) = False
(P ∨ True) = True
(True ∨ P) = True
(P ∨ False) = P
(False ∨ P) = P
(True --> P) = P
(P --> True) = True
(True --> P) = P
(P --> False) = (¬ P)
(False --> P) = True
(False = False) = True
(True = True) = True
(False = True) = False
(True = False) = False
Numeral.Pls BIT bit.B0 = Numeral.Pls
Numeral.Min BIT bit.B1 = Numeral.Min
iszero Numeral.Pls = True
iszero Numeral.Min = False
iszero (x BIT bit.B0) = iszero x
iszero (x BIT bit.B1) = False
neg Numeral.Pls = False
neg Numeral.Min = True
neg (x BIT bit.B0) = neg x
neg (x BIT bit.B1) = neg x
lezero Numeral.Pls = True
lezero Numeral.Min = True
lezero (x BIT bit.B0) = lezero x
lezero (x BIT bit.B1) = neg x
(Numeral.Pls = Numeral.Pls) = True
(Numeral.Min = Numeral.Min) = True
(Numeral.Pls = Numeral.Min) = False
(Numeral.Min = Numeral.Pls) = False
(x BIT bit.B0 = y BIT bit.B0) = (x = y)
(x BIT bit.B1 = y BIT bit.B1) = (x = y)
(x BIT bit.B0 = y BIT bit.B1) = False
(x BIT bit.B1 = y BIT bit.B0) = False
(Numeral.Pls = x BIT bit.B0) = (Numeral.Pls = x)
(Numeral.Pls = x BIT bit.B1) = False
(Numeral.Min = x BIT bit.B0) = False
(Numeral.Min = x BIT bit.B1) = (Numeral.Min = x)
(x BIT bit.B0 = Numeral.Pls) = (x = Numeral.Pls)
(x BIT bit.B1 = Numeral.Pls) = False
(x BIT bit.B0 = Numeral.Min) = False
(x BIT bit.B1 = Numeral.Min) = (x = Numeral.Min)
(Numeral.Pls < Numeral.Min) = False
(Numeral.Pls < Numeral.Pls) = False
(Numeral.Min < Numeral.Pls) = True
(Numeral.Min < Numeral.Min) = False
(x BIT bit.B0 < y BIT bit.B0) = (x < y)
(x BIT bit.B1 < y BIT bit.B1) = (x < y)
(x BIT bit.B0 < y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 < y BIT bit.B0) = (x < y)
(Numeral.Pls < x BIT bit.B0) = (Numeral.Pls < x)
(Numeral.Pls < x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min < x BIT bit.B1) = (Numeral.Min < x)
(x BIT bit.B0 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 < Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 < Numeral.Min) = (x < Numeral.Min)
(Numeral.Pls ≤ Numeral.Min) = False
(Numeral.Pls ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Pls) = True
(Numeral.Min ≤ Numeral.Min) = True
(x BIT bit.B0 ≤ y BIT bit.B0) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B0 ≤ y BIT bit.B1) = (x ≤ y)
(x BIT bit.B1 ≤ y BIT bit.B0) = (x < y)
(Numeral.Pls ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Pls ≤ x BIT bit.B1) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B0) = (Numeral.Pls ≤ x)
(Numeral.Min ≤ x BIT bit.B1) = (Numeral.Min ≤ x)
(x BIT bit.B0 ≤ Numeral.Pls) = (x ≤ Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Pls) = (x < Numeral.Pls)
(x BIT bit.B0 ≤ Numeral.Min) = (x < Numeral.Pls)
(x BIT bit.B1 ≤ Numeral.Min) = (x ≤ Numeral.Min)
Numeral.succ Numeral.Pls = Numeral.Pls BIT bit.B1
Numeral.succ Numeral.Min = Numeral.Pls
Numeral.succ (k BIT bit.B1) = Numeral.succ k BIT bit.B0
Numeral.succ (k BIT bit.B0) = k BIT bit.B1
Numeral.pred Numeral.Pls = Numeral.Min
Numeral.pred Numeral.Min = Numeral.Min BIT bit.B0
Numeral.pred (k BIT bit.B1) = k BIT bit.B0
Numeral.pred (k BIT bit.B0) = Numeral.pred k BIT bit.B1
- Numeral.Pls = Numeral.Pls
- Numeral.Min = Numeral.Pls BIT bit.B1
- k BIT bit.B1 = Numeral.pred (- k) BIT bit.B1
- k BIT bit.B0 = (- k) BIT bit.B0
Numeral.Pls + k = k
k + Numeral.Pls = k
Numeral.Min + k = Numeral.pred k
k + Numeral.Min = Numeral.pred k
k BIT bit.B1 + l BIT bit.B1 = (k + Numeral.succ l) BIT bit.B0
k BIT bit.B1 + l BIT bit.B0 = (k + l) BIT bit.B1
k BIT bit.B0 + l BIT bit.B0 = (k + l) BIT bit.B0
k BIT bit.B0 + l BIT bit.B1 = (k + l) BIT bit.B1
Numeral.Pls * w = Numeral.Pls
Numeral.Min * k = - k
x * Numeral.Pls = Numeral.Pls
x * Numeral.Min = - x
x BIT bit.B0 * y = (x * y) BIT bit.B0
x * y BIT bit.B0 = (x * y) BIT bit.B0
x BIT bit.B1 * y BIT bit.B1 = ((x * y) BIT bit.B0 + x + y) BIT bit.B1
0 = Numeral0
1 = Numeral1
nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)
Suc (number_of x) = (if neg x then 1 else number_of (Numeral.succ x))
number_of x + number_of y =
(if neg x then number_of y
else if neg y then number_of x else number_of (x + y))
number_of x - number_of y =
(if neg x then 0
else if neg y then number_of x else nat_norm_number_of (number_of (x + - y)))
number_of x * number_of y =
(if neg x then 0 else if neg y then 0 else number_of (x * y))
(number_of x = number_of y) = (lezero x ∧ lezero y ∨ x = y)
(number_of x < number_of y) = (x < y ∧ ¬ lezero y)
(number_of x ≤ number_of y) = (y < x --> lezero x)
natfac n = (if n = 0 then 1 else n * natfac (n - 1))
- number_of w = number_of (- w)
number_of v + number_of w = number_of (v + w)
number_of x - number_of y = number_of (x + - y)
number_of v * number_of w = number_of (v * w)
(0::'a) = Numeral0
(1::'a) = Numeral1
(number_of x = number_of y) = (x = y)
(number_of x ≤ number_of y) = (x ≤ y)
(number_of x < number_of y) = (x < y)
max a b = (if a ≤ b then b else a)
min a b = (if a ≤ b then a else b)
real (number_of v) = (if neg v then 0 else number_of v)
nat (number_of v) = number_of v
real (number_of v) = number_of v
z ^ number_of (w BIT bit.B0) = (let w = z ^ number_of w in w * w)
z ^ number_of (w BIT bit.B1) =
(if Numeral0 ≤ number_of w then let w = z ^ number_of w in z * w * w
else Numeral1)
z ^ Numeral0 = Numeral1
z ^ -1 = Numeral1
a div b == fst (divAlg (a, b))
a mod b == snd (divAlg (a, b))
divAlg (a, b) =
(if 0 ≤ a
then if 0 ≤ b then posDivAlg a b
else if a = 0 then 0N else negateSnd (negDivAlg (- a) (- b))
else if 0 < b then negDivAlg a b else negateSnd (posDivAlg (- a) (- b)))
adjust b (q, r) = (if 0 ≤ r - b then (2 * q + 1, r - b) else (2 * q, r))
negateSnd (q, r) = (q, - r)
posDivAlg a b =
(if a < b ∨ b ≤ 0 then (0, a) else adjust b (posDivAlg a (2 * b)))
negDivAlg a b =
(if 0 ≤ a + b ∨ b ≤ 0 then (-1, a + b) else adjust b (negDivAlg a (2 * b)))
even Numeral.Pls = True
even Numeral.Min = False
even (x BIT bit.B0) = True
even (x BIT bit.B1) = False
even (number_of w) = even w