Skip to content
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

scalar + I => scalar #482

Closed
StefanKarpinski opened this issue Oct 23, 2017 · 4 comments
Closed

scalar + I => scalar #482

StefanKarpinski opened this issue Oct 23, 2017 · 4 comments

Comments

@StefanKarpinski
Copy link
Member

Now that we've deprecated matrix + scalar, we can revisit the old A + I + 1 associativity chesnut. If we make scalar + I => scalar then we have (A + I) + 1 and A + (I + 1) both being the same error for matrix + scalar. This also would allow us to write generic polynomials that work for both scalars and square matrices since e.g. x^2 + 2x + I would evaluate to a scalar for scalar x and to a matrix for matrix x. Strictly this isn't breaking, so this need not be done for 1.0, but we may want to at least try it out to see if there are any things we need to break to make this work.

ref #341, cc @eveydee, @dlfivefifty

@KristofferC
Copy link
Member

KristofferC commented Oct 23, 2017

For generic polynomial it needs to be written as x^2 + 2x + I(x), where I(::Int) = 1 and I(m::Matrix) = eye(m)? To handle zero order polynomials and to be type stable (in the reduction variable) when you would implement a function that takes a vector of coefficients and the point to evaluate the polynomial at.

Edit: Alternatively, you could write it as x^2 + 2x^1 + x^0. No need to use I at all. I actually think this is the right way to do it.

@StefanKarpinski
Copy link
Member Author

That's an additional concern, but only for writing very generic polynomial code – for a specific polynomial with positive order, just having scalar + I => scalar is sufficient. In any case, the fact that there are additional concerns doesn't make this not a good change. For generic polynomial code, we can use x^2 + 2x + x^0 or something like that.

@StefanKarpinski
Copy link
Member Author

Oh hey, we already do this:

julia> 1 + I
2

@JeffBezanson
Copy link
Member

Fixed by JuliaLang/julia#23923.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants