Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reed_solomon
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
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
darius.briquet
reed_solomon
Commits
f4a4715f
Commit
f4a4715f
authored
3 years ago
by
Djokzer
Browse files
Options
Downloads
Plain Diff
Lagrange still doesn't work
parents
5421607c
3630a6a7
No related branches found
No related tags found
1 merge request
!10
Resolve "Create Lagrange method"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
reed_solomon.py
+25
-26
25 additions, 26 deletions
reed_solomon.py
with
25 additions
and
26 deletions
reed_solomon.py
+
25
−
26
View file @
f4a4715f
...
@@ -23,35 +23,34 @@ def get_possibilities(l: list):
...
@@ -23,35 +23,34 @@ def get_possibilities(l: list):
return
p
return
p
def
lagrange_compute
(
l
:
list
)
->
polynome
:
def
lagrange_compute
(
l
:
list
)
->
polynome
:
list_s
=
[
0
]
*
len
(
l
)
poly
=
[
0
]
*
len
(
l
)
list_p
=
[
0
]
*
len
(
l
)
for
x_i
,
y_i
in
l
:
sum_poly
=
polynome
(
list_s
)
#Produit des coeffs
#product_poly = polynome(list_p)
coeff
=
[
0
]
*
len
(
l
)
first_time
=
True
denominator
=
1
for
x_i
,
y_i
in
enumerate
(
l
):
for
j
in
range
(
len
(
l
)):
for
x_j
,
y_j
in
enumerate
(
l
):
if
x_i
!=
j
:
if
x_j
!=
x_i
:
denominator
*=
x_i
-
l
[
j
][
0
]
list_p
[
0
]
=
-
x_j
/
(
x_i
-
x_j
)
coeff
[
0
]
=
1
/
denominator
#Produit de chaque denominateur
list_p
[
1
]
=
1
/
(
x_i
-
x_j
)
if
first_time
:
for
k
in
range
(
len
(
l
)):
product_poly
=
polynome
(
list_p
)
new_coeff
=
[
0
]
*
(
len
(
l
)
+
1
)
first_time
=
False
if
x_i
!=
k
:
else
:
for
j
in
range
(
k
+
1
if
k
<
x_i
else
k
,
0
,
-
1
):
product_poly
=
product_poly
.
mul
(
polynome
(
list_p
))
new_coeff
[
j
+
1
]
+=
coeff
[
j
]
product_poly
.
show
()
new_coeff
[
j
]
-=
l
[
k
][
0
]
*
coeff
[
j
]
first_time
=
True
coeff
=
new_coeff
sum_poly
=
sum_poly
.
add
(
product_poly
)
sum_poly
.
show
()
#Somme des coeffs
list_p
=
[
0
]
*
len
(
l
)
for
s
in
range
(
len
(
l
)):
return
sum_poly
poly
[
s
]
+=
y_i
*
coeff
[
s
]
return
poly
def
check_nb_error
(
l
:
list
,
p
:
polynome
)
->
int
:
def
check_nb_error
(
l
:
list
,
p
:
polynome
)
->
int
:
pass
pass
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
list_
=
[
1
,
2
,
3
]
list_
=
[(
0
,
1
),
(
1
,
2
),
(
2
,
3
)]
#print(list_)
poly
=
lagrange_compute
(
list_
)
poly
=
lagrange_compute
(
list_
)
poly
.
show
()
print
(
poly
)
#print(poly.evaluate(0))
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