Ticket #10187: trac_10187_fix_easy_doctests.patch

File trac_10187_fix_easy_doctests.patch, 16.5 KB (added by vbraun, 9 years ago)

Updated patch

  • sage/calculus/calculus.py

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1288372169 -3600
    # Node ID 85a4c19b3cbeed3e006df1c1eb768d647e94c4df
    # Parent  6b5a6e9be12b61e73cbbcb3a1cdd5d7ff69e4dfd
    Trac #10187: Update ecl and maxima
    
    This patch fixes doctests due to the maxima update. In
    most cases, maxima got better at integration.
    
    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/calculus/calculus.py
    a b  
    341341(Trac #9217) is fixed::
    342342
    343343    sage: taylor(gamma(1/3+x),x,0,3)
    344     -1/432*((36*(pi*sqrt(3) + 9*log(3))*euler_gamma^2 + 27*pi^2*log(3) + 72*euler_gamma^3 + 243*log(3)^3 + 18*(6*pi*sqrt(3)*log(3) + pi^2 + 27*log(3)^2)*euler_gamma + 36*(6*euler_gamma + pi*sqrt(3) + 9*log(3))*psi(1, 1/3) + (pi^3 + 81*pi*log(3)^2)*sqrt(3))*gamma(1/3) - 72*gamma(1/3)*psi(2, 1/3))*x^3 + 1/24*(6*pi*sqrt(3)*log(3) + 4*(pi*sqrt(3) + 9*log(3))*euler_gamma + pi^2 + 12*euler_gamma^2 + 27*log(3)^2 + 12*psi(1, 1/3))*x^2*gamma(1/3) - 1/6*(6*euler_gamma + pi*sqrt(3) + 9*log(3))*x*gamma(1/3) + gamma(1/3)
    345 
     344    -1/432*((36*(pi*sqrt(3) + 9*log(3))*euler_gamma^2 + 27*pi^2*log(3) + 72*euler_gamma^3 + 243*log(3)^3 + 18*(6*pi*sqrt(3)*log(3) + pi^2 + 27*log(3)^2 + 12*psi(1, 1/3))*euler_gamma + 324*psi(1, 1/3)*log(3) + (pi^3 + 9*(9*log(3)^2 + 4*psi(1, 1/3))*pi)*sqrt(3))*gamma(1/3) - 72*gamma(1/3)*psi(2, 1/3))*x^3 + 1/24*(6*pi*sqrt(3)*log(3) + 4*(pi*sqrt(3) + 9*log(3))*euler_gamma + pi^2 + 12*euler_gamma^2 + 27*log(3)^2 + 12*psi(1, 1/3))*x^2*gamma(1/3) - 1/6*(6*euler_gamma + pi*sqrt(3) + 9*log(3))*x*gamma(1/3) + gamma(1/3)
     345    sage: map(lambda f:f[0].n(), _.coeffs())  # numerical coefficients to make comparison easier; Maple 12 gives same answer
     346    [2.6789385347..., -8.3905259853..., 26.662447494..., -80.683148377...]
    346347"""
    347348
    348349import re
     
    366367
    367368    sage: maxima = Maxima(init_code = ['load(simplify_sum)'])
    368369    sage: maxima('f1')
    369     binomial(n,k)
     370    f1
    370371    sage: sage.calculus.calculus.maxima('f1')
    371372    f1
    372373"""
    373374maxima = Maxima(init_code = ['display2d:false', 'domain: complex',
    374     'keepfloat: true', 'load(to_poly_solver)', 'load(simplify_sum)',
    375     'kill (g1, g2, g3, g4, g5, g6, g7, f1, f2, f3, f4, f5, f6, f7, f8, f9,\
    376             f10, h1, h2, h3, h4, h5, h6, h6b, h7, h8, h9, h10, h11, h12, h13,\
    377             d1, d2)'],
     375                             'keepfloat: true', 'load(to_poly_solver)', 'load(simplify_sum)'],
    378376                script_subdirectory=None)
    379377
    380378########################################################
     
    422420
    423421    And some truncations thereof::
    424422
     423        sage: assume(n>1)
    425424        sage: symbolic_sum(binomial(n,k),k,1,n)
    426425        2^n - 1
    427426        sage: symbolic_sum(binomial(n,k),k,2,n)
     
    11461145        sage: (z + exp(x)).laplace(x, s)
    11471146        z/s + 1/(s - 1)
    11481147        sage: log(t/t0).laplace(t, s)
    1149          -(euler_gamma + log(s) + log(t0))/s
     1148        -(euler_gamma + log(s) - log(1/t0))/s
    11501149         
    11511150    We do a formal calculation::
    11521151
  • sage/calculus/functional.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/calculus/functional.py
    a b  
    236236   
    237237        sage: integral(abs(x), x, 0, 5)
    238238        25/2
    239         sage: integral(abs(x), x, 0, a)
    240         integrate(abs(x), x, 0, a)
     239        sage: integral(abs(x)*x, x, 0, a)
     240        Traceback (most recent call last):
     241        ...
     242        TypeError: Computation failed since Maxima requested additional
     243        constraints (try the command 'assume(a>0)' before integral or limit
     244        evaluation, for example):
     245        Is  a  positive, negative, or zero?
    241246        sage: assume(a>0)
    242         sage: integral(abs(x), x, 0, a)
    243         1/2*a^2
     247        sage: integral(abs(x)*x, x, 0, a)
     248        1/3*a^3
    244249        sage: forget()      # forget the assumptions.
    245250   
    246251    We integrate and differentiate a huge mess::
  • sage/calculus/tests.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/calculus/tests.py
    a b  
    105105    sage: expand(integrate(log(1-x^2), x))
    106106    x*log(-x^2 + 1) - 2*x - log(x - 1) + log(x + 1)
    107107    sage: integrate(log(1-x^2)/x, x)
    108     log(-x^2 + 1)*log(x) + 1/2*polylog(2, -x^2 + 1)
     108    1/2*log(-x^2 + 1)*log(x^2) + 1/2*polylog(2, -x^2 + 1)
    109109    sage: integrate(exp(1-x^2),x)
    110110    1/2*sqrt(pi)*e*erf(x)
    111111    sage: integrate(sin(x^2),x)
  • sage/calculus/wester.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/calculus/wester.py
    a b  
    500500
    501501::
    502502
    503     sage: # (NO) (Integrate(x)Abs(x))=Abs(x)*x/2
     503    sage: # (YES) (Integrate(x)Abs(x))=Abs(x)*x/2
    504504    sage: integral(abs(x), x)
    505     integrate(abs(x), x)
     505    1/2*x*abs(x)
    506506
    507507::
    508508
  • sage/interfaces/maxima.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/interfaces/maxima.py
    a b  
    537537                        init_code = init_code,
    538538                        logfile = logfile,
    539539                        eval_using_file_cutoff=eval_using_file_cutoff)
    540         self._display_prompt = '<sage-display>'  # must match what is in the file local/ibn/sage-maxima.lisp!!
     540        self._display_prompt = '<sage-display>'  # must match what is in the file local/bin/sage-maxima.lisp!!
    541541        self._output_prompt_re = re.compile('\(\%o[0-9]+\)')
    542542        self._ask = ['zero or nonzero?', 'an integer?', 'positive, negative, or zero?',
    543543                     'positive or negative?', 'positive or zero?']
     
    726726       
    727727        We check that errors are correctly checked::
    728728       
     729            sage: maxima._eval_line('1+1;')
     730            '2'
    729731            sage: maxima.eval('sage0: x == x;')
    730732            Traceback (most recent call last):
    731733            ...
     
    27682770   
    27692771        sage: from sage.interfaces.maxima import maxima_console
    27702772        sage: maxima_console()                    # not tested
    2771         Maxima 5.16.3 http://maxima.sourceforge.net
     2773        Maxima 5.22.1 http://maxima.sourceforge.net
    27722774        ...
    27732775    """
    27742776    os.system('maxima')
     
    27792781   
    27802782        sage: from sage.interfaces.maxima import maxima_version
    27812783        sage: maxima_version()
    2782         '5.20.1'
     2784        '5.22.1'
    27832785    """
    27842786    return os.popen('maxima --version').read().split()[-1]
    27852787
  • sage/misc/functional.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/misc/functional.py
    a b  
    702702
    703703    Numerical approximation::
    704704
    705         sage: h = integral(sin(x)/x^2, (x, 1, pi/2)); h
    706         integrate(sin(x)/x^2, x, 1, 1/2*pi)
    707         sage: h.n()
    708         0.339447940978915...
     705        sage: h = integral(tan(x)/x, (x, 1, pi/3)); h
     706        integrate(tan(x)/x, x, 1, 1/3*pi)
     707        sage: h.n()                                   
     708        0.07571599101...
    709709
    710710    Specific algorithm can be used for integration::
    711711
  • sage/plot/plot3d/transform.pyx

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/plot/plot3d/transform.pyx
    a b  
    213213        And simplify every single entry (which is more effective that simplify
    214214        the whole matrix like above):
    215215       
    216             sage: m = m.parent()([x.simplify_rational() for x in m._list()])
     216            sage: m = m.parent()([x.simplify_full() for x in m._list()])
    217217            sage: m
    218             [                                             -(cos(theta) - 1)*x^2 + cos(theta)                 -(cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*x - sqrt(z^2)*sin(theta)         -((cos(theta) - 1)*x*z^2 - sqrt(-x^2 - z^2 + 1)*sqrt(z^2)*sin(theta))/z]
    219             [                -(cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*x + sqrt(z^2)*sin(theta)                                 (cos(theta) - 1)*x^2 + (cos(theta) - 1)*z^2 + 1 -((cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*sqrt(z^2)*z + x*z*sin(theta))/sqrt(z^2)]
    220             [        -((cos(theta) - 1)*x*z^2 + sqrt(-x^2 - z^2 + 1)*sqrt(z^2)*sin(theta))/z -((cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*sqrt(z^2)*z - x*z*sin(theta))/sqrt(z^2)                                              -(cos(theta) - 1)*z^2 + cos(theta)]
    221            
     218            [                                       -(cos(theta) - 1)*x^2 + cos(theta)              -(cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*x + sin(theta)*abs(z)      -((cos(theta) - 1)*x*z^2 + sqrt(-x^2 - z^2 + 1)*sin(theta)*abs(z))/z]
     219            [             -(cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*x - sin(theta)*abs(z)                           (cos(theta) - 1)*x^2 + (cos(theta) - 1)*z^2 + 1 -((cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*z*abs(z) - x*z*sin(theta))/abs(z)]
     220            [     -((cos(theta) - 1)*x*z^2 - sqrt(-x^2 - z^2 + 1)*sin(theta)*abs(z))/z -((cos(theta) - 1)*sqrt(-x^2 - z^2 + 1)*z*abs(z) + x*z*sin(theta))/abs(z)                                        -(cos(theta) - 1)*z^2 + cos(theta)]
    222221           
    223222        Re-expressing some entries in terms of y and resolving the absolute
    224223        values introduced by eliminating y, we get the desired result.
  • sage/symbolic/expression.pyx

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/symbolic/expression.pyx
    a b  
    63156315            sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t
    63166316            log(sqrt(2) - 1) + log(sqrt(2) + 1)
    63176317            sage: res = t.maxima_methods().logcontract(); res
    6318             0
     6318            log((sqrt(2) - 1)*(sqrt(2) + 1))
    63196319            sage: type(res)
    63206320            <type 'sage.symbolic.expression.Expression'>
    63216321        """
     
    63486348   
    63496349    def simplify_full(self):
    63506350        """
    6351         Applies simplify_factorial, simplify_trig, simplify_rational, and simplify_radical
    6352         to self (in that order).
     6351        Applies simplify_factorial, simplify_trig, simplify_rational,
     6352        simplify_radical, simplify_log, and again simplify_rational to
     6353        self (in that order).
    63536354       
    63546355        ALIAS: simplify_full and full_simplify are the same.
    63556356       
     
    63856386        x = x.simplify_rational()
    63866387        x = x.simplify_radical()
    63876388        x = x.simplify_log('one')
     6389        x = x.simplify_rational()
    63886390        return x
    63896391
    63906392    full_simplify = simplify_full
     
    67466748
    67476749        TESTS:
    67486750       
    6749         This shows that the issue at trac #7344 is fixed::
    6750 
    6751             sage: (log(sqrt(2)-1)+log(sqrt(2)+1)).simplify_full()
     6751        This shows that the issue at trac #7334 is fixed. Maxima intentionally
     6752        keeps the expression inside the log factored::
     6753
     6754            sage: log_expr = (log(sqrt(2)-1)+log(sqrt(2)+1))
     6755            sage: log_expr.simplify_log('all')
     6756            log((sqrt(2) - 1)*(sqrt(2) + 1))
     6757            sage: _.simplify_rational()
     6758            0
     6759            sage: log_expr.simplify_full()   # applies both simplify_log and simplify_rational
    67526760            0
    67536761           
    67546762        AUTHORS:
     
    73447352        The following examples show use of the keyword ``to_poly_solve``::
    73457353
    73467354            sage: solve(abs(1-abs(1-x)) == 10, x)
    7347             []
     7355            [abs(abs(x - 1) - 1) == 10]
    73487356            sage: solve(abs(1-abs(1-x)) == 10, x, to_poly_solve=True)
    7349             [x == 12, x == -10]
     7357            [x == -10, x == 12]
    73507358
    73517359            sage: var('Q')
    73527360            Q
     
    73607368        assumed to be an integer, a real if with ``r``, and so on::
    73617369
    73627370            sage: solve( sin(x)==cos(x), x, to_poly_solve=True)
    7363             [x == 1/4*pi + pi*z45]
     7371            [x == 1/4*pi + pi*z44]
    73647372       
    73657373        An effort is made to only return solutions that satisfy the current assumptions::
    73667374       
     
    74007408            sage: from sage.calculus.calculus import maxima
    74017409            sage: sol = maxima(cos(x)==0).to_poly_solve(x)
    74027410            sage: sol.sage()
    7403             [[x == -1/2*pi + 2*pi*z57], [x == 1/2*pi + 2*pi*z59]]
     7411            [[x == -1/2*pi + 2*pi*z56], [x == 1/2*pi + 2*pi*z58]]
    74047412
    74057413        If a returned unsolved expression has a denominator, but the
    74067414        original one did not, this may also be true::
     
    74107418            sage: from sage.calculus.calculus import maxima
    74117419            sage: sol = maxima(cos(x) * sin(x) == 1/2).to_poly_solve(x)
    74127420            sage: sol.sage()
    7413             [[x == 1/4*pi + pi*z73]]
     7421            [[x == 1/4*pi + pi*z72]]
    74147422
    74157423        Some basic inequalities can be also solved::
    74167424
     
    74677475        ::
    74687476
    74697477            sage: solve(sin(x)==1/2,x,to_poly_solve='force')
    7470             [x == 5/6*pi + 2*pi*z87, x == 1/6*pi + 2*pi*z85]
    7471 
     7478            [x == 5/6*pi + 2*pi*z86, x == 1/6*pi + 2*pi*z84]
    74727479        """
    74737480        import operator
    74747481        cdef Expression ex
     
    76857692            sage: b.solve(t)
    76867693            []
    76877694            sage: b.solve(t, to_poly_solve=True)
    7688             [t == 1/450*I*pi*z99 + 1/900*log(3/4*sqrt(41) + 25/4), t == 1/450*I*pi*z97 + 1/900*log(-3/4*sqrt(41) + 25/4)]
     7695            [t == 1/450*I*pi*z98 + 1/900*log(3/4*sqrt(41) + 25/4), t == 1/450*I*pi*z96 + 1/900*log(-3/4*sqrt(41) + 25/4)]
    76897696            sage: n(1/900*log(-3/4*sqrt(41) + 25/4))
    76907697            0.000411051404934985
    76917698
     
    80298036
    80308037        A well known binomial identity::
    80318038
     8039            sage: assume(n>=0)
    80328040            sage: binomial(n,k).sum(k, 0, n)
    80338041            2^n
    80348042
  • sage/symbolic/integration/integral.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/symbolic/integration/integral.py
    a b  
    183183        EXAMPLES::
    184184
    185185            sage: from sage.symbolic.integration.integral import definite_integral
    186             sage: h = definite_integral(sin(x)/x^2, x, 1, 2); h
    187             integrate(sin(x)/x^2, x, 1, 2)
     186            sage: h = definite_integral(sin(x)*log(x)/x^2, x, 1, 2); h
     187            integrate(log(x)*sin(x)/x^2, x, 1, 2)
    188188            sage: h.n() # indirect doctest
    189             0.4723991772689525...
     189            0.14839875208053...
    190190
    191191        TESTS:
    192192
     
    457457    TESTS:
    458458
    459459    The following integral was broken prior to Maxima 5.15.0 -
    460     see #3013
    461 
    462     ::
     460    see #3013::
    463461
    464462        sage: integrate(sin(x)*cos(10*x)*log(x), x)
    465         1/18*log(x)*cos(9*x) - 1/22*log(x)*cos(11*x) - 1/18*integrate(cos(9*x)/x, x) + 1/22*integrate(cos(11*x)/x, x)
    466        
     463        1/198*(11*cos(9*x) - 9*cos(11*x))*log(x) + 1/44*Ei(-11*I*x) - 1/36*Ei(-9*I*x) - 1/36*Ei(9*I*x) + 1/44*Ei(11*I*x)
    467464
    468465    It is no longer possible to use certain functions without an
    469466    explicit variable.  Instead, evaluate the function at a variable,
     
    484481        sage: _ = var('x,y')
    485482        sage: f = log(x^2+y^2)
    486483        sage: res = integral(f,x,0.0001414, 1.); res
    487         2.0*y*arctan(1/y) - 2.0*y*arctan(0.0001414/y) - 0.0001414*log(y^2 + 1.999396e-08) + log(y^2 + 1.0) - 1.9997172
     484        Traceback (most recent call last):
     485        ...
     486        TypeError: Computation failed since Maxima requested additional
     487        constraints (try the command 'assume((y-1)*(y+1)>0)' before integral
     488        or limit evaluation, for example):
     489        Is  (y-1)*(y+1)  positive, negative, or zero?
     490        sage: assume(y>1)
     491        sage: res = integral(f,x,0.0001414, 1.); res
     492        2*y*arctan(1/y) - 2*y*arctan(0.0001414/y) - 0.0001414*log(y^2 + 1.999396e-08) + log(y^2 + 1.0) - 1.9997172
    488493        sage: nres = numerical_integral(f.subs(y=2), 0.0001414, 1.); nres
    489494        (1.4638323264144..., 1.6251803529759...e-14)
    490495        sage: res.subs(y=2).n()
     
    546551        sage: x.integral()
    547552        doctest:...: DeprecationWarning: Variable of integration should be specified explicitly.
    548553        1/2*x^2
     554
     555    Test that #8729 is fixed::
     556
     557        sage: t = var('t')
     558        sage: a = sqrt((sin(t))^2 + (cos(t))^2)
     559        sage: integrate(a, t, 0, 2*pi)
     560        2*pi
     561        sage: a.simplify_full().simplify_trig()
     562        1
    549563    """           
    550564    if isinstance(v, (list, tuple)) and a is None and b is None:
    551565        if len(v)==1: # bare variable in a tuple
  • sage/symbolic/maxima_wrapper.py

    diff -r 6b5a6e9be12b -r 85a4c19b3cbe sage/symbolic/maxima_wrapper.py
    a b  
    4444            sage: type(u)
    4545            <class 'sage.symbolic.maxima_wrapper.MaximaWrapper'>
    4646            sage: u.logcontract()
    47             0
     47            log((sqrt(2) - 1)*(sqrt(2) + 1))
    4848            sage: u.logcontract().parent()
    4949            Symbolic Ring
    5050