示例#1
0
def split_affine(expr):
    """
    Split an affine scalar function into its three components, namely variable,
    coefficient, and translation from origin.

    Raises
    ------
    ValueError
        If ``expr`` is non affine.
    """
    if expr.is_Number:
        return AffineFunction(None, None, expr)

    # Handle super-quickly the calls like `split_affine(x+1)`, which are
    # the majority.
    if expr.is_Add and len(expr.args) == 2:
        if expr.args[0].is_Number and expr.args[1].is_Symbol:
            # SymPy deterministically orders arguments -- first numbers, then symbols
            return AffineFunction(expr.args[1], 1, expr.args[0])

    # Fallback
    poly = expr.as_poly()
    if not (poly.is_univariate and poly.is_linear) or not LM(poly).is_Symbol:
        raise ValueError
    return AffineFunction(LM(poly), LC(poly), poly.TC())
示例#2
0
def split_affine(expr):
    """
    split_affine(expr)

    Split an affine scalar function into its three components, namely variable,
    coefficient, and translation from origin.

    :raises ValueError: If ``expr`` is non affine.
    """
    if expr.is_Number:
        return AffineFunction(None, None, expr)
    poly = expr.as_poly()
    if not (poly.is_univariate and poly.is_linear) or not LM(poly).is_Symbol:
        raise ValueError
    return AffineFunction(LM(poly), LC(poly), poly.TC())
示例#3
0
def sectionSeparate(formula, lmax):
    x = symbols('x', real=True)
    pos = set([
        x - LM(f).args[0] for f in Add.make_args(formula)
        if len(f.atoms(StepFunc))
    ])
    pos.update([0, lmax])
    pos = list(sorted(pos))
    st = 0
    formularr = []
    # print("Line Segment Function")
    for en in pos[1:]:
        # print(formula.expand(lim=st, func=True))
        formularr.append((formula.expand(lim=st, func=True), (x, st, en)))
        st = en
    return formularr
def calS(f, g, t):
    x_gamma = lcm(LM(f, order=t), LM(g, order=t))
    S = x_gamma / LT(f, order=t) * f - x_gamma / LT(g, order=t) * g
    return S
def s_polynomial(f, g):
    return expand(lcm(LM(f), LM(g)) * (1 / LT(f) * f - 1 / LT(g) * g))