New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewriting with AC (not modulo AC), using a small scale command. #211
Conversation
183a875
to
43ab2d2
Compare
Hi @pi8027! I have had this small dev pending for a while, and after listening to your talk I revived it. |
@CohenCyril I discovered many clever techniques in your code! I am especially surprised that your "spaghetti sort" can be done in O(n log n). Thanks for sharing your work. Here I point out an issue I found (but I don't know how can we solve it...):
|
|
@pi8027 Thank you for your positive feedback! I am glad you found it interesting.
I did not take the time to check (did you?) but I believe it is indeed O(n log n) in time and a call stack of size O(log n).
This is unavoidable when the rule is quantified over a monoid law, (indeed lemmas
AFAIK,
|
@maximedenes this is how I encountered the issue coq/coq#8190 |
Proof. Let us suppose that a reordering However,
I understood it. Thank you.
I compared
I compared two normalized ground terms by
|
Yeah I'm convinced by your proof.
I'd say both
I am surprised... |
oh, but each continuation contains a tree of half of the size of the argument... |
It is easy to check that |
The only comment I have right now is that, as for under, there is quite some ltac code. I think it is good to make a prototype and let people play with it, but at some point things should be rewritten in ML, so that one can just call |
Hi, I think that it is great to have this code available, but I also think that it is not ready (yet) for merge. The roadmap is probably something to be discussed in the next dev working group. By the way, could you document the (names of the) constants that are the user's environment after a |
Hi @amahboubi right now the following notations are exported:
And all the exported constants are prefixed with module Do you want me to add this to the header? |
This PR needs an assignee... |
From the release managers for 1.11: does this PR really need propagation? Could it be merged as is and an issue be opened to propagate? |
I would be happy that this merged, but it has not been reviewed and it had no assignee... and I guess it is difficult to assess. It should at least be rebased, let me do that first... |
022ba6d
to
01253f8
Compare
I rewrote some proof scripts using ssrAC, just for the example. Two are significantly shorter but were badly written in the first place. As such, I will remove the "needs: propagation" label. If we change our minds we can reestablish it. I am also in favor of having this part of the beta, and withdraw it in the final release if necessary (as I said in my previous post) |
Some versions of Coq fail with message I personally don't care about 8.7..8.9 much, but if this PR is the only reason to drop compatibility with them, then I'm not in favor of merging it "as it is". |
You are right, we should not lose compatibility and the tests and the main file used to passe. |
@gares @affeldt-aist @ybertot should we integrate it? |
This replaces opA, opC, opAC, opCA, ... and any combinations of them - Right now the rewrite relies on an rather efficient computation of perm_eq using a "spaghetti sort" in O(n log n) - Wrongly formed AC statements send error messages showing the discrepancy between LHS and RHS patterns. Usage : rewrite [pattern](AC operator pattern-shape re-ordering) rewrite [pattern](ACl operator re-ordering) - pattern is optional, as usual, - operator must have a canonical Monoid.com_law structure (additions, multiplications, conjunction and disjunction do) - pattern-shape is expressed using the syntax p := n | p * p' where "*" is purely formal and n > 0 is number of left associated symbols examples of pattern shapes: + 4 represents (n * m * p * q) + (1*2) represents (n * (m * p)) - re-ordering is expressed using the syntax s := n | s * s' where "*" is purely formal and n is the position in the LHS If the ACl variant is used, the pattern-shape defaults to the pattern fully associated to the left i.e. n i.e (x * y * ...) Examples of re-orderings: - ACl op ((0*1)*2) is the identity (and should fail to rewrite) - opAC == ACl op ((0*2)*1) == AC op 3 ((0*2)*1) - opCA == AC op (2*1) (0*1*2) - rewrite opCA -opA == rewrite (ACl op (0*(2*1)) - opACA == AC (2*2) ((0*2)*(1*3))
%AC annotation are for backward compatilibity with coq <= 8.9
ping @gares |
Replaces
opA
,opC
,opAC
,opCA
, ... and any combinations of themUsage :
rewrite [pattern](AC patternshape reordering)
rewrite [pattern](ACl reordering)
rewrite [pattern](ACof reordering reordering)
rewrite [pattern]op.[AC patternshape reordering]
rewrite [pattern]op.[ACl reordering]
rewrite [pattern]op.[ACof reordering reordering]
if
op
is specified, the rule is specialized to opotherwise, the head symbol is a generic comm_law
and the rewrite might be less efficient
NOTE because of a bug in Coq's notations notations/syndefs with parameters applied to holes result in tac-in-term not being executed coq/coq#8190
op
must not contain any hole.*%R.[AC p s]
currently does not work because of that(@GRing.mul R).[AC p s]
must be used insteadpattern
is optional, as usual, but must be used to select the appropriate operator in case of ambiguity such an operator must have a canonical Monoid.com_law structure (additions, multiplications, conjuction and disjunction do)patternshape
is expressed using the syntaxp := n | p * p'
where
*
is formal andn
(assumingn > 0
) is number of left associated symbolsexamples of pattern shapes:
4
represents(n * m * p * q)
(1*2)
represents(n * (m * p))
reordering
is expressed using the syntaxs := n | s * s'
where
*
is formal andn
(assumingn > 0
) is the position in the LHSpositions start at 1 !
If the
ACl
variant is used, the patternshape defaults to the pattern fully associated to the left i.e.n
i.e(x * y * ...)
Examples of reorderings:
ACl ((1*2)*3)
is the identity (and will fail with error message)opAC <-> op.[ACl (1*3)*2] <-> op.[AC 3 ((1*3)*2)]
opCA <->op.[AC (2*1) (1*2*3)]
opACA <-> op.[AC (2*2) ((1*3)*(2*4))]
rewrite opAC -opA
isrewrite op.[ACl 1*(3*2)]
TODO: