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))" |
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 |