コード例 #1
0
def expands_power_base(expression):
    '''
    Invoke identity (1) and (2)
    The function expand the power of the
    base in the expression
    '''
    return expand_power_base(expression)
コード例 #2
0
def calc_eruption_density():

    _ = calc_hydrostatic_density()
    _ = _.subs(x, calc_eruption_depth())
    _ = sympy.expand_power_base(_, force=True)
    _ = _.simplify()
    return _
コード例 #3
0
def calc_eruption_mass():

    _ = calc_eruption_density()
    _ = _*x**3
    _ = _.subs(x, calc_eruption_depth())
    _ = sympy.expand_power_base(_, force=True)
    _ = _.simplify()
    return _
コード例 #4
0
def derive_breakup_lorentz_factor():

    _ = calc_asymptotic_gamma()
    _ = _.subs({nu:2, eta:sympy.Rational(4,3)})
    _ = _.subs(t, derive_fluid_frame_breakup_time())
    _ = _.subs(p_i, rho_b0*c**2*gamma_i**2)
    _ = sympy.expand_power_base(_, force=True)
    _ = _.simplify()
    return _
コード例 #5
0
def test_issue_19627():
    # if you use force the user must verify
    assert powdenest(sqrt(sin(x)**2), force=True) == sin(x)
    assert powdenest((x**(S.Half / y))**(2 * y), force=True) == x
    from sympy import expand_power_base
    e = 1 - a
    expr = (exp(z / e) * x**(b / e) * y**((1 - b) / e))**e
    assert powdenest(expand_power_base(expr, force=True),
                     force=True) == x**b * y**(1 - b) * exp(z)
コード例 #6
0
def calc_asymptotic_gamma():

    xi = sympy.Symbol('xi', positive=True)
    Gamma = sympy.Symbol('Gamma', positive=True)

    ri = prepare_ri()
    _ = make_equation_of_motion()
    _ = _.subs(A, (alpha*t*c)**2)
    _ = _.subs(M, M_1*(p/p_i)**(1-1/eta))
    _ = _.subs(sympy.solve(ri-1, p,dict=True)[0])
    _ = _.subs(gamma(t).diff(t), gamma(t)/t)
    _ = _.subs(gamma(t), Gamma)
    _ = sympy.expand_power_base(_,force=True)
    _ = _.subs(eta, xi**2+1)
    _ = sympy.solve(_, Gamma)[0]
    _ = sympy.expand_power_base(_, force=True).simplify()
    _ = _.subs(xi,sympy.sqrt(eta-1))
    return _
コード例 #7
0
def derive_fluid_frame_breakup_time():

    _ = derive_instability_growth()
    _ = _.subs(p_i, rho_b0*c**2*gamma_i**2)
    _ = _.subs({eta:sympy.Rational(4,3),
                nu:2})
    _ = _.simplify()
    _ = sympy.solve(_ - 1, t)[0]
    _ = sympy.expand_power_base(_, force=True)
    _ = _.simplify()
    return _
コード例 #8
0
def calc_pressure_history():

    xi = sympy.Symbol('xi', positive=True)

    gamma_sol = calc_asymptotic_gamma()
    ri = prepare_ri()
    _ = sympy.solve(ri-1, p)[0]
    _ = _.subs(gamma(t), gamma_sol)
    _ = _.subs(eta, xi**2+1)
    _ = sympy.expand_power_base(_, force=True)
    _ = _.simplify()
    _ = _.subs(xi, sympy.sqrt(eta-1))
    return _
コード例 #9
0
def extra_simple(mul):
    """Simplification of pysb rates
    
    Arguments:
        mul: psyb reaction (sympy.Mul object)
    
    Returns:
        a simplified version denested of exponents. 
        TODO: make sure it fully simplifies!
    """
    return sp.powsimp((sp.expand_power_base(sp.powdenest(sp.logcombine(
        sp.expand_log(mul.simplify(), force=True), force=True),
                                                         force=True),
                                            force=True)),
                      force=True)
コード例 #10
0
    def define_z_eqns(self) -> None:
        r"""
        Form a polynomial-type ODE in $\hat{z}(\hat{x})$.

        Attributes:
            dzdx_Ci_polylike_eqn
        """
        logging.info("gme.core.profile.define_z_eqns")
        tmp_eqn = Eq(
            (xiv / varphi_r(rvec)),
            solve(
                simplify(
                    self.pz_varphi_beta_eqn.subs(e2d(self.pz_xiv_eqn)).subs(
                        {Abs(sin(beta)): sin(beta)})),
                xiv,
            )[0] / varphi_r(rvec),
        )
        self.xiv_eqn = tmp_eqn.subs({
            sin(beta): sqrt(1 - cos(beta)**2)
        }).subs({cos(beta): sqrt(1 / (1 + tan(beta)**2))})
        self.xvi_abs_eqn = factor(
            Eq(self.xiv_eqn.lhs**4, (self.xiv_eqn.rhs)**4))

        self.dzdx_polylike_eqn = self.xvi_abs_eqn.subs({tan(beta): dzdx})

        self.dzdx_Ci_polylike_prelim_eqn = (expand_power_base(
            self.dzdx_polylike_eqn.subs(e2d(self.varphi_rx_eqn)).subs(
                e2d(self.varphi0_Lc_xiv0_Ci_eqn)).subs({
                    xiv: xiv_0
                }).subs({
                    varepsilon: varepsilonhat * Lc
                }).subs({
                    rx: xhat * Lc
                }).subs({
                    (Lc * varepsilonhat - Lc * xhat + Lc):
                    (Lc * (varepsilonhat - xhat + 1))
                }))).subs({Abs(dzdx): dzdx})

        self.dzdx_Ci_polylike_eqn = Eq(
            self.dzdx_Ci_polylike_prelim_eqn.rhs * ((dzdx**2 + 1)**(2 * eta)) -
            self.dzdx_Ci_polylike_prelim_eqn.lhs * ((dzdx**2 + 1)**(2 * eta)),
            0,
        ).subs({pzhat_0: 1 / xivhat_0})
コード例 #11
0
ファイル: test_subtraction.py プロジェクト: gudrunhe/secdec
    def test_integrate_pole_part(self):
        for j in (0, 1):
            for i, I_j_before in enumerate([
                    Product(self.monomial_product1, self.regulator_poles,
                            self.cal_I),
                    Product(self.monomial_product2, self.regulator_poles,
                            self.cal_I)
            ]):
                I_j_after = integrate_pole_part(I_j_before, j)
                I_j_pole_part = Sum(*I_j_after[:-1])
                I_j_numerically_integrable_part = I_j_after[-1]

                if j == 0:
                    expected_pole_part = sympify_expression('''
                                                         (  1/(-2 + 0 + 1 - eps0 - 3*eps1) * (A + B*x0 + C*x0**2*x1 + D*x1) +
                                                            1/(-2 + 1 + 1 - eps0 - 3*eps1) * (B + 2*C*x0*x1)  ) * (x1**2)**(-2 - eps0 - 3*eps1)
                                                    ''').subs('x0', 0)

                    expected_numerical_integrand = (
                        sympify_expression(str(self.cal_I)) -
                        sympify_expression('A + D*x1 + x0*B')
                    ) * sympify_expression(str(self.exponentiated_monomial1))

                    if i == 0:
                        for summand in I_j_pole_part.summands:
                            np.testing.assert_array_equal(
                                summand.factors[0].factors[0].expolist,
                                [(0, 2, 0, 0)])
                            np.testing.assert_array_equal(
                                summand.factors[0].factors[0].coeffs, [1])
                            self.assertEqual(
                                sympify_expression(
                                    str(summand.factors[0].factors[0].exponent)
                                ) - sympify_expression('-2 - eps0 - 3*eps1'),
                                0)
                    elif i == 1:
                        for summand in I_j_pole_part.summands:
                            np.testing.assert_array_equal(
                                summand.factors[0].factors[0].expolist,
                                [(0, 2, 0, 0)])
                            np.testing.assert_array_equal(
                                summand.factors[0].factors[1].expolist,
                                [(0, 4, 0, 0)])
                            np.testing.assert_array_equal(
                                summand.factors[0].factors[0].coeffs, [1])
                            np.testing.assert_array_equal(
                                summand.factors[0].factors[1].coeffs, [1])
                            self.assertEqual(
                                sympify_expression(
                                    str(summand.factors[0].factors[0].exponent)
                                ) - sympify_expression(-2), 0)
                            self.assertEqual(
                                sympify_expression(
                                    str(summand.factors[0].factors[1].exponent)
                                ) - sympify_expression('- eps0 - 3*eps1') / 2,
                                0)
                    else:
                        raise IndexError('`i` should only run over `(0,1)`!')

                elif j == 1:
                    expected_pole_part = sympify_expression('''
                                                         (  1/( 2*(-2 - eps0 - 3*eps1) + 0 + 1 ) * (A + B*x0 + C*x0**2*x1 + D*x1) +
                                                            1/( 2*(-2 - eps0 - 3*eps1) + 1 + 1 ) * (C*x0**2 + D) +
                                                            0  ) * x0**(-2 - eps0 - 3*eps1)
                                                    ''').subs('x1', 0)

                    expected_numerical_integrand = (
                        sympify_expression(str(self.cal_I)) -
                        sympify_expression('A + B*x0 + C*x0**2*x1 + D*x1')
                    ) * sympify_expression(str(self.exponentiated_monomial1))

                else:
                    raise IndexError('`j` should only run over `(0,1)`!')

                self.assertEqual(
                    sp.powdenest((sympify_expression(str(I_j_pole_part)) -
                                  expected_pole_part),
                                 force=True).simplify(), 0)
                for summand in I_j_pole_part.summands:
                    self.assertEqual(type(summand), Product)
                    self.assertEqual(type(summand.factors[0]), Product)
                    for factor in summand.factors[0].factors:
                        self.assertEqual(type(factor), ExponentiatedPolynomial)

                self.assertEqual(type(I_j_numerically_integrable_part),
                                 Product)
                self.assertEqual(
                    type(I_j_numerically_integrable_part.factors[0]), Product)
                for factor in I_j_numerically_integrable_part.factors[
                        0].factors:
                    self.assertEqual(type(factor), ExponentiatedPolynomial)
                should_be_zero = (
                    sympify_expression(I_j_numerically_integrable_part) -
                    expected_numerical_integrand).simplify()
                if i == 1:
                    # need some simplifications that are not generally true for all complex numbers
                    # see http://docs.sympy.org/dev/tutorial/simplification.html#powers for a discussion
                    should_be_zero = sp.expand_power_base(should_be_zero,
                                                          force=True)
                    should_be_zero = sp.powdenest(should_be_zero, force=True)
                self.assertEqual(should_be_zero, 0)