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

added arithmetic expressions to app functions and main

parent 1c0cd91f
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ SUB= new_abs(x,new_abs(y,new_app(new_app(y,PRED),x))) ...@@ -25,6 +25,7 @@ SUB= new_abs(x,new_abs(y,new_app(new_app(y,PRED),x)))
AND= new_abs(x,new_abs(y,new_app(new_app(x,y),FALSE))) AND= new_abs(x,new_abs(y,new_app(new_app(x,y),FALSE)))
OR= new_abs(x,new_abs(y,new_app(new_app(x,TRUE),y))) OR= new_abs(x,new_abs(y,new_app(new_app(x,TRUE),y)))
NOT = new_abs(x,new_abs(y,new_abs(z, new_app(new_app(x,z),y)))) NOT = new_abs(x,new_abs(y,new_abs(z, new_app(new_app(x,z),y))))
XOR= new_abs(x,new_abs(y,new_app(new_app(x,new_app(new_app(y,FALSE),TRUE)),y)))
#definition des entiers de church #definition des entiers de church
...@@ -69,3 +70,6 @@ def dec_to_lambda_relative_integers(number): ...@@ -69,3 +70,6 @@ def dec_to_lambda_relative_integers(number):
#def predec(n):#done #def predec(n):#done
# return beta_reduction_totale(new_app(PRED, n),None,True) # return beta_reduction_totale(new_app(PRED, n),None,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
...@@ -210,14 +210,11 @@ def captureImage(terme, path, counter=True, date= True): ...@@ -210,14 +210,11 @@ def captureImage(terme, path, counter=True, date= True):
def beta_reduction_totale(terme, path, saveImages=True): def beta_reduction_totale(terme, path, saveImages=True):
save_image_choice = input("Voulez vous sauvegarder les images (y/n)? ") if saveImages==False:
while save_image_choice not in ["y","n"]:
save_image_choice = input("Voulez vous sauvegarder les images (y/n)? ")
if save_image_choice == "n":
if beta_reduction(terme) != None: if beta_reduction(terme) != None:
return beta_reduction_totale(beta_reduction(terme), path, False) return beta_reduction_totale(beta_reduction(terme), path, False)
return (terme) return (terme)
elif save_image_choice == "y": else:
if path == None: if path == None:
captureImage(terme, None) captureImage(terme, None)
else: else:
......
...@@ -17,7 +17,8 @@ main_menu_options = { ...@@ -17,7 +17,8 @@ main_menu_options = {
2: 'Interactive Beta-Reduction', 2: 'Interactive Beta-Reduction',
3: 'Arithmetic Operations', 3: 'Arithmetic Operations',
4: 'Show Numbers', 4: 'Show Numbers',
5: 'Exit', 5: 'boolean expression',
6: 'Exit',
} }
arithmetic_operations_options = { arithmetic_operations_options = {
...@@ -35,15 +36,16 @@ choice_number_representation= { ...@@ -35,15 +36,16 @@ choice_number_representation= {
2: 'Relative numbers', 2: 'Relative numbers',
3: 'Back' 3: 'Back'
} }
#vide un repertoire
def delete_images(path): boolean_representation= {
for file in os.listdir(path): 1: 'NOT',
file_path = os.path.join(path, file) 2: 'AND',
try: 3: 'OR',
if os.path.isfile(file_path): 4: 'XOR',
os.unlink(file_path) 5: 'IS_ZERO',
except Exception as e: 6: 'back'
print(e)
}
def return_main_menu(): def return_main_menu():
not_pressed = True not_pressed = True
...@@ -68,7 +70,13 @@ def run_beta_reduction_totale(terme,path='beta_reduction_totale'): ...@@ -68,7 +70,13 @@ def run_beta_reduction_totale(terme,path='beta_reduction_totale'):
os.makedirs(path, exist_ok=True)# cree le rep si il existe pas, le vide si non os.makedirs(path, exist_ok=True)# cree le rep si il existe pas, le vide si non
if len(os.listdir(path)) > 0: if len(os.listdir(path)) > 0:
logic.image_counter = 0 logic.image_counter = 0
logic.beta_reduction_totale(terme,path) t=logic.beta_reduction_totale(terme,path)
save_image_choice = input('Do you want to save the image? (y/n): ')
while save_image_choice not in ['y','n']:
save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
if save_image_choice == 'y':
logic.captureImage(terme,path)
def run_beta_reduction_interactive_totale(terme,path='beta_reduction_interactive_totale'): def run_beta_reduction_interactive_totale(terme,path='beta_reduction_interactive_totale'):
terme = parsing.parseTerm(terme) terme = parsing.parseTerm(terme)
...@@ -109,6 +117,64 @@ def run_show_numbers(path): ...@@ -109,6 +117,64 @@ def run_show_numbers(path):
elif choice==3: elif choice==3:
run_main_menu() run_main_menu()
def run_boolean_expression(path):
os.makedirs(path, exist_ok=True)
print_menu(boolean_representation)
choice = int(input("enter your choice : "))
while choice not in boolean_representation:
clear()
print_menu(boolean_representation)
choice = int(input('Invalid choice. Enter your choice: '))
if choice ==1:
clear()
t = app_functions.NOT
print('Voici le terme:',logic.to_string(t))
save_image_choice = input('Do you want to save the image? (y/n): ')
while save_image_choice not in ['y','n']:
save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
if save_image_choice == 'y':
logic.captureImage(t,path,'NOT',False)
elif choice==2:
clear()
t = app_functions.AND
print('Voici le terme:',logic.to_string(t))
save_image_choice = input('Do you want to save the image? (y/n): ')
while save_image_choice not in ['y','n']:
save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
if save_image_choice == 'y':
logic.captureImage(t,path,'AND',False)
elif choice==3:
clear()
t = app_functions.OR
print('Voici le terme:',logic.to_string(t))
save_image_choice = input('Do you want to save the image? (y/n): ')
while save_image_choice not in ['y','n']:
save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
if save_image_choice == 'y':
logic.captureImage(t,path,'OR',False)
elif choice ==4:
clear()
t = app_functions.XOR
print('Voici le terme:',logic.to_string(t))
save_image_choice = input('Do you want to save the image? (y/n): ')
while save_image_choice not in ['y','n']:
save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
if save_image_choice == 'y':
logic.captureImage(t,path,'XOR',False)
elif choice==5:
clear()
t = app_functions.IS_ZERO
print('Voici le terme:',logic.to_string(t))
save_image_choice = input('Do you want to save the image? (y/n): ')
while save_image_choice not in ['y','n']:
save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
if save_image_choice == 'y':
logic.captureImage(t,path,'IS_ZERO',False)
elif choice==6:
run_main_menu()
#------------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------------------------------------------
...@@ -150,6 +216,10 @@ def run_main_menu(): ...@@ -150,6 +216,10 @@ def run_main_menu():
run_show_numbers('show_numbers') run_show_numbers('show_numbers')
return_main_menu() return_main_menu()
elif choice== 5: elif choice== 5:
clear()
run_boolean_expression('boolean expression')
return_main_menu()
elif choice == 6:
clear() clear()
print(good_bye_banner) print(good_bye_banner)
...@@ -165,48 +235,34 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): ...@@ -165,48 +235,34 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
clear() clear()
print("Voici le terme: "+ logic.to_string(app_functions.ADD)) print("Voici le terme: "+ logic.to_string(app_functions.ADD))
logic.captureImage(app_functions.ADD,path,'ADD', False) logic.captureImage(app_functions.ADD,path,'ADD', False)
time.sleep(1) return_main_menu()
clear()
run_arithmetic_operations_menu()
elif choice == 2: elif choice == 2:
clear() clear()
print("Voici le terme: "+ logic.to_string(app_functions.SUB)) print("Voici le terme: "+ logic.to_string(app_functions.SUB))
logic.captureImage(app_functions.SUB,path,'SUB', False) logic.captureImage(app_functions.SUB,path,'SUB', False)
time.sleep(1) return_main_menu()
clear()
run_arithmetic_operations_menu()
elif choice == 3: elif choice == 3:
clear() clear()
print("Voici le terme: "+ logic.to_string(app_functions.MUL)) print("Voici le terme: "+ logic.to_string(app_functions.MUL))
logic.captureImage(app_functions.MUL,path,'MUL',False) logic.captureImage(app_functions.MUL,path,'MUL',False)
time.sleep(1) return_main_menu()
clear()
run_arithmetic_operations_menu()
elif choice==4: elif choice==4:
clear() clear()
print("Voici le terme: "+ logic.to_string(app_functions.POW)) print("Voici le terme: "+ logic.to_string(app_functions.POW))
logic.captureImage(app_functions.POW,path,'POWER',False) logic.captureImage(app_functions.POW,path,'POWER',False)
time.sleep(1) return_main_menu()
clear()
run_arithmetic_operations_menu()
elif choice==5: elif choice==5:
clear() clear()
print("Voici le terme: "+ logic.to_string(app_functions.SUCCS)) print("Voici le terme: "+ logic.to_string(app_functions.SUCCS))
logic.captureImage(app_functions.SUCCS,path,'SUCCS',False) logic.captureImage(app_functions.SUCCS,path,'SUCCS',False)
time.sleep(1) return_main_menu()
clear()
run_arithmetic_operations_menu()
elif choice==6: elif choice==6:
clear() clear()
print("Voici le terme: "+ logic.to_string(app_functions.PRED)) print("Voici le terme: "+ logic.to_string(app_functions.PRED))
logic.captureImage(app_functions.PRED,path,'PRED',False) logic.captureImage(app_functions.PRED,path,'PRED',False)
time.sleep(1) return_main_menu
clear()
run_arithmetic_operations_menu()
elif choice == 7: elif choice == 7:
clear() clear()
run_main_menu() run_main_menu()
run_main_menu() run_main_menu()
input()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment