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
5890c3d1
Commit
5890c3d1
authored
2 years ago
by
Tamazouzt AIT ELDJOUDI
Browse files
Options
Downloads
Patches
Plain Diff
added arithmetic functions to the menu and app_functions, added the infinite beta reduction
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
+23
-13
23 additions, 13 deletions
app_functions.py
logic.py
+35
-11
35 additions, 11 deletions
logic.py
main.py
+52
-0
52 additions, 0 deletions
main.py
with
110 additions
and
24 deletions
app_functions.py
+
23
−
13
View file @
5890c3d1
...
...
@@ -53,23 +53,33 @@ def dec_to_lambda_relative_integers(number):
return
pair
(
TRUE
,
dec_to_church
(
number
))
return
pair
(
FALSE
,
dec_to_church
(
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)))
# ajouter les etoiles sur les alligators qui Maangent
# ajoter les sauvegardes
# ajouter le predec ....
# terme qui termine pas
#probleme de l arret
This diff is collapsed.
Click to expand it.
logic.py
+
35
−
11
View file @
5890c3d1
...
...
@@ -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
:
...
...
@@ -461,11 +483,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
"
)
...
...
This diff is collapsed.
Click to expand it.
main.py
+
52
−
0
View file @
5890c3d1
...
...
@@ -309,6 +309,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):
'
)
...
...
@@ -324,6 +333,15 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
clear
()
print
(
"
Voici le terme:
"
+
logic
.
to_string
(
app_functions
.
SUB
))
logic
.
captureImage
(
app_functions
.
SUB
,
path
,
'
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 +357,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 +381,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 +405,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 +428,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