Ticket #10552: sage-symb-matrices.patch

File sage-symb-matrices.patch, 5.3 KB (added by jvkersch, 10 years ago)

Simplification methods for matrices

  • sage/matrix/matrix_symbolic_dense.pyx

    # HG changeset patch
    # User Joris Vankerschaver <joris.vankerschaver@gmail.com>
    # Date 1306807493 25200
    # Node ID 883e83b20d3fc2b45e5e3513881bc30528439331
    # Parent  361a4ad7d52c69b64ae2e658ffd0820af0d87e93
    #11552 -- elementwise simplification of matrices
    
    diff -r 361a4ad7d52c -r 883e83b20d3f sage/matrix/matrix_symbolic_dense.pyx
    a b  
    477477            [    x^2 y^2 + 2]           
    478478        """
    479479        return self.parent()([x.simplify() for x in self.list()])
    480    
     480
     481    def simplify_full(self):
     482        """
     483        Simplifies self by applying :meth:`simplify_full` to each element
     484        of self.  See :meth:`simplify_full` for more details.
     485
     486        ALIAS: simplify_full and full_simplify are the same.
     487
     488        EXAMPLES::
     489       
     490            sage: m = matrix([[log(8)/log(2), 0], [sin(x)^2 + cos(x)^2, log(exp(x))]]); m
     491            [      log(8)/log(2)                   0]
     492            [sin(x)^2 + cos(x)^2            log(e^x)]
     493            sage: m.simplify_full()
     494            [3 0]
     495            [1 x]
     496        """
     497        return self.apply_map(lambda x : x.simplify_full())
     498
     499    full_simplify = simplify_full
    481500
    482501    def simplify_trig(self):
    483502        """
     503        Simplifies `self` using trigonometric identities such as
     504        sin(x)^2 + cos(x)^2 = 1, etc.
     505
     506        ALIAS: :meth:`trig_simplify` and :meth:`simplify_trig` are the same
     507
    484508        EXAMPLES::
    485509       
    486510            sage: theta = var('theta')
     
    494518        """
    495519        return self._maxima_(maxima).trigexpand().trigsimp()._sage_()
    496520
     521    trig_simplify = simplify_trig
     522
    497523    def simplify_rational(self):
    498524        """
     525        Simplifies self by applying rational simplifications.
     526
    499527        EXAMPLES::
    500528       
    501529            sage: M = matrix(SR, 3, 3, range(9)) - var('t')
     
    508536            [0 1 0]
    509537            [0 0 1]
    510538        """
    511         return self._maxima_(maxima).fullratsimp()._sage_()
     539        return self._maxima_(maxima).fullratsimp()._sage_()
     540
     541    def simplify_factorial(self):
     542        """
     543        Simplifies self by applying :meth:`simplify_factorial` to each element
     544        of self.  See :meth:`simplify_factorial` for more details.
     545
     546        ALIAS: factorial_simplify and simplify_factorial are the same
     547
     548        EXAMPLES::
     549
     550            sage: n = var('n')
     551            sage: M = matrix(SR, [[factorial(n+2), factorial(n+1)], [factorial(n), factorial(n-1)]]); M
     552            [factorial(n + 2) factorial(n + 1)]
     553            [    factorial(n) factorial(n - 1)]
     554            sage: MD = M/factorial(n); MD
     555            [factorial(n + 2)/factorial(n) factorial(n + 1)/factorial(n)]
     556            [                            1 factorial(n - 1)/factorial(n)]
     557            sage: MD.simplify_factorial()
     558            [(n + 1)*(n + 2)           n + 1]
     559            [              1             1/n]
     560       
     561        """
     562        return self.apply_map(lambda x : x.simplify_factorial())
     563
     564    factorial_simplify = simplify_factorial
     565
     566    def simplify_radical(self):
     567        """
     568        Simplifies self by applying :meth:`simplify_radical` to each element
     569        of self.  See :meth:`simplify_radical` for more details.
     570
     571        ALIAS: radical_simplify, simplify_radical, exp_simplify, simplify_exp
     572        are all the same
     573
     574        EXAMPLES::
     575       
     576            sage: x, y = var('x, y')
     577            sage: M = matrix([[log(x*y), 0], [0, (e^x-1)/(1+e^(x/2))]]); M
     578            [                 log(x*y)                         0]
     579            [                        0 (e^x - 1)/(e^(1/2*x) + 1)]
     580            sage: M.simplify_radical()
     581            [log(x) + log(y)               0]
     582            [              0   e^(1/2*x) - 1]
     583
     584        """
     585        return self.apply_map(lambda x : x.simplify_radical())
     586
     587    radical_simplify = simplify_radical
     588    simplify_exp = exp_simplify = simplify_radical
     589
     590    def reduce_trig(self, var=None):
     591        """
     592        Reduces self by applying :meth:`reduce_trig` to each element
     593        of self.  See :meth:`reduce_trig` for more details.
     594       
     595        ALIASES: :meth:`trig_reduce` and :meth:`reduce_trig` are the same
     596
     597        INPUT:
     598
     599        - ``var`` - (default: None) the variable which is used for simplification.  If `none` is specified, all variables are used.
     600
     601        EXAMPLES::
     602
     603            sage: x, y = var('x, y')
     604            sage: M = matrix([[cos(x)^2, cos(y)^3], [0, 1/sin(y)^2]]); M
     605            [   cos(x)^2    cos(y)^3]
     606            [          0 sin(y)^(-2)]
     607            sage: M.reduce_trig()
     608            [       1/2*cos(2*x) + 1/2 1/4*cos(3*y) + 3/4*cos(y)]
     609            [                        0                  csc(y)^2]
     610
     611        To reduce only the expressions involving one variable, we supply
     612        that variable as an optional parameter::
     613       
     614            sage: M.reduce_trig(x)
     615            [1/2*cos(2*x) + 1/2           cos(y)^3]
     616            [                 0        sin(y)^(-2)]
     617            sage: M.reduce_trig(y)
     618            [                 cos(x)^2 1/4*cos(3*y) + 3/4*cos(y)]
     619            [                        0                  csc(y)^2]
     620
     621        """
     622        return self.apply_map(lambda x : x.reduce_trig(var))
     623
     624    trig_reduce = reduce_trig
    512625
    513626    def factor(self):
    514627        """