Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] wasting natural fuel is costly

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] wasting natural fuel is costly


Chronological Thread 
  • From: Clément Pit-Claudel <cpitclaudel AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] wasting natural fuel is costly
  • Date: Wed, 16 Dec 2020 21:41:36 -0500
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=cpitclaudel AT gmail.com; spf=Pass smtp.mailfrom=cpitclaudel AT gmail.com; spf=None smtp.helo=postmaster AT mail-qt1-f169.google.com
  • Ironport-phdr: 9a23:R3Ex4BUw6QLFZdgOtZ5g/XsiaqnV8LGtZVwlr6E/grcLSJyIuqrYbBGCt8tkgFKBZ4jH8fUM07OQ7/m/HzVRut3d7jgrS99lb1c9k8IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUhrwOhBoKevrB4Xck9q41/yo+53Ufg5EmCexbal9IRmrrwjdrNQajI9sJ6o+xRbEo2ZDdvhLy29vOV+dhQv36N2q/J5k/SRQuvYh+NBFXK7nYak2TqFWASo/PWwt68LlqRfMTQ2U5nsBSWoWiQZHAxLE7B7hQJj8tDbxu/dn1ymbOc32Sq00WSin4qx2RhLklDsLOjgk+2zRl8d+jr9UoAi5qhJi3YDUboGbOvlwcKzTctwVR3ZOUMlKWixdAI6xdZcDA/YPMOtaqYT2ulsArQG5BQmpHO7i1DtIgWXz3aIk1eQhDRnJ0hYhH9ISqXjZstH1O70PUe+o0qbIySjIYvRK1jfl6YjIbgwuofWWUrJtbMXe100vGhjKjlWVs4PlPjeV2v4RvGic6uptTOSigHMopA9tuDag3NssipXXiYIPzFDJ7Tl1zYI7K9O2VUJ2YNGpHZhMuiyGOIZ7XsMvTmJntisnyrMLuJq2cDUKxZk52xPSZPyKfoqM7x/9V+ufLjZ1iXZjdbmihBiy6VCtxvPgWsSwylpHrSpInsPRun0MyxDf8NWLR/p580u5xzqC2Brf5+BZLUwui6bWJIItzqQzm5YPt0nIAzX4l1/sjKCMc0Up4uio5PrjYrXhvpKcMpV7igD6Mqg3g8y/Hfk0PhEAX2SG+Omx0Kfv/UL+QLVNgf02lrfWvIrGKsQco661Gw5V0oA95BajFzqqzsgUkH0dIF9GeB+LlZXlNlDSLPziEPuyglChnC9ux//cP73hBpvNLmLEkLfkZbty91ZcyAsvzd9D45JbEKwBL+/tVU/1r9HYARo5PBa1w+bjEtlyyoQeWWeXDq+DLKzSqUOI5v4oI+SUeIAVvy/9J+E56P7qkH82gkQQfbKp3JsScHC3BO5qI0SfYXr2g9cOC30GvgQkTL+itFrXWjlKIn22QqgU5zchCYvgA52QaJqqhemq2Ka+E5tKUVhHFhWnFX71e4iAE6MHcCOOKctojzAJUZCuToYg0VelswqsmOkvFfbd5iBN7cGr79Ny/eCGzUhvpwwxNNyU1iS2d08xnm4MQGVojqV2oEg400valKYh3a0eGttU6PdEFAw9MMyElrAoO5XJQgvEO+yxZhO+WNz/WGM+S9swx5kFZEMvQ4zz3CCG5DKjBvour5LOAZU19qzG2H2ofpRyzn/H0O8qiFx0G8Y=

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)






Archive powered by MHonArc 2.6.19+.

Top of Page