Debian Codegraph @

src/Util/ZRange/CornersMonotoneBounds.v

raw
1 From Coq Require Import Morphisms.
2 From Coq Require Import ZArith.
3 From Coq Require Import Lia.
4 Require Import Crypto.Util.ZUtil.Tactics.SplitMinMax.
5 Require Import Crypto.Util.ZUtil.Stabilization.
6 Require Import Crypto.Util.ZUtil.MulSplit.
7 Require Import Crypto.Util.ZUtil.Tactics.LtbToLt.
8 Require Import Crypto.Util.PointedProp.
9 Require Import Crypto.Util.Bool.
10 Require Import Crypto.Util.ZRange.
11 Require Import Crypto.Util.ZRange.Operations.
12 Require Import Crypto.Util.ZRange.BasicLemmas.
13 Require Import Crypto.Util.Tuple.
14 Require Import Crypto.Util.Tactics.DestructHead.
15 Require Import Crypto.Util.Tactics.SpecializeAllWays.
16 Require Import Crypto.Util.Tactics.BreakMatch.
17 Require Import Crypto.Util.Tactics.UniquePose.
18 Require Import Crypto.Util.Tactics.SpecializeBy.
19
20 Local Open Scope Z_scope.
21
22 Module ZRange.
23 Import Operations.ZRange.
24 Local Arguments is_bounded_by' !_ _ _ / .
25 Local Coercion is_true : bool >-> Sortclass.
26
27 Fixpoint app' {A B} {n : nat} : nary_T A B (S n) -> tuple' A n -> B
28 := match n with
29 | O => fun f x => f x
30 | S n => fun f '(xs, x) => @app' A B n (f x) xs
31 end.
32 Definition app {A B} {n : nat} : nary_T A B n -> tuple A n -> B
33 := match n with
34 | O => fun x _ => x
35 | S n => @app' A B n
36 end.
37
38 Local Notation R b := (match b with true => Z.le | false => Basics.flip Z.le end).
39
40 Local Notation Rp b := (match b with true => Pos.le | false => Basics.flip Pos.le end).
41
42 Fixpoint is_monotone_on_projections {n : nat} : nary_T Z Z n -> Prop
43 := match n with
44 | O => fun _ => True
45 | S n' => fun f
46 => (forall x, is_monotone_on_projections (f x))
47 /\ (forall args, exists b, Proper (R b ==> Z.le) (fun x => app (f x) args))
48 end.
49
50 Fixpoint is_piecewise_monotone_on_projections {n : nat} : nary_T Z Z n -> Prop
51 := match n with
52 | O => fun _ => True
53 | S n'
54 => fun f
55 => (forall x, is_piecewise_monotone_on_projections (f x))
56 /\ (forall args, exists b, Proper (Rp b ==> Z.le) (fun x => app (f (Zpos x)) args))
57 /\ (forall args, exists b, Proper (Rp b ==> Z.le) (fun x => app (f (Zneg x)) args))
58 end.
59
60 Definition all_are_bounded_by_bool {n} (v : tuple Z n) (v_bs : tuple zrange n) : bool
61 := Tuple.fieldwiseb is_bounded_by_bool v v_bs.
62
63 Local Ltac fast_split_min_max := rewrite ?Z.min_le_iff, ?Z.max_le_iff.
64
65 Local Ltac t_fin_common_step :=
66 first [ progress cbv [all_are_bounded_by_bool is_bounded_by_bool is_monotone_on_projections is_true is_tighter_than_bool] in *
67 | progress cbv [Proper respectful Basics.flip] in *
68 | progress cbn in *
69 | progress rewrite ?Bool.orb_true_iff, ?Bool.orb_false_iff, ?Bool.andb_true_iff, ?Z.leb_le, ?Z.ltb_lt in *
70 | progress Z.ltb_to_lt
71 | progress fast_split_min_max
72 | progress destruct_head'_and
73 | progress destruct_head'_prod
74 | progress destruct_head'_ex
75 | progress specialize_by exact tt
76 | progress specialize_by exact I
77 | progress destruct_head' zrange
78 | solve [ auto using or_introl, or_intror, Z.le_refl ]
79 | match goal with
80 | [ H : _ -> True |- _ ] => clear H
81 | [ H : ?x <= ?x |- _ ] => clear H
82 | [ H : ?x \/ ?x |- _ ] => assert x by (destruct H; assumption); clear H
83 | [ H : ?x < ?x |- _ ] => exfalso; clear -H; lia
84 | [ H : 0 <= Z.pos _ |- _ ] => clear H
85 | [ H : 0 < Z.pos _ |- _ ] => clear H
86 | [ H : Z.neg _ <= 0 |- _ ] => clear H
87 | [ H : Z.neg _ < 0 |- _ ] => clear H
88 | [ H : Z.pos _ <= Z.neg _ |- _ ] => exfalso; clear -H; lia
89 | [ H : Z.pos _ <= 0 |- _ ] => exfalso; clear -H; lia
90 | [ H : 0 <= Z.neg _ |- _ ] => exfalso; clear -H; lia
91 | [ H : Z.pos _ < 0 |- _ ] => exfalso; clear -H; lia
92 | [ |- context[Z.max 1 (Z.pos ?x)] ] => rewrite (Z.max_r 1 (Zpos x)) by (clear; lia)
93 | [ |- context[Z.min 1 (Z.pos ?x)] ] => rewrite (Z.min_l 1 (Zpos x)) by (clear; lia)
94 | [ H : ?x > ?y |- _ ] => assert (y < x) by (clear -H; lia); clear H
95 | [ H : ?x >= ?y |- _ ] => assert (y <= x) by (clear -H; lia); clear H
96 | [ |- context[Z.max (Z.neg ?x) (-1)] ] => rewrite (Z.max_r (Zneg x) (-1)) by (clear; lia)
97 | [ |- context[Z.min (Z.neg ?x) (-1)] ] => rewrite (Z.min_l (Zneg x) (-1)) by (clear; lia)
98 end ].
99 Local Ltac t_fin_saturate_step :=
100 first [ progress destruct_head'_bool
101 | match goal with
102 | [ H : forall (x : Z) (y : Z), _ <= _ -> _ <= _, v : Z |- _ ]
103 => unique pose proof (H v v ltac:(reflexivity))
104 | [ H : forall (x : Z) (y : Z), _ <= _ -> _ <= _, v : Z, v' : Z |- _ ]
105 => unique pose proof (H v v' ltac:(auto || reflexivity))
106 end
107 | apply conj ].
108 Local Ltac t_fin_specific_pos_step :=
109 first [ match goal with
110 | [ H : _ \/ _ |- _ ] => destruct H as [H|H]; try (exfalso; clear -H; lia); []
111 | [ H : Z.pos _ <= ?v |- _ ] => is_var v; destruct v as [|v|v]; try (exfalso; clear -H; lia)
112 | [ H : ?v <= Z.neg _ |- _ ] => is_var v; destruct v as [|v|v]; try (exfalso; clear -H; lia)
113 | [ H : 0 <= ?v |- _ ] => is_var v; destruct v as [|v|v]; try (exfalso; clear -H; lia)
114 | [ H : ?v <= 0 |- _ ] => is_var v; destruct v as [|v|v]; try (exfalso; clear -H; lia)
115 | [ H : 0 < ?v |- _ ] => is_var v; destruct v as [|v|v]; try (exfalso; clear -H; lia)
116 | [ H : ?v < 0 |- _ ] => is_var v; destruct v as [|v|v]; try (exfalso; clear -H; lia)
117 end
118 | break_innermost_match_step
119 | progress destruct_head'_bool
120 | match goal with
121 | [ H' : Z.le (?f ?p) (?g ?q) |- _ ]
122 => first [ unique assert (Pos.le p q) by (clear -H'; lia)
123 | unique assert (Pos.le q p) by (clear -H'; lia) ]
124 | [ H : forall x y, Pos.le _ _ -> _ <= _, H' : Pos.le _ _ |- _ ]
125 => unique pose proof (H _ _ H')
126 | [ H : forall x y, Pos.le x _ -> _ <= _, v : positive |- _ ]
127 => unique pose proof (H 1%positive v ltac:(clear; lia))
128 | [ H : forall x y, Pos.le _ x -> _ <= _, v : positive |- _ ]
129 => unique pose proof (H v 1%positive ltac:(clear; lia))
130 end
131 | apply conj
132 | progress destruct_head' Z ].
133 Local Ltac t_fin :=
134 repeat first [ t_fin_common_step
135 | t_fin_saturate_step ].
136 Local Ltac t_fin_pos :=
137 repeat first [ t_fin_common_step
138 | t_fin_specific_pos_step ].
139
140 Lemma pull_union_under_args2 A n f g bs
141 : @app' A _ n (under_args2 union f g) bs
142 = union (app' f bs) (app' g bs).
143 Proof. induction n; t_fin. Qed.
144
145 Lemma monotone_n_corners_genb
146 n f
147 (Hmonotone : @is_monotone_on_projections n f)
148 v v_bs
149 (Hboundedx : @all_are_bounded_by_bool n v v_bs)
150 : is_bounded_by_bool (app f v) (app (n_corners f) v_bs).
151 Proof.
152 destruct n as [|n].
153 { cbv [all_are_bounded_by_bool is_bounded_by_bool is_monotone_on_projections is_true] in *; cbn in *.
154 rewrite Bool.andb_true_iff, Z.leb_le; split; reflexivity. }
155 cbv [app tuple all_are_bounded_by_bool fieldwiseb] in *.
156 induction n as [|n IHn].
157 { t_fin. }
158 { destruct v_bs as [ v_bs [l u] ], v as [vs v]; cbn [lower upper] in *.
159 cbn [fieldwiseb' fst snd] in Hboundedx.
160 cbv [is_true] in *.
161 rewrite Bool.andb_true_iff in Hboundedx.
162 destruct Hboundedx as [Hboundedx0 Hboundedx1].
163 destruct Hmonotone as [Hmonotone0 Hmonotone1].
164 specialize (fun x => IHn (f x) (Hmonotone0 _) vs v_bs Hboundedx0).
165 cbn [app'].
166 set (Sn := S n) in *.
167 cbn [n_corners].
168 set (f' := fun x => @n_corners Sn (f x)).
169 lazymatch type of IHn with
170 | forall x, is_bounded_by_bool (@?B x) (app' _ ?v_bs) = true
171 => change (forall x, is_bounded_by_bool (B x) (app' (f' x) v_bs) = true) in IHn
172 end; cbv beta in *.
173 clearbody f'.
174 cbn -[Sn] in *.
175 rewrite pull_union_under_args2.
176 cbv [is_bounded_by_bool app] in *.
177 unfold Sn in Hmonotone1.
178 setoid_rewrite Bool.andb_true_iff in IHn.
179 rewrite ?Bool.andb_true_iff in *.
180 setoid_rewrite Z.leb_le in IHn.
181 rewrite !Z.leb_le in *.
182 specialize (Hmonotone1 vs).
183 destruct Hmonotone1 as [? Hmonotone1].
184 clear -IHn Hboundedx1 Hmonotone1.
185 cbn [lower upper] in *.
186 destruct_head'_bool.
187 all: split; etransitivity; [ | eapply Hmonotone1, Hboundedx1 | eapply Hmonotone1, Hboundedx1 | ].
188 all: first [ etransitivity; [ eapply IHn | ] | etransitivity; [ | eapply IHn ] ].
189 all: clear; t_fin. }
190 Qed.
191
192 Lemma monotone_n_corners_and_zero_genb
193 n f
194 (Hmonotone : @is_piecewise_monotone_on_projections n f)
195 v v_bs
196 (Hboundedx : @all_are_bounded_by_bool n v v_bs)
197 : is_bounded_by_bool (app f v) (app (n_corners_and_zero f) v_bs).
198 Proof.
199 destruct n as [|n].
200 { cbv [all_are_bounded_by_bool is_bounded_by_bool is_piecewise_monotone_on_projections is_true] in *; cbn in *.
201 rewrite Bool.andb_true_iff, Z.leb_le; split; reflexivity. }
202 cbv [app tuple all_are_bounded_by_bool fieldwiseb] in *.
203 induction n as [|n IHn].
204 { t_fin_pos. }
205 { destruct v_bs as [ v_bs [l u] ], v as [vs v]; cbn [lower upper] in *.
206 cbn [fieldwiseb' fst snd] in Hboundedx.
207 cbv [is_true] in *.
208 rewrite Bool.andb_true_iff in Hboundedx.
209 destruct Hboundedx as [Hboundedx0 Hboundedx1].
210 destruct Hmonotone as [Hmonotone0 [Hmonotone1 Hmonotone2] ].
211 specialize (fun f pf => IHn f pf vs v_bs Hboundedx0).
212 specialize (fun x => IHn (f x) (Hmonotone0 _)).
213 cbn [app'].
214 set (Sn := S n) in *.
215 cbn [n_corners_and_zero].
216 set (f' := fun x => @n_corners_and_zero Sn (f x)).
217 lazymatch type of IHn with
218 | forall x, is_bounded_by_bool (@?B x) (app' _ ?v_bs) = true
219 => change (forall x, is_bounded_by_bool (B x) (app' (f' x) v_bs) = true) in IHn
220 end; cbv beta in *.
221 clearbody f'.
222 cbn -[Sn] in *.
223 cbv [is_bounded_by_bool app] in *.
224 unfold Sn in Hmonotone1, Hmonotone2.
225 setoid_rewrite Bool.andb_true_iff in IHn.
226 rewrite ?Bool.andb_true_iff in *.
227 setoid_rewrite Z.leb_le in IHn.
228 rewrite !Z.leb_le in *.
229 specialize (Hmonotone1 vs).
230 specialize (Hmonotone2 vs).
231 destruct Hmonotone1 as [? Hmonotone1].
232 destruct Hmonotone2 as [? Hmonotone2].
233 clear -IHn Hboundedx1 Hmonotone1 Hmonotone2.
234 cbn [lower upper] in *.
235 destruct l as [|l|l], u as [|u|u], v as [|v|v].
236 all: try (exfalso; clear -Hboundedx1; lia).
237 all: cbn -[Sn] in *.
238 all: rewrite !pull_union_under_args2.
239 all: cbv [union]; cbn [lower upper].
240 all: repeat match goal with
241 | [ H : context[Zpos ?p <= Zpos ?q] |- _ ]
242 => unique assert (Pos.le p q) by lia
243 | [ H : context[Zneg ?p <= Zneg ?q] |- _ ]
244 => unique assert (Pos.le q p) by lia
245 end.
246 all: destruct_head'_bool.
247 all: first [ split; etransitivity;
248 [ | first [ eapply Hmonotone1 | eapply Hmonotone2 ];
249 first [ eassumption | eapply Pos.le_1_l ]
250 | first [ eapply Hmonotone1 | eapply Hmonotone2 ];
251 first [ eassumption | eapply Pos.le_1_l ] | ]
252 | split ].
253 all: first [ etransitivity; [ eapply IHn | ] | etransitivity; [ | eapply IHn ] ].
254 all: fast_split_min_max.
255 all: auto using Z.le_refl.
256 all: repeat t_fin_common_step. }
257 Qed.
258
259
260 Lemma monotone_two_corners_genb'
261 (f : Z -> Z)
262 (Hmonotone : exists b, Proper (R b ==> Z.le) f)
263 x_bs x
264 (Hboundedx : is_bounded_by_bool x x_bs)
265 : is_tighter_than_bool (constant (f x)) (two_corners f x_bs).
266 Proof.
267 exact (@monotone_n_corners_genb 1 f (ltac:(repeat split; auto)) x x_bs Hboundedx).
268 Qed.
269
270 Lemma monotone_two_corners_and_zero_genb'
271 (f : Z -> Z)
272 (Hmonotonep : exists b, Proper (Rp b ==> Z.le) (fun x => f (Zpos x)))
273 (Hmonotonen : exists b, Proper (Rp b ==> Z.le) (fun x => f (Zneg x)))
274 x_bs x
275 (Hboundedx : is_bounded_by_bool x x_bs)
276 : is_tighter_than_bool (constant (f x)) (two_corners_and_zero f x_bs).
277 Proof.
278 unshelve eapply (@monotone_n_corners_and_zero_genb 1 f _ x x_bs Hboundedx).
279 repeat split; auto.
280 Qed.
281
282 Lemma monotoneb_two_corners_gen
283 (f : Z -> Z)
284 (Hmonotone : Proper (Z.le ==> Z.le) f \/ Proper (Basics.flip Z.le ==> Z.le) f)
285 x_bs x
286 (Hboundedx : ZRange.is_bounded_by_bool x x_bs = true)
287 : ZRange.is_bounded_by_bool (f x) (ZRange.two_corners f x_bs) = true.
288 Proof.
289 apply (fun pf => monotone_two_corners_genb' f pf _ _ Hboundedx).
290 rewrite Bool.ex_bool_iff_or; auto.
291 Qed.
292
293 Lemma monotoneb_two_corners_and_zero_gen
294 (f : Z -> Z)
295 (Hmonotonep : Proper (Pos.le ==> Z.le) (fun x => f (Zpos x)) \/ Proper (Basics.flip Pos.le ==> Z.le) (fun x => f (Zpos x)))
296 (Hmonotonen : Proper (Pos.le ==> Z.le) (fun x => f (Zneg x)) \/ Proper (Basics.flip Pos.le ==> Z.le) (fun x => f (Zneg x)))
297 x_bs x
298 (Hboundedx : ZRange.is_bounded_by_bool x x_bs = true)
299 : ZRange.is_bounded_by_bool (f x) (ZRange.two_corners_and_zero f x_bs) = true.
300 Proof.
301 apply (fun pf1 pf2 => monotone_two_corners_and_zero_genb' f pf1 pf2 _ _ Hboundedx).
302 all: rewrite Bool.ex_bool_iff_or; auto.
303 Qed.
304
305 Local Ltac t_fill :=
306 intros; rewrite ?Bool.ex_bool_iff_or; auto;
307 cbn in *; cbv [is_true] in *; rewrite ?Bool.andb_true_iff; intuition eauto.
308
309 Local Ltac t_red :=
310 cbv [eight_corners_and_zero four_corners_and_zero two_corners_and_zero n_corners_and_zero apply_to_split_range apply_to_split_range_under_args apply_to_each_split_range apply_to_each_split_range_under_args under_args2 apply_to_range apply_to_range_under_args].
311
312 Lemma two_corners_and_zero_eq f x
313 : two_corners_and_zero f x = @n_corners_and_zero 1 f x.
314 Proof. reflexivity. Qed.
315
316 Lemma monotone_four_corners_genb'
317 (f : Z -> Z -> Z)
318 (Hmonotone1 : forall x, exists b, Proper (R b ==> Z.le) (fun y => f x y))
319 (Hmonotone2 : forall y, exists b, Proper (R b ==> Z.le) (fun x => f x y))
320 x x_bs y y_bs
321 (Hboundedx : is_bounded_by_bool x x_bs)
322 (Hboundedy : is_bounded_by_bool y y_bs)
323 : is_tighter_than_bool (constant (f x y)) (four_corners f x_bs y_bs).
324 Proof.
325 apply (fun pf => @monotone_n_corners_genb 2 f pf (y, x) (y_bs, x_bs)).
326 all: t_fill.
327 Qed.
328
329 Lemma four_corners_and_zero_eq f x y
330 : four_corners_and_zero f x y = @n_corners_and_zero 2 f x y.
331 Proof.
332 set (n:=1%nat).
333 cbv [four_corners_and_zero].
334 cbn [n_corners_and_zero].
335 generalize (fun x => two_corners_and_zero_eq (f x)).
336 subst n.
337 generalize (@two_corners_and_zero) (@n_corners_and_zero 1).
338 t_red.
339 break_innermost_match; intros ?? H; rewrite ?H; reflexivity.
340 Qed.
341
342 Lemma monotone_four_corners_and_zero_genb'
343 (f : Z -> Z -> Z)
344 (Hmonotone1p : forall x, exists b, Proper (Rp b ==> Z.le) (fun y => f x (Zpos y)))
345 (Hmonotone1n : forall x, exists b, Proper (Rp b ==> Z.le) (fun y => f x (Zneg y)))
346 (Hmonotone2p : forall y, exists b, Proper (Rp b ==> Z.le) (fun x => f (Zpos x) y))
347 (Hmonotone2n : forall y, exists b, Proper (Rp b ==> Z.le) (fun x => f (Zneg x) y))
348 x x_bs y y_bs
349 (Hboundedx : is_bounded_by_bool x x_bs)
350 (Hboundedy : is_bounded_by_bool y y_bs)
351 : is_tighter_than_bool (constant (f x y)) (four_corners_and_zero f x_bs y_bs).
352 Proof.
353 rewrite four_corners_and_zero_eq.
354 exact (@monotone_n_corners_and_zero_genb 2 f ltac:(t_fill) (y, x) (y_bs, x_bs) ltac:(t_fill)).
355 Qed.
356
357 Lemma monotoneb_four_corners_gen
358 (f : Z -> Z -> Z)
359 (Hmonotone1 : forall x, Proper (R true ==> Z.le) (fun y => f x y) \/ Proper (R false ==> Z.le) (fun y => f x y))
360 (Hmonotone2 : forall y, Proper (R true ==> Z.le) (fun x => f x y) \/ Proper (R false ==> Z.le) (fun x => f x y))
361 x x_bs y y_bs
362 (Hboundedx : is_bounded_by_bool x x_bs)
363 (Hboundedy : is_bounded_by_bool y y_bs)
364 : is_tighter_than_bool (constant (f x y)) (four_corners f x_bs y_bs).
365 Proof.
366 apply monotone_four_corners_genb'; t_fill.
367 Qed.
368
369 Lemma monotoneb_four_corners_and_zero_gen
370 (f : Z -> Z -> Z)
371 (Hmonotone1p : forall x, Proper (Rp true ==> Z.le) (fun y => f x (Zpos y)) \/ Proper (Rp false ==> Z.le) (fun y => f x (Zpos y)))
372 (Hmonotone1n : forall x, Proper (Rp true ==> Z.le) (fun y => f x (Zneg y)) \/ Proper (Rp false ==> Z.le) (fun y => f x (Zneg y)))
373 (Hmonotone2p : forall y, Proper (Rp true ==> Z.le) (fun x => f (Zpos x) y) \/ Proper (Rp false ==> Z.le) (fun x => f (Zpos x) y))
374 (Hmonotone2n : forall y, Proper (Rp true ==> Z.le) (fun x => f (Zneg x) y) \/ Proper (Rp false ==> Z.le) (fun x => f (Zneg x) y))
375 x x_bs y y_bs
376 (Hboundedx : is_bounded_by_bool x x_bs)
377 (Hboundedy : is_bounded_by_bool y y_bs)
378 : is_tighter_than_bool (constant (f x y)) (four_corners_and_zero f x_bs y_bs).
379 Proof.
380 apply monotone_four_corners_and_zero_genb'; t_fill.
381 Qed.
382
383
384 Lemma monotone_eight_corners_genb'
385 (f : Z -> Z -> Z -> Z)
386 (Hmonotone1 : forall x y, exists b, Proper (R b ==> Z.le) (fun z => f x y z))
387 (Hmonotone2 : forall x z, exists b, Proper (R b ==> Z.le) (fun y => f x y z))
388 (Hmonotone3 : forall y z, exists b, Proper (R b ==> Z.le) (fun x => f x y z))
389 x x_bs y y_bs z z_bs
390 (Hboundedx : is_bounded_by_bool x x_bs)
391 (Hboundedy : is_bounded_by_bool y y_bs)
392 (Hboundedz : is_bounded_by_bool z z_bs)
393 : is_tighter_than_bool (constant (f x y z)) (eight_corners f x_bs y_bs z_bs).
394 Proof.
395 apply (fun pf => @monotone_n_corners_genb 3 f pf (z, y, x) (z_bs, y_bs, x_bs)).
396 all: t_fill.
397 Qed.
398
399 Lemma eight_corners_and_zero_eq f x y z
400 : eight_corners_and_zero f x y z = @n_corners_and_zero 3 f x y z.
401 Proof.
402 set (n:=2%nat).
403 cbv [eight_corners_and_zero].
404 cbn [n_corners_and_zero].
405 generalize (fun x => four_corners_and_zero_eq (f x)).
406 subst n.
407 generalize (@four_corners_and_zero) (@n_corners_and_zero 2).
408 t_red.
409 break_innermost_match; intros ?? H; rewrite ?H; reflexivity.
410 Qed.
411
412 Lemma monotone_eight_corners_and_zero_genb'
413 (f : Z -> Z -> Z -> Z)
414 (Hmonotone1p : forall x y, exists b, Proper (Rp b ==> Z.le) (fun z => f x y (Zpos z)))
415 (Hmonotone1n : forall x y, exists b, Proper (Rp b ==> Z.le) (fun z => f x y (Zneg z)))
416 (Hmonotone2p : forall x z, exists b, Proper (Rp b ==> Z.le) (fun y => f x (Zpos y) z))
417 (Hmonotone2n : forall x z, exists b, Proper (Rp b ==> Z.le) (fun y => f x (Zneg y) z))
418 (Hmonotone3p : forall y z, exists b, Proper (Rp b ==> Z.le) (fun x => f (Zpos x) y z))
419 (Hmonotone3n : forall y z, exists b, Proper (Rp b ==> Z.le) (fun x => f (Zneg x) y z))
420 x x_bs y y_bs z z_bs
421 (Hboundedx : is_bounded_by_bool x x_bs)
422 (Hboundedy : is_bounded_by_bool y y_bs)
423 (Hboundedz : is_bounded_by_bool z z_bs)
424 : is_tighter_than_bool (constant (f x y z)) (eight_corners_and_zero f x_bs y_bs z_bs).
425 Proof.
426 rewrite eight_corners_and_zero_eq.
427 exact (@monotone_n_corners_and_zero_genb 3 f ltac:(t_fill) (z, y, x) (z_bs, y_bs, x_bs) ltac:(t_fill)).
428 Qed.
429
430 Lemma monotoneb_eight_corners_gen
431 (f : Z -> Z -> Z -> Z)
432 (Hmonotone1 : forall x y, Proper (R true ==> Z.le) (fun z => f x y z) \/ Proper (R false ==> Z.le) (fun z => f x y z))
433 (Hmonotone2 : forall x z, Proper (R true ==> Z.le) (fun y => f x y z) \/ Proper (R false ==> Z.le) (fun y => f x y z))
434 (Hmonotone3 : forall y z, Proper (R true ==> Z.le) (fun x => f x y z) \/ Proper (R false ==> Z.le) (fun x => f x y z))
435 x x_bs y y_bs z z_bs
436 (Hboundedx : is_bounded_by_bool x x_bs)
437 (Hboundedy : is_bounded_by_bool y y_bs)
438 (Hboundedz : is_bounded_by_bool z z_bs)
439 : is_tighter_than_bool (constant (f x y z)) (eight_corners f x_bs y_bs z_bs).
440 Proof.
441 apply monotone_eight_corners_genb'; t_fill.
442 Qed.
443
444 Lemma monotoneb_eight_corners_and_zero_gen
445 (f : Z -> Z -> Z -> Z)
446 (Hmonotone1p : forall x y, Proper (Rp true ==> Z.le) (fun z => f x y (Zpos z)) \/ Proper (Rp false ==> Z.le) (fun z => f x y (Zpos z)))
447 (Hmonotone1n : forall x y, Proper (Rp true ==> Z.le) (fun z => f x y (Zneg z)) \/ Proper (Rp false ==> Z.le) (fun z => f x y (Zneg z)))
448 (Hmonotone2p : forall x z, Proper (Rp true ==> Z.le) (fun y => f x (Zpos y) z) \/ Proper (Rp false ==> Z.le) (fun y => f x (Zpos y) z))
449 (Hmonotone2n : forall x z, Proper (Rp true ==> Z.le) (fun y => f x (Zneg y) z) \/ Proper (Rp false ==> Z.le) (fun y => f x (Zneg y) z))
450 (Hmonotone3p : forall y z, Proper (Rp true ==> Z.le) (fun x => f (Zpos x) y z) \/ Proper (Rp false ==> Z.le) (fun x => f (Zpos x) y z))
451 (Hmonotone3n : forall y z, Proper (Rp true ==> Z.le) (fun x => f (Zneg x) y z) \/ Proper (Rp false ==> Z.le) (fun x => f (Zneg x) y z))
452 x x_bs y y_bs z z_bs
453 (Hboundedx : is_bounded_by_bool x x_bs)
454 (Hboundedy : is_bounded_by_bool y y_bs)
455 (Hboundedz : is_bounded_by_bool z z_bs)
456 : is_tighter_than_bool (constant (f x y z)) (eight_corners_and_zero f x_bs y_bs z_bs).
457 Proof.
458 apply monotone_eight_corners_and_zero_genb'; t_fill.
459 Qed.
460 End ZRange.