| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
(** * The tauto and intuition tactics *) |
| 12 |
|
| 13 |
Require Import Notations. |
| 14 |
Require Import Ltac. |
| 15 |
Require Import Datatypes. |
| 16 |
Require Import Logic. |
| 17 |
|
| 18 |
Declare ML Module "rocq-runtime.plugins.tauto". |
| 19 |
|
| 20 |
Local Ltac not_dep_intros := |
| 21 |
repeat match goal with |
| 22 |
| |- (forall (_: ?X1), ?X2) => intro |
| 23 |
| |- (Corelib.Init.Logic.not _) => unfold Corelib.Init.Logic.not at 1; intro |
| 24 |
end. |
| 25 |
|
| 26 |
Local Ltac axioms flags := |
| 27 |
match reverse goal with |
| 28 |
| |- ?X1 => is_unit_or_eq flags X1; constructor 1 |
| 29 |
| H:?X1 |- _ => is_empty flags X1; elim H |
| 30 |
| _ => assumption |
| 31 |
end. |
| 32 |
|
| 33 |
Local Ltac simplif flags := |
| 34 |
not_dep_intros; |
| 35 |
repeat |
| 36 |
(match reverse goal with |
| 37 |
| id: ?X1 |- _ => is_conj flags X1; elim id; do 2 intro; clear id |
| 38 |
| id: (Corelib.Init.Logic.iff _ _) |- _ => elim id; do 2 intro; clear id |
| 39 |
| id: (Corelib.Init.Logic.not _) |- _ => red in id |
| 40 |
| id: ?X1 |- _ => is_disj flags X1; elim id; intro; clear id |
| 41 |
| _ => |
| 42 |
(* behaves as matching [ id0: ?X1 -> ?X2, id1: ?X1 |- _ ] with |
| 43 |
universe-aware conversion *) |
| 44 |
find_cut ltac:(fun id0 id1 X2 => |
| 45 |
(* generalize (id0 id1); intro; clear id0 does not work |
| 46 |
(see Marco Maggiesi's BZ#301) |
| 47 |
so we instead use Assert and exact. *) |
| 48 |
assert X2; [exact (id0 id1) | clear id0] |
| 49 |
) |
| 50 |
| id: forall (_ : ?X1), ?X2|- _ => |
| 51 |
is_unit_or_eq flags X1; cut X2; |
| 52 |
[ intro; clear id |
| 53 |
| (* id : forall (_: ?X1), ?X2 |- ?X2 *) |
| 54 |
cut X1; [exact id| constructor 1; fail] |
| 55 |
] |
| 56 |
| id: forall (_ : ?X1), ?X2|- _ => |
| 57 |
flatten_contravariant_conj flags X1 X2 id |
| 58 |
(* moved from "id:(?A/\?B)->?X2|-" to "?A->?B->?X2|-" *) |
| 59 |
| id: forall (_: Corelib.Init.Logic.iff ?X1 ?X2), ?X3|- _ => |
| 60 |
assert (forall (_: forall _:X1, X2), forall (_: forall _: X2, X1), X3) |
| 61 |
by (do 2 intro; apply id; split; assumption); |
| 62 |
clear id |
| 63 |
| id: forall (_:?X1), ?X2|- _ => |
| 64 |
flatten_contravariant_disj flags X1 X2 id |
| 65 |
(* moved from "id:(?A\/?B)->?X2|-" to "?A->?X2,?B->?X2|-" *) |
| 66 |
| |- ?X1 => is_conj flags X1; split |
| 67 |
| |- (Corelib.Init.Logic.iff _ _) => split |
| 68 |
| |- (Corelib.Init.Logic.not _) => red |
| 69 |
end; |
| 70 |
not_dep_intros). |
| 71 |
|
| 72 |
Local Ltac tauto_intuit flags t_reduce t_solver := |
| 73 |
let rec t_tauto_intuit := |
| 74 |
(simplif flags; axioms flags |
| 75 |
|| match reverse goal with |
| 76 |
| id:forall(_: forall (_: ?X1), ?X2), ?X3|- _ => |
| 77 |
cut X3; |
| 78 |
[ intro; clear id; t_tauto_intuit |
| 79 |
| cut (forall (_: X1), X2); |
| 80 |
[ exact id |
| 81 |
| generalize (fun y:X2 => id (fun x:X1 => y)); intro; clear id; |
| 82 |
solve [ t_tauto_intuit ]]] |
| 83 |
| id:forall (_:not ?X1), ?X3|- _ => |
| 84 |
cut X3; |
| 85 |
[ intro; clear id; t_tauto_intuit |
| 86 |
| cut (not X1); [ exact id | clear id; intro; solve [t_tauto_intuit ]]] |
| 87 |
| |- ?X1 => |
| 88 |
is_disj flags X1; solve [left;t_tauto_intuit | right;t_tauto_intuit] |
| 89 |
end |
| 90 |
|| |
| 91 |
(* NB: [|- _ -> _] matches any product *) |
| 92 |
match goal with | |- forall (_ : _), _ => intro; t_tauto_intuit |
| 93 |
| |- _ => t_reduce;t_solver |
| 94 |
end |
| 95 |
|| |
| 96 |
t_solver |
| 97 |
) in t_tauto_intuit. |
| 98 |
|
| 99 |
Local Ltac intuition_gen flags solver := tauto_intuit flags reduction_not_iff solver. |
| 100 |
Local Ltac tauto_intuitionistic flags := intuition_gen flags fail || fail "tauto failed". |
| 101 |
Local Ltac tauto_classical flags := |
| 102 |
(apply_nnpp || fail "tauto failed"); (tauto_intuitionistic flags || fail "Classical tauto failed"). |
| 103 |
Local Ltac tauto_gen flags := tauto_intuitionistic flags || tauto_classical flags. |
| 104 |
|
| 105 |
Ltac tauto := with_uniform_flags ltac:(fun flags => tauto_gen flags). |
| 106 |
Ltac dtauto := with_power_flags ltac:(fun flags => tauto_gen flags). |
| 107 |
|
| 108 |
Ltac intuition_solver := auto. |
| 109 |
|
| 110 |
Local Ltac intuition_then tac := with_uniform_flags ltac:(fun flags => intuition_gen flags tac). |
| 111 |
Ltac intuition := intuition_then ltac:(idtac;intuition_solver). |
| 112 |
|
| 113 |
Local Ltac dintuition_then tac := with_power_flags ltac:(fun flags => intuition_gen flags tac). |
| 114 |
Ltac dintuition := dintuition_then ltac:(idtac;intuition_solver). |
| 115 |
|
| 116 |
Tactic Notation "intuition" := intuition. |
| 117 |
Tactic Notation "intuition" tactic(t) := intuition_then t. |
| 118 |
|
| 119 |
Tactic Notation "dintuition" := dintuition. |
| 120 |
Tactic Notation "dintuition" tactic(t) := dintuition_then t. |