Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
M1-EEA
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
EEA
M1-EEA
Commits
a8c8245d
Commit
a8c8245d
authored
Mar 01, 2019
by
Pierre-antoine Comby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correction du code
parent
4e367a12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
8 deletions
+58
-8
455-Codage_Sources/algo_code/code_arithmetique.py
455-Codage_Sources/algo_code/code_arithmetique.py
+58
-8
No files found.
455-Codage_Sources/algo_code/code_arithmetique.py
View file @
a8c8245d
...
...
@@ -2,28 +2,78 @@
import
numpy
as
np
p
_s
=
[
0.1
,
0.9
]
N
=
10
p
=
0.2
P
=
np
.
random
.
rand
(
N
)
X
=
[
0
for
p
in
P
if
p
>
p_s
[
0
]
else
1
]
X
=
np
.
zeros
(
N
,
dtype
=
'int'
)
for
i
in
range
(
N
):
if
P
[
i
]
>
p
:
X
[
i
]
=
1
X
=
[
0
,
1
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
0
]
print
(
X
)
def
binary
(
n
,
b
=
2
,
m
):
def
binary
(
n
,
m
,
b
=
2
):
"""
Convertie un nombre décimal en sa version binaire tronqué à m bits.
"""
return
np
.
ceil
(
n
*
b
**
m
)
binaire
=
np
.
floor
(
n
*
b
**
m
)
# on se décale dans les entiers et on floor
return
binaire
,
np
.
binary_repr
(
int
(
binaire
))
def
arithm
(
X
):
def
arithm
(
X
,
p
):
l
=
[
0
]
h
=
[
1
]
for
x
in
X
:
if
x
==
0
:
h
.
append
(
l
[
-
1
]
+
p
_s
[
0
]
*
(
h
[
-
1
]
-
l
[
-
1
]))
h
.
append
(
l
[
-
1
]
+
p
*
(
h
[
-
1
]
-
l
[
-
1
]))
l
.
append
(
l
[
-
1
])
else
:
l
.
append
(
l
[
-
1
]
+
p
_s
[
0
]
*
(
h
[
-
1
]
-
l
[
-
1
]))
l
.
append
(
l
[
-
1
]
+
p
*
(
h
[
-
1
]
-
l
[
-
1
]))
h
.
append
(
h
[
-
1
])
lmb
=
(
l
[
-
1
]
+
h
[
-
1
])
/
2
mu
=
int
(
-
np
.
log2
(
h
[
-
1
]
-
l
[
-
1
]))
+
1
code
=
binary
(
lmb
,
mu
)
return
code
,
lmb
,
mu
def
arithm_pratique
(
X
,
p
):
l
=
[
0
]
# borne inférieur
h
=
[
1
]
# borne supérieur
f
=
0
# follow
c
=
[]
# code
for
k
in
range
(
len
(
X
)):
print
(
"for loop"
)
if
X
[
k
]
==
0
:
l
.
append
(
l
[
-
1
])
h
.
append
(
l
[
-
1
]
+
p
*
(
h
[
-
1
]
-
l
[
-
1
]))
else
:
l
.
append
(
l
[
-
1
]
+
p
*
(
h
[
-
1
]
-
l
[
-
1
]))
h
.
append
(
h
[
-
1
])
print
(
X
[
k
])
print
(
l
[
-
3
:])
print
(
h
[
-
3
:])
while
((
l
[
-
1
]
>=
0
and
h
[
-
1
]
<
0.5
)
or
(
l
[
-
1
]
>=
0.5
and
h
[
-
1
]
<
1
)
or
(
l
[
-
1
]
>=
0.25
and
h
[
-
1
]
<
0.75
)):
print
(
" loop"
)
if
(
l
[
-
1
]
>=
0
and
h
[
-
1
]
<
0.5
):
print
(
" case 1"
)
c
+=
[
0
]
+
[
1
]
*
f
l
[
-
1
]
*=
2
h
[
-
1
]
*=
2
elif
(
l
[
-
1
]
>=
0.5
and
h
[
-
1
]
<
1
):
print
(
" case 2"
)
c
+=
[
1
]
+
[
0
]
*
f
l
[
-
1
]
=
2
*
l
[
-
1
]
-
1
h
[
-
1
]
=
2
*
h
[
-
1
]
-
1
elif
(
l
[
-
1
]
>=
0.25
and
h
[
-
1
]
<
0.75
):
print
(
" case 3"
)
f
+=
1
l
[
-
1
]
=
2
*
l
[
-
1
]
-
0.5
h
[
-
1
]
=
2
*
h
[
-
1
]
-
0.5
return
c
#print(arithm(X,p))
print
(
arithm_pratique
(
X
,
p
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment