-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
1/x not the same as inv(x) for matrix in julia 0.2.0 #75
Comments
Because It is better to ask a question like this to the julia-users list. |
I wonder if that behavior is still a good idea. After all |
1/A computing the elementwise reciprocal of A is inconsistent with A/B computing B\A. Why not make 1./A compute the elementwise reciprocal instead? |
Also there is at least one julia tutorial that expects 1/A == A^-1 |
It feels like 1.0 ./A should be the matrix reciprocal, eye()/A should be the matrix inverse and 1.0/A should just be an error. |
That tutorial is quite outdated. |
Agree. I was too fast here. There is also the consequence
Most linear algebra function accept |
If we were to go down the road of making |
I would seriously consider doing that. The case of |
I'm not convinced, however, that this has to be conflated with |
A few thoughts on the specific issue of matrix inverse notation though:
|
I don't think scalar*matrix could do anything but scale the matrix, no matter how we interpret all the above arguments. |
Hm, maybe I wasn't being clear. My point is that there are plenty of contexts in which |
as opposed to the current behavior of |
I would be very much in favor of that change. I can't imagine a single mathematician who would not prefer for |
This proposal, by the way, is very much as its heart about whether a |
I like the idea of making scalars behave like they're multiplied by If I know I have tons of |
As an aside, the julia> ones(A) == ones(size(A))
true
julia> eye(A) == eye(size(A))
ERROR: no method eye((Int64,Int64))
julia> eye(A) == eye(size(A)...)
true |
@mbauman Tempting as it is to define |
You could always define a custom |
Right, of course, since there is no true inverse for rectangular matrices, there is no universal solution here… perhaps the answer is to punt and throw an error for rectangular matrices? I still like the consistency of (effectively) transforming the scalar (Thanks for the tips, Kevin and Jiahao - I'll be happy to ditch those Matlabisms in my Julia code) |
Also, speaking of customization, probably a special matrix type which just keeps a scalar and represents a matrix proportional to the identity of a variable size, together with a constant
etc. (of course
|
Yes, that solution had occurred to me as well. It's elegant. |
@carlobaldassi the |
It is quite common as notation though ;-) |
don't be trolling now. |
Not to careen too far offpath here, but I've been thinking for awhile that IterativeSolvers.jl really needs a |
A local variable If we add this constant |
@lindahua thanks for the excellent explanation |
I like the One could then define However, I don't think |
I agree with @lindahua on everything, included the preference for deprecating |
@carlobaldassi Unfortunately, the standard notation for the identity matrix really seems to be |
Using |
Sorry for the long break. I can see that you have had a great party here. I am not proposing the following behaviour in julia, but just for completeness, here is Sage A=matrix([[1,1],[1,1]])
A+2
[3 1]
[1 3] I think it will be better to add the Generally, I think that it would be cleaner to let the Finally, even though we might keep |
I'd be fine with removing Number/Array. |
+1 for @andreasnoackjensen's arguments |
I want to put in my vote for letting It was not always obvious that Julia should have both Put another way, when you are writing linear algebra code using When it comes to being explicit about what operations do, I think that If the distributive property should hold for
But I think it would be ok if you have to put in the For
then we need A lot of you have talked about consistency with other languages. I beg of you to consider the internal consistency of Julia as well. For this, we need to consider mathematical arguments. When one gains experience with numerical software, it easy to be lead to believe that it is by necessity much less consistent than mathematics, with corner cases that you have to watch out for everywhere you turn. Experiencing Julia has led me to believe that it does not have be so, it's more that too many programming languages were designed without such considerations, often by people without sufficient mathematical background. I still hope that Julia can be different. I would argue that satisfying basic properties like distributivity and associativity is an important consistency aspect, and generic programming thrives on consistency. |
@toivoh Thanks for the comment. After reading it twice, I am convinced by your arguments, and also annoyed that I didn't see the associativity argument for |
It looks like a lot of the discussion is on the difference between interpreting an Array as just a multidimensional collection of data versus interpreting them as a mathematical object (vector,matrix, tensor = multilinear map). My vote would also be on having number/matrix = number * inv(matrix), and on deprecating array + number and requesting users to change the code to array .+ number, despite @lindahua 's argument that this construction is often used in the technical computing community. I agree with @lindahua 's argument for not having matrix + number adding to the diagonal (cited below), but the same argument also requires not to have matrix + number = adding number everywhere. In fact, I cannot think of any algebraic construction that would ever want to use such a strange operation, but that's probably just my ignorance. Citing @lindahua |
I don't have a problem deprecating If I were asked to design a system, I would prefer such a system:
|
+1 for that |
+1 in favor of @lindahua's proposal.
|
Yes, that seems like a very sane approach. +1 |
+1 |
I support @lindahua's proposal except that I think @toivoh's argument for allowing |
You've caught me reciting scripture (* ̄m ̄) It isn't so much that
You'll notice in your notebook that the spread of errors using I really can't think of a compelling use case for matrix inverses where the right to do is to express it using |
Actually, I think it's the other way around. LU errors are circles, INV errors are x's. |
Oops, fail. I'm not sure why that would be the case. I notice that inv and \ are both using the same LU factorization under the hood, is that right? |
+1 to @lindahua's suggestion, explicit is better than implicit. My argument for 1/A = inv (A) should perhaps even more be taken as argument against elementwise division. I think that we should consider what |
+1 for @lindahua's suggestion. I had no strong preference for 1/A being either inv(A) or just an error (but not elementwise division), and would definitely not use the 1/A notation myself. |
I have updated the pull request JuliaLang/julia#5810 in consequence of the discussion here. @jiahao I understand that there are many situations where the |
(In practice, I suspect that inverting matrices for performance reasons is mostly seen for tiny matrices, e.g. 3×3. On the other hand, for pedagogical and exploration purposes, I compute inverse matrices of moderate-sized matrices all the time.) |
closed by JuliaLang/julia#5810 |
I was trying to figure out how to invert a matrix in a 0.2.0 installation of julia, and I found out that 1/x gives me a different inverse than inv(x).
Here is my output
The text was updated successfully, but these errors were encountered: