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
be76f1d7
Commit
be76f1d7
authored
2 years ago
by
Antonio MATTAR
Browse files
Options
Downloads
Patches
Plain Diff
-Fixed the variables letters problem // -Added operations execution possibilty
parent
ea904a3a
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
app_functions.py
+16
-13
16 additions, 13 deletions
app_functions.py
logic.py
+56
-37
56 additions, 37 deletions
logic.py
main.py
+56
-3
56 additions, 3 deletions
main.py
with
128 additions
and
53 deletions
app_functions.py
+
16
−
13
View file @
be76f1d7
...
...
@@ -51,25 +51,28 @@ def getSecondFromPair(p):
def
dec_to_lambda_relative_integers
(
number
):
if
number
>=
0
:
return
pair
(
TRUE
,
dec_to_church
(
number
))
return
pair
(
FALSE
,
dec_to_church
(
number
))
return
pair
(
FALSE
,
dec_to_church
(
abs
(
number
))
)
#
def succ(n):#done
#
return beta_reduction_totale(new_app(SUCCS,n),
None,Fals
e)
def
succ
(
n
):
#done
return
beta_reduction_totale
(
new_app
(
SUCCS
,
n
),
'
arithmetic expressions
'
,
Tru
e
)
#
def add(n,m):#done
#
return beta_reduction_totale(new_app(new_app(ADD,n),m),
None,Fals
e)
def
add
(
n
,
m
):
#done
return
beta_reduction_totale
(
new_app
(
new_app
(
ADD
,
n
),
m
),
'
arithmetic expressions
'
,
Tru
e
)
#
def power(n,m):# done
#
return beta_reduction_totale(new_app((new_app(POW, n)),m),
None,Fals
e)
def
power
(
n
,
m
):
# done
return
beta_reduction_totale
(
new_app
((
new_app
(
POW
,
n
)),
m
),
'
arithmetic expressions
'
,
Tru
e
)
#
def multiplication(n,m):#done
#
return beta_reduction_totale(new_app(new_app(MUL,n),m),
None,Fals
e)
def
multiplication
(
n
,
m
):
#done
return
beta_reduction_totale
(
new_app
(
new_app
(
MUL
,
n
),
m
),
'
arithmetic expressions
'
,
Tru
e
)
#
def is_zero(n):#done
#
return beta_reduction_totale(new_app(IS_ZERO,n),
None,Fals
e)
def
is_zero
(
n
):
#done
return
beta_reduction_totale
(
new_app
(
IS_ZERO
,
n
),
'
arithmetic expressions
'
,
Tru
e
)
#def predec(n):#done
# return beta_reduction_totale(new_app(PRED, n),None,True)
def
predec
(
n
):
#done
return
beta_reduction_totale
(
new_app
(
PRED
,
n
),
'
arithmetic expressions
'
,
True
)
def
sub
(
n
,
m
):
return
beta_reduction_totale
(
new_app
(
new_app
(
SUB
,
n
),
m
),
'
arithmetic expressions
'
,
True
)
#print(to_string(beta_reduction_totale(new_app(new_app(XOR,TRUE),FALSE),None,False)))
#print(to_string(dec_to_lambda_relative_integers(5)))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
logic.py
+
56
−
37
View file @
be76f1d7
...
...
@@ -235,21 +235,43 @@ def captureImage(terme, path, counter=True, date= True):
image_maker
.
saveImage
(
image_maker
.
createImage
(
terme
),
str
(
counter
),
path
,
date
)
image_counter
+=
1
def
recognize_term
(
terme
):
if
isApplication
(
terme
):
first
=
getFirstTerm
(
terme
)
second
=
getSecondTerm
(
terme
)
if
isAbstraction
(
first
)
and
isAbstraction
(
second
)
:
a
=
getOutputFromAbs
(
first
)
b
=
getOutputFromAbs
(
second
)
if
isApplication
(
a
)
and
isApplication
(
b
):
if
isVariable
(
getFirstTerm
(
a
))
and
isVariable
(
getSecondTerm
(
a
))
and
isVariable
(
getFirstTerm
(
b
))
and
isVariable
(
getSecondTerm
(
b
)):
if
getFirstTerm
(
a
)
==
getSecondTerm
(
a
)
and
getFirstTerm
(
b
)
==
getSecondTerm
(
b
):
if
getFirstTerm
(
a
)
==
getInputFromAbs
(
first
)
and
getFirstTerm
(
b
)
==
getInputFromAbs
(
second
):
return
True
else
:
return
False
else
:
return
False
else
:
return
False
else
:
return
False
else
:
return
False
else
:
return
False
def
beta_reduction_totale
(
terme
,
path
,
saveImages
=
True
):
if
saveImages
==
False
:
if
recognize_term
(
terme
):
print
(
"
reduction infinie detectée
"
)
return
terme
elif
saveImages
==
False
:
if
beta_reduction
(
terme
)
!=
None
:
return
beta_reduction_totale
(
beta_reduction
(
terme
),
path
,
False
)
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
:
...
...
@@ -257,34 +279,31 @@ def beta_reduction_totale(terme, path, saveImages=True):
return
(
terme
)
numbers_to_letters
=
{
0
:
'
x
'
,
1
:
'
y
'
,
2
:
'
z
'
,
3
:
'
q
'
,
4
:
'
w
'
,
5
:
'
e
'
,
6
:
'
r
'
,
7
:
'
t
'
,
8
:
'
u
'
,
9
:
'
p
'
,
10
:
'
d
'
,
11
:
'
a
'
,
12
:
'
k
'
,
13
:
'
m
'
,
14
:
'
n
'
,
15
:
'
v
'
,
16
:
'
f
'
,
17
:
'
ç
'
,
18
:
'
aa
'
,
19
:
'
bb
'
,
20
:
'
cc
'
,
}
variables_letters_couples
=
{}
import
random
,
string
def
random_string
(
type
):
if
type
==
'
lower
'
:
return
''
.
join
(
random
.
choice
(
string
.
ascii_lowercase
)
for
i
in
range
(
1
))
elif
type
==
'
upper
'
:
return
''
.
join
(
random
.
choice
(
string
.
ascii_uppercase
)
for
i
in
range
(
1
))
def
associateVariableWithLetter
(
var
):
if
var
in
variables_letters_couples
:
return
if
len
(
list
(
variables_letters_couples
.
keys
()))
>=
26
:
x
=
random_string
(
'
upper
'
)
else
:
x
=
random_string
(
'
lower
'
)
while
x
in
variables_letters_couples
.
values
():
x
=
random_string
(
'
lower
'
)
variables_letters_couples
[
var
]
=
x
def
to_string_var
(
terme
):
assert
(
isVariable
(
terme
)),
'
The argument is not a variable
'
return
(
numbers_to_letters
[
terme
[
1
]])
associateVariableWithLetter
(
terme
[
1
])
return
variables_letters_couples
[
terme
[
1
]]
def
to_string_abs
(
terme
):
assert
(
isAbstraction
(
terme
)),
'
The argument is not an Abstraction
'
return
"
\u03BB
"
+
to_string
(
getInputFromAbs
(
terme
))
+
"
.
"
+
to_string
(
getOutputFromAbs
(
terme
))
...
...
@@ -461,11 +480,13 @@ def beta_reduction_choice_n(terme,n):
return
new_app
(
A1
,
beta_reduction_choice_n
(
B1
,
n
))
if
A2
==
None
and
B2
==
None
:
return
None
def
beta_reduction_interactive
(
terme
,
at
):
global
counters
if
recognize_term
(
terme
):
print
(
"
reduction interminable detectee
"
)
return
terme
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
"
)
...
...
@@ -505,5 +526,3 @@ def beta_reduction_interactive_totale(terme,path):
This diff is collapsed.
Click to expand it.
main.py
+
56
−
3
View file @
be76f1d7
...
...
@@ -63,6 +63,8 @@ def delete_images(folder):
print
(
e
)
def
moveImages
(
src
,
dest
):
for
filename
in
os
.
listdir
(
src
):
if
os
.
path
.
isfile
(
dest
+
'
/
'
+
filename
):
os
.
remove
(
dest
+
'
/
'
+
filename
)
shutil
.
move
(
src
+
"
/
"
+
filename
,
dest
)
def
return_main_menu
():
...
...
@@ -75,7 +77,6 @@ def return_main_menu():
clear
()
time
.
sleep
(
1
)
logic
.
image_counter
=
0
logic
.
var_counter
=
0
image_maker
.
variables_colors_couple
=
{}
clear
()
break
...
...
@@ -309,6 +310,15 @@ 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
)
choix
=
(
input
(
"
do you want to try an exemple? (y/n) :
"
))
while
choix
not
in
[
'
y
'
,
'
n
'
]:
choix
=
input
(
'
Invalid choice. Do you want to try an exemple? (y/n):
'
)
if
choix
==
'
y
'
:
clear
()
print
(
"
you are going to try n+m
"
)
n
=
int
(
input
(
"
give n :
"
))
m
=
int
(
input
(
"
give m :
"
))
app_functions
.
add
(
app_functions
.
dec_to_church
(
n
),
app_functions
.
dec_to_church
(
m
))
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):
'
)
...
...
@@ -323,7 +333,16 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
elif
choice
==
2
:
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUB
))
logic
.
captureImage
(
app_functions
.
SUB
,
path
,
'
SUB
'
,
False
)
logic
.
captureImage
(
app_functions
.
SUB
,
path
+
'
/SUB
'
,
'
SUB
'
,
False
)
choix
=
(
input
(
"
do you want to try an exemple? (y/n) :
"
))
while
choix
not
in
[
'
y
'
,
'
n
'
]:
choix
=
input
(
'
Invalid choice. Do you want to try an exemple? (y/n):
'
)
if
choix
==
'
y
'
:
clear
()
print
(
"
you are going to try n-m
"
)
n
=
int
(
input
(
"
give n :
"
))
m
=
int
(
input
(
"
give m :
"
))
app_functions
.
sub
(
app_functions
.
dec_to_church
(
n
),
app_functions
.
dec_to_church
(
m
))
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):
'
)
...
...
@@ -339,6 +358,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
MUL
))
logic
.
captureImage
(
app_functions
.
MUL
,
path
,
'
MUL
'
,
False
)
choix
=
(
input
(
"
do you want to try an exemple? (y/n) :
"
))
while
choix
not
in
[
'
y
'
,
'
n
'
]:
choix
=
input
(
'
Invalid choice. Do you want to try an exemple? (y/n):
'
)
if
choix
==
'
y
'
:
clear
()
print
(
"
you are going to try n*m
"
)
n
=
int
(
input
(
"
give n :
"
))
m
=
int
(
input
(
"
give m :
"
))
app_functions
.
mul
(
app_functions
.
dec_to_church
(
n
),
app_functions
.
dec_to_church
(
m
))
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):
'
)
...
...
@@ -354,6 +382,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
POW
))
logic
.
captureImage
(
app_functions
.
POW
,
path
,
'
POWER
'
,
False
)
choix
=
(
input
(
"
do you want to try an exemple? (y/n) :
"
))
while
choix
not
in
[
'
y
'
,
'
n
'
]:
choix
=
input
(
'
Invalid choice. Do you want to try an exemple? (y/n):
'
)
if
choix
==
'
y
'
:
clear
()
print
(
"
you are going to try n puiss m
"
)
n
=
int
(
input
(
"
give n :
"
))
m
=
int
(
input
(
"
give m :
"
))
app_functions
.
power
(
app_functions
.
dec_to_church
(
n
),
app_functions
.
dec_to_church
(
m
))
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):
'
)
...
...
@@ -369,6 +406,14 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUCCS
))
logic
.
captureImage
(
app_functions
.
SUCCS
,
path
,
'
SUCCS
'
,
False
)
choix
=
(
input
(
"
do you want to try an exemple? (y/n) :
"
))
while
choix
not
in
[
'
y
'
,
'
n
'
]:
choix
=
input
(
'
Invalid choice. Do you want to try an exemple? (y/n):
'
)
if
choix
==
'
y
'
:
clear
()
print
(
"
you are going to try n+1
"
)
n
=
int
(
input
(
"
give n :
"
))
app_functions
.
succ
(
app_functions
.
dec_to_church
(
n
))
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):
'
)
...
...
@@ -384,6 +429,14 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
PRED
))
logic
.
captureImage
(
app_functions
.
PRED
,
path
,
'
PRED
'
,
False
)
choix
=
(
input
(
"
do you want to try an exemple? (y/n) :
"
))
while
choix
not
in
[
'
y
'
,
'
n
'
]:
choix
=
input
(
'
Invalid choice. Do you want to try an exemple? (y/n):
'
)
if
choix
==
'
y
'
:
clear
()
print
(
"
you are going to try n-1
"
)
n
=
int
(
input
(
"
give n :
"
))
app_functions
.
predec
(
app_functions
.
dec_to_church
(
n
))
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):
'
)
...
...
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