you could try (this time I tested it sorry about the first failed attempt)
safe_op(_ex) := block([inflag : true], if mapatom(_ex) then false else op(_ex))$
f([v]):=
block(
[_a,_b,_c,_d, _l],
if length(v) = 2 then
if safe_op(first(v)) = 'Interval and safe_op(second(v)) = 'Interval then
(
_l:args(first(v)),
_a:first(_l), _b:second(_l),
_l:args(second(v)),
_c:first(_l), _d:second(_l),
Interval(min(_a*_c,_a*_d,_b*_c,_b*_d),max(_a*_c,_a*_d,_b*_c,_b*_d))
)
else
first(v) * second(v)
else
error("Function takes two arguments")
)$
----- Original Message -----
From: "Richard Hennessy" <rich.hennessy at verizon.net>
To: "Sheldon Newhouse" <sen1 at math.msu.edu>; <maxima at math.utexas.edu>
Sent: Thursday, June 04, 2009 10:28 PM
Subject: Re: [Maxima] parsing arguments for functions
I think you have to define f(x,y) as
f([v]):=
block(
if length(v) = 2 then
if not freeof('Interval,first(v)) and not freeof('Interval, second(v)) then
Interval(min(a*c,a*d,b*c,b*d),max(a*c,a*d,b*c,b*d))
else
first(v) * second(v)
else
error("Function takes two arguments")
)$
----- Original Message -----
From: "Sheldon Newhouse" <sen1 at math.msu.edu>
To: <maxima at math.utexas.edu>
Sent: Thursday, June 04, 2009 9:40 PM
Subject: parsing arguments for functions
Hello,
Suppose I have a function f(x,y) which does different operations for
different types of arguments. How can I parse the arguments of f(x,y)
and decide what properties x and y have?
For instance, the function f(x,y) = x*y already does this, say for x, y
real numbers or matrices.
How can I do this for other types of arguments?
For instance, consider real closed intervals [a,b] denoted by Interval(a,b).
Then, the usual definition of the multiplication is
Interval(a,b)*Interval(c,d) = Interval(min(ac,ad,bc,bd),max(ac,ad,bc,bd))
Suppose f(x,y) = x*y
Then, I would like to have '*' defined so that
if x, y are real numbers, then f(x,y) = x*y is the usual product,
but if x=Interval(a,b) and y=Interval(c,d), then
f(Interval(a,b),Interval(c,d)) =
Interval(min(ac,ad,bc,bd),max(ac,ad,bc,bd))
Is there a simple way this can be done?
TIA for any suggestions.
-sen
_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima
_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima