Ticket #12737: sage-trac_12737.patch

File sage-trac_12737.patch, 6.3 KB (added by mjo, 7 years ago)

Add the flag and update doctests.

  • sage/calculus/wester.py

    # HG changeset patch
    # User Michael Orlitzky <michael@orlitzky.com>
    # Date 1332528226 14400
    # Node ID ba68cbfe757ac121cb7a4f5708e862ef0e17457d
    # Parent  ecc1a402f16668f9f48daa347d7c91a36425cff3
    Add an `unsafe` flag to Expression.full_simplify().
    
    Specify the 'one' algorithm for simplify_log() in simplify(). This
    prevents some doctest churn and does not have a (noticeable) negative
    impact anywhere else.
    
    Add an `unsafe` argument to the simplify_full() method. The default
    is unsafe=False, and this skips the call to simplify_radical().
    
    Fix all doctests that depended on simplify_radical() by passing
    unsafe=True to simplify_full().
    
    diff --git a/sage/calculus/wester.py b/sage/calculus/wester.py
    a b  
    120120    (e^x - 1)/(e^(1/2*x) + 1)
    121121    sage: g
    122122    e^(1/2*x) - 1
    123     sage: f.simplify_full(),g
     123    sage: f.simplify_full(unsafe=True),g
    124124    (e^(1/2*x) - 1, e^(1/2*x) - 1)
    125125    sage: f(x=10.0).n(53), g(x=10.0).n(53)
    126126    (147.413159102577, 147.413159102577)
  • sage/functions/other.py

    diff --git a/sage/functions/other.py b/sage/functions/other.py
    a b  
    340340                return lower_ceil
    341341            else:
    342342                try:
    343                     return ceil(SR(x).full_simplify())
     343                    # We're not too worried about unsafe=True here
     344                    # because ceil() will only work on simpler
     345                    # expressions anyway.
     346                    return ceil(SR(x).full_simplify(unsafe=True))
    344347                except ValueError:
    345348                    pass
    346349                raise ValueError, "x (= %s) requires more than %s bits of precision to compute its ceiling"%(x, maximum_bits)
     
    501504                return lower_floor
    502505            else:
    503506                try:
    504                     return floor(SR(x).full_simplify())
     507                    # We're not too worried about unsafe=True here
     508                    # because floor() will only work on simpler
     509                    # expressions anyway.
     510                    return floor(SR(x).full_simplify(unsafe=True))
    505511                except ValueError:
    506512                    pass
    507513                raise ValueError, "x (= %s) requires more than %s bits of precision to compute its floor"%(x, maximum_bits)
  • sage/interfaces/maxima_lib.py

    diff --git a/sage/interfaces/maxima_lib.py b/sage/interfaces/maxima_lib.py
    a b  
    713713
    714714        ::
    715715
    716             sage: integrate(sqrt(x + sqrt(x)), x).simplify_full()
     716            sage: integrate(sqrt(x + sqrt(x)), x).simplify_full(unsafe=True)
    717717            1/12*sqrt(sqrt(x) + 1)*((8*x - 3)*x^(1/4) + 2*x^(3/4)) - 1/8*log(sqrt(sqrt(x) + 1) - x^(1/4)) + 1/8*log(sqrt(sqrt(x) + 1) + x^(1/4))
    718718
    719719        And trac #11594::
  • sage/misc/functional.py

    diff --git a/sage/misc/functional.py b/sage/misc/functional.py
    a b  
    11491149        sage: norm(a + b).simplify()
    11501150        a^2 + 2*a*b + b^2
    11511151        sage: v = vector([a, b, c])
    1152         sage: bool(norm(v).simplify_full() == sqrt(a^2 + b^2 + c^2))
     1152        sage: bool(norm(v).simplify_full(unsafe=True) == sqrt(a^2 + b^2 + c^2))
    11531153        True
    11541154    """
    11551155    return x.norm()
  • sage/modules/vector_symbolic_dense.py

    diff --git a/sage/modules/vector_symbolic_dense.py b/sage/modules/vector_symbolic_dense.py
    a b  
    1717    sage: type(u)
    1818    <class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
    1919    sage: u.simplify_full()
    20     (1, log(6) + 2*log(y))
     20    (1, log(6*y^2))
    2121
    2222TESTS:
    2323
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    69176917        x = self.simplify_factorial()
    69186918        x = x.simplify_trig()
    69196919        x = x.simplify_rational()
    6920         x = x.simplify_log()
     6920        x = x.simplify_log('one')
    69216921
    69226922        return x
    69236923
    69246924
    6925     def simplify_full(self):
    6926         """
    6927         Applies simplify_factorial, simplify_trig, simplify_rational,
    6928         simplify_radical, simplify_log, and again simplify_rational to
    6929         self (in that order).
    6930        
    6931         ALIAS: simplify_full and full_simplify are the same.
     6925    def simplify_full(self, unsafe=False):
     6926        """
     6927        Applies :meth:`simplify`, and then optionally attempts some
     6928        unsafe simplifications if ``unsafe`` is ``True``. Finally,
     6929        :meth:`simplify` is applied again.
     6930
     6931        INPUT:
     6932
     6933        - ``self`` - expression to be simplified
     6934
     6935        - ``unsafe`` - (default: ``False``) if ``True``, perform
     6936          simplifications for which the input may not be
     6937          mathematically equivalent to the simplified output.
     6938
     6939        ALIAS: :meth:`simplify_full` and :meth:`full_simplify` are the
     6940        same.
    69326941       
    69336942        EXAMPLES::
    69346943       
    69356944            sage: a = log(8)/log(2)
    6936             sage: a.simplify_full()
     6945            sage: a.simplify_full(unsafe=True)
    69376946            3
    69386947       
    69396948        ::
     
    69556964            sage: f = binomial(n,k)*factorial(k)*factorial(n-k)
    69566965            sage: f.simplify_full()
    69576966            factorial(n)
     6967
     6968        The following simplification is invalid if you consider `f` to
     6969        be a function of `x`::
     6970
     6971            sage: f = sqrt( (x+1)^2 )
     6972            sage: f.simplify_full()
     6973            sqrt(x^2 + 2*x + 1)
     6974            sage: f.simplify_full(unsafe=True)
     6975            x + 1
     6976
    69586977        """
    69596978        x = self
    6960         x = x.simplify_factorial()
    6961         x = x.simplify_trig()
    6962         x = x.simplify_rational()
    6963         x = x.simplify_radical()
    6964         x = x.simplify_log('one')
    6965         x = x.simplify_rational()
     6979        x = x.simplify()
     6980        if unsafe:
     6981            x = x.simplify_radical()
     6982        x = x.simplify()
    69666983        return x
    69676984
    69686985    full_simplify = simplify_full
  • sage/symbolic/integration/integral.py

    diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py
    a b  
    578578
    579579        sage: actual_result = integral(e^(-1/x^2), x, 0, 1)
    580580        sage: actual_result.full_simplify()
    581         ((e*erf(1) - e)*sqrt(pi) + 1)*e^(-1)
     581        (sqrt(pi)*e*erf(1) - sqrt(pi)*e + 1)*e^(-1)
    582582        sage: ideal_result = 1/2*gamma(-1/2, 1)
    583583        sage: error = actual_result - ideal_result
    584584        sage: error.numerical_approx() # abs tol 10e-10