-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exponential complexity? #3
Comments
Good catch!
…On Tue, 20 Jul 2021 at 12:29, Andrius Stankevičius ***@***.***> wrote:
Simple example with fibonacci numbers:
n :: Int
n = 50
fibN :: Num a => a -> a
fibN x0 = fibs !! n
where
fibs = 0 : x0 : zipWith (+) fibs (tail fibs)
fibInt :: Integer
fibInt = fibN 1
fibAD :: (Integer, Integer)
fibAD = rad1g 0 1 fibN 1
fibInt evaluates instantly. fibAD takes a long time and throws stack
overflow exception.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNBDKBDDNKNBHFZGVVSA2TTYVFXRANCNFSM5AVQOBHA>
.
|
I don't know what to make of this though. On one hand, this example is not what I'd call a typical application of AD. But you're right, there's certainly a fundamental limitation in the code somewhere. I hope someone with more expertise in debugging laziness issues can shed some light on this. |
Yeah, there is some potential for lazyness to build up in some places, e.g. the |
Just replacing it by |
Thank you @turion . It really sounds like a radical redesign is in order. In its current version, |
Somewhat simper example:
I don't think lazyness is a problem here. At worst it may cause memory consumption to be proportional to the amount of computation, which shouldn't be an issue with only tens of variables. My guess would be that this piece of code causes combinatorial explosion:
Maybe Anyway, I don't really grok the code, so it's all just wild guesses. |
Have you tried UseStrict to see if it goes away? |
@tonyday567 thanks but I just tried, -XStrict doesn't help. |
Simple example with fibonacci numbers:
fibInt
evaluates instantly.fibAD
takes a long time and throws stack overflow exception.The text was updated successfully, but these errors were encountered: