# Ticket #11381: 11381-vector-simplify-reviewer-changes.2.patch

File 11381-vector-simplify-reviewer-changes.2.patch, 3.8 KB (added by robertwb, 10 years ago)

apply only this patch

• ## sage/modules/vector_symbolic_dense.py

```# HG changeset patch
# User Robert Bradshaw <robertwb@math.washington.edu>
# Date 1306390972 25200
# Node ID 987158037a789b28e11903cc4a2b0c3f1719b2ae
# Parent  5fdd05d6b87e3552620f96e4b7d90c91b8cfca87
#11381 - more vector simplification methods

diff -r 5fdd05d6b87e -r 987158037a78 sage/modules/vector_symbolic_dense.py```
 a """ Vectors over the symbolic ring. Implements vectors over the symbolic ring.  Currently, this class only provides methods for the simplification of symbolic vectors, as this functionality was needed during the development of Trac #10132.  In the long run, this class could be extended along the lines of ``sage.matrix.matrix_symbolic_dense``. Implements vectors over the symbolic ring. AUTHOR: -- Joris Vankerschaver (2011-05-15) -- Robert Bradshaw (2011-05-25): Added more element-wise simplification methods -- Joris Vankerschaver (2011-05-15): Initial version EXAMPLES:: #***************************************************************************** import free_module_element from sage.symbolic.ring import SR from sage.symbolic.all import SR, Expression def apply_map(phi): """ Returns a function that applies phi to its argument. EXAMPLES:: sage: from sage.modules.vector_symbolic_dense import apply_map sage: v = vector([1,2,3]) sage: f = apply_map(lambda x: x+1) sage: f(v) (2, 3, 4) """ def apply(self, *args, **kwds): """ Generic function used to implement common symbolic operations elementwise as methods of a vector. EXAMPLES:: sage: var('x,y') (x, y) sage: v = vector([sin(x)^2 + cos(x)^2, log(x*y), sin(x/(x^2 + x)), factorial(x+1)/factorial(x)]) sage: v.simplify_trig() (1, log(x*y), sin(1/(x + 1)), factorial(x + 1)/factorial(x)) sage: v.simplify_radical() (sin(x)^2 + cos(x)^2, log(x) + log(y), sin(1/(x + 1)), factorial(x + 1)/factorial(x)) sage: v.simplify_rational() (sin(x)^2 + cos(x)^2, log(x*y), sin(1/(x + 1)), factorial(x + 1)/factorial(x)) sage: v.simplify_factorial() (sin(x)^2 + cos(x)^2, log(x*y), sin(x/(x^2 + x)), x + 1) sage: v.simplify_full() (1, log(x*y), sin(1/(x + 1)), x + 1) sage: v = vector([sin(2*x), sin(3*x)]) sage: v.simplify_trig() (2*sin(x)*cos(x), (4*cos(x)^2 - 1)*sin(x)) sage: v.simplify_trig(False) (sin(2*x), sin(3*x)) sage: v.simplify_trig(expand=False) (sin(2*x), sin(3*x)) """ return self.apply_map(lambda x: phi(x, *args, **kwds)) apply.__doc__ += "\nSee Expression." + phi.__name__ + "() for optional arguments." return apply class Vector_symbolic_dense(free_module_element.FreeModuleElement_generic_dense): pass def simplify_full(self): """ Applies :meth:`simplify_full` to the entries of self. EXAMPLES:: sage: u = vector([sin(x)^2 + cos(x)^2, 1]) sage: u.simplify_full() (1, 1) sage: v = vector([log(exp(x))]) sage: v.simplify_full() (x) """ return (SR**len(self))([fun.simplify_full() for fun in self]) # Add elementwise methods. for method in ['simplify', 'simplify_exp', 'simplify_factorial', 'simplify_log', 'simplify_radical', 'simplify_rational', 'simplify_trig', 'simplify_full', 'trig_expand', 'trig_reduce']: setattr(Vector_symbolic_dense, method, apply_map(getattr(Expression, method)))