Skip to content

Add fabs support to Taylor series expander #1275

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pavpanchekha
Copy link
Contributor

@pavpanchekha pavpanchekha commented Jun 12, 2025

This PR adds support for fabs in the Taylor expander. It thus fixes #1271. Specifically, (fabs (+ x 1)) expands to (+ 1 x); (fabs (- x 1)) expands to (+ 1 (neg x)) (it gets negated because the constant term is positive); and finally, terms like (fabs (+ x (* x x)) expands to (+ (fabs x) (* (fabs x) x)) which is confusing but accurate in a neighborhood near 0.

Initially I had copilot write it and I was impressed that it came up with something plausible, but actually its code didn't work at all, so I had to rewrite from scratch basically. https://chatgpt.com/codex/tasks/task_e_684b1775fec4833193db8dcc2a906e7a

This PR also includes a tiny amount of cleanup for trigonometric stuff, leveraging new helper function I added for fabs.

@pavpanchekha pavpanchekha requested a review from AYadrov June 12, 2025 21:35
@pavpanchekha
Copy link
Contributor Author

I can confirm that this fixes #1271, at least on my machine.

@pavpanchekha
Copy link
Contributor Author

Unfortunately this seems to hurt accuracy a bit, branch vs main. I'll try to look into it. The effects aren't huge but not worth it just for less weird output.

Copy link
Contributor

@AYadrov AYadrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly misunderstand how the code works, but it looks fine to me

@pavpanchekha
Copy link
Contributor Author

The biggest drop is "a from scale-rotated-ellipse" but it's kind of impossible to tell what's going on there.

@pavpanchekha
Copy link
Contributor Author

Looking a bit more I realize that this branch wasn't up to date with main, so the comparison might not be apples-to-apples, will look again tomorrow morning.

@pavpanchekha
Copy link
Contributor Author

Ok, I looked at a couple of cases and they are all cases of over-greediness. Basically, the ability to Taylor-expand more stuff means that Herbie achieves better results after iter 1, but that only prevents it from searching harder for a rewrite-based solution.

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

Successfully merging this pull request may close these issues.

abs (absolute value) should simplify in the alternatives
2 participants