login  home  contents  what's new  discussion  bug reports help  links  subscribe  changes  refresh  edit

# Edit detail for Unevaluated Expressions revision 3 of 3

 1 2 3 Editor: test1 Time: 2015/05/08 15:47:29 GMT+0 Note:

added:
Note: In FriCAS 'max' on expressions is currently undefined.

This happens because arguments are symbols and FriCAS consider 'a' smaller than 'b'

However
\begin{axiom}
max(2,b)
\end{axiom}

because for expressions order is undefined.

Note: Axiom used to produce results depending on internal order of expressions here.



Note: In FriCAS max on expressions is currently undefined.

On 15-11-2007 Marc Boyer posted to "sci.math.symbolic"

Subject: [Axiom] Bug or feature of max

Dear all,

I would like to prevent the max operator to be reduce when there is no order between two operands.

Here is a minimal example:

fricas
max(a,b)
 (1)
Type: Symbol

This happens because arguments are symbols and FriCAS consider a smaller than b

However

fricas
max(2,b)
There are 1 exposed and 2 unexposed library operations named max
having 2 argument(s) but none was determined to be applicable.
Use HyperDoc Browse, or issue
)display op max
package-calling the operation or using coercions on the arguments
will allow you to apply the operation.
Cannot find a definition or applicable library operation named max
with argument type(s)
PositiveInteger
Variable(b)
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need. because for expressions order is undefined. Note: Axiom used to produce results depending on internal order of expressions here. How did he deduce than symbol b is greater than a. I imagine that the implantation of max is something like:  max(x,y) == if x > y then return x else return y  and because a is not greater than b, it returns b. I would like to have a mymax such that it does not reduce when values can not be compared. Any idea? Thank in advance, Marc Boyer Martin Rubey replied: Dear Marc, Marc Boyer writes:  > I would like to prevent the max operator to be reduce > when there is no order between two operands.  In fact, that's the way it is in axiom, however, with a subtle point to keep in mind. Axiom knows about one operation "max" with two arguments, which is implemented for any domain of (axiom) category OrderedSet?. Marc Boyer writes:  > How did he deduce than symbol 'b' is greater than 'a'.  You have to look at the type of the arguments of max. Here, the interpreter infers that it is "Symbol": you didn't say anything else, the domain "Symbol" is an OrderedSet? (look it up in HyperDoc), and both "x" and "y" can be most conveniently interpreted as members of this domain. HOWEVER: if a domain has OrderedSet?, that does not at all mean that the ordering of it's elements is in any sense "mathematical". Most disappointing for newcomers: the elements of the domain "Expression Integer" are ordered mostly by hash code, which gives surprising results when comparing %pi and %e. So, what you really want is probably a domain that satisfies "OrderedRing?", i.e., an order relation compatible with "+" and "*", or so. Interesting domains having "OrderedRing?" include: • Float • Integer • RealClosure R where R is an OrderedIntegralDomain? • Fraction R where R is an OrderedIntegralDomain? (HyperDoc browse, enter OrderedRing?, select Constructors, select Domains) Marc Boyer writes:  > I would like to have a 'mymax' such that it does not reduce > when values can not be compared. Any idea ?  It depends a bit on which domain you want to compute in. • Polynomials over, say, Fraction Integer: Create a file:  axiom10165Frh.input  with this function definition: fricas mymax(a: POLY FRAC INT, b: POLY FRAC INT): Union("failed", POLY FRAC INT) == r: Union("failed", FRAC INT) := retractIfCan a (r case "failed") => "failed" s: Union("failed", FRAC INT) := retractIfCan b (s case "failed") => "failed" max(r::FRAC INT, s::FRAC INT) Function declaration mymax : (Polynomial(Fraction(Integer)), Polynomial(Fraction(Integer))) -> Union("failed",Polynomial( Fraction(Integer))) has been added to workspace. Type: Void Start Axiom and enter:  )read axiom10165Frh.input  then try: fricas mymax(x+y, x-y) fricas Compiling function mymax with type (Polynomial(Fraction(Integer)), Polynomial(Fraction(Integer))) -> Union("failed",Polynomial( Fraction(Integer)))  (2) Type: Union("failed",...) fricas mymax(x+y, 2)  (3) Type: Union("failed",...) fricas mymax(3, 2)  (4) Type: Union(Polynomial(Fraction(Integer)),...) • Expression Integer: WARNING: this is only a heuristical comparison! Save this to a file: fricas mymax(a: EXPR INT, b: EXPR INT): Union("failed", EXPR INT) == r := a::EXPR FLOAT (not ground? r) => "failed" s := b::EXPR FLOAT (not ground? s) => "failed" if r < s then b else a Function declaration mymax : (Expression(Integer),Expression(Integer )) -> Union("failed",Expression(Integer)) has been added to workspace. Compiled code for mymax has been cleared. 1 old definition(s) deleted for function or rule mymax Type: Void )read it and then try: fricas mymax(%e/4, sin(%pi/2-1/5)) There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named < with argument type(s) Expression(Float) Expression(Float) Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.
FriCAS will attempt to step through and interpret the code.
fricas
Compiling function mymax with type (Expression(Integer),Expression(
Integer)) -> Union("failed",Expression(Integer))
 (5)
