       Two problems

• Subject: Two problems
• From: Richard Petti <petti at ALLEGHENY.SCRC.Symbolics.COM>
• Date: Thu, 22 Jun 89 13:51:01 -0500
• Apparently-to: mathgroup-out at yoda.ncsa.uiuc.edu

```    Date: Wed, 21 Jun 89 00:35:34 -0500
From: Dallas_Burtraw at um.cc.umich.edu

Greetings.  I am in the Economics Dept at Michigan and have been using
Mathematica for a little while.  Two questions have surfaced that we
have not been able to resolve.  Can you help?
First, I want to attach a penalty in a function within a program, so
for example, I always want x > xo. The number x is a real.  I want to write
((x - xo)^2)^(.5) - (x - xo) which is 0 for x nonnegative and greater than
0 for x negative.  The problem is Mathematica automatically simplifies this
algebra.  Is there a way to prevent that?

I can only suggest how these problems are solved using MACSYMA. Perhaps
Mathematica has similar features. MACSYMA is quite careful about assumptions
like SQRT(X^2) -> ABS(X), and has a data base for storing facts about
symbolic variables. It helps in this case:

(C1) F1:SQRT((X-X0)^2)-(X-X0);

(D1) 							 ABS(X0 - X) + X0 - X

(C2) ASSUME(X-X0 > 0);

(D2) 							       [X > X0]

(C3) F2:SQRT((X-X0)^2)-(X-X0);

(D3) 								   0

(C4) FORGET(X-X0 > 0);

(D4) 							       [X > X0]

(C5) F3:SQRT((X-X0)^2)-(X-X0);

(D5) 							 ABS(X0 - X) + X0 - X

(C6) ASSUME(X-X0 < 0);

(D6) 							       [X0 > X]

(C7) F4:SQRT((X-X0)^2)-(X-X0);

(D7) 							      2 X0 - 2 X

(C8) FORGET(X-X0 < 0);

(D8) 							       [X0 > X]

The MACSYMA data base can store many other types of properties and use them
in calculuations. For example consider the greatest integer function ENTIER:

(C16) ENTIER(3/2);

(D16) 								   1

(C17) ENTIER(Y);

(D17) 							       ENTIER(Y)

(C18) DECLARE(Y,INTEGER);

(D18) 								 DONE

(C19) ENTIER(Y);

(D19) 								   Y

-------------------------

The second, more substantial question is the reason the first came up.
It seems Mathematica can not use its problem solving techniques, either
Solve or FindRoot, over conditional statements.  For example,
f(x) = x if ....
f(x) = x^2 otherwise.
Writing such a conditional with If or Which, then FindRoot can not
solve because it can not compute the derivatives.  Is there a way around
this other than calculating maximization conditions separately and then
rewriting a new conditional?  It seems like an easy fix within the
program if it truly is a bug.

The real issue on this second question is the construction of a constrained
maximization or Lagrangian problem.  It seems clumsy, but I have had to
solve each f(x) = x, etc. and then test the "if" statement.  This wastes
time and I lose any numerical value for the Lagrangian weight on the
constraint.  Do you have suggestions?

Regards, Dallas Burtraw
Dallas_Burtraw at um.cc.umich.edu

MACSYMA's ROOT_BY_BISECTION command handles functions, including compiled
user-defined functions. The functions can include logical operations like
conditional branching (if-then) statements. Example:

(C1) F(X):=IF X > 0 THEN 2*(X-3) ELSE 3*(X-3);

(D1) 			    F(X) := IF X > 0 THEN 2 (X - 3) ELSE 3 (X - 3)

(C2) COMPILE(F);

(D2) 						  [F]

(C3) ROOT_BY_BISECTION(F,0.0,10.0);

(D3) 						  3.0

Dick Petti
Director,
Computer Aided Mathematics Group
Symbolics, Inc.
email: petti at symbolics.com

```

• Prev by Date: Quaternions in Mathematica?
• Previous by thread: Two problems
• Next by thread: Quaternions in Mathematica?