Skip to content

add primitives with better numerical properties #1595

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

Closed
ghorn opened this issue Sep 28, 2015 · 4 comments
Closed

add primitives with better numerical properties #1595

ghorn opened this issue Sep 28, 2015 · 4 comments

Comments

@ghorn
Copy link
Member

ghorn commented Sep 28, 2015

sqrt(x*x+y*y) = hypot(x,y)
log(1+x) = log1p(x)
expm1(x) = exp x - 1
@jaeandersson
Copy link
Member

I didn't know about "hypot". Looks like a useful function and the derivative rule is trivial: If f = hypot(x,y), then, df/dx = x/f.

@jaeandersson
Copy link
Member

If you want to avoid a not-a-number, you could define the derivative rule as x/(f + std::numeric_limits<double>::min())...

@ghorn
Copy link
Member Author

ghorn commented Sep 28, 2015

That derivative is undefined, what is casadi's policy on such things?

Either way, I would try to keep the properties of hypot(x,y) the same as sqrt(x*x+y*y)

@jaeandersson
Copy link
Member

Policy is that 0/0 will give you a not a number. But you're never guaranteed to get not-a-number. x/x will simplify to 1, for example. Derivative of sqrt(x*x+y*y) will follow the chain rule, of course.For f=sqrt(x), derivative is 0.5/f, so and multiplied with 2*x, the expression may or may not simplify to x/f. So there might not be any gain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants