Skip to content

Commit 45af31f

Browse files
authored
Merge pull request #115 from coq-community/backport-master-8.15
Backport master fixes and improvements to 8.15
2 parents a67e3d7 + 3bacd2e commit 45af31f

File tree

9 files changed

+294
-255
lines changed

9 files changed

+294
-255
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ Namely, it contains instances for:
108108

109109
- Peano naturals (`Import Instances.Peano.`)
110110
- Z binary numbers (`Import Instances.Z.`)
111+
- Lists (`Import Instances.Lists.`)
111112
- N binary numbers (`Import Instances.N.`)
112113
- P binary numbers (`Import Instances.P.`)
113114
- Rational numbers (`Import Instances.Q.`)
114-
- Prop (`Import Instances.Prop_ops.`)
115+
- Prop (`Import Instances.Prop_ops.`)
115116
- Booleans (`Import Instances.Bool.`)
116117
- Relations (`Import Instances.Relations.`)
117118
- all of the above (`Import Instances.All.`)

meta.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ documentation: |
109109
110110
- Peano naturals (`Import Instances.Peano.`)
111111
- Z binary numbers (`Import Instances.Z.`)
112+
- Lists (`Import Instances.Lists.`)
112113
- N binary numbers (`Import Instances.N.`)
113114
- P binary numbers (`Import Instances.P.`)
114115
- Rational numbers (`Import Instances.Q.`)
115-
- Prop (`Import Instances.Prop_ops.`)
116+
- Prop (`Import Instances.Prop_ops.`)
116117
- Booleans (`Import Instances.Bool.`)
117118
- Relations (`Import Instances.Relations.`)
118119
- all of the above (`Import Instances.All.`)

src/aac_rewrite.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ let aac_reflexivity : unit Proofview.tactic =
232232
mkApp (Coq.get_efresh (Theory.Stubs.lift_reflexivity),
233233
[| x; r; lift.e.Coq.Equivalence.eq; lift.lift; reflexive |])
234234
in
235-
Unsafe.tclEVARS sigma
235+
Unsafe.tclEVARS sigma
236+
<*> Coq.tclRETYPE lift_reflexivity
236237
<*> Tactics.apply lift_reflexivity
237238
<*> (let concl = Goal.concl goal in
238239
tclEVARMAP >>= fun sigma ->

theories/AAC.v

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(* Copyright 2009-2010: Thomas Braibant, Damien Pous. *)
77
(***************************************************************************)
88

9-
(** * Theory file for the aac_rewrite tactic
9+
(** * Theory for AAC Tactics
1010
1111
We define several base classes to package associative and possibly
1212
commutative/idempotent operators, and define a data-type for reified (or
@@ -26,21 +26,19 @@
2626
where one occurrence of [+] operates on nat while the other one
2727
operates on positive. *)
2828

29-
Require Import Arith NArith.
30-
Require Import List.
31-
Require Import FMapPositive FMapFacts.
32-
Require Import RelationClasses Equality.
33-
Require Export Morphisms.
34-
35-
From AAC_tactics
36-
Require Import Utils Constants.
29+
From Coq Require Import Arith NArith List.
30+
From Coq Require Import FMapPositive FMapFacts RelationClasses Equality.
31+
From Coq Require Export Morphisms.
32+
From AAC_tactics Require Import Utils Constants.
3733

3834
Set Implicit Arguments.
3935
Set Asymmetric Patterns.
4036

4137
Local Open Scope signature_scope.
4238

43-
(** * Environments for the reification process: we use positive maps to index elements *)
39+
(** ** Environments for the reification process
40+
41+
We use positive maps to index elements. *)
4442

4543
Section sigma.
4644
Definition sigma := PositiveMap.t.
@@ -57,8 +55,7 @@ Section sigma.
5755
Register sigma_empty as aac_tactics.sigma.empty.
5856
End sigma.
5957

60-
61-
(** * Classes for properties of operators *)
58+
(** ** Classes for properties of operators *)
6259

6360
Class Associative (X:Type) (R:relation X) (dot: X -> X -> X) :=
6461
law_assoc : forall x y z, R (dot x (dot y z)) (dot (dot x y) z).
@@ -75,7 +72,6 @@ Register Commutative as aac_tactics.classes.Commutative.
7572
Register Idempotent as aac_tactics.classes.Idempotent.
7673
Register Unit as aac_tactics.classes.Unit.
7774

78-
7975
(** Class used to find the equivalence relation on which operations
8076
are A or AC, starting from the relation appearing in the goal *)
8177

@@ -88,24 +84,21 @@ Register aac_lift_equivalence as aac_tactics.internal.aac_lift_equivalence.
8884

8985
(** simple instances, when we have a subrelation, or an equivalence *)
9086

91-
#[global]
92-
Instance aac_lift_subrelation {X} {R} {E} {HE: Equivalence E}
93-
{HR: @Transitive X R} {HER: subrelation E R}: AAC_lift R E | 3.
87+
#[export] Instance aac_lift_subrelation {X} {R} {E} {HE: Equivalence E}
88+
{HR: @Transitive X R} {HER: subrelation E R} : AAC_lift R E | 3.
9489
Proof.
9590
constructor; trivial.
9691
intros ? ? H ? ? H'. split; intro G.
9792
rewrite <- H, G. apply HER, H'.
9893
rewrite H, G. apply HER. symmetry. apply H'.
9994
Qed.
10095

101-
#[global]
102-
Instance aac_lift_proper {X} {R : relation X} {E} {HE: Equivalence E}
103-
{HR: Proper (E==>E==>iff) R}: AAC_lift R E | 4 := {}.
104-
96+
#[export] Instance aac_lift_proper {X} {R : relation X} {E}
97+
{HE: Equivalence E} {HR: Proper (E==>E==>iff) R} : AAC_lift R E | 4 := {}.
10598

99+
(** ** Utilities for the evaluation function *)
106100

107101
Module Internal.
108-
(** * Utilities for the evaluation function *)
109102

110103
Section copy.
111104

@@ -132,7 +125,7 @@ Section copy.
132125
Lemma copy_Psucc : forall n x, R (copy (Pos.succ n) x) (plus x (copy n x)).
133126
Proof. intros; unfold copy; rewrite Prect_succ. reflexivity. Qed.
134127

135-
Global Instance copy_compat n: Proper (R ==> R) (copy n).
128+
#[export] Instance copy_compat n: Proper (R ==> R) (copy n).
136129
Proof.
137130
unfold copy.
138131
induction n using Pind; intros x y H.
@@ -142,9 +135,9 @@ Section copy.
142135

143136
End copy.
144137

145-
(** * Packaging structures *)
138+
(** ** Packaging structures *)
146139

147-
(** ** free symbols *)
140+
(** *** Free symbols *)
148141

149142
Module Sym.
150143
Section t.
@@ -189,7 +182,7 @@ Module Sym.
189182

190183
End Sym.
191184

192-
(** ** binary operations *)
185+
(** *** Binary operations *)
193186

194187
Module Bin.
195188
Section t.
@@ -211,7 +204,7 @@ Module Bin.
211204
End Bin.
212205

213206

214-
(** * Reification, normalisation, and decision *)
207+
(** ** Reification, normalisation, and decision *)
215208

216209
Section s.
217210
Context {X} {R: relation X} {E: @Equivalence X R}.
@@ -247,8 +240,9 @@ Section s.
247240
#[local]
248241
Hint Resolve e_bin e_unit: typeclass_instances.
249242

250-
(** ** Almost normalised syntax
251-
a term in [T] is in normal form if:
243+
(** *** Almost normalised syntax
244+
245+
A term in [T] is in normal form if:
252246
- sums do not contain sums
253247
- products do not contain products
254248
- there are no unary sums or products
@@ -303,7 +297,7 @@ Section s.
303297

304298

305299

306-
(** ** Evaluation from syntax to the abstract domain *)
300+
(** *** Evaluation from syntax to the abstract domain *)
307301

308302
Fixpoint eval u: X :=
309303
match u with
@@ -373,7 +367,7 @@ Section s.
373367
match Bin.idem (e_bin i) with Some _ => true | None => false end.
374368

375369

376-
(** ** Normalisation *)
370+
(** *** Normalisation *)
377371

378372
#[universes(template)]
379373
Inductive discr {A} : Type :=
@@ -519,7 +513,7 @@ Section s.
519513
| vcons _ u l => vcons (norm u) (vnorm l)
520514
end.
521515

522-
(** ** Correctness *)
516+
(** *** Correctness *)
523517

524518
Lemma is_unit_of_Unit : forall i j : idx,
525519
is_unit_of i j = true -> Unit R (Bin.value (e_bin i)) (eval (unit j)).
@@ -554,17 +548,16 @@ Section s.
554548
Proof.
555549
destruct ((e_bin i)); auto.
556550
Qed.
557-
#[local]
558-
Hint Resolve Binvalue_Proper Binvalue_Associative Binvalue_Commutative : core.
551+
#[local] Hint Resolve Binvalue_Proper Binvalue_Associative Binvalue_Commutative : core.
559552

560553
(** auxiliary lemmas about sums *)
561554

562-
#[local]
563-
Hint Resolve is_unit_of_Unit : core.
555+
#[local] Hint Resolve is_unit_of_Unit : core.
564556
Section sum_correctness.
565557
Variable i : idx.
566558
Variable is_unit : idx -> bool.
567-
Hypothesis is_unit_sum_Unit : forall j, is_unit j = true-> @Unit X R (Bin.value (e_bin i)) (eval (unit j)).
559+
Hypothesis is_unit_sum_Unit : forall j, is_unit j = true ->
560+
@Unit X R (Bin.value (e_bin i)) (eval (unit j)).
568561

569562
Inductive is_sum_spec_ind : T -> @discr (mset T) -> Prop :=
570563
| is_sum_spec_op : forall j l, j = i -> is_sum_spec_ind (sum j l) (Is_op l)
@@ -974,8 +967,7 @@ Local Ltac internal_normalize :=
974967
compute [Internal.eval Utils.fold_map Internal.copy Prect]; simpl.
975968

976969

977-
(** * Lemmas for performing transitivity steps
978-
given an instance of AAC_lift *)
970+
(** ** Lemmas for performing transitivity steps given an AAC_lift instance *)
979971

980972
Section t.
981973
Context `{AAC_lift}.

theories/Caveats.v

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@
66
(* Copyright 2009-2010: Thomas Braibant, Damien Pous. *)
77
(***************************************************************************)
88

9-
(** * Currently known caveats and limitations of the [aac_tactics] library.
10-
11-
Depending on your installation, either uncomment the following two
12-
lines, or add them to your .coqrc files, replacing "."
13-
with the path to the [aac_tactics] library
14-
*)
15-
16-
Require NArith PeanoNat.
9+
(** * Currently known caveats and limitations of AAC Tactics *)
1710

11+
From Coq Require NArith PeanoNat.
1812
From AAC_tactics Require Import AAC.
1913
From AAC_tactics Require Instances.
2014

2115
(** ** Limitations *)
2216

23-
(** *** 1. Dependent parameters
17+
(** *** Dependent parameters
18+
2419
The type of the rewriting hypothesis must be of the form
2520
2621
[forall (x_1: T_1) ... (x_n: T_n), R l r],
@@ -70,13 +65,14 @@ Section parameters.
7065
End parameters.
7166

7267

73-
(** *** 2. Exogeneous morphisms
68+
(** *** Exogeneous morphisms
7469
7570
We do not handle `exogeneous' morphisms: morphisms that move from
7671
type [T] to some other type [T']. *)
7772

7873
Section morphism.
7974
Import NArith PeanoNat.
75+
Import Instances.N Instances.Peano.
8076
Open Scope nat_scope.
8177

8278
(** Typically, although [N_of_nat] is a proper morphism from
@@ -115,7 +111,7 @@ Section morphism.
115111
End morphism.
116112

117113

118-
(** *** 3. Treatment of variance with inequations.
114+
(** *** Treatment of variance with inequations
119115
120116
We do not take variance into account when we compute the set of
121117
solutions to a matching problem modulo AC. As a consequence,
@@ -145,11 +141,10 @@ Section ineq.
145141

146142
End ineq.
147143

148-
149-
150144
(** ** Caveats *)
151145

152-
(** *** 1. Special treatment for units.
146+
(** *** Special treatment for units
147+
153148
[S O] is considered as a unit for multiplication whenever a [Peano.mult]
154149
appears in the goal. The downside is that [S x] does not match [1],
155150
and [1] does not match [S(0+0)] whenever [Peano.mult] appears in
@@ -192,11 +187,12 @@ End Peano.
192187

193188

194189

195-
(** *** 2. Existential variables.
196-
We implemented an algorithm for _matching_ modulo AC, not for
197-
_unifying_ modulo AC. As a consequence, existential variables
198-
appearing in a goal are considered as constants, they will not be
199-
instantiated. *)
190+
(** *** Existential variables
191+
192+
We implemented an algorithm for _matching_ modulo AC, not for
193+
_unifying_ modulo AC. As a consequence, existential variables
194+
appearing in a goal are considered as constants, they will not be
195+
instantiated. *)
200196

201197
Section evars.
202198
Import ZArith.
@@ -220,7 +216,7 @@ Section evars.
220216
End evars.
221217

222218

223-
(** *** 3. Distinction between [aac_rewrite] and [aacu_rewrite] *)
219+
(** *** Distinction between [aac_rewrite] and [aacu_rewrite] *)
224220

225221
Section U.
226222
Context {X} {R} {E: @Equivalence X R}
@@ -255,7 +251,7 @@ Section U.
255251

256252
End U.
257253

258-
(** *** 4. Rewriting units *)
254+
(** *** Rewriting units *)
259255
Section V.
260256
Context {X} {R} {E: @Equivalence X R}
261257
{dot} {dot_A: Associative R dot} {dot_Proper: Proper (R ==> R ==> R) dot}
@@ -283,8 +279,9 @@ Section V.
283279
Qed.
284280
End V.
285281

286-
(** *** 5. Rewriting too much things. *)
282+
(** *** Rewriting too many things *)
287283
Section W.
284+
Import Instances.Peano.
288285
Variables a b c: nat.
289286
Hypothesis H: 0 = c.
290287

@@ -308,8 +305,9 @@ Section W.
308305

309306
End W.
310307

311-
(** *** 6. Rewriting nullifiable patterns. *)
308+
(** *** Rewriting nullifiable patterns *)
312309
Section Z.
310+
Import Instances.Peano.
313311

314312
(** If the pattern of the rewritten hypothesis does not contain "hard"
315313
symbols (like constants, function symbols, AC or A symbols without
@@ -335,14 +333,12 @@ Goal a+b*c = c.
335333
*)
336334
Abort.
337335

338-
(** **** If the pattern is a unit or can be instantiated to be equal
339-
to a unit:
336+
(** *** If the pattern is a unit or can be instantiated to be equal to a unit
340337
341338
The heuristic is to make the unit appear at each possible position
342339
in the term, e.g. transforming [a] into [1*a] and [a*1], but this
343340
process is not recursive (we will not transform [1*a]) into
344341
[(1+0*1)*a] *)
345-
346342
Goal a+b+c = c.
347343

348344
aac_instances H0 [mult].
@@ -352,7 +348,10 @@ Goal a+b+c = c.
352348
(** 7 solutions, we miss solutions like [(a+b+c+0*(1+0*[]))]*)
353349
Abort.
354350

355-
(** *** Another example of the former case is the following, where the hypothesis can be instantiated to be equal to [1] *)
351+
(** *** Another example of the former case
352+
353+
In the following, the hypothesis can be instantiated
354+
to be equal to [1]. *)
356355
Hypothesis H : forall x y, (x+y)*x = x*x + y *x.
357356
Goal a*a+b*a + c = c.
358357
(** Here, only one solution if we use the aac_instance tactic *)
@@ -371,4 +370,3 @@ still unclear how to handle properly this kind of situation : we plan
371370
to investigate on this in the future *)
372371

373372
End Z.
374-

0 commit comments

Comments
 (0)