Skip to content
Snippets Groups Projects
Commit 5890c3d1 authored by Tamazouzt AIT ELDJOUDI's avatar Tamazouzt AIT ELDJOUDI
Browse files

added arithmetic functions to the menu and app_functions, added the infinite beta reduction

parent ea904a3a
No related branches found
No related tags found
No related merge requests found
......@@ -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)))
# ajouter les etoiles sur les alligators qui Maangent
# ajoter les sauvegardes
# ajouter le predec ....
# terme qui termine pas
#probleme de l arret
......@@ -235,21 +235,43 @@ 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)
else:
if annotate_reductor(terme) != None:
captureImage(annotate_reductor(terme), path)
else:
captureImage(terme,path)
if beta_reduction(terme) != None:
......@@ -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")
......
......@@ -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): ')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment