Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Alligators-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Monmege
Alligators-python
Commits
df3c4d43
Commit
df3c4d43
authored
2 years ago
by
Antonio MATTAR
Browse files
Options
Downloads
Patches
Plain Diff
Merge branch 'main' of
https://gitlab.lis-lab.fr/benjamin.monmege/alligators-python
parent
f39ab522
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
image_maker.py
+15
-0
15 additions, 0 deletions
image_maker.py
logic.py
+36
-17
36 additions, 17 deletions
logic.py
main.py
+131
-26
131 additions, 26 deletions
main.py
with
182 additions
and
43 deletions
image_maker.py
+
15
−
0
View file @
df3c4d43
...
...
@@ -26,11 +26,23 @@ def new_color():
b
=
random
.
randint
(
0
,
255
)
return
(
r
,
g
,
b
)
def
close_colors
(
a
,
b
):
r
=
abs
(
a
[
0
]
-
b
[
0
])
g
=
abs
(
a
[
1
]
-
b
[
1
])
b
=
abs
(
a
[
2
]
-
b
[
2
])
return
r
*
r
+
g
*
g
+
b
*
b
<=
70
*
70
variables_colors_couple
=
{}
def
associateVariableWithColor
(
variable
):
assert
(
logic
.
isVariable
(
variable
))
c
=
new_color
()
colors
=
list
(
variables_colors_couple
.
values
())
for
color
in
colors
:
if
close_colors
(
c
,
color
):
associateVariableWithColor
(
variable
)
break
if
c
in
list
(
variables_colors_couple
.
values
()):
associateVariableWithColor
(
variable
)
# recursive call to not get the same color
if
str
(
variable
)
not
in
variables_colors_couple
:
...
...
@@ -130,6 +142,9 @@ def createAppImage(terme):
left
=
logic
.
getFirstTerm
(
terme
)
right
=
logic
.
getSecondTerm
(
terme
)
im1
=
createImage
(
left
)
if
len
(
terme
)
==
4
:
im1
=
addNumberToImage
(
im1
,
terme
[
3
])
left
=
left
[:
3
]
if
len
(
terme
)
==
5
:
im1
=
addNumberToImage
(
im1
,
terme
[
-
1
])
if
logic
.
isApplication
(
right
):
...
...
This diff is collapsed.
Click to expand it.
logic.py
+
36
−
17
View file @
df3c4d43
...
...
@@ -191,6 +191,33 @@ def beta_reduction(t):
else
:
return
None
def
annotate_reductor
(
t
):
if
isVariable
(
t
):
return
None
elif
isAbstraction
(
t
):
x
=
getInputFromAbs
(
t
)
A
=
getOutputFromAbs
(
t
)
B
=
annotate_reductor
(
A
)
if
B
!=
None
:
return
new_abs
(
x
.
copy
(),
B
)
### x.copy() sont inutiles car on ne change jamais le tableau de variables
else
:
return
None
elif
isApplication
(
t
):
A1
=
getFirstTerm
(
t
)
B1
=
getSecondTerm
(
t
)
A2
=
annotate_reductor
(
A1
)
if
A2
!=
None
:
return
(
new_app
(
A2
,
B1
))
elif
A2
==
None
:
B2
=
annotate_reductor
(
B1
)
if
B2
!=
None
:
return
(
new_app
(
A1
,
B2
))
elif
isAbstraction
(
A1
):
t
=
t
.
append
(
'
*
'
)
return
t
else
:
return
None
import
image_maker
image_counter
=
0
def
captureImage
(
terme
,
path
,
counter
=
True
,
date
=
True
):
...
...
@@ -216,7 +243,13 @@ def beta_reduction_totale(terme, path, saveImages=True):
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
:
...
...
@@ -432,7 +465,7 @@ def beta_reduction_choice_n(terme,n):
def
beta_reduction_interactive
(
terme
,
at
):
global
counters
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
"
)
...
...
@@ -454,8 +487,6 @@ def cleanReductions(l):
return
l
def
beta_reduction_interactive_totale
(
terme
,
path
):
save_image_choice
=
int
(
input
(
"
Save image? (1 for yes, 0 for no):
"
))
if
save_image_choice
==
1
:
if
beta_reduction
((
terme
))
!=
None
:
# print(to_string(terme))
at
=
(
annotate_beta_reduction
((
terme
)))
...
...
@@ -470,18 +501,6 @@ def beta_reduction_interactive_totale(terme,path):
else
:
captureImage
(
terme
,
path
)
return
(
terme
)
else
:
if
beta_reduction
((
terme
))
!=
None
:
# print(to_string(terme))
at
=
(
annotate_beta_reduction
((
terme
)))
choix
=
int
(
input
(
"
voulez-vous faire la reduction tapez sur 1 pour oui tapez sur 2 pour non
"
))
if
choix
==
1
:
return
beta_reduction_interactive_totale
(
beta_reduction_interactive
(
terme
,
at
),
path
)
else
:
terme
=
cleanReductions
(
terme
)
print
(
"
C
'
est fini, le terme obtenu est :
"
+
to_string
(
terme
))
else
:
return
(
terme
)
...
...
This diff is collapsed.
Click to expand it.
main.py
+
131
−
26
View file @
df3c4d43
...
...
@@ -7,6 +7,7 @@ import os
import
time
import
pyfiglet
import
keyboard
import
shutil
clear
=
lambda
:
os
.
system
(
'
cls
'
)
welcome_banner
=
pyfiglet
.
figlet_format
(
'
LambdaCalculus Interpreter
'
)
...
...
@@ -47,6 +48,23 @@ boolean_representation= {
}
def
save_images
(
terme
,
nom
,
date
):
os
.
makedirs
(
"
/sauvegarde
"
,
exist_ok
=
True
)
logic
.
captureImage
(
terme
,
"
/sauvegarde
"
,
nom
,
date
)
def
delete_images
(
folder
):
if
os
.
path
.
exists
(
folder
):
for
the_file
in
os
.
listdir
(
folder
):
file_path
=
os
.
path
.
join
(
folder
,
the_file
)
try
:
if
os
.
path
.
isfile
(
file_path
):
os
.
unlink
(
file_path
)
except
Exception
as
e
:
print
(
e
)
def
moveImages
(
src
,
dest
):
for
filename
in
os
.
listdir
(
src
):
shutil
.
move
(
src
+
"
/
"
+
filename
,
dest
)
def
return_main_menu
():
not_pressed
=
True
print
(
'
Press ENTER to return to the main menu
'
)
...
...
@@ -70,13 +88,15 @@ 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
if
len
(
os
.
listdir
(
path
))
>
0
:
logic
.
image_counter
=
0
t
=
logic
.
beta_reduction_totale
(
terme
,
path
)
save_image_choice
=
input
(
'
Do you want to save the image? (y/n):
'
)
logic
.
beta_reduction_totale
(
terme
,
path
)
save_image_choice
=
input
(
'
Do you want to save the image
s
? (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):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
terme
,
path
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
def
run_beta_reduction_interactive_totale
(
terme
,
path
=
'
beta_reduction_interactive_totale
'
):
terme
=
parsing
.
parseTerm
(
terme
)
...
...
@@ -84,6 +104,14 @@ def run_beta_reduction_interactive_totale(terme,path='beta_reduction_interactive
if
len
(
os
.
listdir
(
path
))
>
0
:
logic
.
image_counter
=
0
logic
.
beta_reduction_interactive_totale
(
terme
,
path
)
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
def
run_show_numbers
(
path
):
os
.
makedirs
(
path
,
exist_ok
=
True
)
...
...
@@ -98,11 +126,15 @@ def run_show_numbers(path):
terme
=
int
(
input
(
'
Enter a number:
'
))
t
=
app_functions
.
dec_to_church
(
terme
)
print
(
'
Voici le terme:
'
,
logic
.
to_string
(
t
))
save_image_choice
=
input
(
'
Do you want to save the image? (y/n):
'
)
logic
.
captureImage
(
t
,
path
,
'
ENTIER
'
+
str
(
terme
),
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
ENTIER
'
+
str
(
terme
),
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
elif
choice
==
2
:
clear
()
...
...
@@ -110,10 +142,15 @@ def run_show_numbers(path):
t
=
app_functions
.
dec_to_lambda_relative_integers
(
terme
)
print
(
'
Voici le terme:
'
,
logic
.
to_string
(
t
))
save_image_choice
=
input
(
'
Do you want to save the image? (y/n):
'
)
logic
.
captureImage
(
t
,
path
,
'
ENTIER-RELATIF-
'
+
str
(
terme
),
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
ENTIER-RELATIF-
'
+
str
(
terme
),
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
elif
choice
==
3
:
run_main_menu
()
...
...
@@ -129,48 +166,68 @@ def run_boolean_expression(path):
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):
'
)
logic
.
captureImage
(
t
,
path
,
'
NOT
'
,
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
NOT
'
,
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
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):
'
)
logic
.
captureImage
(
t
,
path
,
'
AND
'
,
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
AND
'
,
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
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):
'
)
logic
.
captureImage
(
t
,
path
,
'
OR
'
,
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
OR
'
,
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
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):
'
)
logic
.
captureImage
(
t
,
path
,
'
XOR
'
,
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
XOR
'
,
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
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):
'
)
logic
.
captureImage
(
t
,
path
,
'
IS_ZERO
'
,
False
)
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 image? (y/n):
'
)
save_image_choice
=
input
(
'
Invalid choice. Do you want to save the image
s of the reduction
? (y/n):
'
)
if
save_image_choice
==
'
y
'
:
logic
.
captureImage
(
t
,
path
,
'
IS_ZERO
'
,
False
)
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
elif
choice
==
6
:
run_main_menu
()
...
...
@@ -235,32 +292,80 @@ 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
)
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
return_main_menu
()
elif
choice
==
2
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUB
))
logic
.
captureImage
(
app_functions
.
SUB
,
path
,
'
SUB
'
,
False
)
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
return_main_menu
()
elif
choice
==
3
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
MUL
))
logic
.
captureImage
(
app_functions
.
MUL
,
path
,
'
MUL
'
,
False
)
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
return_main_menu
()
elif
choice
==
4
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
POW
))
logic
.
captureImage
(
app_functions
.
POW
,
path
,
'
POWER
'
,
False
)
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
return_main_menu
()
elif
choice
==
5
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUCCS
))
logic
.
captureImage
(
app_functions
.
SUCCS
,
path
,
'
SUCCS
'
,
False
)
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
return_main_menu
()
elif
choice
==
6
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
PRED
))
logic
.
captureImage
(
app_functions
.
PRED
,
path
,
'
PRED
'
,
False
)
return_main_menu
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):
'
)
if
save_image_choice
==
'
y
'
:
os
.
makedirs
(
"
./sauvegarde/
"
+
path
,
exist_ok
=
True
)
moveImages
(
path
,
'
./sauvegarde/
'
+
path
)
elif
save_image_choice
==
'
n
'
:
delete_images
(
path
)
return_main_menu
()
elif
choice
==
7
:
clear
()
run_main_menu
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment