coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Gregory Malecha <gregory AT bedrocksystems.com>
- To: coq-club AT inria.fr
- Subject: [Coq-Club] Ltac2 Performance Question
- Date: Fri, 31 Jul 2020 23:03:44 -0400
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gregory AT bedrocksystems.com; spf=None smtp.mailfrom=gregory AT bedrocksystems.com; spf=None smtp.helo=postmaster AT mail-pj1-f54.google.com
- Ironport-phdr: 9a23:rR1RexHLdD33jK8xIjyrkZ1GYnF86YWxBRYc798ds5kLTJ7zpcmwAkXT6L1XgUPTWs2DsrQY0rSQ7fGrBzRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfLJ/IA+3oAjVucUbgJduIbstxxXUpXdFZ/5Yzn5yK1KJmBb86Maw/Jp9/ClVpvks6c1OX7jkcqohVbBXAygoPG4z5M3wqBnMVhCP6WcGUmUXiRVHHQ7I5wznU5jrsyv6su192DSGPcDzULs5Vyiu47ttRRT1jioMKjw3/3zNisFog61VoByvqR9izYDKfI6YL+Bxcr/HcN4AWWZNQsRcWipcCY28dYsPCO8BMP5ZoYnnuVQOohy+BROsBejyzTFHnHv20rMm3OQhCw7NwQstH90UsHvKo9X1M70SUOCuwabT0zrMculW2TDh54jLaRAgoeqMXa5ufsrU0kkjDR/KjlKVqYH8OT6ey+sCvXSB4eV6SeKvl3Aoqxt3ojW3xMohjobEi40bx17K6Cl3zpg5KMGmRUN1fdOpFIZcuS6ZOoV5TM0vR29mtTgmxrMGp5O2cycHxYkpyhPcdfCKcY6F6Q/gWuaJOTp0mm5pdbalixux8UWs0PPwWtS13VpQridInd/BvW0X2RPJ8MiIUP5981+h2TmR0wDT7flJIUUumqraL54t26YwlpgOvUjaEC/7mEr7gLWZdkUj/eio5ODnbav8qpCAMI90jxnyMqUomsOhHeQ1KhYCU3Sf9Oim17Du/Vf1TKtXgvA3iKXUsJ/XKdwepqGjAg9V1ogj6wy4DzejyNkYkmMHI0xKeBKAlYjoO0rDL+vmAviimVSslytkx/PdPrzhGZXNMmbMkLL6fbpn90Fczw8zwchF551IErEBPO7zWkjpudPECR85KhW4zPrjCNVgzYwTQnmPA6+cMKPKq1CE/OMvI++WZI8UojnxMfYl5+S9xUM+zFQaZOyi2YYdQHG+BPVvZUuDMlT2hdJUPn0HsQ0kXaTPgVmPWj5aLyK9Ra8z4SsqIIirAZ3ETYO2kaed0SKgWJZRYzYVWRi3DX70etDcCL83YyWIL5o5y2FWZf2aU4YkkCqWmkr6xr5gdLeG/yQZsdf71oEw6bCP0x418jNwAoKW1GTfFzgozFNNfCc/2eVEmWI40k2Ki/AqifFUD9tY5OhYSRs3MIWaxOt/WYirC1DxO+yRQVPjee2IRDQ4T9Y/2dgLOR4vEdiulBfI3DG7GKMYkqfND5sxoPrR
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.
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)).
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.
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.
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
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+.