| 1 |
From Coq Require Import Lia. |
| 2 |
From Coq Require Import ZArith. |
| 3 |
|
| 4 |
Ltac rewrite_min_max_side_condition_t := lia. |
| 5 |
|
| 6 |
Ltac revert_min_max := |
| 7 |
repeat match goal with |
| 8 |
| [ H : context[Z.min _ _] |- _ ] => revert H |
| 9 |
| [ H : context[Z.max _ _] |- _ ] => revert H |
| 10 |
end. |
| 11 |
Ltac rewrite_min_max_step_fast := |
| 12 |
match goal with |
| 13 |
| [ H : (?a <= ?b)%Z |- context[Z.max ?a ?b] ] |
| 14 |
=> rewrite (Z.max_r a b) by assumption |
| 15 |
| [ H : (?b <= ?a)%Z |- context[Z.max ?a ?b] ] |
| 16 |
=> rewrite (Z.max_l a b) by assumption |
| 17 |
| [ H : (?a <= ?b)%Z |- context[Z.min ?a ?b] ] |
| 18 |
=> rewrite (Z.min_l a b) by assumption |
| 19 |
| [ H : (?b <= ?a)%Z |- context[Z.min ?a ?b] ] |
| 20 |
=> rewrite (Z.min_r a b) by assumption |
| 21 |
end. |
| 22 |
Ltac rewrite_min_max_step := |
| 23 |
match goal with |
| 24 |
| _ => rewrite_min_max_step_fast |
| 25 |
| [ |- context[Z.max ?a ?b] ] |
| 26 |
=> first [ rewrite (Z.max_l a b) by rewrite_min_max_side_condition_t |
| 27 |
| rewrite (Z.max_r a b) by rewrite_min_max_side_condition_t ] |
| 28 |
| [ |- context[Z.min ?a ?b] ] |
| 29 |
=> first [ rewrite (Z.min_l a b) by rewrite_min_max_side_condition_t |
| 30 |
| rewrite (Z.min_r a b) by rewrite_min_max_side_condition_t ] |
| 31 |
end. |
| 32 |
Ltac only_split_min_max_step := |
| 33 |
match goal with |
| 34 |
| _ => revert_min_max; progress repeat apply Z.min_case_strong; intros |
| 35 |
| _ => revert_min_max; progress repeat apply Z.max_case_strong; intros |
| 36 |
end. |
| 37 |
Ltac split_min_max_step := |
| 38 |
match goal with |
| 39 |
| _ => rewrite_min_max_step |
| 40 |
| _ => only_split_min_max_step |
| 41 |
end. |
| 42 |
Ltac split_min_max := repeat split_min_max_step. |