Maxima: Simplify expressions containing minimum

548 views Asked by At

I am trying to use Maxima to simplify mathematical expressions involving min(a, b). Say I have defined
z = min(x1, x2) and d = abs(x1 - x2), then the identities x1 * x2 = z*(z+d) and x1 + x2 = 2*z + d follow.

For example, take the following expression:

(2*z^3+(−3*x2−3*x1)*z^2+6*x1*x2*z)/6

If I manually apply the above identities, I can simplify it to

z^3 / 3 + (z^2 * d) / 2

In Maxima, naively trying

subst(min(x1, x2), v, ((6*v*x1−3*v^2)*x2−3*v^2*x1+2*v^3)/6), ratsimp

Produces a long expression.

How can I make Maxima find the occurrences of x1 * x2 and x1 + x2 buried deep inside the expression? I have tried various forms of tellsimp, let and letsimp, for example:

let(x1*x2, z * (z+d))

or

let(K * x1*x2, K * z * (z + d), K, integer)

or

matchdeclare(R, true)
let(R * x1*x2 * z, R * z * (z+d))

How can I make Maxima produce the nice short expression that I can manually arrive at? I need to work with much larger expressions.

1

There are 1 answers

1
Pankaj Sejwal On BEST ANSWER

May be this is helpful,

load("lrats");

    lratsubst([x1*x2=z*(z+d),x1+x2=2*z+d],
    (2*z^3+(−3*x2−3*x1)*z^2+6*x1*x2*z)/6)

(2*z^3+3*d*z^2)/6

Also if you want to test your identities, you could do

z(x1,x2):=min(x1,x2)$
d(x1,x2):=abs(x1-x2)$

Now put numerical values say, z(2,3)*(z(2,3)+d(2,3))=6. Apparently these don't help in simplifying your expression.