-
Notifications
You must be signed in to change notification settings - Fork 2
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
Lra #54
Lra #54
Conversation
@pi8027 I think algebra-tactics is the best place for that but let me know if you disagree. |
Wow, this is quite surprising since I didn't think the reflexive checker of
I agree, but I have to spend some time understanding how it works. (Also, I'm quite busy these days...) |
No hurry, I could do a short demo at the next MathComp (Analysis) meeting. Here is the big picture:
So the reflexive checker is actually run on Q, nothing is computed in any realField. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a quick look. This is a note for myself rather than an actual review comment.
theories/lra.v
Outdated
Ltac lraF F ffQ := | ||
let ff := fresh "ff" in | ||
let wit := fresh "wit" in | ||
let prf := fresh "prf" in | ||
let varmap := fresh "varmap" in | ||
match eval hnf in (ltac:(lra) : ffQ) with | ||
| QMicromega.QTautoChecker_sound ?ffq ?witq ?prfq (VarMap.find _ ?varmapq) => | ||
pose (ff := ffq); | ||
pose (wit := witq); | ||
pose (prf := prfq <: QMicromega.QTautoChecker ff wit = true); | ||
let vm := rmF2Q F varmapq in | ||
pose (varmap := vm) | ||
end; | ||
change (eval_bf (Internals.Feval_formula (VarMap.find 0 varmap)) ff); | ||
exact (@Internals.FTautoChecker_sound F ff wit prf (VarMap.find 0 varmap)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this part explains how it works. I'm thinking about exposing some more internals of lra
on the Coq side (e.g., to take a reified term instead) so that we can avoid traversing the input term twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, isn't it possible to do the last two tactic calls (change
and exact
) inside the match
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, the only goal of the pose is to get a resulting proof term that is smaller and looks nicer with let-ins rather than having terms like ff
and varmap
duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following your suggestion, this is now based on coq/coq#15921 exporting micromega witness generators. We needed it anyway as the micromega builtin parser was ignoring boolean operators (&&
, ||
, ~~
and ==>
).
1d8c0ea
to
dc9c0f6
Compare
Lemma l1 x y z : `|x - z| <= `|x - y| + `|y - z|. | ||
Proof. | ||
Fail intros; split_Rabs; lra. (* TODO should work *) | ||
Abort. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess lra
cannot solve this. Some sort of preprocessing (like zify
, or maybe Trakt?) is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. Trakt could indeed probably turn the current goal into this one:
forall (x y z : Z), Z.abs (x - z) <= Z.abs (x - y) + Z.abs (y - z)
To that end, it would need an embedding declaration from F
to Z
, as well as declaring the following mappings:
- from
GRing.add
onF
toZ.add
; - same for
opp
; - from
Num.Def.normr
toZ.abs
; - from
Order.le
toZ.le
.
Finally, it would require allowing conversion on most of these terms, so thatzmodType F
,numDomainType F
, etc, can be identified.
Unfortunately, for a technical reason, Order.le
and Num.Def.normr
cannot be declared ATM. But I can make the change. I am also not sure a local embedding can be declared (as F
is a variable). I think this needs further investigation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed looks like a case where an external preprocessing thing may be useful.
Talking about preprocessing, we could also support terms like |
Export micromega witness generators as tactics so that micromega can be used with external parsers. This is used for MathComp in math-comp/algebra-tactics#54 . Ack-by: JasonGross Reviewed-by: fajb Ack-by: jfehrle
73452e8
to
35338c4
Compare
FYI: and also closed_term. Your code also tests it does not contain axioms, but that seems a bit far fetched. Anyway, your code is fine, these apis are there just in case it becomes a bottle neck |
Thanks, the result will then go through the migromega plugin which is expecting axiom free terms: https://github.com/coq/coq/blob/bb5e7e5fa39f11ec222b0c1434148a02f6d3c587/plugins/micromega/coq_micromega.ml#L333 |
@pi8027 thanks, done
|
@proux01 Do you think it is possible to support Coq <= 8.15 and Coq >= 8.16 in the same branch? If so, I prefer to delay dropping the support for Coq <=8.15. If not, we can consider maintaining two branches. |
In any case, I'm fine with the first two items. |
Maybe, let me try. |
9198d8b
to
b085883
Compare
W.r.t compat, you skinned the cat this way which is OK, but there is also another way which may be is a bit more lightweight (but less precise).
Eg
It is an OCaml regex, so it is a bit more hackish than |
Is anything blocking this PR? |
Not really, it's just a rather large PR whose review requires some time. |
bump |
@pi8027 any chance we could ship this in a new release of algebra-tactics, along the forthcoming mathcomp 1.16 and 2.0 beta (hopefully before the end of the year)? That would be great |
Sorry, it takes a few more days. |
No worries. Once merged, I'll try to rebase #71 |
@proux01 Could you confirm that Micromega at this moment does not provide a witness generator (like |
@pi8027 I confirm that. IIRC avoiding the translation would require non trivial changes to micromega (but my memory might betray me, I wrote that code a few months ago now). |
Almost done, but I ended up removing:
I will push my result soon. |
Works for any realFieldType
If a realFieldType is found, rationals are considered as constants, otherwise a realDomainType is looked for and only integer constants are considered.
Following the method described in the paper Kazuhiko Sakaguchi Reflexive tactics for algebra, revisited
This is a bit hackish and slower (goals are reified multiple times) but enables using lra for MathComp without waiting for 8.16 to be the minimum required version for MathComp.
3677250
to
3eb14d3
Compare
@proux01 I will do a few more fixes and then merge, but feel free to ask questions. |
@pi8027 thanks!
Well, this made sense six months ago, maybe less so now. After a quick look, the only thing I'm a bit worried about are the |
Thanks. Done in #72 and there is no such an issue. (Note that |
This is a Work In Progress to get lra (Linear Real Arithmetic) with MathComp. The parser needs to be completed but it already handles the following examples:
We also have
nra
andpsatz
.The minimal assumption is a
realDomainType
because we need both a total order and a ring structure. This enables integer constants. In presence of arealFieldType
, rational constants are understood.This requires coq/coq#15921 to export micromega witness generation as Ltac1 tactics and use an elpi parser.