diff --git a/app_functions.py b/app_functions.py index 3fabad7ee3d567a8e654971ef5c48c98741452f5..7a8bbf0fae00e70caf31bc57f12ab06f16af3f5b 100644 --- a/app_functions.py +++ b/app_functions.py @@ -53,23 +53,33 @@ def dec_to_lambda_relative_integers(number): return pair(TRUE,dec_to_church(number)) return pair(FALSE, dec_to_church(number)) -# def succ(n):#done -# return beta_reduction_totale(new_app(SUCCS,n),None,False) +def succ(n):#done + return beta_reduction_totale(new_app(SUCCS,n),'arithmetic expressions',True) -# def add(n,m):#done -# return beta_reduction_totale(new_app(new_app(ADD,n),m),None,False) +def add(n,m):#done + return beta_reduction_totale(new_app(new_app(ADD,n),m),'arithmetic expressions',True) -# def power(n,m):# done -# return beta_reduction_totale(new_app((new_app(POW, n)),m),None,False) +def power(n,m):# done + return beta_reduction_totale(new_app((new_app(POW, n)),m),'arithmetic expressions',True) -# def multiplication(n,m):#done -# return beta_reduction_totale(new_app(new_app(MUL,n),m),None,False) +def multiplication(n,m):#done + return beta_reduction_totale(new_app(new_app(MUL,n),m),'arithmetic expressions',True) -# def is_zero(n):#done -# return beta_reduction_totale(new_app(IS_ZERO,n),None,False) +def is_zero(n):#done + return beta_reduction_totale(new_app(IS_ZERO,n),'arithmetic expressions',True) -#def predec(n):#done -# return beta_reduction_totale(new_app(PRED, n),None,True) +def predec(n):#done + return beta_reduction_totale(new_app(PRED, n),'arithmetic expressions',True) + +def sub(n,m): + return beta_reduction_totale(new_app(new_app(SUB,n),m),'arithmetic expressions',True) #print(to_string(beta_reduction_totale(new_app(new_app(XOR,TRUE),FALSE),None,False))) -#print(to_string(dec_to_lambda_relative_integers(5))) \ No newline at end of file +#print(to_string(dec_to_lambda_relative_integers(5))) + +# ajouter les etoiles sur les alligators qui Maangent +# ajoter les sauvegardes +# ajouter le predec .... +# terme qui termine pas +#probleme de l arret + diff --git a/logic.py b/logic.py index c24f4f864870c6c3cc30d410130b6343d69fbc55..b6d0887594033eb353e3c06c1cdd84a8bd53b5ab 100644 --- a/logic.py +++ b/logic.py @@ -235,23 +235,45 @@ def captureImage(terme, path, counter=True, date= True): image_maker.saveImage(image_maker.createImage(terme),str(counter),path,date) image_counter += 1 +def recognize_term(terme): + if isApplication(terme): + first=getFirstTerm(terme) + second= getSecondTerm(terme) + if isAbstraction(first) and isAbstraction(second) : + a=getOutputFromAbs(first) + b=getOutputFromAbs(second) + if isApplication(a) and isApplication(b): + if isVariable(getFirstTerm(a)) and isVariable(getSecondTerm(a)) and isVariable(getFirstTerm(b)) and isVariable(getSecondTerm(b)): + if getFirstTerm(a)==getSecondTerm(a) and getFirstTerm(b)==getSecondTerm(b): + if getFirstTerm(a)==getInputFromAbs(first) and getFirstTerm(b)==getInputFromAbs(second): + return True + else: + return False + else: + return False + else: + return False + else: + return False + else: + return False + else: + return False + def beta_reduction_totale(terme, path, saveImages=True): - if saveImages==False: + if recognize_term(terme): + print("reduction infinie detectée ") + return terme + elif saveImages==False: if beta_reduction(terme) != None: return beta_reduction_totale(beta_reduction(terme), path, False) return (terme) else: if path == None: - if annotate_reductor(terme) != None: - captureImage(annotate_reductor(terme), None) - else: - captureImage(terme, None) + captureImage(terme, None) else: - if annotate_reductor(terme) != None: - captureImage(annotate_reductor(terme), path) - else: - captureImage(terme,path) + captureImage(terme,path) if beta_reduction(terme) != None: return beta_reduction_totale(beta_reduction(terme), path) return (terme) @@ -461,11 +483,13 @@ def beta_reduction_choice_n(terme,n): return new_app(A1,beta_reduction_choice_n(B1,n)) if A2 == None and B2 == None: return None - def beta_reduction_interactive(terme, at): global counters + if recognize_term(terme): + print(" reduction interminable detectee") + return terme if at != None: - print(annotated_to_string(at)) + # print(annotated_to_string(at)) choice = int(input("Choose a beta reduction: ")) while choice <= 0 or choice > counters: print("Invalid choice") diff --git a/main.py b/main.py index 3a46111d0376c73b17b35d6f90e584043d15c719..934f6ad67a7f58cb7f05a86ed6dde5862bf26508 100644 --- a/main.py +++ b/main.py @@ -309,6 +309,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.ADD)) logic.captureImage(app_functions.ADD,path,'ADD', False) + choix=(input("do you want to try an exemple? (y/n) : ")) + while choix not in ['y','n']: + choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') + if choix=='y': + clear() + print("you are going to try n+m") + n=int(input("give n : ")) + m=int(input("give m : ")) + app_functions.add(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) save_image_choice = input('Do you want to save the images? (y/n): ') while save_image_choice not in ['y','n']: save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') @@ -324,6 +333,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.SUB)) logic.captureImage(app_functions.SUB,path,'SUB', False) + choix=(input("do you want to try an exemple? (y/n) : ")) + while choix not in ['y','n']: + choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') + if choix=='y': + clear() + print("you are going to try n-m") + n=int(input("give n : ")) + m=int(input("give m : ")) + app_functions.sub(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) save_image_choice = input('Do you want to save the images? (y/n): ') while save_image_choice not in ['y','n']: save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') @@ -339,6 +357,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.MUL)) logic.captureImage(app_functions.MUL,path,'MUL',False) + choix=(input("do you want to try an exemple? (y/n) : ")) + while choix not in ['y','n']: + choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') + if choix=='y': + clear() + print("you are going to try n*m") + n=int(input("give n : ")) + m=int(input("give m : ")) + app_functions.mul(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) save_image_choice = input('Do you want to save the images? (y/n): ') while save_image_choice not in ['y','n']: save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') @@ -354,6 +381,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.POW)) logic.captureImage(app_functions.POW,path,'POWER',False) + choix=(input("do you want to try an exemple? (y/n) : ")) + while choix not in ['y','n']: + choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') + if choix=='y': + clear() + print("you are going to try n puiss m") + n=int(input("give n : ")) + m=int(input("give m : ")) + app_functions.power(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) save_image_choice = input('Do you want to save the images? (y/n): ') while save_image_choice not in ['y','n']: save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') @@ -369,6 +405,14 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.SUCCS)) logic.captureImage(app_functions.SUCCS,path,'SUCCS',False) + choix=(input("do you want to try an exemple? (y/n) : ")) + while choix not in ['y','n']: + choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') + if choix=='y': + clear() + print("you are going to try n+1") + n=int(input("give n : ")) + app_functions.succ(app_functions.dec_to_church(n)) save_image_choice = input('Do you want to save the images? (y/n): ') while save_image_choice not in ['y','n']: save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') @@ -384,6 +428,14 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.PRED)) logic.captureImage(app_functions.PRED,path,'PRED',False) + choix=(input("do you want to try an exemple? (y/n) : ")) + while choix not in ['y','n']: + choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') + if choix=='y': + clear() + print("you are going to try n-1") + n=int(input("give n : ")) + app_functions.predec(app_functions.dec_to_church(n)) save_image_choice = input('Do you want to save the images? (y/n): ') while save_image_choice not in ['y','n']: save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ')