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>
- Cc: Clément Pit-Claudel <cpitclaudel AT gmail.com>
- Subject: Re: [Coq-Club] wasting natural fuel is costly
- Date: Thu, 17 Dec 2020 11:35:17 -0500
- 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-il1-f173.google.com
- Ironport-phdr: 9a23:LQVZ8hCLIFrnpHAJUzOcUyQJP3N1i/DPJgcQr6AfoPdwSPT+ocbcNUDSrc9gkEXOFd2Cra4d1KyP4vurADRRqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba5wIRmssAncsscbjYR/JqotzhbCv2dFdflRyW50P1yYggzy5t23/J5t8iRQv+wu+stdWqjkfKo2UKJVAi0+P286+MPkux/DTRCS5nQHSWUZjgBIAwne4x7kWJr6rzb3ufB82CmeOs32UKw0VDG/5KplVBPklCEKPCMi/WrJlsJ/kr5UoBO5pxx+3YHUZp2VNOFjda/ZZN8WWHZNUtpUWyFHH4iybZYAD/AZMOlXoYnypVsAoxW9CwexGu3g1iRFiWXq0aAgyektDR3K0Q4mEtkTsHrUttL1NKIKXO6x1qbI1jLDb/VL0jn88ojIdQshoeqRVr93c8re01IvFwTDjlWfs4zlOCiV1v8JvmWA4OpgUPigi28jqw1rvjevwcIsh5DPi4kIxV/K6T93z5wpJd2kVkF7e9ikHYNSuiyYK4Z7Q8wvTmNptSsm1rAKpJ62cSwOxZkk2RPRZP6KfYaV7x/gUOudPzd2iWxldr+/mhq//1Wsx+zgWsS71ltBsylLksHUu3wTyxDe7tKLR/h980u7xDqC1gHe5vtZLU02m6fWLYMqzKQqmZoJq0vDGzf7mEXog6+ScUUp4u2o5P7mYrXiv5OcNot0hhznPqQgh8CyA+o1PhIBX2ic/uS827nj8lPjTLpWif02l7HVsJHcJcsFuq60GxFZ3pon5hqlDDqr0M4UkWQGIV9EYh6LkorkNl/WLPD9F/i/glCskDlxx/DBO73sGpfNIWLYkLfme7Z95FRcyA0ozdBE459ZEb4BIPfpVU/wsNzUFAM2Mwuxw+r/EtVyypseWX6TAq+eKK7drViI5vs2L+aQYI8VpS3yJuM+5//uiH85gUUScbOo3ZsRcnC4H+5pL1+XYXr20Z89FjIBuRN7R+j3ghXWWjlKIn22QqgU5zchCYvgA52VFa63h7nU/i6gGZseSXpBEUvERXXhbIKCVO0LcznDCsBkmz0AE7OmTtlyhlmVqAbmxu8/faLv8SoCuMemjYAtvryBpVQJ7TVxSv+l/SSIRmBwkHkPQmZvjq96qE15jFyE1Poh2qEKJZlo//pMFzwCG9vcwuh9UY6gXwvAepKITA/jTIz5Wnc+SdU+x9JIaEF4SY370kLzmhGyCrpQrISlQYQu+/uFjXf0Lsd5jX3B0ft5gg==
There's the printing effects plugin and Set Debug Cbv which will let you do rudimentary debugging in cbv. You can also extract your code to OCaml and debug it there.
My bad. There is something else going on in the recursive function.
It passes the recursive call as a continuation, which is being called
more often than I thought, and is running until out of fuel in some
cases even though the outer recursion doesn't.
I wish there was an easy way to debug Gallina code.
Thanks anyway to Jason and Clément for the suggestions.
On Wed, 16 Dec 2020 21:41:36 -0500
Clément Pit-Claudel <cpitclaudel AT gmail.com> wrote:
> On 12/16/20 8:31 PM, jonikelee AT gmail.com wrote:
> > I have a recursive Gallina function that uses a nat-typed fuel arg
> > to guarantee termination. In cases where the function terminates
> > prior to running out of fuel, I've found that larger than necessary
> > fuel args are very costly. For example, with a fuel value of 100,
> > the function takes 30 times longer than if the fuel value is 10
> > (neither runs out of fuel, all other args are the same).
>
> What if you pass much larger fuel values, like 10000?
>
> > I guess this is probably due to the overhead of nats in Gallina.
> > But it is still surprising to me, considering that if I wrote a
> > function to traverse the first 8 links in a list, I wouldn't expect
> > it to take 30 times longer with a 100-element list than a 10-element
> > list.
>
> The 30x factor is surprising, but a small difference wouldn't be
> entirely unexpected for large constants, since they have to be
> constructed. Try replacing 100 with (Nat.of_uint 100%uint), or
> passing 10000 as the fuel (which will automatically get interpreted
> as (Nat.of_uint 10000%uint)):
>
> Fixpoint collatz (fuel: nat) (start: positive) :=
> match fuel with
> | O => false
> | S fuel =>
> match start with
> | xO x => collatz fuel x
> | xI _ => collatz fuel (start * 3 + 1)
> | xH => true
> end
> end.
>
> Require Import Decimal.
>
> Time Compute (collatz 50 150). 0s
> Time Compute (collatz 2000 150). 0.006s
> Time Compute (collatz 5000 150). 0.021s
> Time Compute (collatz 10000 150). 0s (w/ warning)
>
>
>
- [Coq-Club] wasting natural fuel is costly, jonikelee AT gmail.com, 12/17/2020
- Re: [Coq-Club] wasting natural fuel is costly, Jason Gross, 12/17/2020
- Re: [Coq-Club] wasting natural fuel is costly, Clément Pit-Claudel, 12/17/2020
- Re: [Coq-Club] wasting natural fuel is costly, jonikelee AT gmail.com, 12/17/2020
- Re: [Coq-Club] wasting natural fuel is costly, Jason Gross, 12/17/2020
- Re: [Coq-Club] wasting natural fuel is costly, jonikelee AT gmail.com, 12/17/2020
Archive powered by MHonArc 2.6.19+.