parsing arguments for functions



you could do this:
matchdeclare([a,b,c,d],any);

f[Interval(a,b),Interval(b,c)):=fInterval(a,b,c,d)
now define fInterval...

etc.

Richard Hennessy wrote:
> 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
>