-
Notifications
You must be signed in to change notification settings - Fork 13
Question: negation for f64 #32
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
Comments
Hey @wbthomason thanks for giving this a spin! I believe the issue is that the upstream egglog library does not support negation yet for f64. I doubt this is due to an intentional choice, but just that they hadn't needed it yet. Once it is added to egglog, we can add it here. It can be added to the |
Got it, thanks! I'll take a look at making a quick PR. If, in the meanwhile, I wanted to make a custom "float-like" type with negation support, would this be as easy as making a separate |
Yeah I believe that should work! Something like this (untested): @egraph.class_
class MyFloat(BaseExpr):
def __init__(self, f: f64Like) -> None: ...
def __add__(self, other: MyFloat) -> MyFloat: ...
def __neg__(self) -> MyFloat: ...
x, y = vars_("x y", f64)
egraph.register(
replace(MyFloat(x) + MyFloat(y)).with_(MyFloat(x - y)),
replace(-MyFloat(x)).with_(MyFloat(f64(0) - x)),
) |
Thanks for the library! I've been trying to use
egglog
for some numerical code, and have run into the missing unary negation operator forf64
. I've tried patching this in myself analogously to its implementation forRational
, but I only end up with an errorNo matching primitive for: (neg f64)
.Is there a more fundamental reason that negation is unsupported for
f64
? Could you help me figure out how to add this? Thanks!The text was updated successfully, but these errors were encountered: