예제 #1
0
파일: integration.py 프로젝트: cplally/CAS
def integrate(expr, var):
    def sub_int(expr, var):
        try:
            if not isinstance(expr, ParseTree):
                return int_rules[type(expr)](expr, var)
            else:
                return int_rules[type(expr.root)](expr, var)
        except KeyError:
            print(expr)
            print('No rule to integrate given expression')
        
    return reduce(sub_int(expr, var))
예제 #2
0
def diff(expr, var):
    '''
    Apply the differentiation rules given in diff_rules to expr_tree.
    '''
    def sub_diff(expr, var):
        try:
            if not isinstance(expr, ParseTree):
                return diff_rules[type(expr)](expr, var)
            else:
                return diff_rules[type(expr.root)](expr, var)
        except KeyError:
            print(expr)
            print('No rule to differentiate given expression -- check input')
    
    return reduce(sub_diff(expr, var))