Re: Apparent Bug In "Permutations" Function In Maxima 5.9.3
- From: "Robert Dodier" <robert.dodier@xxxxxxxxx>
- Date: 16 Jul 2006 11:37:27 -0700
Mark Lawton wrote:
A bit of debugging yielded the fact that the "permutations" function is
altering variables that it shouldn't.
Thanks for reporting this bug. The problem is that the Lisp SORT
function modifies its argument in-place. I've committed a 1-line patch
to Maxima cvs to copy the argument before sorting in permutations.
Here is the patch -- you can fix your copy of maxima/src/nset.lisp by
hand if you wish.
--- nset.lisp 3 Jul 2006 18:47:45 -0000 1.11
+++ nset.lisp 16 Jul 2006 18:13:17 -0000
@@ -333,7 +333,7 @@
(defun $permutations (a)
(cond (($listp a)
- (setq a (sort (cdr a) '$orderlessp)))
+ (setq a (sort (copy-list (cdr a)) '$orderlessp)))
(t
(setq a (require-set a "$permutations"))))
bas: part(basSoln, 3),
basVol: part(basSoln,2),
vol: part(volSoln,3),
twoGames: socBas + socVol + basVol,
print("Soc",soc,", bas",bas,", vol",vol,",
soc&bas",socBas,", soc&vol",socVol,", bas&vol",basVol,", two
games",twoGames))))$
You didn't ask for my advice but here it is all the same.
(1) I don't recommend calling part in general. Maybe foo[1],
foo[2] etc works OK here.
(2) Instead of printing all the partial results, construct a list
to hold the results. This obviates printing in the loop (which
might take an appreciable fraction of the run time) and also
makes the results available for inspection afterwards.
(3) I find code with some whitespace in it easier to read.
E.g. instead of fooBar write foo_bar, and instead of
foobar(bazquux(mumble(x))) write foobar (bazquux (mumble (x)))
(put a space between function name and parenthesis).
FWIW, YMMV, HTH.
Robert Dodier
.
- References:
- Apparent Bug In "Permutations" Function In Maxima 5.9.3
- From: Mark Lawton
- Apparent Bug In "Permutations" Function In Maxima 5.9.3
- Prev by Date: Re: Solving a polynomial
- Next by Date: Re: Solving a polynomial
- Previous by thread: Re: Apparent Bug In "Permutations" Function In Maxima 5.9.3
- Next by thread: Solving a polynomial
- Index(es):