-
Notifications
You must be signed in to change notification settings - Fork 6
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
Handling of rewrites with respect to types #46
Comments
Related to this is your comment on issue #19 with regards to associativity. It's well known that floating point addition is not associative in general. However, I tend to be of the opinion that the differences between floating point numbers and real numbers are a bug and not a feature so I don't see much point in trying to mimic them. I think that in general, if Rewrite can do better than floating point by taking advantage of known algebraic structure, then we should and the differences that arise should be treated as a shortcoming of floating point arithmetic, not the symbolic manipulations. In practice, I think my opinion is that floating point addition should be treated as associative, and Also, in the case of |
I would absolutely agree that all imprecision with floating point calculations should be considered more of a bug than a feature. julia> f(x) = sin(x)^2 + cos(x)^2; # expected: always 1.0
julia> f(2)
1.0
julia> f(3)
0.9999999999999999 Depending on use cases, though, types may or may not be important to retain. For example, if we run Rewrite as a Cassette Maybe it's worth having two different (but intersecting) sets of standard rules: one which strictly retains types and one which is more lenient about types but with stronger rules. After thinking about this more, I'd like to build on it even further. It seems like that it could be very helpful (if not beneficial) to have a custom numerical type for storing "infinite-precision" decimals using Here are a few side-effects of this approach that may be worth considering:
|
I like the idea of using rationals everywhere that's possible. That's actually what Mathematica does, come to think of it. We can just do rationals everywhere its possible to do so and then fall back on I'm not sure it's a good idea to use By the way, does the rules system have a way of parameterizing rules on type? It'd solve a lot of problems to be able to do something like
|
Ah, fantastic! Glad there's a precedence for that. I'd rather not fall back to any floating-point arithmetic, since that's accepting an approximation; instead, it seems more pure to just retain the full term (e.g. The rule system has something close to this feature, but not using the syntax you showed (yet?). It does not allow for usage x = Variable(:x, TypeSet(AbstractFloat))
y = Variable(:y, TypeSet(Int))
@term RULES [
sin($x)^2 + cos($x)^2 => 1.0
sin($y)^2 + cos($y)^2 => 1
end |
We should maybe make some sort of rewrite specific type |
How much should we care about the types of equivalent expressions? For example:
Int
value ofa
, should(3 ^ a) ^ a
be rewritten to3 ^ (a^2)
, even though this would normally throw an error ifa
isn't converted to a float?A * 0.0
be rewritten tozero(A)
, even though the resulting value may be of a different type?The text was updated successfully, but these errors were encountered: