From 2235f4f7a93bf77b7b80338b21322d4ed5127891 Mon Sep 17 00:00:00 2001
From: Antonio MATTAR <antonio.mattar@etu.univ-amu.fr>
Date: Wed, 22 Jun 2022 11:43:48 +0200
Subject: [PATCH] -Fixed the beta reduction (alpha-rename issue)// -Fixed the
 to_string to show uo lambdas // -Fixed the image maker to get a fixed spae
 width between applications

---
 image_maker.py | 14 ++++++++++----
 logic.py       | 18 +++++++++---------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/image_maker.py b/image_maker.py
index f92a303..16233d4 100644
--- a/image_maker.py
+++ b/image_maker.py
@@ -55,18 +55,24 @@ def createAbsImage(terme):
     abstraction.paste(im2.image, ( 0 , im1.height))
     return abstraction
 
+space_width = 0
+
+def get_space_wdith():
+    return space_width
 
 def get_concat_h_multi_resize(im_list, resample=Image.BICUBIC):
+    global space_width
     max_height=max(im.height for im in im_list)
     min_height = min(im.height for im in im_list)
     max_width = sum(im.width for im in im_list)
     min_width=min(im.width for im in im_list)
-    space_width=int(min_width*0.3)
-    total_init_width = sum(im.width for im in im_list) + space_width * (len(im_list) - 1)
+    if space_width == 0:
+        space_width=(int(min_width*0.3))
+    else:
+        space_width=min(get_space_wdith(),int(min_width*0.3))
+    total_init_width = sum(im.width for im in im_list) + get_space_wdith() * (len(im_list) - 1)
     im_list_resize = [im.resize((int(im.width * min_height / im.height), min_height), resample=resample)
                       for im in im_list]
-
-    
     total_width = sum(im.width for im in im_list_resize) + (len(im_list_resize) -1) * space_width
     dst = Image.new('RGB', (total_init_width, max_height),(255,255,255))
     pos_x = 0
diff --git a/logic.py b/logic.py
index 957226b..f8ce1e9 100644
--- a/logic.py
+++ b/logic.py
@@ -185,7 +185,7 @@ def beta_reduction(t):
                 else: 
                     terme=A1
                     for var in communBoundVars:
-                        terme=alpha_rename(terme,new_var(var))
+                        terme=alpha_rename(terme,(var))
                         return substitute(getInputFromAbs(terme),B1,getOutputFromAbs(terme))
 
         else:
@@ -221,10 +221,10 @@ def to_string_var(terme):
     return (numbers_to_letters[terme[1]])
 def to_string_abs(terme):
     assert (isAbstraction(terme)), 'The argument is not an Abstraction'
-    return "#"+to_string(getInputFromAbs(terme))+"."+to_string(getOutputFromAbs(terme))
+    return "\u03BB"+to_string(getInputFromAbs(terme))+"."+to_string(getOutputFromAbs(terme))
 
 def to_string_app(terme):
-    assert (isApplication(terme)), 'The argument is not an application' #() ons econd term if application / no () over variable/ if ABS inside APP ()
+    assert (isApplication(terme)), 'The argument is not an application' #ons econd term if application / no () over variable/ if ABS inside APP ()
     premier_terme = ''
     deuxieme_terme = ''
     if isVariable(getFirstTerm(terme)):
@@ -280,7 +280,7 @@ def annotate_beta_reduction(terme):
                 else: 
                     t=A1
                     for var in communBoundVars:
-                        t=alpha_rename(t,new_var(var))
+                        t=alpha_rename(t,(var))
                 
                         return new_app(annotate_beta_reduction(A1),annotate_beta_reduction(B1)) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
             if A2 != None and B2 == None:
@@ -293,7 +293,7 @@ def annotate_beta_reduction(terme):
                 else: 
                     t=A1
                     for var in communBoundVars:
-                        t=alpha_rename(t,new_var(var))
+                        t=alpha_rename(t,(var))
                 
                     return new_app(annotate_beta_reduction(A1),B1) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
             if A2 == None and B2 != None:
@@ -306,7 +306,7 @@ def annotate_beta_reduction(terme):
                 else: 
                     t=A1
                     for var in communBoundVars:
-                        t=alpha_rename(t,new_var(var))
+                        t=alpha_rename(t,(var))
                 
                         return new_app(A1,annotate_beta_reduction(B1)) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
             else:
@@ -319,7 +319,7 @@ def annotate_beta_reduction(terme):
                 else: 
                     t=A1
                     for var in communBoundVars:
-                        t=alpha_rename(t,new_var(var))
+                        t=alpha_rename(t,(var))
                 
                         return new_app(A1,B1) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
         else:
@@ -337,7 +337,7 @@ def annotated_to_string(terme):
     if len(terme)==5:
         first=getFirstTerm(terme)
         second=getSecondTerm(terme)
-        String_term+="(#"+str(terme[4])+to_string(getInputFromAbs(first))+"."+annotated_to_string(getOutputFromAbs(first))+') '
+        String_term+="(\u03BB"+str(terme[4])+to_string(getInputFromAbs(first))+"."+annotated_to_string(getOutputFromAbs(first))+') '
         String_term+='('+ annotated_to_string(second)+ ')'
     else:
         if isApplication(terme):
@@ -346,7 +346,7 @@ def annotated_to_string(terme):
             String_term+='(' + annotated_to_string(first) + ') '
             String_term+= '('+ annotated_to_string(second) + ') '
         elif isAbstraction(terme):
-            String_term+='#'+ to_string(getInputFromAbs(terme))+ '.' +annotated_to_string(getOutputFromAbs(terme))
+            String_term+='\u03BB'+ to_string(getInputFromAbs(terme))+ '.' +annotated_to_string(getOutputFromAbs(terme))
         else:
             String_term+=to_string(terme)
 
-- 
GitLab