It looks like you'd call something a 3-cycle if for some x_0 we had
f(f(f(x_0))) == x_0, right? Then we should be able to do this
numerically, with some caveats:
# can't remember the slick way, so brute force
def iter_apply(f0, n):
fs = [f0()]
for i in xrange(n-1):
last = fs[-1]
fs.append(f0(last))
return fs
def find_pcycles(f0, n):
fs = iter_apply(f0, n)
req = fs[-1] == x # defining equation of the cycle
roots = req.roots(ring=RR)
for root, mult in roots:
yield [fi(x=root) for fi in fs]
which gives
sage: f(x) = x^2-1.76
sage:
sage: p1 = list(find_pcycles(f, 1))
sage: p1
[[-0.917744687875782], [1.91774468787578]]
sage: f(p1[0][0])
-0.917744687875783
sage: f(p1[1][0])
1.91774468787578
sage: list(find_pcycles(f, 2))
[[0.504987562112089, -1.50498756211209], [-0.917744687875783,
-0.917744687875782], [-1.50498756211209, 0.504987562112089],
[1.91774468787578, 1.91774468787578]]
sage: list(find_pcycles(f, 3))
[[1.33560128916886, 0.0238308036295167, -1.75943209279837],
[1.27545967679486, -0.133202612870350, -1.74225706392451],
[-0.917744687875783, -0.917744687875782, -0.917744687875783],
[-1.74225706392451, 1.27545967679486, -0.133202612870348],
[-1.75943209279837, 1.33560128916886, 0.0238308036295143],
[-0.133202612870349, -1.74225706392451, 1.27545967679486],
[0.0238308036295150, -1.75943209279837, 1.33560128916886],
[1.91774468787578, 1.91774468787578, 1.91774468787578]]
Note that this says [-0.917744687875783, -0.917744687875782,
-0.917744687875783] is a 3-cycle, which it kind of is..
Anyway, maybe playing off of something like that would help?
Doug
Do you know the standard trick (as used for instance in the Pollard
rho method of factorization) which avoids storing lots of terms of the
sequence and instead runs two variables through the sequence
simultaneously, starting at the same point, but with one sequence
applying the iteration twice? then you just have to check when the
two values coincide.
Details left to the reader, or see
http://en.wikipedia.org/wiki/Floyd%27s_cycle-finding_algorithm#Tortoise_and_hare
John
> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org