Skip to content

Commit ee147b9

Browse files
lczielinskiwjbs
andauthored
Add results about permutations (#42)
* added bunch of results to permutations * everything * Proof repair; added decidability of permutations * name change * final cleanup * fixes to small files * modulus * new file yay * dirty work * delay progress * final move * fix build * opam --------- Co-authored-by: William Spencer <wjbs@uchicago.edu>
1 parent 37865be commit ee147b9

9 files changed

Lines changed: 2815 additions & 680 deletions

File tree

Bits.v

Lines changed: 803 additions & 0 deletions
Large diffs are not rendered by default.

DiscreteProb.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Require Import VectorStates Measurement.
1+
Require Import Bits VectorStates Measurement.
22

33
(** This file describes some theory of discrete probability distributions.
44
Its main feature is 'apply_u', a function to describe the output distribution

Modulus.v

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Require Import Prelim.
2+
3+
Lemma div_mod_inj {a b} (c :nat) : c > 0 ->
4+
(a mod c) = (b mod c) /\ (a / c) = (b / c) -> a = b.
5+
Proof.
6+
intros Hc.
7+
intros [Hmod Hdiv].
8+
rewrite (Nat.div_mod_eq a c).
9+
rewrite (Nat.div_mod_eq b c).
10+
rewrite Hmod, Hdiv.
11+
easy.
12+
Qed.
13+
14+
Lemma mod_add_n_r : forall m n,
15+
(m + n) mod n = m mod n.
16+
Proof.
17+
intros m n.
18+
replace (m + n)%nat with (m + 1 * n)%nat by lia.
19+
destruct n.
20+
- cbn; easy.
21+
- rewrite Nat.mod_add;
22+
lia.
23+
Qed.
24+
25+
Lemma mod_eq_sub : forall m n,
26+
m mod n = (m - n * (m / n))%nat.
27+
Proof.
28+
intros m n.
29+
destruct n.
30+
- cbn; lia.
31+
- assert (H: (S n <> 0)%nat) by easy.
32+
pose proof (Nat.div_mod m (S n) H) as Heq.
33+
lia.
34+
Qed.
35+
36+
Lemma mod_of_scale : forall m n q,
37+
(n * q <= m < n * S q)%nat -> m mod n = (m - q * n)%nat.
38+
Proof.
39+
intros m n q [Hmq HmSq].
40+
rewrite mod_eq_sub.
41+
replace (m/n)%nat with q; [lia|].
42+
apply Nat.le_antisymm.
43+
- apply Nat.div_le_lower_bound; lia.
44+
- epose proof (Nat.div_lt_upper_bound m n (S q) _ _).
45+
lia.
46+
Unshelve.
47+
all: lia.
48+
Qed.
49+
50+
Lemma mod_n_to_2n : forall m n,
51+
(n <= m < 2 * n)%nat -> m mod n = (m - n)%nat.
52+
Proof.
53+
intros.
54+
epose proof (mod_of_scale m n 1 _).
55+
lia.
56+
Unshelve.
57+
lia.
58+
Qed.
59+
60+
Lemma mod_n_to_n_plus_n : forall m n,
61+
(n <= m < n + n)%nat -> m mod n = (m - n)%nat.
62+
Proof.
63+
intros.
64+
apply mod_n_to_2n; lia.
65+
Qed.
66+
67+
Ltac simplify_mods_of a b :=
68+
first [
69+
rewrite (Nat.mod_small a b) in * by lia
70+
| rewrite (mod_n_to_2n a b) in * by lia
71+
].
72+
73+
Ltac solve_simple_mod_eqns :=
74+
let __fail_if_has_mods a :=
75+
match a with
76+
| context[_ mod _] => fail 1
77+
| _ => idtac
78+
end
79+
in
80+
match goal with
81+
| |- context[if _ then _ else _] => fail 1 "Cannot solve equation with if"
82+
| _ =>
83+
repeat first [
84+
easy
85+
| lia
86+
| match goal with
87+
| |- context[?a mod ?b] => __fail_if_has_mods a; __fail_if_has_mods b;
88+
simplify_mods_of a b
89+
| H: context[?a mod ?b] |- _ => __fail_if_has_mods a; __fail_if_has_mods b;
90+
simplify_mods_of a b
91+
end
92+
| match goal with
93+
| |- context[?a mod ?b] => (* idtac a b; *) bdestruct (a <? b);
94+
[rewrite (Nat.mod_small a b) by lia
95+
| try rewrite (mod_n_to_2n a b) by lia]
96+
end
97+
]
98+
end.

0 commit comments

Comments
 (0)