SSL Bin.thy
Interaktion und PortierbarkeitIsabelle
(* Title: ZF/Bin.thy Author: Lawrence C Paulson, Cambridge University Computer Laboratory Copyright 1994 University of Cambridge
The sign Pls stands for an infinite string of leading 0's. The sign Min stands for an infinite string of leading 1's.
A number can have multiple representations, namely leading 0's with sign Pls and leading 1's with sign Min. See twos-compl.ML/int_of_binary for the numerical interpretation.
The representation expects that (m mod 2) is 0 or 1, even if m is negative; For instance, \<not>5 div 2 = \<not>3 and \<not>5 mod 2 = 1; thus \<not>5 = (\<not>3)*2 + 1
*)
section\<open>Arithmetic on Binary Integers\<close>
theory Bin imports Int Datatype begin
consts bin :: i datatype "bin" = Pls
| Min
| Bit ("w \ bin", "b \ bool") (infixl \BIT\ 90)
primrec
integ_of_Pls: "integ_of (Pls) = $# 0"
integ_of_Min: "integ_of (Min) = $-($#1)"
integ_of_BIT: "integ_of (w BIT b) = $#b $+ integ_of(w) $+ integ_of(w)"
(** recall that cond(1,b,c)=b and cond(0,b,c)=0 **)
primrec(*NCons adds a bit, suppressing leading 0s and 1s*)
NCons_Pls: "NCons (Pls,b) = cond(b,Pls BIT b,Pls)"
NCons_Min: "NCons (Min,b) = cond(b,Min,Min BIT b)"
NCons_BIT: "NCons (w BIT c,b) = w BIT c BIT b"
primrec(*successor. If a BIT, can change a 0 to a 1 without recursion.*)
bin_succ_Pls: "bin_succ (Pls) = Pls BIT 1"
bin_succ_Min: "bin_succ (Min) = Pls"
bin_succ_BIT: "bin_succ (w BIT b) = cond(b, bin_succ(w) BIT 0, NCons(w,1))"
primrec(*predecessor*)
bin_pred_Pls: "bin_pred (Pls) = Min"
bin_pred_Min: "bin_pred (Min) = Min BIT 0"
bin_pred_BIT: "bin_pred (w BIT b) = cond(b, NCons(w,0), bin_pred(w) BIT 1)"
primrec(*unary negation*)
bin_minus_Pls: "bin_minus (Pls) = Pls"
bin_minus_Min: "bin_minus (Min) = Pls BIT 1"
bin_minus_BIT: "bin_minus (w BIT b) = cond(b, bin_pred(NCons(bin_minus(w),0)),
bin_minus(w) BIT 0)"
primrec(*sum*)
bin_adder_Pls: "bin_adder (Pls) = (\w\bin. w)"
bin_adder_Min: "bin_adder (Min) = (\w\bin. bin_pred(w))"
bin_adder_BIT: "bin_adder (v BIT x) =
(\<lambda>w\<in>bin.
bin_case (v BIT x, bin_pred(v BIT x), \<lambda>w y. NCons(bin_adder (v) ` cond(x and y, bin_succ(w), w),
x xor y),
w))"
(*The bin_case above replaces the following mutually recursive function: primrec "adding (v,x,Pls) = v BIT x" "adding (v,x,Min) = bin_pred(v BIT x)" "adding (v,x,w BIT y) = NCons(bin_adder (v, cond(x and y, bin_succ(w), w)), x xor y)"
*)
definition
bin_add :: "[i,i]\i" where "bin_add(v,w) \ bin_adder(v)`w"
primrec
bin_mult_Pls: "bin_mult (Pls,w) = Pls"
bin_mult_Min: "bin_mult (Min,w) = bin_minus(w)"
bin_mult_BIT: "bin_mult (v BIT b,w) = cond(b, bin_add(NCons(bin_mult(v,w),0),w),
NCons(bin_mult(v,w),0))"
syntax "_Int0" :: i (\<open>#()0\<close>) "_Int1" :: i (\<open>#()1\<close>) "_Int2" :: i (\<open>#()2\<close>) "_Neg_Int1" :: i (\<open>#-()1\<close>) "_Neg_Int2" :: i (\<open>#-()2\<close>) translations "#0"\<rightleftharpoons> "CONST integ_of(CONST Pls)" "#1"\<rightleftharpoons> "CONST integ_of(CONST Pls BIT 1)" "#2"\<rightleftharpoons> "CONST integ_of(CONST Pls BIT 1 BIT 0)" "#-1"\<rightleftharpoons> "CONST integ_of(CONST Min)" "#-2"\<rightleftharpoons> "CONST integ_of(CONST Min BIT 0)"
lemma bin_add_BIT_Pls [simp]: "bin_add(v BIT x,Pls) = v BIT x" by (unfold bin_add_def, simp)
lemma bin_add_BIT_Min [simp]: "bin_add(v BIT x,Min) = bin_pred(v BIT x)" by (unfold bin_add_def, simp)
lemma bin_add_BIT_BIT [simp]: "\w \ bin; y \ bool\ \<Longrightarrow> bin_add(v BIT x, w BIT y) =
NCons(bin_add(v, cond(x and y, bin_succ(w), w)), x xor y)" by (unfold bin_add_def, simp)
(*For making a minimal simpset, one must include these default simprules
of thy. Also include simp_thms, or at least (\<not>False)=True*) lemmas bin_arith_simps =
bin_pred_Pls bin_pred_Min
bin_succ_Pls bin_succ_Min
bin_add_Pls bin_add_Min
bin_minus_Pls bin_minus_Min
bin_mult_Pls bin_mult_Min
bin_arith_extra_simps
(*This simprule cannot be added unless we can find a way to make eq_integ_of_eq unconditional! [The condition "True" is a hack to prevent looping. Conditional rewrite rules are tried after unconditional ones, so a rule like eq_nat_number_of will be tried first to eliminate #mm=#nn.] lemma integ_of_reorient [simp]: "True \<Longrightarrow> (integ_of(w) = x) \<longleftrightarrow> (x = integ_of(w))" by auto
*)
lemma integ_of_minus_reorient [simp]: "(integ_of(w) = $- x) \ ($- x = integ_of(w))" by auto
lemma integ_of_add_reorient [simp]: "(integ_of(w) = x $+ y) \ (x $+ y = integ_of(w))" by auto
lemma integ_of_diff_reorient [simp]: "(integ_of(w) = x $- y) \ (x $- y = integ_of(w))" by auto
lemma integ_of_mult_reorient [simp]: "(integ_of(w) = x $* y) \ (x $* y = integ_of(w))" by auto
(** To simplify inequalities involving integer negation and literals, such as -x = #3
**)
lemmas [simp] =
zminus_equation [where y = "integ_of(w)"]
equation_zminus [where x = "integ_of(w)"] for w
lemmas [iff] =
zminus_zless [where y = "integ_of(w)"]
zless_zminus [where x = "integ_of(w)"] for w
lemmas [iff] =
zminus_zle [where y = "integ_of(w)"]
zle_zminus [where x = "integ_of(w)"] for w
lemmas [simp] =
Let_def [where s = "integ_of(w)"] for w
(*** Simprocs for numeric literals ***)
(** Combining of literal coefficients in sums of products **)
lemmas rel_iff_rel_0_rls =
zless_iff_zdiff_zless_0 [where y = "u $+ v"]
eq_iff_zdiff_eq_0 [where y = "u $+ v"]
zle_iff_zdiff_zle_0 [where y = "u $+ v"]
zless_iff_zdiff_zless_0 [where y = n]
eq_iff_zdiff_eq_0 [where y = n]
zle_iff_zdiff_zle_0 [where y = n] for u v
text\<open>\<open>combine_numerals_prod\<close> (products of separate literals)\<close> lemma"#5 $* x $* #3 = y"apply simp oops
schematic_goal "y2 $+ ?x42 = y $+ y2"apply simp oops
lemma"oo : int \ l $+ (l $+ #2) $+ oo = oo" apply simp oops
lemma"#9$*x $+ y = x$*#23 $+ z"apply simp oops lemma"y $+ x = x $+ z"apply simp oops
lemma"x : int \ x $+ y $+ z = x $+ z" apply simp oops lemma"x : int \ y $+ (z $+ x) = z $+ x" apply simp oops lemma"z : int \ x $+ y $+ z = (z $+ y) $+ (x $+ w)" apply simp oops lemma"z : int \ x$*y $+ z = (z $+ y) $+ (y$*x $+ w)" apply simp oops
lemma"#-3 $* x $+ y $\ x $* #2 $+ z" apply simp oops lemma"y $+ x $\ x $+ z" apply simp oops lemma"x $+ y $+ z $\ x $+ z" apply simp oops
lemma"y $+ (z $+ x) $< z $+ x"apply simp oops lemma"x $+ y $+ z $< (z $+ y) $+ (x $+ w)"apply simp oops lemma"x$*y $+ z $< (z $+ y) $+ (y$*x $+ w)"apply simp oops
lemma"y $- b $< b"apply simp oops lemma"y $- (#3 $* b $+ c) $< b $- #2 $* c"apply simp oops
lemma"(#2 $* x $- (u $* v) $+ y) $- v $* #3 $* u = w"apply simp oops lemma"(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u $* #4 = w"apply simp oops lemma"(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u = w"apply simp oops lemma"u $* v $- (x $* u $* v $+ (u $* v) $* #4 $+ y) = w"apply simp oops
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.