by portent · 9y ago · 0 comments
Simple example: can you tell me if this snippet of (python) code will ever terminate or not?
x=0.5
while x<0.6 or x>0.7:
x=3.59*x*(1-x)
print x
... and what if the 3.59 was replaced by a different number - maybe 3.60 ? or 3.84 ?What my code snippet is doing is running a sample of a particular chaotic function that was originally inspired by biology (a simple predator/prey model). Ultimately, what happens is that you just cannot predict how the function will behave - it is chaotic.
Ultimately most complex systems start to show some chaotic behaviour, which basically means that the behaviour of the system cannot be predicted in detail, even if virtually everything is known about the system in advance.
One example is if you try saving a simulation to disk you need to copy all internal state or you get a different output.
x=5
y=5
while True:
if y%2 == 0:
y=y/2
else:
y=3y+1
if y == 1:
x=x+1
y=x
if y==x:
return x
Please predict the code. I'll even give you $500 in memory of some guy named Erdos if you get it right (and I haven't even gone for a provably undecidable example! :) )PS: Don't waste time checking x values less than 1000000000000000000
That said, we can still see what that code does, even if we don't know precisely what code path it takes. Great example though!
The original poster seems to imply that knowing the code means that you can know the behaviour of the system; I do not think that is the case, and my simple (chaotic) example tries to demonstrate this.
The issue is not so much how this code is translated from higher abstraction level to lower abstraction level... the issue is, that this code represents a simple chaotic function (the logistic map). As such, for a simple few lines of code the behaviour is very complex and virtually impossible to predict; for certain values of the controlling number it will (1) halt relatively quickly, (2) never halt, or (3) halt after a very long time... but good luck in distinguishing between cases 2 and 3!