Exemplo n.º 1
0
def p_formula_subtract(t):
    """formula_subtract : NUMBER '-' NUMBER
                        | formula '-' NUMBER
                        | formula '-' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] - t[3]
    elif is_number(t[1]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('add', ([t[1]], {})), t[3].ast),
            t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('add', ([-t[3]], {})), t[1].ast),
            t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator([
                    stream.get_operator('paste', ([], {
                        'sort': None
                    })),
                    stream.get_operator('diff', ([], {
                        'axis': 1
                    }))
                ]), t[3].ast, t[1].ast), t[3].restrict + t[1].restrict)
Exemplo n.º 2
0
def p_formula_multiply(t):
    """formula_multiply : NUMBER '*' formula
                        | formula '*' NUMBER
                        | NUMBER '*' NUMBER
                        | formula '*' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] * t[3]
    elif is_number(t[1]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('multiply', ([t[1]], {})),
                          t[3].ast), t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('multiply', ([t[3]], {})),
                          t[1].ast), t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator([
                    stream.get_operator('paste', ([], {
                        'sort': None
                    })),
                    stream.get_operator('product', ([], {
                        'axis': 1
                    }))
                ]), t[1].ast, t[3].ast), t[1].restrict + t[3].restrict)
Exemplo n.º 3
0
def p_formula_multiply(t):
    """formula_multiply : NUMBER '*' formula
                        | formula '*' NUMBER
                        | NUMBER '*' NUMBER
                        | formula '*' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] * t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator("multiply", ([t[1]], {})), t[3].ast), t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator("multiply", ([t[3]], {})), t[1].ast), t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator(
                    [
                        stream.get_operator("paste", ([], {"sort": None})),
                        stream.get_operator("product", ([], {"axis": 1})),
                    ]
                ),
                t[1].ast,
                t[3].ast,
            ),
            t[1].restrict + t[3].restrict,
        )
Exemplo n.º 4
0
def p_formula_subtract(t):
    """formula_subtract : NUMBER '-' NUMBER
                        | formula '-' NUMBER
                        | formula '-' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] - t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator('add', ([t[1]], {})), t[3].ast),
                       t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator('add', ([- t[3]], {})), t[1].ast),
                       t[1].restrict)
    else:
        t[0] = formula(ast.nodemaker(operators.make_composition_operator(
                    [stream.get_operator('paste', ([], {'sort': None})),
                     stream.get_operator('diff', ([], {'axis': 1}))]),
                                     t[3].ast, t[1].ast),
                       t[3].restrict + t[1].restrict)
Exemplo n.º 5
0
def p_formula_multiply(t):
    """formula_multiply : NUMBER '*' formula
                        | formula '*' NUMBER
                        | NUMBER '*' NUMBER
                        | formula '*' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] * t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator('multiply', ([t[1]], {})), t[3].ast),
                       t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator('multiply', ([t[3]], {})), t[1].ast),
                       t[1].restrict)
    else:
        t[0] = formula(ast.nodemaker(operators.make_composition_operator(
                    [stream.get_operator('paste', ([], {'sort': None})),
                     stream.get_operator('product', ([], {'axis': 1}))]),
                                     t[1].ast, t[3].ast),
                       t[1].restrict + t[3].restrict)
Exemplo n.º 6
0
def p_formula_subtract(t):
    """formula_subtract : NUMBER '-' NUMBER
                        | formula '-' NUMBER
                        | formula '-' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] - t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator("add", ([t[1]], {})), t[3].ast), t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator("add", ([-t[3]], {})), t[1].ast), t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator(
                    [stream.get_operator("paste", ([], {"sort": None})), stream.get_operator("diff", ([], {"axis": 1}))]
                ),
                t[3].ast,
                t[1].ast,
            ),
            t[3].restrict + t[1].restrict,
        )
Exemplo n.º 7
0
def make_operator(name, args, where=None):
    if where == None:
        return stream.get_operator(name, args)
    else:
        return operators.make_composition_operator(
            [where, stream.get_operator(name, args)])
Exemplo n.º 8
0
def make_operator(name, args, where=None):
    if where == None:
        return stream.get_operator(name, args)
    else:
        return operators.make_composition_operator(
            [where, stream.get_operator(name, args)])