- assigned_to: nobody --> robert_dodier
The function 'permanent' has an optional second
argument that shows in the user documentation but its
meaning isn't explained. I don't know what the
2nd argument is suppose to do. These are both correct
(%i5) permanent(matrix([a,b],[c,d]));
(%o5) a*d+b*c
(%i6) permanent(matrix([a,b],[c,d]),2);
(%o6) a*d+b*c
This seems bogus
(%i7) permanent(matrix([a,b],[c,d]),3);
(%o7) (d+c+b+a)*false^2+(a*d+b*c)*false
(%i8) describe("permanent")$
0: PERMANENT :(maxima.info)Definitions for Matrices
and Linear Algebra.
Info from file c:/msys/1.0/maxinstall/info/maxima.info:
- Function: PERMANENT (M,n)
computes the permanent of the matrix M. A
permanent is like a determinant but with no sign
changes.
Barton
Logged In: YES
user_id=895922
Robert,
If you haven't figured this out already, when the
first argument is a symbolic matrix or an array
(anything else?) the second argument is the size.
Maybe when matrixp(a) --> true and there is a second
argument, the code should give the user a warning and
then ignore the 2nd argument.
(%i1) permanent(a,2);
(%o1)/R/ a a + a a a
1, 1 2, 2 1, 2 2, 1
(%i2) permanent(a);
Wrong number of args to PERM
-- an error. Quitting. To debug this try DEBUGMODE(TRUE);
(%i3) array(b,2,2);
(%o3) b
(%i4) permanent(b,2);
(%o4)/R/ b b + b b
1, 1 2, 2 1, 2 2, 1
(%i5)
(%i1) permanent(a,2);
(%o1)/R/ a a + a a
1, 1 2, 2 1, 2 2, 1
(%i2) permanent(a);
Wrong number of args to PERM
-- an error. Quitting. To debug this try DEBUGMODE(TRUE);
Barton
Logged In: YES
user_id=501686
Barton, it looks like the second argument, n, can be
something less than the size of the matrix or array, in
which case permanent just works on the submatrix 1..n by
1..n. So it does something, of doubtful utility but there
you have it. I guess I'm inclined to document n as it stands
and leave a code fix for another day. -- Robert
Logged In: NO
Do you mean this-ish? (Caution: newbie.)
RCS file: /cvsroot/maxima/maxima/doc/info/Matrices.texi,v
retrieving revision 1.17
diff -u -r1.17 Matrices.texi
--- doc/info/Matrices.texi 7 Sep 2005 05:15:35 -0000 1.17
+++ doc/info/Matrices.texi 6 Oct 2005 04:21:10 -0000
@@ -1245,6 +1245,7 @@
@deffn {Function} permanent (@var{M}, @var{n})
Computes the permanent of the matrix @var{M}. A permanent
is like a determinant but with no sign changes.
+The argument @var{n} is the order; it is optional if
@var{M} is a matrix.
@end deffn
RCS file: /cvsroot/maxima/maxima/src/newdet.lisp,v
retrieving revision 1.3
diff -u -r1.3 newdet.lisp
--- src/newdet.lisp 25 Nov 2004 02:36:03 -0000 1.3
+++ src/newdet.lisp 6 Oct 2005 04:21:11 -0000
@@ -38,12 +38,13 @@
(defmfun $permanent n
((lambda (a)
- (cond ((= n 2)
- (cond ((not (integerp (arg 2)))
- (merror "Wrong arg to `perm': ~M" (arg 2))))
- (setq a (arg 1) n (arg 2)))
- ((and (= n 1) ($matrixp (setq a (arg 1))))
+ (setq a (arg 1))
+ (cond ((or (= n 1) ($matrixp a))
(setq n (length (cdr (arg 1)))))
+ ((= n 2)
+ (setq n (arg 2))
+ (cond ((not n)
+ (merror "Wrong arg to `perm': ~M" n))))
(t (merror "Wrong number of args to `perm'")))
(newdet a n t))
nil))
Logged In: NO
Do you mean this-ish? (Caution: newbie.)
RCS file: /cvsroot/maxima/maxima/doc/info/Matrices.texi,v
retrieving revision 1.17
diff -u -r1.17 Matrices.texi
--- doc/info/Matrices.texi 7 Sep 2005 05:15:35 -0000 1.17
+++ doc/info/Matrices.texi 6 Oct 2005 04:21:10 -0000
@@ -1245,6 +1245,7 @@
@deffn {Function} permanent (@var{M}, @var{n})
Computes the permanent of the matrix @var{M}. A permanent
is like a determinant but with no sign changes.
+The argument @var{n} is the order; it is optional if
@var{M} is a matrix.
@end deffn
RCS file: /cvsroot/maxima/maxima/src/newdet.lisp,v
retrieving revision 1.3
diff -u -r1.3 newdet.lisp
--- src/newdet.lisp 25 Nov 2004 02:36:03 -0000 1.3
+++ src/newdet.lisp 6 Oct 2005 04:21:11 -0000
@@ -38,12 +38,13 @@
(defmfun $permanent n
((lambda (a)
- (cond ((= n 2)
- (cond ((not (integerp (arg 2)))
- (merror "Wrong arg to `perm': ~M" (arg 2))))
- (setq a (arg 1) n (arg 2)))
- ((and (= n 1) ($matrixp (setq a (arg 1))))
+ (setq a (arg 1))
+ (cond ((or (= n 1) ($matrixp a))
(setq n (length (cdr (arg 1)))))
+ ((= n 2)
+ (setq n (arg 2))
+ (cond ((not n)
+ (merror "Wrong arg to `perm': ~M" n))))
(t (merror "Wrong number of args to `perm'")))
(newdet a n t))
nil))
The implementation has changed with revision 1.7 of newdet.lisp. The code for checking the arguments has been cut out. Now we get a Lisp error if we have a symbol as the first argument and no second argument.
(%i2) permanent(a);
Maxima encountered a Lisp error:
The value $A is not of type LIST.
Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
Any other argument different from a matrix gives the error "Wrong number of indices":
(%i3) permanent(2*a);
Wrong number of indices:
[1, 1]
-- an error. To debug this try: debugmode(true);
(%i4) permanent([a,b,c]);
Wrong number of indices:
[1, 1]
-- an error. To debug this try: debugmode(true);
We get the same results for the function newdet.
The case with a second argument to permanent or newdet only works for a symbol as a first argument:
(%i1) permanent(a,2);
(%o1) a[1,1]*a[2,2]+a[1,2]*a[2,1]
(%i2) permanent(2*b,2);
Wrong number of indices:
[1, 1]
-- an error. To debug this try: debugmode(true);
It is arguable if this case is of interest. We might to the following:
(%i1) array(a,2,2)$
(%i2) a[1,1]:1$
(%i3) a[1,2]:2$
(%i4) a[2,1]:3$
(%i5) a[2,2]:4$
(%i6) permanent(a,2);
(%o6) a[1,1]*a[2,2]+a[1,2]*a[2,1]
(%i7) ev(%);
(%o7) 10
I would like to suggest to cut out the optional second argument for the functions newdet and permanent. Both functions should be implemented like the function determinant and other functions related to matrices.
This would be the implementation for newdet which works like the function determinant:
(defmfun $newdet (mat)
(cond ((not (or (mbagp mat) ($matrixp mat)))
(if ($scalarp mat) mat (list '(%newdet simp) mat)))
(t
(setq mat (check mat))
(unless (= (length mat) (length (cadr mat)))
(merror
(intl:gettext
"newdet: Matrix must be square; found ~m rows, ~M columns.")
(length (cdr mat))
(length (cdadr mat))))
(newdet mat (length (cdr mat)) nil))))
Dieter Kaiser
The implementation of newdet and permanent has been changed in newdet.lisp revision 1.9 to be similar to the implementation of the function determiant. The documentation has been updated in Matrices.lisp revision 1.36.
Closing this bug report as fixed.
Dieter Kaiser
Log in to post a comment.