def test_builder(): from hornet import build_term from hornet.symbols import _, f, a, b, c, d, e, X, Y, Z print(build_term(a)) print(build_term(f(a, b) << b & c & d)) print(build_term(f(X, Y) << b(X) & c(Y) & d)) print(build_term(f(X, Y) << b(X) & c(Y) & d(_, Z, [e, d | a]))) print(build_term(f(X, Y) << b(X) & c(Y) & d(_, Z, [e, d | [a]]))) print(build_term(a * (b + c)))
def diff_test(db): F = x ** -3 + 2 * x ** 2 + 7 * (x + 9) #F = --x #F = 5 + x * 3 + 5 * x ** 4 * 5 #F = (2 + x) ** 3 #F = x * y * (x + 3) print(build_term(F)) for subst in db.ask(simp(F, A) & d(A, x, B) & simp(B, C)): pass print(subst[A]) print(subst[B]) print(subst[C])
def diff_rules(db): db.tell( d(X, X, 1) << cut, d(C, X, 0) << atomic(C) & cut, d(U + V, X, A + B) << d(U, X, A) & d(V, X, B) & cut, d(U - V, X, A - B) << d(U, X, A) & d(V, X, B) & cut, d(C * U, X, C * A) << atomic(C) & unequal(C, X) & d(U, X, A) & cut, d(U * V, X, B * U + A * V) << d(U, X, A) & d(V, X, B) & cut, d(U / V, X, (A * V - B * U) / (V * V)) << d(U, X, A) & d(V, X, B) & cut, d(U ** C, X, C * A * U ** (C - 1)) << atomic(C) & unequal(C, X) & d(U, X, A) & cut, d(U ** -C, X, -C * A * U ** (-C - 1)) << d(U, X, A) & cut, d(U ** C, X, C * A * U ** (C - 1)) << equal(C, -C1) & atomic(C1) & unequal(C1, X) & d(U, X, A) & cut, d(sin(W), X, Z * cos(W)) << d(W, X, Z) & cut, d(exp(W), X, Z * exp(W)) << d(W, X, Z) & cut, d(log(W), X, Z / W) << d(W, X, Z) & cut, d(cos(W), X, -(Z * sin(W))) << d(W, X, Z) & cut, )