import sympy as smp
from sympy import *

def prgrm_iter():
    x, k, n, h = smp.symbols ('x k n h')
    f = smp.sin(x)

    print (" ")
    print ("This program comes from the GitHub repository")
    print ("AndreiMurashev/pos.int_diff_formula")
    print (" ")
    print ("The purpose of this program is to check if the formula")
    print ("for the derivative of a certain positive integer order holds")
    print (" ")

    print ("For which positive integer case would you like to check")
    n = int(input("if the formula works?: "))

    d = diff(f, x, n)
    D = smp.limit((smp.Sum(((-1)**k)*(smp.binomial(n,k))*(f.subs(x,x+(n-k)*h)), (k, 0, n)).doit())/(h**n), h, 0)
    print(d," ?=? ", D)
    print (" ")

    if d == D:
        print (d," = ", D)
        print ("[VALID]: The formula holds for the derivative of order", n)

    if d != D:
        print (d," =/= ", D)
        print ("[INVALID]: The formula fails for the derivative of order", n)
        print ("Please screenshot this and email the creator of the GitHub repository")


def prgrm():
    while True:
        prgrm_iter()
        ans = input("Repeat? (y/n): ")
        if ans != "y":
            break


if __name__ == '__main__':
    try:
        prgrm()
    finally:
        input("Done. Press any key to exit: ")
