Note: In FriCAS 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,
Type: Symbol
This happens because arguments are symbols and FriCAS consider However fricas max(2, 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 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 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:
(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.
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:
is a representation of
together with
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 Thank you very much. Marc Boyer Martin Rubey replies: Marc Boyer 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,
Type: BasicOperator?
fricas Max(a: EXPR COEFFS, Type: Void
fricas evaluate(opmax, fricas Compiling function Max with type (Expression(Integer),
Type: BasicOperator?
then )read it in. Then you get (You have to use "Max" instead of "max"!): fricas Max(%e,
Type: Expression(Integer)
fricas Max(%e/4,
Type: Expression(Integer)
fricas Beta(x, Type: Void
fricas To(o) == R * T + b - r * o Type: Void
fricas Beta(x, fricas Compiling function To with type Fraction(Polynomial(Integer)) -> Fraction(Polynomial(Integer)) fricas Compiling function Beta with type (Variable(x),
Type: Expression(Integer)
fricas eval(%,
Type: Expression(Integer)
No need to understand domains anymore. Martin |