Zulip Chat Archive

Stream: new members

Topic: infinite loop


Raffaele Rossi (Jul 31 2020 at 14:54):

Hi all, I'm new to Lean and I'm going through the Number Game. At level 6/13 of Advanced Addition World, I noticed that given the hypothesis h: t+a=t+b if you type repeat {rw add_comm at h} it gets stuck an infinite loop :) Is this "intended" or ideally lean should detect and abort with a failure?

Kenny Lau (Jul 31 2020 at 14:54):

do you have a solution to the halting problem?

Raffaele Rossi (Jul 31 2020 at 14:55):

this is not a halting problem, this is just detecting that you've come back to the current state.

Kenny Lau (Jul 31 2020 at 14:56):

that would make the tactic slower

Kenny Lau (Jul 31 2020 at 14:56):

tactics are tools, not magic algorithms that prove every theorem

Raffaele Rossi (Jul 31 2020 at 14:56):

only the repeat tactic, though

Raffaele Rossi (Jul 31 2020 at 14:58):

of course it's a tool, I did not ask for a magic wand. Just that if I say repeat {x} it could, conceptually, determine that it's going round an infinite loop

Raffaele Rossi (Jul 31 2020 at 14:58):

and it makes sense to slow down only the repeat tactic in this case

Reid Barton (Jul 31 2020 at 14:58):

That's not what repeat is defined to do, but also it's generally not that useful to detect loops anyways--what would it do if it detects one?

Kenny Lau (Jul 31 2020 at 14:59):

right, why not just use iterate n { rw foo } if you know it will be in a loop

Raffaele Rossi (Jul 31 2020 at 14:59):

I did not know about iterate

Raffaele Rossi (Jul 31 2020 at 14:59):

I'm literally just at level 6/13 of that world

Reid Barton (Jul 31 2020 at 15:02):

Oh, you said raise an error--but I think that's too expensive in the non-erroring case, and usually it's pretty obvious where the problem is if you just added repeat { foo } to your proof and Lean starts taking a long time

Jalex Stark (Jul 31 2020 at 15:03):

So to answer your original question, this is intended behavior

Jalex Stark (Jul 31 2020 at 15:03):

there are in fact smarter tactics that can figure out how to apply commutativity,

Jalex Stark (Jul 31 2020 at 15:03):

but the point of the natural number game is to learn how to do things without them :)

Kenny Lau (Jul 31 2020 at 15:03):

well I understand where you are coming from

Kenny Lau (Jul 31 2020 at 15:03):

the NNG is marketed as a game

Reid Barton (Jul 31 2020 at 15:04):

The original example isn't a good use of repeated rw anyways because the first rewrite will change t+a=t+b to a+t=t+b and the second one will change it back to t+a=t+b.

Kenny Lau (Jul 31 2020 at 15:04):

so in a game I would expect rw to have loop detection feature I guess

Kevin Buzzard (Jul 31 2020 at 15:07):

You mean repeat? I can just remove it if you like :-) Or replace with iterate 37, that should be enough for everyone

Kevin Buzzard (Jul 31 2020 at 15:07):

A few months ago the user would lose all their progress if they did this :-/

Raffaele Rossi (Jul 31 2020 at 15:09):

yeah so far the game did not mention iterate although even if it did I am sure I would have not used it :) was just food for thoughts and I understand this might have been a very trivial example that in real practice would not even actually happen

Raffaele Rossi (Jul 31 2020 at 15:09):

but I like that this community is very active

Jalex Stark (Jul 31 2020 at 15:09):

i would probably have had a better time with the nng my first time if repeat were a synonym for iterate 37 or maybe just iterate 3

Jasmin Blanchette (Jul 31 2020 at 15:13):

One can see that you guys aren't computer scientists. ;)

Jalex Stark (Jul 31 2020 at 15:30):

yes, the computer scientist's version of the nng might have ~none of the overrides that kevin made. thankfully the computer scientists have less trouble installing lean locally and playing more faithful tutorials

Mario Carneiro (Jul 31 2020 at 23:36):

I think repeat is actually defined as iterate 100000

Yury G. Kudryashov (Aug 01 2020 at 03:06):

I don't see 100000 in src#tactic.repeat

Jalex Stark (Aug 01 2020 at 03:16):

yeah it looks like it's a plain old infinite loop

Mario Carneiro (Aug 01 2020 at 04:29):

It appears that the definition of repeat has changed since my recollection. It has since been renamed to src#tactic.iterate, which differs from the current tactic.repeat only in the abnormally high limit

Kevin Buzzard (Aug 01 2020 at 06:28):

Yeah I think I even remember reading in some docs (maybe Programming in Lean?) that repeat was iterate 10^n for some n which should be enough for everyone


Last updated: Dec 20 2023 at 11:08 UTC