Пример #1
0
def derive_mult(expression, respect_to):
    # U dv + V du
    return construct_binary_ast_node(
        label("+"),
        construct_binary_ast_node(label("*"), expression[1], derivative.derive(expression[2], respect_to)),
        construct_binary_ast_node(label("*"), derivative.derive(expression[1], respect_to), expression[2]),
    )
Пример #2
0
def derive_mult(expression, respect_to):
    # U dv + V du
    return construct_binary_ast_node(
        label('+'),
        construct_binary_ast_node(label('*'), expression[1],
                                  derivative.derive(expression[2],
                                                    respect_to)),
        construct_binary_ast_node(label('*'),
                                  derivative.derive(expression[1], respect_to),
                                  expression[2]))
Пример #3
0
def derive_div(expression, respect_to):
    return construct_binary_ast_node(
        label("/"),
        construct_binary_ast_node(
            label("-"),
            construct_binary_ast_node(label("*"), derivative.derive(expression[1], respect_to), expression[2]),
            construct_binary_ast_node(label("*"), expression[1], derivative.derive(expression[2], respect_to)),
        ),
        construct_binary_ast_node(label("*"), expression[2], expression[2]),
    )
Пример #4
0
def derive_pow(expression, respect_to):
    # TODO CURRENTLY ASSUMES A CONSTANT IN THE EXPONENT, FIX THIS
    # TODO WOW THIS METHOD IS BAD, FIX THIS
    return construct_binary_ast_node(
        label('*'), expression[2],
        construct_binary_ast_node(
            label('*'),
            construct_binary_ast_node(
                label('^'), expression[1],
                (str(float(expression[2][0]) - 1), 'CONSTANT')),
            derivative.derive(expression[1], respect_to)))
Пример #5
0
def derive_div(expression, respect_to):
    return construct_binary_ast_node(
        label('/'),
        construct_binary_ast_node(
            label('-'),
            construct_binary_ast_node(
                label('*'), derivative.derive(expression[1], respect_to),
                expression[2]),
            construct_binary_ast_node(
                label('*'), expression[1],
                derivative.derive(expression[2], respect_to)),
        ), construct_binary_ast_node(label('*'), expression[2], expression[2]))
Пример #6
0
def derive_pow(expression, respect_to):
    # TODO CURRENTLY ASSUMES A CONSTANT IN THE EXPONENT, FIX THIS
    # TODO WOW THIS METHOD IS BAD, FIX THIS
    return construct_binary_ast_node(
        label("*"),
        expression[2],
        construct_binary_ast_node(
            label("*"),
            construct_binary_ast_node(label("^"), expression[1], (str(float(expression[2][0]) - 1), "CONSTANT")),
            derivative.derive(expression[1], respect_to),
        ),
    )