File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -542,6 +542,43 @@ Proof.
542
542
lia.
543
543
Qed .
544
544
545
+ (** Floor: [floor n amount] returns the greatest multiple of [amount]
546
+ less than or equal to [n]. *)
547
+
548
+ Definition floor (n: Z) (amount: Z) := (n / amount) * amount.
549
+
550
+ Lemma floor_interval:
551
+ forall x y, y > 0 -> floor x y <= x < floor x y + y.
552
+ Proof .
553
+ unfold floor; intros.
554
+ generalize (Z_div_mod_eq x y H) (Z_mod_lt x y H).
555
+ set (q := x / y). set (r := x mod y). intros. lia.
556
+ Qed .
557
+
558
+ Lemma floor_divides:
559
+ forall x y, y > 0 -> (y | floor x y).
560
+ Proof .
561
+ unfold floor; intros. exists (x / y); auto.
562
+ Qed .
563
+
564
+ Lemma floor_same:
565
+ forall x y, y > 0 -> (y | x) -> floor x y = x.
566
+ Proof .
567
+ unfold floor; intros. rewrite (Zdivide_Zdiv_eq y x) at 2; auto; lia.
568
+ Qed .
569
+
570
+ Lemma floor_align_interval:
571
+ forall x y, y > 0 ->
572
+ floor x y <= align x y <= floor x y + y.
573
+ Proof .
574
+ unfold floor, align; intros.
575
+ replace (x / y * y + y) with ((x + 1 * y) / y * y).
576
+ assert (A: forall a b, a <= b -> a / y * y <= b / y * y).
577
+ { intros. apply Z.mul_le_mono_nonneg_r. lia. apply Z.div_le_mono; lia. }
578
+ split; apply A; lia.
579
+ rewrite Z.div_add by lia. lia.
580
+ Qed .
581
+
545
582
(** * Definitions and theorems on the data types [option], [sum] and [list] *)
546
583
547
584
Set Implicit Arguments .
You can’t perform that action at this time.
0 commit comments