Fix for $matrix (Was: "matrix([matrix([" returned with mat_function (Was: Re: Symbolic matrix power))
Subject: Fix for $matrix (Was: "matrix([matrix([" returned with mat_function (Was: Re: Symbolic matrix power))
From: Stavros Macrakis
Date: Tue, 29 Oct 2013 09:23:27 -0400
oops, remove the "maximap" argument... how did that stay in there...?
On Tue, Oct 29, 2013 at 9:19 AM, Stavros Macrakis <macrakis at alum.mit.edu>wrote:
> How about this? This defines matrix as a multi-argument *Maxima* function.
> Slight overhead in GCL only.
>
> -s
>
>
> (remprop '$matrix 'mfexpr*)
>
> ;;; Define $matrix so that apply(matrix,...) does not need to use Lisp
> ;;; apply -- in GCL, apply is limited to 63 arguments.
>
> ;;; Assume we can't call $define here, but mputprop is defined in
> maxmac.lisp
>
> ;;; Equivalent to matrix([?rows]) := ?matrixhelper(?rows)$
> #+gcl (mputprop '$matrix
> '((lambda) ((mlist) ((mlist) rows)) ((matrixhelper) rows))
> 'mprops)
> #+gcl (mputprop '$matrix t 'mlexprp)
>
> #-gcl (defun $matrix (&rest rows) (matrixhelper rows))
>
> ;; Call ONLY from $matrix
> (defun matrixhelper (rows maximap)
> #+gcl (progn (if (not ($listp rows))
> (merror "matrixhelper expects a Maxima list"))
> (setq rows (cdr rows)))
> (dolist (row rows)
> (if (not ($listp row))
> (merror (intl:gettext "matrix: row must be a list; found: ~M") row)))
> (matcheck rows)
> (cons '($matrix) rows))
>
>
>
> On Tue, Oct 29, 2013 at 12:38 AM, Stavros Macrakis <macrakis at alum.mit.edu>wrote:
>
>> Hmm. GCL seems to support 200 arguments in eval, but not in apply:
>>
>> (defun f (&rest x) x)
>> (setq l (do ((i 0 (1+ i)) (l nil (cons i l))) ((> i 200) l)))
>> (apply 'f l) => error
>> (eval (cons 'f l)) => correct value
>>
>> I don't think rewriting $matrix can help. Rewriting meval/mapply might
>> help, but it would be bizarre to have to wrap all arguments with (quote
>> ...), but maybe necessary for > 63 arguments ?!
>>
>> The best fix would of course be to improve GCL.
>>
>> -s
>>
>>
>> On Mon, Oct 28, 2013 at 11:27 PM, Robert Dodier <robert.dodier at gmail.com>wrote:
>>
>>> On 2013-10-29, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>>>
>>> > (defun $matrix (&rest rows)
>>>
>>> >> But that only matters if an object is being *evaluated* where it
>>> >> shouldn't be. And sure enough, applying the 'matrix' function
>>> incorrectly
>>> >> re-evaluates its arguments.
>>>
>>> Excellent catch, spot on. However, the current version of $MATRIX is
>>> pretty recent, and it's written as a MFEXPR* because GCL allows only a
>>> small number of arguments -- 63 iirc. So it was easy to bump into
>>> something like matrix([1], [2], ..., [64]) => Lisp error: too many
>>> arguments. For the record: commit 9bcad16b9e.
>>>
>>> I suppose all Lisps must have a limit on the number of arguments, but
>>> aside from GCL, the limit is so big that nobody bumped into it. Is there
>>> a way to write $MATRIX which accommodates both a long argument list and
>>> ordinary evaluation?
>>>
>>> best
>>>
>>> Robert Dodier
>>>
>>> _______________________________________________
>>> Maxima mailing list
>>> Maxima at math.utexas.edu
>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
>>
>>
>