コード例 #1
0
def test_sympyissue_8821():
    s = str(pi.evalf(128))
    p = N(s)
    assert abs(sin(p)) < 1e-15
    p = N(s, 64)
    assert abs(sin(p)) < 1e-64
    s = str(pi.evalf(128))
    p = sympify(s)
    assert abs(sin(p)) < 1e-127
コード例 #2
0
ファイル: test_codegen.py プロジェクト: Blendify/diofant
def test_intrinsic_math1_codegen():
    # not included: log10
    name_expr = [
        ("test_fabs", abs(x)),
        ("test_acos", acos(x)),
        ("test_asin", asin(x)),
        ("test_atan", atan(x)),
        ("test_cos", cos(x)),
        ("test_cosh", cosh(x)),
        ("test_log", log(x)),
        ("test_ln", ln(x)),
        ("test_sin", sin(x)),
        ("test_sinh", sinh(x)),
        ("test_sqrt", sqrt(x)),
        ("test_tan", tan(x)),
        ("test_tanh", tanh(x)),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval in 0.2, 0.5, 0.8:
            expected = N(expr.subs(x, xval), strict=False)
            numerical_tests.append((name, (xval, ), expected, 1e-14))
    for lang, commands in valid_lang_commands:
        if lang == "C":
            name_expr_C = [("test_floor", floor(x)), ("test_ceil", ceiling(x))]
        else:
            name_expr_C = []
        run_test("intrinsic_math1", name_expr + name_expr_C, numerical_tests,
                 lang, commands)
コード例 #3
0
def test_lognormal():
    mean = Symbol('mu', real=True)
    std = Symbol('sigma', positive=True, real=True)
    X = LogNormal('x', mean, std)
    # The diofant integrator can't do this too well
    # assert E(X) == exp(mean+std**2/2)
    # assert variance(X) == (exp(std**2)-1) * exp(2*mean + std**2)

    # Right now, only density function and sampling works
    # Test sampling: Only e^mean in sample std of 0
    for i in range(3):
        X = LogNormal('x', i, 0)
        assert sample(X) == N(exp(i))
    # The diofant integrator can't do this too well
    # assert E(X) ==

    mu = Symbol('mu', extended_real=True)
    sigma = Symbol('sigma', positive=True)

    X = LogNormal('x', mu, sigma)
    assert density(X)(x) == (sqrt(2)*exp(-(-mu + log(x))**2
                                         / (2*sigma**2))/(2*x*sqrt(pi)*sigma))

    X = LogNormal('x', 0, 1)  # Mean 0, standard deviation 1
    assert density(X)(x) == sqrt(2)*exp(-log(x)**2/2)/(2*x*sqrt(pi))
コード例 #4
0
ファイル: test_codegen.py プロジェクト: fagan2888/diofant
def test_intrinsic_math1_codegen():
    # not included: log10
    name_expr = [
        ('test_fabs', abs(x)),
        ('test_acos', acos(x)),
        ('test_asin', asin(x)),
        ('test_atan', atan(x)),
        ('test_cos', cos(x)),
        ('test_cosh', cosh(x)),
        ('test_log', log(x)),
        ('test_ln', ln(x)),
        ('test_sin', sin(x)),
        ('test_sinh', sinh(x)),
        ('test_sqrt', sqrt(x)),
        ('test_tan', tan(x)),
        ('test_tanh', tanh(x)),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval in 0.2, 0.5, 0.8:
            expected = N(expr.subs({x: xval}), strict=False)
            numerical_tests.append((name, (xval, ), expected, 1e-14))
    for lang, commands in valid_lang_commands:
        if lang == 'C':
            name_expr_C = [('test_floor', floor(x)), ('test_ceil', ceiling(x))]
        else:
            name_expr_C = []
        run_test('intrinsic_math1', name_expr + name_expr_C, numerical_tests,
                 lang, commands)
コード例 #5
0
ファイル: test_codegen.py プロジェクト: Blendify/diofant
def test_instrinsic_math2_codegen():
    # not included: frexp, ldexp, modf, fmod
    name_expr = [
        ("test_atan2", atan2(x, y)),
        ("test_pow", x**y),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval, yval in (0.2, 1.3), (0.5, -0.2), (0.8, 0.8):
            expected = N(expr.subs(x, xval).subs(y, yval), strict=False)
            numerical_tests.append((name, (xval, yval), expected, 1e-14))
    for lang, commands in valid_lang_commands:
        run_test("intrinsic_math2", name_expr, numerical_tests, lang, commands)
コード例 #6
0
ファイル: test_codegen.py プロジェクト: fagan2888/diofant
def test_complicated_codegen():
    name_expr = [
        ('test1', ((sin(x) + cos(y) + tan(z))**7).expand()),
        ('test2', cos(cos(cos(cos(cos(cos(cos(cos(x + y + z))))))))),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval, yval, zval in (0.2, 1.3, -0.3), (0.5, -0.2, 0.0), (0.8, 2.1,
                                                                     0.8):
            expected = N(expr.subs({x: xval, y: yval, z: zval}), strict=False)
            numerical_tests.append((name, (xval, yval, zval), expected, 1e-12))
    for lang, commands in valid_lang_commands:
        run_test('complicated_codegen', name_expr, numerical_tests, lang,
                 commands)
コード例 #7
0
def test_complicated_codegen():
    from diofant import sin, cos, tan, N
    name_expr = [
        ("test1", ((sin(x) + cos(y) + tan(z))**7).expand()),
        ("test2", cos(cos(cos(cos(cos(cos(cos(cos(x + y + z))))))))),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval, yval, zval in (0.2, 1.3, -0.3), (0.5, -0.2, 0.0), (0.8, 2.1, 0.8):
            expected = N(expr.subs(x, xval).subs(y, yval).subs(z, zval))
            numerical_tests.append((name, (xval, yval, zval), expected, 1e-12))
    for lang, commands in valid_lang_commands:
        run_test(
            "complicated_codegen", name_expr, numerical_tests, lang, commands)
コード例 #8
0
def test_issue_8821_highprec_from_str():
    s = str(pi.evalf(128))
    p = N(s)
    assert Abs(sin(p)) < 1e-15
    p = N(s, 64)
    assert Abs(sin(p)) < 1e-64