coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Jason Gross <jasongross9 AT gmail.com>
- To: coq-club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Ltac2 Performance Question
- Date: Sat, 1 Aug 2020 13:29:11 -0400
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-ed1-f43.google.com
- Ironport-phdr: 9a23:7j8DgxQ5o+PkRD77XQXQX76bUNpsv+yvbD5Q0YIujvd0So/mwa6yZBKN2/xhgRfzUJnB7Loc0qyK6v6mBjRLuM/b+Fk5M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAi3oAnLtMQanYRuJrssxhfXv3BFZ/lYyWR0KFyJgh3y/N2w/Jlt8yRRv/Iu6ctNWrjkcqo7ULJVEi0oP3g668P3uxbDSxCP5mYHXWUNjhVIGQnF4wrkUZr3ryD3q/By2CiePc3xULA0RTGv5LplRRP0lCsKMSMy/WfKgcJyka1bugqsqBNxw4HWYI+bOvlwcL7Dc9wGXmdORNpdWjZbD4+gc4cCDewMNvtYoYnnoFsOqAOzCw22C+P0zT9IgGL906wg0+QmCgHGxxErEtUMsHvOt9X1M6ESUe+vzKnP1jXDdPdb1Czy6IjNaB8hoPWMUahsfsrWzEkiDgXIhUifpoL5JT2azPgNs3SF4Op6U+Kik2wqpgNtrzWuycohiIjEi54Jx1zZ9Sh0xII4KN6mRUB0Y9OqHoZduiKeOodoQs0vXWFmtSYnxrAIpJK2fTQGxZshyhXCaPKHa5CF7gz/WOuVOzt1h3JodKihixqu8kWs0OLxW8ey3V1XtCRKiMPMuWoI1xHL6siIVP99/kC51DaKzQ/T6+VELVkqmqXGNpIt27Awm5UdvEjZES/2n0L2jKCSdko64OSn9+PnYrD+qp+dMY97lB3+P7wwlsCjBek0KAsDUmiB9eiiyLHu/lf1TbpEg/Eul6nWqpHaJcAVpq6jBA9V154u6xSlADe919QYm3YHLEhCeBKclIjkP0rDIP/9DfilglSslC1nyOzBPr3kGpnNNGTMkK/9fbZh7E5R0BY8zddG555NFr4BJO/zVVTqudzDDh45NhS0zPz9BNV80IMeQ2OPDbWDPKPcq1/brt4oduKLfcoevCv3Y6wu4Oerhnskk3cce7Oo1N0ZcibrMO5hJhC7aGHrhJ8uC2ARpUJqTuXxj1uNSzlIfCeaUKc15zV9A4WjW9SQDruxiaCMiX/oVqZdYXpLXwjVQCXYMr6cUvJJUxq8Z8pokzgKT7+kEtZz2hSntQu8wL1ifLONpn8o8Kn73d0w3NX90Ako/GUtXcuY2mCJCWpzmzFQHmJk7OVEuUV4j2y7/+14jvhfT4EB4vpIVkI3OceZwbAhTd/1XQ3Fc5GCT1P0Gtg=
Unsafe is in fact unsafe, and constr does more checks, not to mention more type inference. I still think it's worth reporting as a bug that transcribing Ltac to Ltac2 incurs a 3x performance overhead in this case; this seems worth understanding and fixing, or else there's not much hope of getting people to switch from Ltac to Ltac2.
On Sat, Aug 1, 2020, 13:17 Gregory Malecha <gregory AT bedrocksystems.com> wrote:
Thanks for pointing that out. It inspired me to look at the resulting code. I get the following:build : constr -> constr
build :=
fun x =>
let rec build :=
fun p =>
let m :=
[Pattern.MatchPattern, pattern:(True), (fun _ => fun _ => constr:(I)); Pattern.MatchPattern, pattern:(and ?p ?q),
(fun _ =>
fun p => let q := Array.get p 1 with p := Array.get p 0 in let l := build p in let r := build q in constr:(@conj _ _ _ _))] with
t := p in
Pattern.lazy_match0 t m in
build xI assume that the `_`s in the constr: are printing artifacts.You are right, building the term with Unsafe gets me performance on par with Ltac. It seems like this would be a natural implementation of constr, and for some reason I thought that I had read that it was in the manual, but I must be mistaken.On Sat, Aug 1, 2020 at 10:09 AM Jason Gross <jasongross9 AT gmail.com> wrote:I'm not sure how to get Ltac2 that is similar to Ltac and comparably fast (though this example looks like a bug worth reporting), if you use the low-level features in Constr.Unsafe to build your term, I expect you'll get something somewhat faster than uconstr. Note that if you do this, you'll have to build the types at the same time as the terms, so that you can avoid evars.On Fri, Jul 31, 2020, 23:04 Gregory Malecha <gregory AT bedrocksystems.com> wrote:Hello --I'm trying to evaluate whether Ltac2 is viable for some automation that I'm writing and I'm having a lot of difficulty understanding how to write things efficiently. I cooked up the following as a stupidly simple problem to get myself started:Ltac2 rec build p :=
lazy_match! p with
| True => constr:(I)
| ?p /\ ?q =>
let l := build p in
let r := build q in
constr:(@conj _ _ $l $r)
end.Fixpoint foo (n : nat) : Prop :=
match n with
| 0 => True
| S n => foo n /\ foo n
end.
Goal foo 10.
simpl.
Time Control.enter (fun () =>
let g := Control.goal () in
let r := build g in
exact ($r)).But it runs about 3x slower than `repeat constructor` suggesting that I'm doing something inefficient. The following Ltac1 program also seems significantly faster, suggesting that it isn't simply the fact that I'm doing an extra match.Ltac prove_it :=
lazymatch goal with
| |- True => exact I
| |- _ /\ _ => refine (conj _ _); [ prove_it | prove_it ]
end.(though replacing [refine] with [apply] is comparable). Even constructing the term in Ltac using cps is significantly faster despite all of the continuations that are constructed. Similarly, the following program is also much faster:Ltac build_it p k :=
lazymatch p with
| True => k constr:(I)
| ?p /\ ?q => build_it p ltac:(fun P => build_it q ltac:(fun Q => k uconstr:(conj P Q)))
end.Even replacing [uconstr] with [constr] is faster. How do you prove things efficiently in Ltac2? Is there a pattern that I'm missing? Is the interpreter much slower?Any suggestions or pointers would be greatly appreciated. Thank you!
--Gregory Malecha
Mail: gregory AT bedrocksystems.com
BedRock
Systems Inc
FORMALLY SECURED COMPUTING
UNBREAKABLE FOUNDATION FOR
--Gregory Malecha
Mail: gregory AT bedrocksystems.com
BedRock
Systems Inc
FORMALLY SECURED COMPUTING
UNBREAKABLE FOUNDATION FOR
- [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/01/2020
- Re: [Coq-Club] Ltac2 Performance Question, Jason Gross, 08/01/2020
- Re: [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/01/2020
- Re: [Coq-Club] Ltac2 Performance Question, Jason Gross, 08/01/2020
- Re: [Coq-Club] Ltac2 Performance Question, jonikelee AT gmail.com, 08/01/2020
- Re: [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Jason Gross, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Jason Gross, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, jonikelee AT gmail.com, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Jason Gross, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/02/2020
- Re: [Coq-Club] Ltac2 Performance Question, Gregory Malecha, 08/01/2020
- Re: [Coq-Club] Ltac2 Performance Question, Jason Gross, 08/01/2020
Archive powered by MHonArc 2.6.19+.