src/ZF/Bin.thy
changeset 46821 ff6b0c1087f2
parent 46820 c656222c4dc1
child 46953 2b6e55924af3
equal deleted inserted replaced
46820:c656222c4dc1 46821:ff6b0c1087f2
   344 
   344 
   345 (** Equals (=) **)
   345 (** Equals (=) **)
   346 
   346 
   347 lemma eq_integ_of_eq:
   347 lemma eq_integ_of_eq:
   348      "[| v: bin;  w: bin |]
   348      "[| v: bin;  w: bin |]
   349       ==> ((integ_of(v)) = integ_of(w)) <->
   349       ==> ((integ_of(v)) = integ_of(w)) \<longleftrightarrow>
   350           iszero (integ_of (bin_add (v, bin_minus(w))))"
   350           iszero (integ_of (bin_add (v, bin_minus(w))))"
   351 apply (unfold iszero_def)
   351 apply (unfold iszero_def)
   352 apply (simp add: zcompare_rls integ_of_add integ_of_minus)
   352 apply (simp add: zcompare_rls integ_of_add integ_of_minus)
   353 done
   353 done
   354 
   354 
   361 apply (simp add: zminus_equation)
   361 apply (simp add: zminus_equation)
   362 done
   362 done
   363 
   363 
   364 lemma iszero_integ_of_BIT:
   364 lemma iszero_integ_of_BIT:
   365      "[| w: bin; x: bool |]
   365      "[| w: bin; x: bool |]
   366       ==> iszero (integ_of (w BIT x)) <-> (x=0 & iszero (integ_of(w)))"
   366       ==> iszero (integ_of (w BIT x)) \<longleftrightarrow> (x=0 & iszero (integ_of(w)))"
   367 apply (unfold iszero_def, simp)
   367 apply (unfold iszero_def, simp)
   368 apply (subgoal_tac "integ_of (w) \<in> int")
   368 apply (subgoal_tac "integ_of (w) \<in> int")
   369 apply typecheck
   369 apply typecheck
   370 apply (drule int_cases)
   370 apply (drule int_cases)
   371 apply (safe elim!: boolE)
   371 apply (safe elim!: boolE)
   372 apply (simp_all (asm_lr) add: zcompare_rls zminus_zadd_distrib [symmetric]
   372 apply (simp_all (asm_lr) add: zcompare_rls zminus_zadd_distrib [symmetric]
   373                      int_of_add [symmetric])
   373                      int_of_add [symmetric])
   374 done
   374 done
   375 
   375 
   376 lemma iszero_integ_of_0:
   376 lemma iszero_integ_of_0:
   377      "w: bin ==> iszero (integ_of (w BIT 0)) <-> iszero (integ_of(w))"
   377      "w: bin ==> iszero (integ_of (w BIT 0)) \<longleftrightarrow> iszero (integ_of(w))"
   378 by (simp only: iszero_integ_of_BIT, blast)
   378 by (simp only: iszero_integ_of_BIT, blast)
   379 
   379 
   380 lemma iszero_integ_of_1: "w: bin ==> ~ iszero (integ_of (w BIT 1))"
   380 lemma iszero_integ_of_1: "w: bin ==> ~ iszero (integ_of (w BIT 1))"
   381 by (simp only: iszero_integ_of_BIT, blast)
   381 by (simp only: iszero_integ_of_BIT, blast)
   382 
   382 
   385 (** Less-than (<) **)
   385 (** Less-than (<) **)
   386 
   386 
   387 lemma less_integ_of_eq_neg:
   387 lemma less_integ_of_eq_neg:
   388      "[| v: bin;  w: bin |]
   388      "[| v: bin;  w: bin |]
   389       ==> integ_of(v) $< integ_of(w)
   389       ==> integ_of(v) $< integ_of(w)
   390           <-> znegative (integ_of (bin_add (v, bin_minus(w))))"
   390           \<longleftrightarrow> znegative (integ_of (bin_add (v, bin_minus(w))))"
   391 apply (unfold zless_def zdiff_def)
   391 apply (unfold zless_def zdiff_def)
   392 apply (simp add: integ_of_minus integ_of_add)
   392 apply (simp add: integ_of_minus integ_of_add)
   393 done
   393 done
   394 
   394 
   395 lemma not_neg_integ_of_Pls: "~ znegative (integ_of(Pls))"
   395 lemma not_neg_integ_of_Pls: "~ znegative (integ_of(Pls))"
   398 lemma neg_integ_of_Min: "znegative (integ_of(Min))"
   398 lemma neg_integ_of_Min: "znegative (integ_of(Min))"
   399 by simp
   399 by simp
   400 
   400 
   401 lemma neg_integ_of_BIT:
   401 lemma neg_integ_of_BIT:
   402      "[| w: bin; x: bool |]
   402      "[| w: bin; x: bool |]
   403       ==> znegative (integ_of (w BIT x)) <-> znegative (integ_of(w))"
   403       ==> znegative (integ_of (w BIT x)) \<longleftrightarrow> znegative (integ_of(w))"
   404 apply simp
   404 apply simp
   405 apply (subgoal_tac "integ_of (w) \<in> int")
   405 apply (subgoal_tac "integ_of (w) \<in> int")
   406 apply typecheck
   406 apply typecheck
   407 apply (drule int_cases)
   407 apply (drule int_cases)
   408 apply (auto elim!: boolE simp add: int_of_add [symmetric]  zcompare_rls)
   408 apply (auto elim!: boolE simp add: int_of_add [symmetric]  zcompare_rls)
   414 done
   414 done
   415 
   415 
   416 (** Less-than-or-equals (<=) **)
   416 (** Less-than-or-equals (<=) **)
   417 
   417 
   418 lemma le_integ_of_eq_not_less:
   418 lemma le_integ_of_eq_not_less:
   419      "(integ_of(x) $<= (integ_of(w))) <-> ~ (integ_of(w) $< (integ_of(x)))"
   419      "(integ_of(x) $<= (integ_of(w))) \<longleftrightarrow> ~ (integ_of(w) $< (integ_of(x)))"
   420 by (simp add: not_zless_iff_zle [THEN iff_sym])
   420 by (simp add: not_zless_iff_zle [THEN iff_sym])
   421 
   421 
   422 
   422 
   423 (*Delete the original rewrites, with their clumsy conditional expressions*)
   423 (*Delete the original rewrites, with their clumsy conditional expressions*)
   424 declare bin_succ_BIT [simp del]
   424 declare bin_succ_BIT [simp del]
   507 by (simp add: zdiff_def)
   507 by (simp add: zdiff_def)
   508 
   508 
   509 lemma zdiff_self [simp]: "x $- x = #0"
   509 lemma zdiff_self [simp]: "x $- x = #0"
   510 by (simp add: zdiff_def)
   510 by (simp add: zdiff_def)
   511 
   511 
   512 lemma znegative_iff_zless_0: "k: int ==> znegative(k) <-> k $< #0"
   512 lemma znegative_iff_zless_0: "k: int ==> znegative(k) \<longleftrightarrow> k $< #0"
   513 by (simp add: zless_def)
   513 by (simp add: zless_def)
   514 
   514 
   515 lemma zero_zless_imp_znegative_zminus: "[|#0 $< k; k: int|] ==> znegative($-k)"
   515 lemma zero_zless_imp_znegative_zminus: "[|#0 $< k; k: int|] ==> znegative($-k)"
   516 by (simp add: zless_def)
   516 by (simp add: zless_def)
   517 
   517 
   543 declare int_of_nat_of [simp] nat_of_zminus_int_of [simp]
   543 declare int_of_nat_of [simp] nat_of_zminus_int_of [simp]
   544 
   544 
   545 lemma int_of_nat_of_if: "$# nat_of(z) = (if #0 $<= z then intify(z) else #0)"
   545 lemma int_of_nat_of_if: "$# nat_of(z) = (if #0 $<= z then intify(z) else #0)"
   546 by (simp add: int_of_nat_of znegative_iff_zless_0 not_zle_iff_zless)
   546 by (simp add: int_of_nat_of znegative_iff_zless_0 not_zle_iff_zless)
   547 
   547 
   548 lemma zless_nat_iff_int_zless: "[| m: nat; z: int |] ==> (m < nat_of(z)) <-> ($#m $< z)"
   548 lemma zless_nat_iff_int_zless: "[| m: nat; z: int |] ==> (m < nat_of(z)) \<longleftrightarrow> ($#m $< z)"
   549 apply (case_tac "znegative (z) ")
   549 apply (case_tac "znegative (z) ")
   550 apply (erule_tac [2] not_zneg_nat_of [THEN subst])
   550 apply (erule_tac [2] not_zneg_nat_of [THEN subst])
   551 apply (auto dest: zless_trans dest!: zero_zle_int_of [THEN zle_zless_trans]
   551 apply (auto dest: zless_trans dest!: zero_zle_int_of [THEN zle_zless_trans]
   552             simp add: znegative_iff_zless_0)
   552             simp add: znegative_iff_zless_0)
   553 done
   553 done
   554 
   554 
   555 
   555 
   556 (** nat_of and zless **)
   556 (** nat_of and zless **)
   557 
   557 
   558 (*An alternative condition is  @{term"$#0 \<subseteq> w"}  *)
   558 (*An alternative condition is  @{term"$#0 \<subseteq> w"}  *)
   559 lemma zless_nat_conj_lemma: "$#0 $< z ==> (nat_of(w) < nat_of(z)) <-> (w $< z)"
   559 lemma zless_nat_conj_lemma: "$#0 $< z ==> (nat_of(w) < nat_of(z)) \<longleftrightarrow> (w $< z)"
   560 apply (rule iff_trans)
   560 apply (rule iff_trans)
   561 apply (rule zless_int_of [THEN iff_sym])
   561 apply (rule zless_int_of [THEN iff_sym])
   562 apply (auto simp add: int_of_nat_of_if simp del: zless_int_of)
   562 apply (auto simp add: int_of_nat_of_if simp del: zless_int_of)
   563 apply (auto elim: zless_asym simp add: not_zle_iff_zless)
   563 apply (auto elim: zless_asym simp add: not_zle_iff_zless)
   564 apply (blast intro: zless_zle_trans)
   564 apply (blast intro: zless_zle_trans)
   565 done
   565 done
   566 
   566 
   567 lemma zless_nat_conj: "(nat_of(w) < nat_of(z)) <-> ($#0 $< z & w $< z)"
   567 lemma zless_nat_conj: "(nat_of(w) < nat_of(z)) \<longleftrightarrow> ($#0 $< z & w $< z)"
   568 apply (case_tac "$#0 $< z")
   568 apply (case_tac "$#0 $< z")
   569 apply (auto simp add: zless_nat_conj_lemma nat_le_int0 not_zless_iff_zle)
   569 apply (auto simp add: zless_nat_conj_lemma nat_le_int0 not_zless_iff_zle)
   570 done
   570 done
   571 
   571 
   572 (*This simprule cannot be added unless we can find a way to make eq_integ_of_eq
   572 (*This simprule cannot be added unless we can find a way to make eq_integ_of_eq
   573   unconditional!
   573   unconditional!
   574   [The condition "True" is a hack to prevent looping.
   574   [The condition "True" is a hack to prevent looping.
   575     Conditional rewrite rules are tried after unconditional ones, so a rule
   575     Conditional rewrite rules are tried after unconditional ones, so a rule
   576     like eq_nat_number_of will be tried first to eliminate #mm=#nn.]
   576     like eq_nat_number_of will be tried first to eliminate #mm=#nn.]
   577   lemma integ_of_reorient [simp]:
   577   lemma integ_of_reorient [simp]:
   578        "True ==> (integ_of(w) = x) <-> (x = integ_of(w))"
   578        "True ==> (integ_of(w) = x) \<longleftrightarrow> (x = integ_of(w))"
   579   by auto
   579   by auto
   580 *)
   580 *)
   581 
   581 
   582 lemma integ_of_minus_reorient [simp]:
   582 lemma integ_of_minus_reorient [simp]:
   583      "(integ_of(w) = $- x) <-> ($- x = integ_of(w))"
   583      "(integ_of(w) = $- x) \<longleftrightarrow> ($- x = integ_of(w))"
   584 by auto
   584 by auto
   585 
   585 
   586 lemma integ_of_add_reorient [simp]:
   586 lemma integ_of_add_reorient [simp]:
   587      "(integ_of(w) = x $+ y) <-> (x $+ y = integ_of(w))"
   587      "(integ_of(w) = x $+ y) \<longleftrightarrow> (x $+ y = integ_of(w))"
   588 by auto
   588 by auto
   589 
   589 
   590 lemma integ_of_diff_reorient [simp]:
   590 lemma integ_of_diff_reorient [simp]:
   591      "(integ_of(w) = x $- y) <-> (x $- y = integ_of(w))"
   591      "(integ_of(w) = x $- y) \<longleftrightarrow> (x $- y = integ_of(w))"
   592 by auto
   592 by auto
   593 
   593 
   594 lemma integ_of_mult_reorient [simp]:
   594 lemma integ_of_mult_reorient [simp]:
   595      "(integ_of(w) = x $* y) <-> (x $* y = integ_of(w))"
   595      "(integ_of(w) = x $* y) \<longleftrightarrow> (x $* y = integ_of(w))"
   596 by auto
   596 by auto
   597 
   597 
   598 end
   598 end