|
|
last edited 9 years ago by test1 |
1 2 3 | ||
Editor: 127.0.0.1
Time: 2007/11/15 20:08:11 GMT-8 |
||
Note: new |
changed: - **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: \begin{axiom} max(a,b) \end{axiom} 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: \begin{axiom} 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) \end{axiom} Start Axiom and enter:: )read axiom10165Frh.input then try: \begin{axiom} mymax(x+y, x-y) mymax(x+y, 2) mymax(3, 2) \end{axiom} - Expression Integer: WARNING: this is only a heuristical comparison! Save this to a file: \begin{axiom} 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 \end{axiom} ')read' it and then try: \begin{axiom} mymax(%e/4, sin(%pi/2-1/5)) \end{axiom} 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 <Marc.Boyer@enseeiht.yahoo.fr.invalid> 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: \begin{axiom} COEFFS ==> INT -- if you are going to work with expressions over floats once, put -- COEFFS ==> FLOAT -- instead opmax := operator 'Max 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 evaluate(opmax, _ (l: List EXPR COEFFS): EXPR COEFFS +-> Max(first l, second l))_ $BOP1(EXPR COEFFS) \end{axiom} then )read it in. Then you get (You have to use "Max" instead of "max"!): \begin{axiom} Max(%e, %pi) Max(%e/4, sin(%pi/2-1/5)) Beta(x,R,T) == R * Max( x - T , 0 ) To(o) == R * T + b - r * o Beta(x,R,To(R+b/r)) eval(%,[x=1,R=2,r=10,b=5,o=3]) \end{axiom} No need to understand domains anymore. *Martin*
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:
axiommax(a,b)
(1) |
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:
(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.
Create a file:
axiom10165Frh.input
with this function definition:
axiommymax(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.
Start Axiom and enter:
)read axiom10165Frh.input
then try:
axiommymax(x+y, x-y)
Compiling function mymax with type (Polynomial Fraction Integer, Polynomial Fraction Integer) -> Union("failed",Polynomial Fraction Integer)
(2) |
axiommymax(x+y, 2)
(3) |
axiommymax(3, 2)
(4) |
WARNING: this is only a heuristical comparison!
Save this to a file:
axiommymax(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
)read
it and then try:
axiommymax(%e/4, sin(%pi/2-1/5))
Compiling function mymax with type (Expression Integer,Expression Integer) -> Union("failed",Expression Integer)
(5) |
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 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
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:
axiomCOEFFS ==> INT
axiom-- if you are going to work with expressions over floats once, put -- COEFFS ==> FLOAT -- instead opmax := operator 'Max
(6) |
axiomMax(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.
axiomevaluate(opmax, _ (l: List EXPR COEFFS): EXPR COEFFS +-> Max(first l, second l))_ $BOP1(EXPR COEFFS)
Compiling function Max with type (Expression Integer,Expression Integer) -> Expression Integer
(7) |
then )read it in. Then you get (You have to use "Max" instead of "max"!):
axiomMax(%e, %pi)
(8) |
axiomMax(%e/4, sin(%pi/2-1/5))
(9) |
axiomBeta(x,R,T) == R * Max( x - T , 0 )
axiomTo(o) == R * T + b - r * o
axiomBeta(x,R,To(R+b/r))
Compiling function To with type Fraction Polynomial Integer -> Fraction Polynomial Integer
Compiling function Beta with type (Variable x,Variable R,Fraction Polynomial Integer) -> Expression Integer
(10) |
axiomeval(%,[x=1,R=2,r=10,b=5,o=3])
(11) |
No need to understand domains anymore.
Martin