Type: Union(Expression(Integer),...)

Best thing however for EXPR INT would probably to introduce a new operator "max", which stays unevaluated if the expressions contain variables. Not so sure, though.

Hope this helps, (don't hesitate to ask if it doesn't)

Martin

Marc Boyer replies:

Thank you for you very long and complex response. I think this is a bit hard to me. I am a very occasionnal user of Axiom, just using it to solve simple linear expressions...

Marc Boyer

**Martin Rubey replied:

Marc Boyer writes:

 > I dont think I am going to study this notions of domains now...


Although, the snippets I sent you should work without "understanding". Apart from that, the notion of domain should be something quite easy:

• a domain (eg. Integer, or PrimeField? 5, or Expression Integer)

is a representation of

• a set of things (eg, integers, elements of the Z/5Z, expressions)

together with

• operations (eg. x + y, x^-1, sin x) on them.

The set of operations depends - of course - on the domain. The domain Integer does not have an operation "sin", for example. Neither does it have multiplicative inverse, i.e. x^-1. To find out which operations a domain exports, just use HyperDoc or enter something like:

  )show Integer


(The % sign you will see in the output refers to the domain in question, i.e., in this example, Integer)

Martin

Marc Boyer replies:

The real problem I was trying to solve was:

  Let be
Beta(x,R,T) = R * Max( x - T , 0 )
To(o) = ( R * T + b - r * o )
with functions and parametres are Real.
How does looks the following expression
Beta(x,R,T(R+b/r))


I was a bit surprised to see that the max part of the expression was no more there. But I can also solve it by hand.

Thank you very much.

Marc Boyer

Martin Rubey replies:

Marc Boyer writes:

I guess you mean To(R+b/r) here?

Marc Boyer wrote:

 I was a bit surprised to see that the 'max' part of the expression was no
more there.


Yes, that's surprising at first.

> But I can also solve it by hand.

But you don't want to. Just put this in a file:

fricas
COEFFS ==> INT
Type: Void
fricas
-- if you are going to work with expressions over floats once, put
-- COEFFS ==> FLOAT
opmax := operator 'Max
 (6)
Type: BasicOperator?
fricas
Max(a: EXPR COEFFS, b: EXPR COEFFS): EXPR COEFFS ==
s := numericIfCan a
(s case "failed") => kernel(opmax, [a, b])
t := numericIfCan b
(t case "failed") => kernel(opmax, [a, b])
if s > t then a else b
Function declaration Max : (Expression(Integer),Expression(Integer))
-> Expression(Integer) has been added to workspace.
Type: Void
fricas
evaluate(opmax, _
(l: List EXPR COEFFS): EXPR COEFFS +-> Max(first l, second l))_
\$BOP1(EXPR COEFFS)
fricas
Compiling function Max with type (Expression(Integer),Expression(
Integer)) -> Expression(Integer)
 (7)
Type: BasicOperator?

then )read it in. Then you get (You have to use "Max" instead of "max"!):

fricas
Max(%e, %pi)
 (8)
Type: Expression(Integer)
fricas
Max(%e/4, sin(%pi/2-1/5))
 (9)
Type: Expression(Integer)
fricas
Beta(x,R,T) == R * Max( x - T , 0 )
Type: Void
fricas
To(o) == R * T + b - r * o
Type: Void
fricas
Beta(x,R,To(R+b/r))
fricas
Compiling function To with type Fraction(Polynomial(Integer)) ->
Fraction(Polynomial(Integer))
fricas
Compiling function Beta with type (Variable(x),Variable(R),Fraction(
Polynomial(Integer))) -> Expression(Integer)
 (10)
Type: Expression(Integer)
fricas
eval(%,[x=1,R=2,T=1,r=10,b=5,o=3])
 (11)
Type: Expression(Integer)

No need to understand domains anymore.

Martin