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
5c7f0842
Commit
5c7f0842
authored
2 years ago
by
Antonio MATTAR
Browse files
Options
Downloads
Patches
Plain Diff
-Added the SUB-AND-OR-NOT operators // -Added 2 parameters for date and counter in captureImage
parent
3c31d61d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
app_functions.py
+5
-1
5 additions, 1 deletion
app_functions.py
image_maker.py
+17
-5
17 additions, 5 deletions
image_maker.py
logic.py
+41
-17
41 additions, 17 deletions
logic.py
main.py
+104
-32
104 additions, 32 deletions
main.py
with
167 additions
and
55 deletions
app_functions.py
+
5
−
1
View file @
5c7f0842
...
...
@@ -17,10 +17,14 @@ MUL= new_abs(y,new_abs(z,new_abs(f,new_abs(x,new_app(new_app(y,new_app(z,f)),x))
ADD
=
new_abs
(
x
,
new_abs
(
y
,
new_app
(
new_app
(
y
,
SUCCS
),
x
)))
IS_ZERO
=
new_abs
(
z
,
new_app
(
new_app
(
z
,
new_abs
(
x
,
FALSE
)),
TRUE
))
PRED
=
new_abs
(
z
,(
new_abs
(
f
,
new_abs
(
x
,
new_app
((
new_app
((
new_app
(
z
,
new_abs
(
w
,
new_abs
(
h
,
new_app
(
h
,
new_app
(
w
,
f
)))))),
new_abs
(
u
,
x
))),
new_abs
(
u
,
u
))))))
POW
=
new_abs
(
y
,
new_abs
(
h
,(
new_abs
(
x
,
new_app
(
new_app
(
h
,
y
)
,
x
))))
)
POW
=
new_abs
(
x
,(
new_abs
(
y
,
new_app
(
y
,
x
))))
PAIR
=
new_abs
(
x
,
new_abs
(
y
,(
new_abs
(
f
,
new_app
(
new_app
(
f
,
x
),
y
)))))
FIRST
=
new_abs
(
x
,(
new_app
(
x
,
TRUE
)))
SECOND
=
new_abs
(
x
,(
new_app
(
x
,
FALSE
)))
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
)))
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
))))
#definition des entiers de church
...
...
This diff is collapsed.
Click to expand it.
image_maker.py
+
17
−
5
View file @
5c7f0842
...
...
@@ -6,6 +6,7 @@ from PIL import ImageFont
import
logic
import
parsing
import
random
import
datetime
def
color_image
(
img
,
color
):
width
=
img
.
size
[
0
]
...
...
@@ -29,8 +30,11 @@ variables_colors_couple = {}
def
associateVariableWithColor
(
variable
):
assert
(
logic
.
isVariable
(
variable
))
c
=
new_color
()
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
:
variables_colors_couple
[
str
(
variable
)]
=
new_color
()
variables_colors_couple
[
str
(
variable
)]
=
c
#------------------------------------------------------------------------------------------------------------------------------------------
class
My_image
:
def
__init__
(
self
,
image
,
b
):
...
...
@@ -146,7 +150,15 @@ def createImage(terme):
else
:
raise
Exception
(
"
Unsupported term type
"
)
def
saveImage
(
image
,
name
,
path
):
def
saveImage
(
image
,
name
,
path
,
date
=
True
):
if
date
:
now
=
datetime
.
datetime
.
now
()
now_string
=
now
.
strftime
(
"
%Y-%m-%d__%H-%M-%S
"
)
if
path
==
None
:
image
.
image
.
save
(
now_string
+
'
---
'
+
name
+
'
.png
'
,
'
PNG
'
)
else
:
image
.
image
.
save
(
path
+
'
/
'
+
now_string
+
'
---
'
+
name
+
'
.png
'
,
'
PNG
'
)
else
:
if
path
==
None
:
image
.
image
.
save
(
name
+
'
.png
'
,
'
PNG
'
)
else
:
...
...
This diff is collapsed.
Click to expand it.
logic.py
+
41
−
17
View file @
5c7f0842
...
...
@@ -193,13 +193,22 @@ def beta_reduction(t):
import
image_maker
image_counter
=
0
def
captureImage
(
terme
,
path
):
def
captureImage
(
terme
,
path
,
counter
=
True
,
date
=
True
):
global
image_counter
print
(
counter
)
if
type
(
counter
)
==
bool
and
counter
:
if
path
==
None
:
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
image_counter
),
None
)
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
image_counter
),
None
,
date
)
else
:
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
image_counter
),
path
)
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
image_counter
),
path
,
date
)
image_counter
+=
1
else
:
if
path
==
None
:
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
counter
),
None
,
date
)
else
:
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
counter
),
path
,
date
)
image_counter
+=
1
def
beta_reduction_totale
(
terme
,
path
,
saveImages
=
True
):
if
saveImages
==
False
:
...
...
@@ -445,6 +454,8 @@ 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
)))
...
...
@@ -459,6 +470,19 @@ 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
+
104
−
32
View file @
5c7f0842
from
ast
import
Not
import
logic
import
parsing
import
image_maker
...
...
@@ -5,6 +6,7 @@ import app_functions
import
os
import
time
import
pyfiglet
import
keyboard
clear
=
lambda
:
os
.
system
(
'
cls
'
)
welcome_banner
=
pyfiglet
.
figlet_format
(
'
LambdaCalculus Interpreter
'
)
...
...
@@ -18,11 +20,19 @@ main_menu_options = {
5
:
'
Exit
'
,
}
arithmetic_operatins_options
=
{
arithmetic_operati
o
ns_options
=
{
1
:
'
Addition
'
,
2
:
'
Subtraction
'
,
3
:
'
Multiplication
'
,
4
:
'
Back
'
,
4
:
'
power
'
,
5
:
'
successor
'
,
6
:
'
predecessor
'
,
7
:
'
Back
'
,
}
choice_number_representation
=
{
1
:
'
integer numbers (church representation)
'
,
2
:
'
relative numbers
'
}
#vide un repertoire
def
delete_images
(
path
):
...
...
@@ -34,26 +44,68 @@ def delete_images(path):
except
Exception
as
e
:
print
(
e
)
def
return_main_menu
():
not_pressed
=
True
print
(
'
Press ENTER to return to the main menu
'
)
while
not_pressed
:
# making a loop
try
:
# used try so that if user pressed other than the given key error will not be shown
if
keyboard
.
is_pressed
(
'
ENTER
'
):
# if key 'ENTER' is pressed
not_pressed
=
False
# finishing the loop
clear
()
time
.
sleep
(
1
)
logic
.
image_counter
=
0
logic
.
var_counter
=
0
image_maker
.
variables_colors_couple
=
{}
clear
()
break
except
:
break
# if user pressed a key other than the given key the loop will break
run_main_menu
()
def
run_beta_reduction_totale
(
terme
,
path
=
'
beta_reduction_totale
'
):
terme
=
parsing
.
parseTerm
(
terme
)
os
.
makedirs
(
path
,
exist_ok
=
True
)
# cree le rep si il existe pas, le vide si non
if
len
(
os
.
listdir
(
path
))
>
0
:
delete_images
(
path
)
logic
.
image_counter
=
0
logic
.
beta_reduction_totale
(
terme
,
path
)
def
run_beta_reduction_interactive_totale
(
terme
,
path
=
'
beta_reduction_interactive_totale
'
):
terme
=
parsing
.
parseTerm
(
terme
)
os
.
makedirs
(
path
,
exist_ok
=
True
)
if
len
(
os
.
listdir
(
path
))
>
0
:
delete_images
(
path
)
logic
.
image_counter
=
0
logic
.
beta_reduction_interactive_totale
(
terme
,
path
)
def
run_show_numbers
(
path
):
os
.
makedirs
(
path
,
exist_ok
=
True
)
print_menu
(
choice_number_representation
)
choice
=
int
(
input
(
'
Enter your choice:
'
))
while
choice
not
in
main_menu_options
:
clear
()
print_menu
(
choice_number_representation
)
choice
=
int
(
input
(
'
Invalid choice. Enter your choice:
'
))
if
choice
==
1
:
clear
()
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):
'
)
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
,
'
ENTIER
'
+
str
(
terme
),
False
)
elif
choice
==
2
:
clear
()
terme
=
int
(
input
(
'
Enter a number:
'
))
t
=
app_functions
.
dec_to_lambda_relative_integers
(
terme
)
print
(
'
Voici le terme:
'
,
logic
.
to_string
(
t
))
logic
.
captureImage
(
t
,
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
(
t
,
path
,
'
ENTIER-RELATIF-
'
+
str
(
terme
),
False
)
#------------------------------------------------------------------------------------------------------------------------------------
...
...
@@ -63,72 +115,92 @@ def print_menu(options):
print
(
key
,
'
--
'
,
value
)
def
run_main_menu
():
choice
=
''
print
(
welcome_banner
)
print_menu
(
main_menu_options
)
try
:
choice
=
int
(
input
(
'
Enter your choice:
'
))
except
ValueError
:
clear
()
print_menu
(
main_menu_options
)
while
choice
not
in
main_menu_options
:
choice
=
int
(
input
(
'
Invalid choice.
Enter your choice:
'
))
choice
=
int
(
input
(
'
Enter your choice:
'
))
if
choice
==
1
:
clear
()
terme1
=
input
(
'
Enter a term:
'
)
run_beta_reduction_totale
(
terme1
)
clear
()
print
(
'
Done!
'
)
time
.
sleep
(
1
)
logic
.
image_counter
=
0
clear
()
run_main_menu
()
return_main_menu
()
elif
choice
==
2
:
clear
()
terme2
=
input
(
'
Enter a term:
'
)
run_beta_reduction_interactive_totale
(
terme2
)
clear
()
print
(
'
Done!
'
)
logic
.
image_counter
=
0
time
.
sleep
(
1
)
clear
()
run_main_menu
()
return_main_menu
()
elif
choice
==
3
:
clear
()
run_arithmetic_operations_menu
()
elif
choice
==
4
:
clear
()
run_show_numbers
(
'
show_numbers
'
)
logic
.
image_counter
=
0
time
.
sleep
(
3
)
clear
()
run_main_menu
()
return_main_menu
()
elif
choice
==
5
:
clear
()
print
(
good_bye_banner
)
else
:
print
(
'
Invalid choice
'
)
run_main_menu
()
def
run_arithmetic_operations_menu
():
print_menu
(
arithmetic_operatins_options
)
def
run_arithmetic_operations_menu
(
path
=
'
arithmetic expressions
'
):
os
.
makedirs
(
path
,
exist_ok
=
True
)
print_menu
(
arithmetic_operations_options
)
choice
=
int
(
input
(
'
Enter your choice:
'
))
while
choice
not
in
arithmetic_operatins_options
:
while
choice
not
in
arithmetic_operations_options
:
clear
()
print_menu
(
arithmetic_operations_options
)
choice
=
int
(
input
(
'
Invalid choice. Enter your choice:
'
))
if
choice
==
1
:
clear
()
print
(
'
addition COMING SOON...
'
)
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
ADD
))
logic
.
captureImage
(
app_functions
.
ADD
,
path
,
'
ADD
'
,
False
)
time
.
sleep
(
1
)
clear
()
run_arithmetic_operations_menu
()
elif
choice
==
2
:
clear
()
print
(
'
subtraction COMING SOON...
'
)
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUB
))
logic
.
captureImage
(
app_functions
.
SUB
,
path
,
'
SUB
'
,
False
)
time
.
sleep
(
1
)
clear
()
run_arithmetic_operations_menu
()
elif
choice
==
3
:
clear
()
print
(
'
multiplication COMING SOON...
'
)
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
MUL
))
logic
.
captureImage
(
app_functions
.
MUL
,
path
,
'
MUL
'
,
False
)
time
.
sleep
(
1
)
clear
()
run_arithmetic_operations_menu
()
elif
choice
==
4
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
POW
))
logic
.
captureImage
(
app_functions
.
POW
,
path
,
'
POWER
'
,
False
)
time
.
sleep
(
1
)
clear
()
run_arithmetic_operations_menu
()
elif
choice
==
5
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUCCS
))
logic
.
captureImage
(
app_functions
.
SUCCS
,
path
,
'
SUCCS
'
,
False
)
time
.
sleep
(
1
)
clear
()
run_arithmetic_operations_menu
()
elif
choice
==
6
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
PRED
))
logic
.
captureImage
(
app_functions
.
PRED
,
path
,
'
PRED
'
,
False
)
time
.
sleep
(
1
)
clear
()
run_arithmetic_operations_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