Ticket #10268: trac_10268_enhance_simplify_rational.patch

File trac_10268_enhance_simplify_rational.patch, 3.1 KB (added by bgoodri, 10 years ago)
  • sage/libs/ginac/decl.pxi

    # HG changeset patch
    # User Ben Goodrich <bg2382@columbia.edu>
    # Date 1289775164 18000
    # Node ID 632a8f4cf2dbe6aec270a7ce8a1d5054b5dc9c8f
    # Parent  120c07be6358d93bcff503363d379c26b8342f2b
    Trac 10268: adding GiNaC method to simplify_rational()
    
    diff -r 120c07be6358 -r 632a8f4cf2db sage/libs/ginac/decl.pxi
    a b  
    5757        unsigned int gethash()        except +
    5858        int compare(GEx other)        except +
    5959        GEx expand(unsigned int opt)  except +
     60        GEx normal()                  except +
    6061        GEx collect(GEx s, bint dist) except +
    6162        GEx diff(GSymbol s, int d)    except +
    6263        GEx series(GEx s, int order, unsigned options) except +
  • sage/symbolic/expression.pyx

    diff -r 120c07be6358 -r 632a8f4cf2db sage/symbolic/expression.pyx
    a b  
    64606460
    64616461          - 'noexpand' (convert to commmon denominator and add)
    64626462
     6463          - 'normal' (similar to 'full' but utilizing GiNaC)
     6464
    64636465        - ``map`` - (default: False) if True, the result is an
    64646466          expression whose leading operator is the same as that of the
    64656467          expression ``self`` but whose subparts are the results of
     
    64706472        are the same
    64716473
    64726474        DETAILS: We call Maxima functions ratsimp, fullratsimp and
    6473         xthru. If each part of the expression has to be simplified
    6474         separately, we use Maxima function map.
     6475        xthru or GiNaC function normal. If each part of the expression
     6476        has to be simplified separately, we use Maxima function map, which
     6477        is silently ignored if method is 'normal'.
    64756478       
    64766479        EXAMPLES::
    64776480       
     
    64876490            ((x - 1)^(3/2) - sqrt(x - 1)*(x + 1))/sqrt((x - 1)*(x + 1))
    64886491            sage: f.simplify_rational()
    64896492            -2*sqrt(x - 1)/sqrt(x^2 - 1)
     6493            sage: f.simplify_rational(method='normal')
     6494            ((x - 1)^(3/2) - sqrt(x - 1)*x - sqrt(x - 1))/sqrt((x - 1)*(x + 1))
     6495            sage: f.simplify_rational(method='normal').simplify_rational()
     6496            -2*sqrt(x - 1)/sqrt(x^2 - 1)
    64906497
    64916498        With ``map=True`` each term in a sum is simplified separately
    64926499        and thus the resuls are shorter for functions which are
     
    65226529            ((x + 1)*x + (x + 2)^2)/((x + 1)*(x + 2)^2)
    65236530
    65246531        """
    6525         self_m = self._maxima_()
     6532        _sig_on
     6533        cdef GEx x
     6534        _sig_off
    65266535        if method == 'full':
    65276536            maxima_method = 'fullratsimp'
    65286537        elif method == 'simple':
    65296538            maxima_method = 'ratsimp'
    65306539        elif method == 'noexpand':
    65316540            maxima_method = 'xthru'
     6541        elif method == 'normal':
     6542            x = self._gobj.normal()
     6543            return new_Expression_from_GEx(self._parent, x)
    65326544        else:
    65336545            raise NotImplementedError, "unknown method, see the help for available methods"
     6546        self_m = self._maxima_()
    65346547        P = self_m.parent()
    65356548        self_str=self_m.str()
    65366549        if map: