aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ZUtil
diff options
context:
space:
mode:
authorGravatar Jason Gross <jgross@mit.edu>2018-02-10 16:17:16 -0500
committerGravatar Jason Gross <jgross@mit.edu>2018-02-10 16:17:16 -0500
commit051ccf4d0666e195c0022c1e5948892bbc7aeca0 (patch)
treeb87502c04b2d39bb302ed943ea7c24ee2b66d899 /src/Util/ZUtil
parentd62ffb1a68a76cc33c502e1a8351f14104bc7ee2 (diff)
Split off ZRange lemmas
Diffstat (limited to 'src/Util/ZUtil')
-rw-r--r--src/Util/ZUtil/Tactics/SplitMinMax.v42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Util/ZUtil/Tactics/SplitMinMax.v b/src/Util/ZUtil/Tactics/SplitMinMax.v
new file mode 100644
index 000000000..901cfde88
--- /dev/null
+++ b/src/Util/ZUtil/Tactics/SplitMinMax.v
@@ -0,0 +1,42 @@
+Require Import Coq.omega.Omega.
+Require Import Coq.ZArith.BinInt.
+
+Ltac rewrite_min_max_side_condition_t := omega.
+
+Ltac revert_min_max :=
+ repeat match goal with
+ | [ H : context[Z.min _ _] |- _ ] => revert H
+ | [ H : context[Z.max _ _] |- _ ] => revert H
+ end.
+Ltac rewrite_min_max_step_fast :=
+ match goal with
+ | [ H : (?a <= ?b)%Z |- context[Z.max ?a ?b] ]
+ => rewrite (Z.max_r a b) by assumption
+ | [ H : (?b <= ?a)%Z |- context[Z.max ?a ?b] ]
+ => rewrite (Z.max_l a b) by assumption
+ | [ H : (?a <= ?b)%Z |- context[Z.min ?a ?b] ]
+ => rewrite (Z.min_l a b) by assumption
+ | [ H : (?b <= ?a)%Z |- context[Z.min ?a ?b] ]
+ => rewrite (Z.min_r a b) by assumption
+ end.
+Ltac rewrite_min_max_step :=
+ match goal with
+ | _ => rewrite_min_max_step_fast
+ | [ |- context[Z.max ?a ?b] ]
+ => first [ rewrite (Z.max_l a b) by rewrite_min_max_side_condition_t
+ | rewrite (Z.max_r a b) by rewrite_min_max_side_condition_t ]
+ | [ |- context[Z.min ?a ?b] ]
+ => first [ rewrite (Z.min_l a b) by rewrite_min_max_side_condition_t
+ | rewrite (Z.min_r a b) by rewrite_min_max_side_condition_t ]
+ end.
+Ltac only_split_min_max_step :=
+ match goal with
+ | _ => revert_min_max; progress repeat apply Z.min_case_strong; intros
+ | _ => revert_min_max; progress repeat apply Z.max_case_strong; intros
+ end.
+Ltac split_min_max_step :=
+ match goal with
+ | _ => rewrite_min_max_step
+ | _ => only_split_min_max_step
+ end.
+Ltac split_min_max := repeat split_min_max_step.