I believe you found a bug in rassociative or its friends:
(C1) infix("&");
(D1) "&"
(C2) a & (b & c);
(D2) a & (b & C)
(C3) declare("&",rassociative)$
a & b is no problem, but a & (b & c) is a problem. My commercial Macsyma
doesn't have a problem with a & (b & c).
(C4) a & b;
(D4) a & b
(C5) a & (b & c);
Wrong number of arguments to "&"
-- an error. Quitting. To debug this try DEBUGMODE(TRUE);)
Maybe you can do what you want by using parenthesis to indicate grouping
and skip declaring "&" to be right associative. For example (starting
with a
fresh Maxima session)
(C1) infix("&");
(D1) "&"
/* Doesn't seem to be a problem now */
(C2) a & (b & c);
(D2) a & (b & C)
Additionally, you can declare a nary operator using
(C1) nary("@");
(D1) "@"
(C2) a @ (b @ c);
(D2) a @ (b @ C)
To give @ a formula, use (for example)
(C3) "@"([x]) := apply("*",x)^(1/length(x))$
(C4) 1 @ 2 @ 3;
1/3
(D4) 6
Barton
wang yin <wang-y01@mails.tsinghua.edu.cn>
Sent by: maxima-admin@www.ma.utexas.edu
01/21/2003 02:08 AM
To: maxima@mail.ma.utexas.edu
cc:
Subject: [Maxima] How can I define a NARY operator?
Hi,
I'm declaring an operator "&", which is INFIX, RASSOCIATIVE. I input these
lines:
(C1) INFIX("&");
(D1) "&"
(C2) DECLARE("&",RASSOCIATIVE);
(D2) DONE
(C3) X&Y&5;
Wrong number of arguments to "&"
-- an error. Quitting. To debug this try DEBUGMODE(TRUE);)
when I input X&Y&5, MAXIMA throw out this error. But I want to get
something like x & (y & 5)
I then define this operator as:
(C12) "&"(a,b):=(a-b)/(a*b);
a - b
(D12) a & b := -----
a b
this time I get
(C15) X&Y&5;
X - Y
X (----- - 5) Y
X Y
(D15) ---------------
5 (X - Y)
Not an error. But I don't want to define "&" now.
How can I get rid of the error before?
If I declare "&" as NARY, I can get the answer I want.
Must I declare a NARY operator?
But the MAXIMA manual doesn't describe how to define a NARY operator.
If I define a NARY "&" as:
(C29) "&"(a,b):=a+b;
(D29) a & b := a + b
(C30) x&y&5;
Too many arguments supplied to a & b:
[x, y, 5]
#0: \&(a=x,b=y)
#1: \&(a=x,b=y)
#2: \&(a=3,b=7)
-- an error. Quitting. To debug this try DEBUGMODE(TRUE);)
How can I define NARY operators?
Can anyone tell me? Thanks!
--
Wang Yin
DA Lab, Tsinghua University,
100084
Beijing China