Ticket #11335: sage-symb-vectors.patch

File sage-symb-vectors.patch, 5.7 KB (added by jvkersch, 11 years ago)

symbolic vector class

  • sage/modules/all.py

    # HG changeset patch
    # User Joris Vankerschaver <joris.vankerschaver@gmail.com>
    # Date 1305526202 25200
    # Node ID 5fdd05d6b87e3552620f96e4b7d90c91b8cfca87
    # Parent  361a4ad7d52c69b64ae2e658ffd0820af0d87e93
    #11335: adds a symbolic vector class 
    Adds a class for dense symbolic vectors whose functionality currently consists of an element-wise simplify_full method.
    
    diff -r 361a4ad7d52c -r 5fdd05d6b87e sage/modules/all.py
    a b  
    2828from module_element import ModuleElement, is_ModuleElement
    2929
    3030import vector_callable_symbolic_dense
     31
     32import vector_symbolic_dense
  • sage/modules/free_module.py

    diff -r 361a4ad7d52c -r 5fdd05d6b87e sage/modules/free_module.py
    a b  
    62676267        return sage.modules.vector_real_double_dense.Vector_real_double_dense
    62686268    elif sage.rings.complex_double.is_ComplexDoubleField(R) and not is_sparse:
    62696269        return sage.modules.vector_complex_double_dense.Vector_complex_double_dense
     6270    elif sage.symbolic.ring.is_SymbolicExpressionRing(R) and not is_sparse:
     6271        return sage.modules.vector_symbolic_dense.Vector_symbolic_dense
    62706272    elif sage.symbolic.callable.is_CallableSymbolicExpressionRing(R) and not is_sparse:
    62716273        return sage.modules.vector_callable_symbolic_dense.Vector_callable_symbolic_dense
    62726274    else:
  • sage/modules/free_module_element.pyx

    diff -r 361a4ad7d52c -r 5fdd05d6b87e sage/modules/free_module_element.pyx
    a b  
    25982598
    25992599            sage: v = vector([-1,0,3,pi])
    26002600            sage: type(v)
    2601             <type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
     2601            <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
    26022602            sage: v._hash()   # random output
    26032603        """
    26042604        return hash(tuple(list(self)))
     
    26112611       
    26122612            sage: v = vector([-1,0,3,pi])
    26132613            sage: type(v)
    2614             <type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
     2614            <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
    26152615            sage: v.__copy__()
    26162616            (-1, 0, 3, pi)
    26172617            sage: v.__copy__() is v
     
    26312631        EXAMPLES::
    26322632
    26332633            sage: type(vector([-1,0,3,pi]))   # indirect doctest
    2634             <type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
     2634            <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
    26352635        """
    26362636        FreeModuleElement.__init__(self, parent)
    26372637        R = self.parent().base_ring()
     
    28632863
    28642864            sage: v = vector([1,2/3,pi])
    28652865            sage: type(v)
    2866             <type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
     2866            <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
    28672867            sage: a = v.list(); a
    28682868            [1, 2/3, pi]
    28692869            sage: a[0] = 20; v
     
    29042904            sage: g
    29052905            (2*x, 2*y)
    29062906            sage: type(g)
    2907             <type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
     2907            <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
    29082908            sage: g(y=2, x=3)
    29092909            (6, 4)
    29102910            sage: f(x,y) = x^2 + y^2
  • new file sage/modules/vector_symbolic_dense.py

    diff -r 361a4ad7d52c -r 5fdd05d6b87e sage/modules/vector_symbolic_dense.py
    - +  
     1"""
     2Vectors over the symbolic ring.
     3
     4Implements vectors over the symbolic ring.  Currently, this class only
     5provides methods for the simplification of symbolic vectors, as this
     6functionality was needed during the development of Trac #10132.  In the
     7long run, this class could be extended along the lines of
     8``sage.matrix.matrix_symbolic_dense``.
     9
     10
     11AUTHOR:
     12
     13    -- Joris Vankerschaver (2011-05-15)
     14
     15EXAMPLES::
     16
     17    sage: x, y = var('x, y')
     18    sage: u = vector([sin(x)^2 + cos(x)^2, log(2*y) + log(3*y)]); u
     19    (sin(x)^2 + cos(x)^2, log(2*y) + log(3*y))
     20    sage: type(u)
     21    <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
     22    sage: u.simplify_full()
     23    (1, log(6) + 2*log(y))
     24
     25TESTS::
     26
     27    sage: u = vector(SR, [sin(x^2)])
     28    sage: loads(dumps(u)) == u
     29    True
     30
     31"""
     32
     33#*****************************************************************************
     34#       Copyright (C) 2011 Joris Vankerschaver (jv@caltech.edu)
     35#
     36#  Distributed under the terms of the GNU General Public License (GPL)
     37#
     38#    This code is distributed in the hope that it will be useful,
     39#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     40#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     41#    General Public License for more details.
     42#
     43#  The full text of the GPL is available at:
     44#
     45#                  http://www.gnu.org/licenses/
     46#*****************************************************************************
     47
     48import free_module_element
     49from sage.symbolic.ring import SR
     50
     51
     52class Vector_symbolic_dense(free_module_element.FreeModuleElement_generic_dense):
     53
     54    def simplify_full(self):
     55        """
     56        Applies :meth:`simplify_full` to the entries of self.
     57
     58        EXAMPLES::
     59
     60            sage: u = vector([sin(x)^2 + cos(x)^2, 1])
     61            sage: u.simplify_full()
     62            (1, 1)
     63            sage: v = vector([log(exp(x))])
     64            sage: v.simplify_full()
     65            (x)
     66
     67        """
     68        return (SR**len(self))([fun.simplify_full() for fun in self])