Skip to content
Snippets Groups Projects
Commit 2235f4f7 authored by Antonio MATTAR's avatar Antonio MATTAR
Browse files

-Fixed the beta reduction (alpha-rename issue)// -Fixed the to_string to show...

-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
parent 993b6bc9
No related branches found
No related tags found
No related merge requests found
...@@ -55,18 +55,24 @@ def createAbsImage(terme): ...@@ -55,18 +55,24 @@ def createAbsImage(terme):
abstraction.paste(im2.image, ( 0 , im1.height)) abstraction.paste(im2.image, ( 0 , im1.height))
return abstraction return abstraction
space_width = 0
def get_space_wdith():
return space_width
def get_concat_h_multi_resize(im_list, resample=Image.BICUBIC): def get_concat_h_multi_resize(im_list, resample=Image.BICUBIC):
global space_width
max_height=max(im.height for im in im_list) max_height=max(im.height for im in im_list)
min_height = min(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) max_width = sum(im.width for im in im_list)
min_width=min(im.width for im in im_list) min_width=min(im.width for im in im_list)
space_width=int(min_width*0.3) if space_width == 0:
total_init_width = sum(im.width for im in im_list) + space_width * (len(im_list) - 1) 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) im_list_resize = [im.resize((int(im.width * min_height / im.height), min_height), resample=resample)
for im in im_list] for im in im_list]
total_width = sum(im.width for im in im_list_resize) + (len(im_list_resize) -1) * space_width 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)) dst = Image.new('RGB', (total_init_width, max_height),(255,255,255))
pos_x = 0 pos_x = 0
......
...@@ -185,7 +185,7 @@ def beta_reduction(t): ...@@ -185,7 +185,7 @@ def beta_reduction(t):
else: else:
terme=A1 terme=A1
for var in communBoundVars: for var in communBoundVars:
terme=alpha_rename(terme,new_var(var)) terme=alpha_rename(terme,(var))
return substitute(getInputFromAbs(terme),B1,getOutputFromAbs(terme)) return substitute(getInputFromAbs(terme),B1,getOutputFromAbs(terme))
else: else:
...@@ -221,10 +221,10 @@ def to_string_var(terme): ...@@ -221,10 +221,10 @@ def to_string_var(terme):
return (numbers_to_letters[terme[1]]) return (numbers_to_letters[terme[1]])
def to_string_abs(terme): def to_string_abs(terme):
assert (isAbstraction(terme)), 'The argument is not an Abstraction' 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): 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 = '' premier_terme = ''
deuxieme_terme = '' deuxieme_terme = ''
if isVariable(getFirstTerm(terme)): if isVariable(getFirstTerm(terme)):
...@@ -280,7 +280,7 @@ def annotate_beta_reduction(terme): ...@@ -280,7 +280,7 @@ def annotate_beta_reduction(terme):
else: else:
t=A1 t=A1
for var in communBoundVars: 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()] return new_app(annotate_beta_reduction(A1),annotate_beta_reduction(B1)) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
if A2 != None and B2 == None: if A2 != None and B2 == None:
...@@ -293,7 +293,7 @@ def annotate_beta_reduction(terme): ...@@ -293,7 +293,7 @@ def annotate_beta_reduction(terme):
else: else:
t=A1 t=A1
for var in communBoundVars: 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()] return new_app(annotate_beta_reduction(A1),B1) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
if A2 == None and B2 != None: if A2 == None and B2 != None:
...@@ -306,7 +306,7 @@ def annotate_beta_reduction(terme): ...@@ -306,7 +306,7 @@ def annotate_beta_reduction(terme):
else: else:
t=A1 t=A1
for var in communBoundVars: 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()] return new_app(A1,annotate_beta_reduction(B1)) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
else: else:
...@@ -319,7 +319,7 @@ def annotate_beta_reduction(terme): ...@@ -319,7 +319,7 @@ def annotate_beta_reduction(terme):
else: else:
t=A1 t=A1
for var in communBoundVars: 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()] return new_app(A1,B1) + [substitute(getInputFromAbs(t),B1,getOutputFromAbs(t))] + [counter()]
else: else:
...@@ -337,7 +337,7 @@ def annotated_to_string(terme): ...@@ -337,7 +337,7 @@ def annotated_to_string(terme):
if len(terme)==5: if len(terme)==5:
first=getFirstTerm(terme) first=getFirstTerm(terme)
second=getSecondTerm(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)+ ')' String_term+='('+ annotated_to_string(second)+ ')'
else: else:
if isApplication(terme): if isApplication(terme):
...@@ -346,7 +346,7 @@ def annotated_to_string(terme): ...@@ -346,7 +346,7 @@ def annotated_to_string(terme):
String_term+='(' + annotated_to_string(first) + ') ' String_term+='(' + annotated_to_string(first) + ') '
String_term+= '('+ annotated_to_string(second) + ') ' String_term+= '('+ annotated_to_string(second) + ') '
elif isAbstraction(terme): 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: else:
String_term+=to_string(terme) String_term+=to_string(terme)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment