> > More important is the option to apply a lot of things to a matrix.
> > Simon's got the right idea (lambda functions) for what you want to
> > do.  But we should make this easier.  My guess is that even the
> > 'magic' decorator for turning methods into functions wouldn't help
> > here, and that is too bad.  Maybe matrices need some way for that to
> > happen - but I have no idea how one would implement something general
> > like that, esp. if one couldn't tell ahead of time whether all the
> > elements would have the method.
>
> sage: A = random_matrix(SR, 3) - x; A
> [    -x     -2     -2]
> [     2 -x - 1     -2]
> [    -1     -2 -x + 1]
> sage: A.apply_map(type(x).simplify_full)
> [    -x     -2     -2]
> [     2 -x - 1     -2]
> [    -1     -2 -x + 1]
>
> sage: A = matrix(3, 3, [(1+x)^k for k in range(9)]); A
> [        1     x + 1 (x + 1)^2]
> [(x + 1)^3 (x + 1)^4 (x + 1)^5]
> [(x + 1)^6 (x + 1)^7 (x + 1)^8]
> sage: type(x)
> <type 'sage.symbolic.expression.Expression'>
> sage: A.apply_map(Expression.expand)
> [                                                                 1
>                                                           x + 1
>                                               x^2 + 2*x + 1]
> [                                             x^3 + 3*x^2 + 3*x + 1
>                                   x^4 + 4*x^3 + 6*x^2 + 4*x + 1
>                     x^5 + 5*x^4 + 10*x^3 + 10*x^2 + 5*x + 1]
> [                  x^6 + 6*x^5 + 15*x^4 + 20*x^3 + 15*x^2 + 6*x + 1
>       x^7 + 7*x^6 + 21*x^5 + 35*x^4 + 35*x^3 + 21*x^2 + 7*x + 1 x^8 +
> 8*x^7 + 28*x^6 + 56*x^5 + 70*x^4 + 56*x^3 + 28*x^2 + 8*x + 1]
>

I'm impressed by these examples, but they seem just as 'hermetic' to
me as using the lambda function.  Certainly it would be worth adding
some of these to the documentation... but for which module?

- kcrisman

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to