def test_issue1512(): assert abs(pi._evalf(50) - 3.14159265358979) < 1e-10 assert abs(E._evalf(50) - 2.71828182845905) < 1e-10 assert abs(Catalan._evalf(50) - 0.915965594177219) < 1e-10 assert abs(EulerGamma._evalf(50) - 0.577215664901533) < 1e-10 assert abs(GoldenRatio._evalf(50) - 1.61803398874989) < 1e-10 x = Symbol("x") assert (pi+x).evalf() == pi.evalf()+x assert (E+x).evalf() == E.evalf()+x assert (Catalan+x).evalf() == Catalan.evalf()+x assert (EulerGamma+x).evalf() == EulerGamma.evalf()+x assert (GoldenRatio+x).evalf() == GoldenRatio.evalf()+x
def test_issue_4611(): assert abs(pi._evalf(50) - 3.14159265358979) < 1e-10 assert abs(E._evalf(50) - 2.71828182845905) < 1e-10 assert abs(Catalan._evalf(50) - 0.915965594177219) < 1e-10 assert abs(EulerGamma._evalf(50) - 0.577215664901533) < 1e-10 assert abs(GoldenRatio._evalf(50) - 1.61803398874989) < 1e-10 x = Symbol("x") assert (pi + x).evalf() == pi.evalf() + x assert (E + x).evalf() == E.evalf() + x assert (Catalan + x).evalf() == Catalan.evalf() + x assert (EulerGamma + x).evalf() == EulerGamma.evalf() + x assert (GoldenRatio + x).evalf() == GoldenRatio.evalf() + x
def test_fcode_NumberSymbol(): prec = 17 p = FCodePrinter() assert fcode( Catalan ) == " parameter (Catalan = %sd0)\n Catalan" % Catalan.evalf( prec) assert fcode( EulerGamma ) == " parameter (EulerGamma = %sd0)\n EulerGamma" % EulerGamma.evalf( prec) assert fcode(E) == " parameter (E = %sd0)\n E" % E.evalf(prec) assert fcode( GoldenRatio ) == " parameter (GoldenRatio = %sd0)\n GoldenRatio" % GoldenRatio.evalf( prec) assert fcode( pi) == " parameter (pi = %sd0)\n pi" % pi.evalf(prec) assert fcode( pi, precision=5) == " parameter (pi = %sd0)\n pi" % pi.evalf(5) assert fcode(Catalan, human=False) == ( set([(Catalan, p._print(Catalan.evalf(prec)))]), set([]), " Catalan", ) assert fcode(EulerGamma, human=False) == ( set([(EulerGamma, p._print(EulerGamma.evalf(prec)))]), set([]), " EulerGamma", ) assert fcode(E, human=False) == ( set([(E, p._print(E.evalf(prec)))]), set([]), " E", ) assert fcode(GoldenRatio, human=False) == ( set([(GoldenRatio, p._print(GoldenRatio.evalf(prec)))]), set([]), " GoldenRatio", ) assert fcode(pi, human=False) == ( set([(pi, p._print(pi.evalf(prec)))]), set([]), " pi", ) assert fcode(pi, precision=5, human=False) == ( set([(pi, p._print(pi.evalf(5)))]), set([]), " pi", )
def test_acceleration(): e = (1 + 1/n)**n assert round(richardson(e, n, 10, 20).evalf(), 10) == round(E.evalf(), 10) A = Sum(Integer(-1)**(k + 1) / k, (k, 1, n)) assert round(shanks(A, n, 25).evalf(), 4) == round(log(2).evalf(), 4) assert round(shanks(A, n, 25, 5).evalf(), 10) == round(log(2).evalf(), 10)
def test_fcode_NumberSymbol(): p = FCodePrinter() assert fcode( Catalan ) == ' parameter (Catalan = 0.915965594177219d0)\n Catalan' assert fcode( EulerGamma ) == ' parameter (EulerGamma = 0.577215664901533d0)\n EulerGamma' assert fcode(E) == ' parameter (E = 2.71828182845905d0)\n E' assert fcode( GoldenRatio ) == ' parameter (GoldenRatio = 1.61803398874989d0)\n GoldenRatio' assert fcode(pi) == ' parameter (pi = 3.14159265358979d0)\n pi' assert fcode(pi, precision=5) == ' parameter (pi = 3.1416d0)\n pi' assert fcode(Catalan, human=False) == (set([ (Catalan, p._print(Catalan.evalf(15))) ]), set([]), ' Catalan') assert fcode(EulerGamma, human=False) == (set([ (EulerGamma, p._print(EulerGamma.evalf(15))) ]), set([]), ' EulerGamma') assert fcode(E, human=False) == (set([(E, p._print(E.evalf(15)))]), set([]), ' E') assert fcode(GoldenRatio, human=False) == (set([ (GoldenRatio, p._print(GoldenRatio.evalf(15))) ]), set([]), ' GoldenRatio') assert fcode(pi, human=False) == (set([(pi, p._print(pi.evalf(15)))]), set([]), ' pi') assert fcode(pi, precision=5, human=False) == (set([ (pi, p._print(pi.evalf(5))) ]), set([]), ' pi')
def test_fcode_NumberSymbol(): assert fcode( Catalan ) == ' parameter (Catalan = 0.915965594177219)\n Catalan' assert fcode( EulerGamma ) == ' parameter (EulerGamma = 0.577215664901533)\n EulerGamma' assert fcode(E) == ' parameter (E = 2.71828182845905)\n E' assert fcode( GoldenRatio ) == ' parameter (GoldenRatio = 1.61803398874989)\n GoldenRatio' assert fcode(pi) == ' parameter (pi = 3.14159265358979)\n pi' assert fcode(pi, precision=5) == ' parameter (pi = 3.1416)\n pi' assert fcode(Catalan, human=False) == ([('Catalan', Catalan.evalf(15))], set([]), ' Catalan') assert fcode(EulerGamma, human=False) == ([('EulerGamma', EulerGamma.evalf(15))], set([]), ' EulerGamma') assert fcode(E, human=False) == ([('E', E.evalf(15))], set([]), ' E') assert fcode(GoldenRatio, human=False) == ([('GoldenRatio', GoldenRatio.evalf(15))], set([]), ' GoldenRatio') assert fcode(pi, human=False) == ([('pi', pi.evalf(15))], set([]), ' pi') assert fcode(pi, precision=5, human=False) == ([('pi', pi.evalf(5))], set([]), ' pi')
def test_sympy(): x = Symbol('x', real = True) assert -oo < oo assert not(-1.5 < -oo) assert (1 - exp(x)).is_negative is None assert Matrix([[1, 2], [3, 4]])**Integer(2) == Matrix([[7, 10], [15, 22]]) assertAlmostEqual(E._evalf(50), math.e) assert solve(1/x, x) == [] # issue 1694 assert solve(-(1 + x)/(2 + x)**2 + 1/(2 + x), x) == [] # issue 1694 assert limit(1 + 1/x, x, 0, dir='-') == -oo assert limit(1/x**2, x, 0, dir='-') == oo assert sympify(u'45') == 45 # issue 2508
def test_sympy(): x = Symbol('x', real=True) assert -oo < oo assert not (-1.5 < -oo) assert (1 - exp(x)).is_negative is None assert Matrix([[1, 2], [3, 4]])**Integer(2) == Matrix([[7, 10], [15, 22]]) assertAlmostEqual(E._evalf(50), math.e) assert solve(1 / x, x) == [] # issue 1694 assert solve(-(1 + x) / (2 + x)**2 + 1 / (2 + x), x) == [] # issue 1694 assert limit(1 + 1 / x, x, 0, dir='-') == -oo assert limit(1 / x**2, x, 0, dir='-') == oo assert sympify(u'45') == 45 # issue 2508
def test_fcode_NumberSymbol(): prec = 17 p = FCodePrinter() assert fcode(Catalan) == ' parameter (Catalan = %sd0)\n Catalan' % Catalan.evalf(prec) assert fcode(EulerGamma) == ' parameter (EulerGamma = %sd0)\n EulerGamma' % EulerGamma.evalf(prec) assert fcode(E) == ' parameter (E = %sd0)\n E' % E.evalf(prec) assert fcode(GoldenRatio) == ' parameter (GoldenRatio = %sd0)\n GoldenRatio' % GoldenRatio.evalf(prec) assert fcode(pi) == ' parameter (pi = %sd0)\n pi' % pi.evalf(prec) assert fcode( pi, precision=5) == ' parameter (pi = %sd0)\n pi' % pi.evalf(5) assert fcode(Catalan, human=False) == (set( [(Catalan, p._print(Catalan.evalf(prec)))]), set([]), ' Catalan') assert fcode(EulerGamma, human=False) == (set([(EulerGamma, p._print( EulerGamma.evalf(prec)))]), set([]), ' EulerGamma') assert fcode(E, human=False) == ( set([(E, p._print(E.evalf(prec)))]), set([]), ' E') assert fcode(GoldenRatio, human=False) == (set([(GoldenRatio, p._print( GoldenRatio.evalf(prec)))]), set([]), ' GoldenRatio') assert fcode(pi, human=False) == ( set([(pi, p._print(pi.evalf(prec)))]), set([]), ' pi') assert fcode(pi, precision=5, human=False) == ( set([(pi, p._print(pi.evalf(5)))]), set([]), ' pi')
def test_fcode_NumberSymbol(): assert fcode(Catalan) == ' parameter (Catalan = 0.915965594177219)\n Catalan' assert fcode(EulerGamma) == ' parameter (EulerGamma = 0.577215664901533)\n EulerGamma' assert fcode(E) == ' parameter (E = 2.71828182845905)\n E' assert fcode(GoldenRatio) == ' parameter (GoldenRatio = 1.61803398874989)\n GoldenRatio' assert fcode(pi) == ' parameter (pi = 3.14159265358979)\n pi' assert fcode(pi,precision=5) == ' parameter (pi = 3.1416)\n pi' assert fcode(Catalan,human=False) == ([('Catalan', Catalan.evalf(15))], set([]), ' Catalan') assert fcode(EulerGamma,human=False) == ([('EulerGamma', EulerGamma.evalf(15))], set([]), ' EulerGamma') assert fcode(E,human=False) == ([('E', E.evalf(15))], set([]), ' E') assert fcode(GoldenRatio,human=False) == ([('GoldenRatio', GoldenRatio.evalf(15))], set([]), ' GoldenRatio') assert fcode(pi,human=False) == ([('pi', pi.evalf(15))], set([]), ' pi') assert fcode(pi,precision=5,human=False) == ([('pi', pi.evalf(5))], set([]), ' pi')
def test_fcode_NumberSymbol(): p = FCodePrinter() assert fcode(Catalan) == ' parameter (Catalan = 0.915965594177219d0)\n Catalan' assert fcode(EulerGamma) == ' parameter (EulerGamma = 0.577215664901533d0)\n EulerGamma' assert fcode(E) == ' parameter (E = 2.71828182845905d0)\n E' assert fcode(GoldenRatio) == ' parameter (GoldenRatio = 1.61803398874989d0)\n GoldenRatio' assert fcode(pi) == ' parameter (pi = 3.14159265358979d0)\n pi' assert fcode(pi,precision=5) == ' parameter (pi = 3.1416d0)\n pi' assert fcode(Catalan,human=False) == (set([(Catalan, p._print(Catalan.evalf(15)))]), set([]), ' Catalan') assert fcode(EulerGamma,human=False) == (set([(EulerGamma, p._print(EulerGamma.evalf(15)))]), set([]), ' EulerGamma') assert fcode(E,human=False) == (set([(E, p._print(E.evalf(15)))]), set([]), ' E') assert fcode(GoldenRatio,human=False) == (set([(GoldenRatio, p._print(GoldenRatio.evalf(15)))]), set([]), ' GoldenRatio') assert fcode(pi,human=False) == (set([(pi, p._print(pi.evalf(15)))]), set([]), ' pi') assert fcode(pi,precision=5,human=False) == (set([(pi, p._print(pi.evalf(5)))]), set([]), ' pi')
def test_issue_5383(): func = (1.0 * 1 + 1.0 * x)**(1.0 * 1 / x) assert limit(func, x, 0) == E.n()
# -*- coding: utf-8 -*- """ Created on Mon Jun 24 09:48:39 2019 @author: arianafm """ from sympy import pi, E, oo, cos #E : Euler #oo : Infinito radio = 5 #Sin el evalf la operación queda expresada únicamente. area = pow((pi.evalf() * radio), 2) print(area) #5**3 print(E.evalf()) print(oo.evalf()) # V A R I A B L E S S I M B Ó L I C A S #a #Símbolos x = Symbol('x') y = Symbol('y') print(x) print(y) #Muchos símbolos a la vez a, b, c = symbols('a,b,c') print(a, b, c) #Te devuelve una tupla que va desde q hasta w variables = var('q:w')