예제 #1
0
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])
예제 #2
0
def simp_rules(db):

    db.tell(

        simp(X, X) <<
            atomic(X) & cut,

        simp(--X, Y) <<
            simp(X, Y) & cut,

        simp(-A + -B, C) <<
            simp(A + B, C1) &
            simp(-C1, C) & cut,

        simp(-A + B, C) <<
            simp(B - A, C) & cut,

        simp(A + -B, C) <<
            simp(A - B, C) & cut,

        simp(-A - -B, C) <<
            simp(B - A, C) & cut,

        simp(-A - B, C) <<
            simp(-A + -B, C) & cut,

        simp(A - -B, C) <<
            simp(A + B, C) & cut,

        simp(-A * -B, C) <<
            simp(A * B, C) & cut,

        simp(-A * B, C) <<
            simp(A * B, C1) &
            simp(-C1, C) & cut,

        simp(A * -B, -C) <<
            simp(A * B, C1) &
            simp(-C1, C) & cut,

        simp(X + 0, Y) <<
            simp(X, Y) & cut,

        simp(0 + X, Y) <<
            simp(X, Y) & cut,

        simp(X - 0, Y) <<
            simp(X, Y) & cut,

        simp(0 - X, -Y) <<
            simp(X, Y) & cut,

        simp(A + B, C) <<
            numeric(A) &
            numeric(B) &
            let(C, A + B) & cut,

        simp(A - A, 0) << cut,

        simp(A - B, C) <<
            numeric(A) &
            numeric(B) &
            let(C, A - B) & cut,

        simp(X * 0, 0) << cut,

        simp(0 * X, 0) << cut,

        simp(0 / X, 0) << cut,

        simp(X * 1, X) << cut,

        simp(1 * X, X) << cut,

        simp(X / 1, X) << cut,

        simp(X / X, 1) << cut,

        simp(X ** 1, X) << cut,

        simp(X ** 0, 1) << cut,

        simp(A + A + B, Y) <<
            simp(2 * A + B, Y) & cut,

        simp(A + B + A, 2 * A + B) <<
            simp(2 * A + B, Y) & cut,

        simp(B + A + A, 2 * A + B) <<
            simp(2 * A + B, Y) & cut,

        simp(A + (B + C), D) <<
            simp(A + B + C, D) & cut,

        simp(A * (B * C), D) <<
            simp(A * B * C, D) & cut,

        simp(X * X, X ** 2) << cut,

        simp(X * X ** A, Y) <<
            simp(X ** (A + 1), Y) & cut,

        simp(X ** A * X, Y) <<
            simp(X ** (A + 1), Y) & cut,

        simp(A * B + A * C, Y) <<
            simp(A * (B + C), Y) & cut,

        simp(A * B + C * A, Y) <<
            simp(A * (B + C), Y) & cut,

        simp(A * B + B * C, Y) <<
            simp(B * (A + C), Y) & cut,

        simp(A * B + C * B, Y) <<
            simp(B * (A + C), Y) & cut,

        simp(A * (A + B), A ** 2 + A * Y) <<
            simp(B, Y) & cut,

        simp(A * (B + A), A ** 2 + A * Y) <<
            simp(B, Y) & cut,

        simp(A * B, X) <<
            numeric(A) &
            numeric(B) &
            let(X, A * B) & cut,

        simp(A * X + B * X, Z) <<
            unequal(A, X) &
            unequal(B, X) &
            simp((A + B) * X, Z) & cut,

        simp((A + B) * (A - B), X ** 2 - Y ** 2) <<
            simp(A, X) &
            simp(B, Y) & cut,

        simp(X ** A / X ** B, X ** C) <<
            numeric(A) &
            numeric(B) &
            let(C, A - B) & cut,

        simp(A / B, X) <<
            numeric(A) &
            numeric(B) &
            let(X, A / B) & cut,

        simp(A ** B, X) <<
            numeric(A) &
            numeric(B) &
            let(X, A ** B) & cut,

        simp(A + B, C) <<
            simp(A, X) &
            simp(B, Y) &
            unequal([A, B], [X, Y]) &
            simp(X + Y, C) & cut,

        simp(A - B, C) <<
            simp(A, X) &
            simp(B, Y) &
            unequal([A, B], [X, Y]) &
            simp(X - Y, C) & cut,

        simp(A * B, C) <<
            simp(A, X) &
            simp(B, Y) &
            unequal([A, B], [X, Y]) &
            simp(X * Y, C) & cut,

        simp(A / B, C) <<
            simp(A, X) &
            simp(B, Y) &
            unequal([A, B], [X, Y]) &
            simp(X / Y, C) & cut,

        simp(X ** A, C) <<
            simp(A, B) &
            unequal(A, B) &
            simp(X ** B, C) & cut,

        simp(X, X) << cut,

    )