Debian Codegraph @

src/Util/FsatzAutoLemmas.v

raw
1 From Coq.Program Require Import Basics Tactics.
2 From Coq Require Import Morphisms.
3
4 Require Import Crypto.Util.Decidable.
5 Require Import Crypto.Algebra.Field.
6 Require Import Crypto.Util.Notations.
7
8 Create HintDb fsatz_lookup discriminated.
9
10 Module F.
11 Section with_field.
12 Context {F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv}
13 {field:@Algebra.Hierarchy.field F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv}
14 {char_ge_3:@Ring.char_ge F Feq Fzero Fone Fopp Fadd Fsub Fmul (BinNat.N.succ_pos (BinNat.N.two))}
15 {Feq_dec:DecidableRel Feq}.
16 Local Infix "=" := Feq : type_scope. Local Notation "a <> b" := (not (a = b)) : type_scope.
17 Local Notation "0" := Fzero. Local Notation "1" := Fone.
18 Local Infix "+" := Fadd. Local Infix "-" := Fsub.
19 Local Infix "*" := Fmul. Local Infix "/" := Fdiv.
20 Local Notation "x ^ 2" := (x*x). Local Notation "x ^ 3" := (x^2*x).
21
22 Local Obligation Tactic := abstract (intros; fsatz).
23
24 Program Definition eq_opp__eq_zero a : a = Fopp a -> a = 0 := _.
25 Program Definition neq_opp__neq_zero a : a <> Fopp a -> a <> 0 := _.
26 Program Definition twice_eq_zero a : a + a = 0 -> a = 0 := _.
27 Program Definition twice_neq_zero a : a + a <> 0 -> a <> 0 := _.
28 Program Definition inv_cube_eq_zero__neq_zero__absurd a : Finv (a^3) = 0 -> a <> 0 -> False := _.
29 Program Definition sub_eq_zero_eq a b : a - b = 0 -> a = b := _.
30 Program Definition sub_eq_zero_eq_sym a b : a - b = 0 -> b = a := _.
31 Program Definition sub_neq_zero_eq a b : a - b <> 0 -> a <> b := _.
32 Program Definition sub_neq_zero_eq_sym a b : a - b <> 0 -> b <> a := _.
33 Program Definition mul3_nonzero_drop_mid a b c : (a * b) * c <> 0 -> a * c <> 0 := _.
34 Program Definition mul_nonzero_l a b : a * b <> 0 -> a <> 0 := _.
35 Program Definition mul_nonzero_r a b : a * b <> 0 -> b <> 0 := _.
36 Program Definition factor_difference_of_squares a b c : a^2 - b^2 = c -> (a - b) * (a + b) = c := _.
37 Program Definition expand_square_sum a b : (a + b)^2 - (a^2 + b^2) = 0 -> a * b = 0 := _.
38 Program Definition expand_square_sum_neq a b : (a + b)^2 - (a^2 + b^2) <> 0 -> a * b <> 0 := _.
39 Program Definition expand_square_sum_sub a b : (a + b)^2 - a^2 - b^2 = 0 -> a * b = 0 := _.
40 Program Definition expand_square_sum_sub_neq a b : (a + b)^2 - a^2 - b^2 <> 0 -> a * b <> 0 := _.
41 Program Definition factor_square_sum a b : a * b = 0 -> (a + b)^2 - (a^2 + b^2) = 0 := _.
42 Program Definition factor_square_sum_neq a b : a * b <> 0 -> (a + b)^2 - (a^2 + b^2) <> 0 := _.
43 Program Definition factor_square_sum_sub a b : a * b = 0 -> (a + b)^2 - a^2 - b^2 = 0 := _.
44 Program Definition factor_square_sum_sub_neq a b : a * b <> 0 -> (a + b)^2 - a^2 - b^2 <> 0 := _.
45 Program Definition mul_eq_0_r_nz a b : a * b = 0 -> a <> 0 -> b = 0 := _.
46 Program Definition mul_eq_0_l_nz a b : a * b = 0 -> b <> 0 -> a = 0 := _.
47 Program Definition mul_eq_0_l a b : a = 0 -> a * b = 0 := _.
48 Program Definition mul_eq_0_r a b : b = 0 -> a * b = 0 := _.
49 Program Definition mul_neq_0 a b : a <> 0 -> b <> 0 -> a * b <> 0 := _.
50 Program Definition helper1 a b c : a + b * c = 0 -> a <> Fopp (c * b) -> False := _.
51 Program Definition helper2 a b c d : a - b * c <> d -> b = 1 -> a - c <> d := _.
52 Program Definition helper3 a b c d : a - b * c = d -> b = 1 -> a - c = d := _.
53 Program Definition helper4 a b c d e : a - b * c * d <> e -> b = 1 -> a - c * d <> e := _.
54 Program Definition helper5 a b c d e : a - b * c * d = e -> b = 1 -> a - c * d = e := _.
55 Program Definition helper6 a b c d : a - b * c^2 <> d -> c = 1 -> a - b <> d := _.
56 Program Definition helper7 a b c d : a - b * c^2 = d -> c = 1 -> a - b = d := _.
57 Program Definition helper8 a b c d : a - b + c <> d -> b = 0 -> a + c <> d := _.
58 Program Definition helper9 a b c : a - b <> c -> b = 0 -> a <> c := _.
59 Program Definition helper10 a b c d : a * b + c <> d -> a = 0 -> c <> d := _.
60 Program Definition helper11 a b c d : a * b + c <> d -> b = 0 -> c <> d := _.
61 Program Definition helper12 a b c : a * b <> c -> a = 0 -> c <> 0 := _.
62 Program Definition helper13 a b c : a * b <> c -> b = 0 -> c <> 0 := _.
63 Program Definition helper14 a b c : Fopp (a * b) <> c -> a = 0 -> c <> 0 := _.
64 Program Definition helper15 a b c : Fopp (a * b) <> c -> b = 0 -> c <> 0 := _.
65 Program Definition helper16 a b c : a * b^3 = c -> b = 0 -> c = 0 := _.
66 Program Definition helper17 a b c : a * b = c -> a = 0 -> c = 0 := _.
67 Program Definition helper18 a b c : a * b - c <> 0 -> a = 0 -> c <> 0 := _.
68 Program Definition helper19 a b c : a * b - c <> 0 -> b = 0 -> c <> 0 := _.
69 Program Definition helper20 a b c : a * b - c = 0 -> a = 0 -> c = 0 := _.
70 Program Definition helper21 a b c : a * b - c = 0 -> b = 0 -> c = 0 := _.
71 Program Definition helper22 a b c : a - b * c = 0 -> c = 0 -> a = 0 := _.
72 Program Definition helper23 a b c d : a * (b * b^2) - c <> d -> a * (b^3) - c <> d := _.
73 Program Definition helper24 a b c d : a * (b * b^2) - c = d -> a * (b^3) - c = d := _.
74 Program Definition helper25 a b c d : a - (b * b^2) * c <> d -> a - (b^3) * c <> d := _.
75 Program Definition helper26 a b c d : a - (b * b^2) * c = d -> a - (b^3) * c = d := _.
76 Program Definition helper27 a b : a * (b * b^2) = 0 -> b <> 0 -> a = 0 := _.
77 Program Definition helper28 a b c : c <> 0 -> a * (b * c) = 0 -> a * b = 0 := _.
78 Program Definition helper29 a b c : a = 0 -> a * b + c = 0 -> c = 0 := _.
79 Program Definition helper30 a b c d : a * b^3 + d * c^3 = 0 -> a * (b * b^2) - c * c^2 * d = 0 -> a * b^3 = 0 := _.
80 Program Definition helper31 a b c d : a * Finv (b^2) <> c * Finv (d^2) -> b <> 0 -> d <> 0 -> a * (d^2) <> c * (b^2) := _.
81 Program Definition helper32 a b c d : a * Finv (b^2) = c * Finv (d^2) -> b <> 0 -> d <> 0 -> a * (d^2) = c * (b^2) := _.
82 Program Definition helper33 a b c d : a * Finv (b^3) = Fopp (c * Finv (d^3)) -> b <> 0 -> d <> 0 -> a * (d^3) = Fopp (c * (b^3)) := _.
83 Program Definition helper34 a b c d : a * Finv (b^3) <> Fopp (c * Finv (d^3)) -> b <> 0 -> d <> 0 -> a * (d^3) <> Fopp (c * (b^3)) := _.
84 Program Definition helper35 a b c : a = Fopp (b * c) -> a - c * b = 0 -> a = 0 := _.
85 Program Definition helper36 a b c : a <> Fopp (b * c) -> a - c * b = 0 -> a * b * c <> 0 := _.
86 Program Definition helper37 X Y X' Y' A B C C' : Y^2 = C^3 + A * C * (X^2)^2 + B * (X^3)^2 -> Y'^2 = C'^3 + A * C' * (X'^2)^2 + B * (X'^3)^2 -> C' * X^2 - C * X'^2 = 0 -> (Y' * (X^3))^2 - ((X'^3) * Y)^2 = 0 := _.
87 Program Definition helper38 X Y X' Y' A B C C' : Y^2 = C^3 + A * C * (X^2)^2 + B * (X^3)^2 -> Y'^2 = C'^3 + A * C' * (X'^2)^2 + B * (X'^3)^2 -> C' * X^2 = C * X'^2 -> (Y' * (X^3))^2 - ((X'^3) * Y)^2 = 0 := _.
88 Program Definition helper39 a : a <> 0 -> Finv (a^2) = (Finv a)^2 := _.
89 Program Definition helper40 a : a <> 0 -> Finv (a^3) = (Finv a)^3 := _.
90 Program Definition helper41 a : a <> 0 -> Finv (Finv a) = a := _.
91 Program Definition helper42 a b : (a + b)^2 - a^2 - b^2 = (1+1) * a * b := _.
92 Program Definition helper42' a b : (a + b)^2 - (a^2 + b^2) = (1+1) * a * b := _.
93 Program Definition helper43 a b : a * b <> 0 -> Finv (a * b) = Finv a * Finv b := _.
94 Program Definition helper_zero_1 a b c : a = b * c -> b = 0 -> a = 0 := _.
95 Program Definition helper44 x y z w A B C D
96 (H0 : x * y^3 = A * B^3)
97 (H1 : x * z^3 - B^3 * D = 0)
98 (H2 : D * C^3 = w * z^3)
99 (H3 : A * C^3 - y^3 * w <> 0)
100 (Hz : z <> 0)
101 (HB : B <> 0)
102 : False := _.
103 Program Definition helper45 x y z w A B C D
104 (H0 : x * y^3 = A * B^3)
105 (H1 : x * z^3 - B^3 * D <> 0)
106 (H2 : D * C^3 = w * z^3)
107 (H3 : A * C^3 - y^3 * w = 0)
108 (Hy : y <> 0)
109 (HC : C <> 0)
110 : False := _.
111 Program Definition helper46 x y z w A B C D
112 (H0 : x * y^2 = A * B^2)
113 (H1 : x * z^2 - D * B^2 = 0)
114 (H2 : D * C^2 = w * z^2)
115 (H3 : A * C^2 - w * y^2 <> 0)
116 (Hz : z <> 0)
117 (HB : B <> 0)
118 : False := _.
119 Program Definition helper47 x y z w A B C D
120 (H0 : A * B^2 = x * y^2)
121 (H1 : x * z^2 - D * B^2 = 0)
122 (H2 : w * z^2 = D * C^2)
123 (H3 : A * C^2 - w * y^2 <> 0)
124 (Hz : z <> 0)
125 (HB : B <> 0)
126 : False := _.
127
128 Record dyn := { ty : Prop ; lem : ty }.
129
130 Local Notation "[ x , .. , z ]"
131 := (cons {| lem := x |} .. (cons {| lem := z |} nil) .. ).
132
133 (* grep -o 'Program Definition [^ ]*' src/Util/FsatzAutoLemmas.v | sed s'/Program Definition /, /g' *)
134 Definition all_lemmas
135 := [I
136 , eq_opp__eq_zero
137 , neq_opp__neq_zero
138 , twice_eq_zero
139 , twice_neq_zero
140 , inv_cube_eq_zero__neq_zero__absurd
141 , sub_eq_zero_eq
142 , sub_eq_zero_eq_sym
143 , sub_neq_zero_eq
144 , sub_neq_zero_eq_sym
145 , mul3_nonzero_drop_mid
146 , mul_nonzero_l
147 , mul_nonzero_r
148 , factor_difference_of_squares
149 , expand_square_sum
150 , expand_square_sum_neq
151 , expand_square_sum_sub
152 , expand_square_sum_sub_neq
153 , factor_square_sum
154 , factor_square_sum_neq
155 , factor_square_sum_sub
156 , factor_square_sum_sub_neq
157 , mul_eq_0_r_nz
158 , mul_eq_0_l_nz
159 , mul_eq_0_l
160 , mul_eq_0_r
161 , mul_neq_0
162 , helper1
163 , helper2
164 , helper3
165 , helper4
166 , helper5
167 , helper6
168 , helper7
169 , helper8
170 , helper9
171 , helper10
172 , helper11
173 , helper12
174 , helper13
175 , helper14
176 , helper15
177 , helper16
178 , helper17
179 , helper18
180 , helper19
181 , helper20
182 , helper21
183 , helper22
184 , helper23
185 , helper24
186 , helper25
187 , helper26
188 , helper27
189 , helper28
190 , helper29
191 , helper30
192 , helper31
193 , helper32
194 , helper33
195 , helper34
196 , helper35
197 , helper36
198 , helper37
199 , helper38
200 , helper39
201 , helper40
202 , helper41
203 , helper42
204 , helper42'
205 , helper43
206 , helper_zero_1
207 , helper44
208 , helper45
209 , helper46
210 , helper47
211 ].
212 End with_field.
213
214 Ltac get_package_on fld :=
215 let pkg := constr:(all_lemmas (field:=fld)) in
216 let pkg := (eval cbv [all_lemmas] in pkg) in
217 pkg.
218
219 Ltac lookup_lemma_on pkg ty :=
220 lazymatch pkg with
221 | context[@Build_dyn ty ?lem] => lem
222 end.
223
224 Ltac lookup_lemma ty :=
225 let fld := guess_field in
226 let pkg := get_package_on fld in
227 lookup_lemma_on fld ty.
228
229 Ltac with_lemma_on pkg ty tac :=
230 let H := lookup_lemma_on pkg ty in
231 tac H.
232
233 Ltac goal_exact_lemma_on pkg :=
234 lazymatch goal with
235 | [ |- ?G ] => with_lemma_on pkg G ltac:(fun H' => exact H')
236 end.
237 Ltac goal_apply_lemma_on pkg ty :=
238 with_lemma_on pkg ty ltac:(fun H' => apply H').
239 Ltac apply_lemma_in_on pkg H ty :=
240 with_lemma_on pkg ty ltac:(fun H' => apply H' in H).
241 Ltac apply2_lemma_in_on pkg H0 H1 ty :=
242 with_lemma_on pkg ty ltac:(fun H' => apply H' in H0; [ | exact H1 ]).
243 Ltac apply_lemma_in_on' pkg H ty preapp :=
244 with_lemma_on pkg ty ltac:(fun H' => let H' := preapp H' in apply H' in H).
245 End F.