Calculus.jl icon indicating copy to clipboard operation
Calculus.jl copied to clipboard

Add cancellation of common variables in 'simplify'

Open magistere opened this issue 12 years ago • 7 comments

magistere avatar Oct 15 '13 06:10 magistere

These simplifications breaks matrix algebra.

ivarne avatar Oct 15 '13 07:10 ivarne

Ivar, I tested it only on simple expressions. Can you give some matrix example that breaks after this commit?

magistere avatar Oct 15 '13 19:10 magistere

If you have a matrix in the denumerator, you can not shorten it by this kind of simple elimination. Sometimes you will end up with an identity matrix eye(A), but in more complicated cases you will get a completely wrong answer. I am not sure if that is a common use case. We might have a setting in simplify to restrict to matrix safe operations.

ivarne avatar Oct 17 '13 09:10 ivarne

So this is because * means normal or matrix multiplication depending on argument types. It is not very convenient for symbolic computations, but cannot be changed. Another symbolic math software (Mathematica and Maple) use . (dot) for matrix multiplication. Making multiple dispatch to identify arguments with acceptable type will be not very helpful. Let's wait for @johnmyleswhite comments on this issue.

magistere avatar Oct 18 '13 11:10 magistere

Yes, it is because (users of) julia does not follow its basic API design principle for \ and*. One function should only have one meaning and behave roughly the same way for different types. You could argue that it is concistent if users would use .* for all scalar operations, but I don't think that is the behavior we are seeing.

For simplify or simplify! I think that we must respect the design of the language and assume that \ and* refers to matrix operations and must adhere to matrix associativity rules.

ivarne avatar Oct 18 '13 13:10 ivarne

Because I'm traveling I won't have time to think a lot about this, but I had never intended for these symbolic operations to work on matrices, just real numbers. If we can make them more general, that would be great.

I think it would be very helpful to discuss this issue on the julia-users mailing list, specifically asking for feedback from Stefan, Viral, Steven Johnson and Alan Edelman.

johnmyleswhite avatar Oct 18 '13 13:10 johnmyleswhite

I think we should restrict to real numbers only. Anyway now all functions in the package don't support matrix/vector arguments. For example with matrices even diff(x_x, x) will be not 2_x, but (Mathematica code):

In[1]:= D[x.x, x]
Out[1]= 1.x + x.1

magistere avatar Oct 18 '13 22:10 magistere