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

l

parent 426d9c34
Branches
No related tags found
No related merge requests found
from ast import Raise from ast import Raise
from logging import exception from logging import exception
from pprint import pprint
from PIL import Image from PIL import Image
import logic import logic
import parser import parser
...@@ -16,6 +17,18 @@ def associateVariableWithColor(variable): ...@@ -16,6 +17,18 @@ def associateVariableWithColor(variable):
variables_colors_couple[str(variable)] = colors[-1] variables_colors_couple[str(variable)] = colors[-1]
colors.pop() colors.pop()
class MyImage:
def __init__(self, image, boolean):
self.image = image
self.isEgg = boolean
self.width = self.image.width
self.height = self.image.height
def resize(self, given_width, given_height):
if (self.isEgg):
self.image = self.image.resize((min((self.image.width), given_width), min((self.image.height), given_height)), Image.BICUBIC)
else:
self.image = self.image.resize((given_width, given_width))
def createVarImage(variable): def createVarImage(variable):
assert (logic.isVariable(variable)) assert (logic.isVariable(variable))
associateVariableWithColor(variable) associateVariableWithColor(variable)
...@@ -43,12 +56,14 @@ def get_concat_h_multi_resize(im_list, resample=Image.BICUBIC): ...@@ -43,12 +56,14 @@ def get_concat_h_multi_resize(im_list, resample=Image.BICUBIC):
min_height = min(im.height for im in im_list) min_height = min(im.height for im in im_list)
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) min_width = min(im.width for im in im_list_resize)
dst = Image.new('RGB', (total_width, min_height)) space_width = int(min_width * 0.25)
total_width = sum(im.width for im in im_list_resize) + (len(im_list_resize) - 1) * space_width
dst = Image.new('RGB', (total_width, min_height), (255, 255, 255))
pos_x = 0 pos_x = 0
for im in im_list_resize: for im in im_list_resize:
dst.paste(im, (pos_x, 0)) dst.paste(im, (pos_x, 0))
pos_x += im.width pos_x += im.width + space_width
return dst return dst
def createAppImage(terme): def createAppImage(terme):
...@@ -58,7 +73,7 @@ def createAppImage(terme): ...@@ -58,7 +73,7 @@ def createAppImage(terme):
im1 = createImage(left) im1 = createImage(left)
im2 = createImage(right) im2 = createImage(right)
space = Image.open("figures/space.png") space = Image.open("figures/space.png")
application = get_concat_h_multi_resize([im1,space,im2]) application = get_concat_h_multi_resize([im1,im2])
return application return application
def createImage(terme): def createImage(terme):
......
...@@ -210,11 +210,11 @@ def to_string_var(terme): ...@@ -210,11 +210,11 @@ def to_string_var(terme):
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 "#"+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' assert (isApplication(terme)), 'The argument is not an application'
return "("+to_string(getFirstTerm(terme))+")"+"("+to_string(getSecondTerm(terme))+")" return "("+to_string(getFirstTerm(terme))+")"+' '+"("+to_string(getSecondTerm(terme))+")"
def to_string(terme): def to_string(terme):
if isVariable(terme): if isVariable(terme):
return to_string_var(terme) return to_string_var(terme)
......
from main import * from logic import *
x=new_var(freshVar()) x=new_var(freshVar())
y=new_var(freshVar()) y=new_var(freshVar())
z=new_var(freshVar()) z=new_var(freshVar())
...@@ -48,7 +48,7 @@ E = new_app(new_abs(x,new_abs(y,new_app(x,y))),new_abs(y,new_abs(z,new_app(x,z)) ...@@ -48,7 +48,7 @@ E = new_app(new_abs(x,new_abs(y,new_app(x,y))),new_abs(y,new_abs(z,new_app(x,z))
F = new_app(new_app(new_abs(x,x),y),new_abs(z,z)) F = new_app(new_app(new_abs(x,x),y),new_abs(z,z))
Y_COMBINATOR = new_app(new_abs(x,new_app(x,x)),new_abs(y,new_app(y,y))) Y_COMBINATOR = new_app(new_abs(x,new_app(x,x)),new_abs(y,new_app(y,y)))
print('/n') print('/n')
print(E) print(to_string(E))
print('/n') print('/n')
print((beta_reduction(E))) print((beta_reduction(E)))
print(x) print(x)
...@@ -57,7 +57,7 @@ print(to_string([APP, [APP, [ABS, x, y], y] , z])) ...@@ -57,7 +57,7 @@ print(to_string([APP, [APP, [ABS, x, y], y] , z]))
# print(beta_reduction_totale(Y_COMBINATOR)) # print(beta_reduction_totale(Y_COMBINATOR))
############################################################################################################################# #############################################################################################################################
from parser import * import parser
A = "#x.(x)(y)" A = "#x.(x)(y)"
print(getTermsFromParantheses("(AAAAAA)(BBBBBBBBB)(CCCCCCCCC)")) print(getTermsFromParantheses("(AAAAAA)(BBBBBBBBB)(CCCCCCCCC)"))
print(buildTerm(A)) print(buildTerm(A))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment