Example #1
0
def test_expi_complex():
    dataset = []
    for r in np.logspace(-99, 2, 10):
        for p in np.linspace(0, 2*np.pi, 30):
            z = r*np.exp(1j*p)
            dataset.append((z, complex(mpmath.ei(z))))
    dataset = np.array(dataset, dtype=np.complex_)

    FuncData(sc.expi, dataset, 0, 1).check()
Example #2
0
def test_expi_complex():
    dataset = []
    for r in np.logspace(-99, 2, 10):
        for p in np.linspace(0, 2 * np.pi, 30):
            z = r * np.exp(1j * p)
            dataset.append((z, complex(mpmath.ei(z))))
    dataset = np.array(dataset, dtype=np.complex_)

    FuncData(sc.expi, dataset, 0, 1).check()
def product_term(
    n,
    electron_charge,
    positron_charge,
    vacuum_permativity,
    electron_number_density,
    ionisation_potential,
    initial_energy,
):
    a = (electron_number_density * (positron_charge ** 2) * (electron_charge ** 4)) / \
        (8 * mpmath.pi * (vacuum_permativity ** 2))
    b = 4 / ionisation_potential

    constant_of_integration = mpmath.ei(
        2 * mpmath.ln(b * initial_energy)) / (a * (b**2))
    exp_integral_inv = exponential_integral_inverse(
        a * (b**2) * (constant_of_integration - n))
    denominator = mpmath.e**(exp_integral_inv / 2)
    energy_proportionality_correction = mpmath.sqrt(
        ELECTRON_MASS / (2 * (electron_number_density**2)))

    return 1 - (mpmath.sqrt(
        b / denominator)) / energy_proportionality_correction
def f59(x):
    # expint_Ei_scaled
    return mpmath.ei(x) * mpmath.exp(-x)
def f58(x):
    # expint_Ei
    return mpmath.ei(x)
Example #6
0
def test_negative_values():
    # For negative values `ei` is simply implemented using `e1`, which
    # is tested elsewhere. Just check a single value to make sure we
    # got the connection formula correct.
    assert_allclose(sc.ei(-1), float(mpmath.ei(-1)), atol=0, rtol=_ε)
Example #7
0
    x_str = mpm.nstr(x_mpm, n=n)
    v_str = x_str.split('e')
    try:
        l_m = np.log(np.float(v_str[0]))
        e = np.log(10) * np.float(v_str[1]) if len(v_str) == 2 else 0.0
        mpm.mp.prec, mpm.mp.dps = prec_def, dps_def  # reset
        return l_m + e
    except:  # ValueError:
        s_ut.my_print('pid: ' + str(os.getpid()) +
                      ' ERROR:::erlang_utils::log_gammainc:: a: ' + str(a) +
                      ' lwr: ' + str(lwr) + ' upr: ' + str(upr) + ' dps: ' +
                      str(mpm.mp.dps))
        return None


expi = np.frompyfunc(lambda x: float(mpm.ei(x)), 1, 1)

# #########################################################################
# ########## Framework for recursions and log sums ########################
# #########################################################################


def trampoline(gen, *args, **kwargs):
    g = gen(*args, **kwargs)
    while isinstance(g, types.GeneratorType):
        g = next(g)
    return g


def log_trick(arr):
    # 1. if Y = a1 + a2 + ... , then the log_trick input is an array of the form arr = [[log(|a1|), sign(a1)], [log(|a2|), sign(a2)]], ] ...