#12075: Create callable matrices in function notation
---------------------------+------------------------------------------------
Reporter: kcrisman | Owner: burcin
Type: enhancement | Status: new
Priority: major | Milestone: sage-4.8
Component: symbolics | Keywords: sd35.5
Work_issues: | Upstream: N/A
Reviewer: | Author: Geoffrey Ehrman
Merged: | Dependencies:
---------------------------+------------------------------------------------
Changes (by newvalueoldvalue):
* author: => Geoffrey Ehrman
Old description:
> In [http://groups.google.com/group/sage-
> support/browse_thread/thread/6c11a5fed4fb39b5 this sage-support post],
> the poster wants the following notation to work.
> {{{
> R_theta(theta)=matrix(SR,[[cos(theta),sin(theta),0],[-sin(theta),cos(theta),0],[0,0,1]])
> }}}
> This is sort of #1722 on steroids.
>
> In the thread above, there are a number of good ideas. The final one is
> {{{
> I think this would be a good project for a person wanting to learn more
> about how to do Sage development. The modifications to
> symbolic_expression should be easy (check for a nested list/tuple
> structure). Then you would need to make a new function() method, in
> $SAGE_ROOT/devel/sage/sage/matrix/matrix2.pyx probably, that would
> create a corresponding matrix over the CallableSymbolicRing. You can
> see an example for vectors in
> $SAGE_ROOT/devel/sage/sage/modules/free_module.pyx (look for "def
> function" in that file).
> Then if you are ambitious, create a new matrix subclass for callable
> symbolic expressions that mirrors what
> $SAGE_ROOT/devel/sage/sage/modules/vector_callable_symbolic_dense.py
> does for vectors (i.e., changes the printing).
> }}}
New description:
In [http://groups.google.com/group/sage-
support/browse_thread/thread/6c11a5fed4fb39b5 this sage-support post], the
poster wants the following notation to work.
{{{
R_theta(theta)=matrix(SR,[[cos(theta),sin(theta),0],[-sin(theta),cos(theta),0],[0,0,1]])
}}}
This is sort of #1722 on steroids.
In the thread above, there are a number of good ideas. The final one is
{{{
I think this would be a good project for a person wanting to learn more
about how to do Sage development. The modifications to
symbolic_expression should be easy (check for a nested list/tuple
structure). Then you would need to make a new function() method, in
$SAGE_ROOT/devel/sage/sage/matrix/matrix2.pyx probably, that would
create a corresponding matrix over the CallableSymbolicRing. You can
see an example for vectors in
$SAGE_ROOT/devel/sage/sage/modules/free_module.pyx (look for "def
function" in that file).
Then if you are ambitious, create a new matrix subclass for callable
symbolic expressions that mirrors what
$SAGE_ROOT/devel/sage/sage/modules/vector_callable_symbolic_dense.py
does for vectors (i.e., changes the printing).
}}}[[Image()]]
--
Comment:
'''Progress thus far:'''
1. calculus/all.py is modified so that sage recognizes the creation of
callable symbolic matrices via function notation. In particular:
{{{
sage: m(X) = [[cos(X), -sin(X)],[sin(X), cos(X)]]
}}}
and is now valid syntax.
2. sage.matrix.matrix2.Matrix now has a method function() so the function
notation syntax correctly returns a callable matrix. ''However,'' the
method function() currently is creating a matrix of type
Matrix_generic_dense; in analogy to the vector this this should probably
be Matrix_callable_symbolic_dense. I'm unsure how significant an issue
this is as most of the important things work. This certain ''does'' affect
how these matrices are displayed - in all the following examples, the
entries are of the form "X |--> f(X)" where what should probably be output
is something like "X |--> [f(X), g(X)]\n[h(X), j(X)]".
3. Things that work correctly:
{{{
sage: m(pi/2)
[ 0 -1]
[ 1 0]
sage: m.trace()
X |--> 2*cos(X)
sage: m(3).eigenvalues()
[-I*sin(3) + cos(3), I*sin(3) + cos(3)]
sage: m.derivative()
[X |--> -sin(X) X |--> -cos(X)]
[ X |--> cos(X) X |--> -sin(X)]
sage: m.kernel()
Vector space of degree 2 and dimension 0 over Callable function ring with
arguments (X,)
Basis matrix:
[]
sage: m.image()
Vector space of degree 2 and dimension 2 over Callable function ring with
arguments (X,)
Basis matrix:
[X |--> 1 X |--> 0]
[X |--> 0 X |--> 1]
}}}
Things that don't work (and should?):
{{{
sage: m.eigenvalues()
NotImplementedError ...
}}}
Things that I'm not sure about/work incorrectly(?):
{{{
sage: m.charpoly()
(X |--> 1)*x^2 + (X |--> -2*cos(X))*x + X |--> sin(X)^2 + cos(X)^2
sage: m.echelon_form()
[X |--> 1 X |--> 0]
[X |--> 0 X |--> 1]
}}}
'''What remains to do:'''
4. Matrix.function() is defined in sage/matrix/matrix2.pyx. It might be
better placed in sage/matrix/matrix_generic_dense.pyx as the method for
function() is defined only for FreeModuleElement_generic_dense. (Minor)
5. Matrix.function() is written as an exact analog to
FreeModuleElement_generic_dense.function(). This is the cause of the
problem I mentioned in (2). I think the root of the problem is that the
vector case is being coerced to the correct class via the category
framework and the matrix class is currently lacks the code needed to
coerce correctly. It's also quite possible there's a better way to write
this method. I've looked through some of the matrix and module code
however, and I don't yet have any sensible ideas.
6. Generalizing from (2) I've tried to make function notation for matrices
as similar to function notation for vectors as similar as possible. Is
this sensible, or are there enough salient differences that this is
unreasonable?
7. The file sage/matrix/matrix_callable_symbolic_dense.py purposely
produces several doctest failures due again to the type issue in (2). Any
other failures should be considered bugs.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12075#comment:7>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
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-trac?hl=en.