upiterbarg / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

giant_steps #219

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. giant_steps(1, 100)

What is the expected output? 

[4, 5, 7, 10, 16, 28, 52, 100]

What do you see instead?

hangs

What version of the product are you using? On what operating system?
0.17

Please provide any additional information below.

The following may be a more robust code for that routine:

    L = [target]
    while 1:
        Li = L[-1]//n + 2
        if Li >= L[-1]:
            break
        L.append(Li)
    return L[::-1]

Original issue reported on code.google.com by smi...@gmail.com on 22 Feb 2012 at 3:51

GoogleCodeExporter commented 9 years ago
I guess `if Li >= L[-1] or Li < start` would be better for the break condition.

Original comment by smi...@gmail.com on 22 Feb 2012 at 4:01

GoogleCodeExporter commented 9 years ago
I don't see much need to change this function, as it's really only intended 
internally for numerical Newton iteration where the starting precision is much 
higher than 1.

For algebraic Newton iteration, where the starting precision might be 1, it is 
better to use a more exact version, precisely doing ceiling divisions by n.

The proposed change would not really be correct anyway as it should start with 
something like 1, 2, 3, ...

Original comment by fredrik....@gmail.com on 23 Feb 2012 at 4:03

GoogleCodeExporter commented 9 years ago
OK. And it only hangs if you happen to start at 1. Since it wasn't a
private function it caught my attention.

Original comment by smi...@gmail.com on 23 Feb 2012 at 6:43