Property maps over lists for functions



Sometimes ago, we had a discussion about the implementation of the
feature that functions maps automatically over a list or a matrix like
the operators +,*,/,^.

This would be the implementation for a function, e.g. the factorial
function:

((and (mbagp y) $listarith) 
 (cons (car y) 
       (mapcar #'(lambda (u) (simplify (list '(mfactorial) u)))
               (cdr y))))

(%i37) [1,2,3,4]!;
(%o37) [1,2,6,24]
(%i38) [[1,2],[3,4]]!;
(%o38) [[1,2],[6,24]]
(%i39) [x=4]!;
(%o39) [x! = 24]

This is a more general approach. The code is added to the simplifier in
the routine simplifya:

((and (mbagp (cadr x))
      $listarith
      (get (caar x) 'maps-over-lists))
 ;; A list or matrix, $listarith is T and the function has the
 ;; property to map over lists.
 ;; Simplify e.g. f([x,y,z]) -> [f(x),f(y),f(z)]
 ;; Only functions with one argument can have this property.
 ;; This code does not check it, but generates a Lisp error
 ;; if the property 'maps-over-lists is provided for a function
 ;; with more than one argument.
 (cons (caadr x)
       (mapcar #'(lambda (u) (simplify (list (car x) u)))
               (cdadr x))))

We can support the property for functions with one argument, e.g. 

(dolist (x '(%sin 
             %cos 
             %tan))
  (setf (get x 'maps-over-lists) t))

Two examples for the results:

(%i5) sin([1,2,3]);
(%o5) [sin(1), sin(2), sin(3)]

(%i10) a*sin([x,y,z]);
(%o10) [a*sin(x),a*sin(y),a*sin(z)]

Is it of interest to support this feature? Comments?

Dieter Kaiser