Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
SPAENLEHAUER Pierre-Jean
tinygb
Commits
812e8768
Commit
812e8768
authored
Sep 08, 2017
by
SPAENLEHAUER Pierre-Jean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polymat.tpp cleaned
parent
49250122
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
181 deletions
+78
-181
src/polymat.tpp
src/polymat.tpp
+48
-85
src/polynomial.h
src/polynomial.h
+30
-96
No files found.
src/polymat.tpp
View file @
812e8768
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
#include "monomial.h"
#include <map>
#include <set>
#include <utility>
#include <vector>
#include "./monomial.h"
#ifdef BILIN
template
<
class
T
>
unsigned
polymat
<
T
>::
degree_bilin
()
const
{
unsigned
res
=
0
;
if
(
row
<
M
->
Asize
)
{
if
(
M
->
v1
[
row
].
degree_bilin
()
>
res
)
unsigned
polymat
<
T
>::
degree_bilin
()
const
{
unsigned
res
=
0
;
if
(
row
<
M
->
Asize
)
{
if
(
M
->
v1
[
row
].
degree_bilin
()
>
res
)
res
=
M
->
v1
[
row
].
degree_bilin
();
for
(
unsigned
j
=
0
;
j
<
M
->
B
->
get_csize
();
++
j
)
if
(
!
(
*
(
M
->
B
))(
row
,
j
).
is_zero
())
if
(
M
->
v2
[
j
].
degree_bilin
()
>
res
)
if
(
M
->
v2
[
j
].
degree_bilin
()
>
res
)
res
=
M
->
v2
[
j
].
degree_bilin
();
}
else
}
else
{
for
(
unsigned
j
=
0
;
j
<
M
->
D
->
get_csize
();
++
j
)
if
(
!
(
*
(
M
->
D
))(
row
-
M
->
Asize
,
j
).
is_zero
())
if
(
M
->
v2
[
j
].
degree_bilin
()
>
res
)
if
(
!
(
*
(
M
->
D
))(
row
-
M
->
Asize
,
j
).
is_zero
())
if
(
M
->
v2
[
j
].
degree_bilin
()
>
res
)
res
=
M
->
v2
[
j
].
degree_bilin
();
}
return
res
;
}
#endif
template
<
class
T
>
void
polymat
<
T
>::
to_polynomial
(
polynomial
<
T
>
&
P
)
const
{
void
polymat
<
T
>::
to_polynomial
(
polynomial
<
T
>
&
P
)
const
{
P
.
clear
();
if
(
M
==
NULL
)
return
;
if
(
row
<
M
->
get_Asize
())
{
P
.
insert
(
M
->
get_v1
()[
row
],
1
);
if
(
M
->
get_B
()
!=
NULL
&&
M
->
get_B
()
->
get_csize
())
if
(
row
<
M
->
get_Asize
())
{
P
.
insert
(
M
->
get_v1
()[
row
],
1
);
if
(
M
->
get_B
()
!=
NULL
&&
M
->
get_B
()
->
get_csize
())
{
for
(
unsigned
j
=
0
;
j
<
M
->
get_B
()
->
get_csize
();
++
j
)
if
(
!
(
*
(
M
->
get_B
()))(
row
,
j
).
is_zero
())
P
.
insert
(
M
->
get_v2
()[
j
],
(
*
(
M
->
get_B
()))(
row
,
j
));
P
.
insert
(
M
->
get_v2
()[
j
],
(
*
(
M
->
get_B
()))(
row
,
j
));
}
P
.
normalize
();
P
.
set_monic
();
}
else
{
}
else
{
assert
(
row
<
M
->
get_rsize
());
P
.
insert
(
M
->
get_pivots_LM
()[
row
-
M
->
get_Asize
()],
1
);
if
(
M
->
get_D
()
!=
NULL
&&
M
->
get_D
()
->
get_csize
())
P
.
insert
(
M
->
get_pivots_LM
()[
row
-
M
->
get_Asize
()],
1
);
if
(
M
->
get_D
()
!=
NULL
&&
M
->
get_D
()
->
get_csize
())
{
for
(
unsigned
j
=
0
;
j
<
M
->
get_D
()
->
get_csize
();
++
j
)
if
(
!
(
*
(
M
->
get_D
()))(
row
-
M
->
get_Asize
(),
j
).
is_zero
())
P
.
insert
(
M
->
get_v2
()[
j
],
(
*
(
M
->
get_D
()))(
row
-
M
->
get_Asize
(),
j
));
}
P
.
normalize
();
P
.
set_monic
();
}
}
template
<
class
T
>
std
::
ostream
&
operator
<<
(
ostream
&
o
,
const
polymat
<
T
>
&
P
)
{
std
::
ostream
&
operator
<<
(
ostream
&
o
,
const
polymat
<
T
>
&
P
)
{
polynomial
<
T
>
p
;
P
.
to_polynomial
(
p
);
return
o
<<
p
;
return
o
<<
p
;
}
template
<
class
T
>
void
polymat
<
T
>::
construct_polymats
(
vector
<
polymat
<
T
>
>
&
new_pols
,
const
matrixF4
<
T
>
*
M
)
{
void
polymat
<
T
>::
construct_polymats
(
vector
<
polymat
<
T
>
>
&
new_pols
,
const
matrixF4
<
T
>
*
M
)
{
new_pols
.
clear
();
polymat
<
T
>
tmp
;
for
(
unsigned
i
=
0
;
i
<
M
->
get_rsize
();
++
i
)
{
for
(
unsigned
i
=
0
;
i
<
M
->
get_rsize
();
++
i
)
{
tmp
=
polymat
(
M
,
i
);
new_pols
.
push_back
(
tmp
);
}
}
}
template
<
class
T
>
unsigned
polymat
<
T
>::
nb_non_zero
()
const
{
unsigned
polymat
<
T
>::
nb_non_zero
()
const
{
unsigned
res
=
1
;
if
(
M
->
get_csize
()
==
M
->
get_Asize
())
if
(
M
->
get_csize
()
==
M
->
get_Asize
())
return
1
;
if
(
row
<
M
->
get_Asize
())
{
if
(
row
<
M
->
get_Asize
())
{
for
(
unsigned
j
=
0
;
j
<
M
->
get_B
()
->
get_csize
();
j
++
)
if
(
!
(
*
(
M
->
get_B
()))(
row
,
j
).
is_zero
())
if
(
!
(
*
(
M
->
get_B
()))(
row
,
j
).
is_zero
())
res
++
;
}
else
{
if
(
M
->
get_D
()
==
NULL
)
}
else
{
if
(
M
->
get_D
()
==
NULL
)
return
1
;
for
(
unsigned
j
=
0
;
j
<
M
->
get_D
()
->
get_csize
();
j
++
)
if
(
!
(
*
(
M
->
get_D
()))(
row
-
M
->
get_Asize
(),
j
).
is_zero
())
...
...
@@ -120,44 +90,37 @@ unsigned polymat<T>::nb_non_zero() const
template
<
class
T
>
void
polymat
<
T
>::
merge_sets
(
set
<
monomial
>
&
prio
,
const
monomial
&
m
)
const
{
void
polymat
<
T
>::
merge_sets
(
set
<
monomial
>
&
prio
,
const
monomial
&
m
)
const
{
monomial
tmp_m
;
if
(
row
<
M
->
get_Asize
()
&&
M
->
get_B
()
!=
NULL
)
{
if
(
row
<
M
->
get_Asize
()
&&
M
->
get_B
()
!=
NULL
)
{
for
(
unsigned
j
=
0
;
j
<
M
->
get_B
()
->
get_csize
();
j
++
)
if
(
!
(
*
(
M
->
get_B
()))(
row
,
j
).
is_zero
())
{
if
(
!
(
*
(
M
->
get_B
()))(
row
,
j
).
is_zero
())
{
tmp_m
=
monomial
(
M
->
get_v2
()[
j
]);
tmp_m
*=
m
;
prio
.
insert
(
tmp_m
);
}
}
else
if
(
M
->
get_D
()
!=
NULL
)
for
(
unsigned
j
=
0
;
j
<
M
->
get_csize
();
j
++
)
{
if
(
!
(
*
(
M
->
get_D
()))(
row
-
M
->
get_Asize
(),
j
).
is_zero
())
{
}
}
else
if
(
M
->
get_D
()
!=
NULL
)
{
for
(
unsigned
j
=
0
;
j
<
M
->
get_csize
();
j
++
)
{
if
(
!
(
*
(
M
->
get_D
()))(
row
-
M
->
get_Asize
(),
j
).
is_zero
())
{
tmp_m
=
monomial
(
M
->
get_v2
()[
j
]);
tmp_m
*=
m
;
prio
.
insert
(
tmp_m
);
}
}
}
}
}
template
<
class
T
>
bool
polymat
<
T
>::
istopred
(
const
vector
<
polymat
<
T
>
>
&
G
)
const
{
bool
polymat
<
T
>::
istopred
(
const
vector
<
polymat
<
T
>
>
&
G
)
const
{
for
(
unsigned
i
=
0
;
i
<
G
.
size
();
++
i
)
if
(
LM
.
isDivisibleBy
(
G
[
i
].
get_LM
()))
if
(
LM
.
isDivisibleBy
(
G
[
i
].
get_LM
()))
return
true
;
return
false
;
}
template
<
class
T
>
bool
operator
<
(
const
pair
<
monomial
,
polymat
<
T
>
>
cp1
,
const
pair
<
monomial
,
polymat
<
T
>
>
cp2
)
{
bool
operator
<
(
const
pair
<
monomial
,
polymat
<
T
>
>
cp1
,
const
pair
<
monomial
,
polymat
<
T
>
>
cp2
)
{
if
(
cp1
.
first
<
cp2
.
first
)
return
true
;
if
(
cp2
.
first
<
cp1
.
first
)
return
false
;
if
(
cp1
.
second
.
M
<
cp2
.
second
.
M
)
return
true
;
...
...
src/polynomial.h
View file @
812e8768
/* Written by <pierre-jean.spaenlehauer@inria.fr>
*
* ========LICENCE========
* This file is part of tinygb.
*
* tinygb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
*/
/// @file
/// @brief Polynomials in sparse representation
#ifndef __POLYNOMIAL_H__
#define __POLYNOMIAL_H__
#ifndef POLYNOMIAL_H_
#define POLYNOMIAL_H_
#include <list>
#include "param.h"
#include "monomial.h"
#include <utility>
#include "./param.h"
#include "./monomial.h"
template
<
class
T
>
class
polynomial
;
...
...
@@ -36,99 +12,63 @@ class polynomial;
template
<
class
T
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
o
,
const
polynomial
<
T
>
&
p
);
/// @class
/// @brief Class for manipulating polynomials in sparse representation
template
<
class
T
>
class
polynomial
{
class
polynomial
{
void
combine_LM
();
std
::
list
<
std
::
pair
<
monomial
,
T
>
>
vp
;
std
::
list
<
std
::
pair
<
monomial
,
T
>
>
vp
;
public:
/// @brief default constructor, construct the zero polynomial
polynomial
()
{
vp
=
std
::
list
<
std
::
pair
<
monomial
,
T
>
>
();
public:
polynomial
()
{
vp
=
std
::
list
<
std
::
pair
<
monomial
,
T
>
>
();
}
/// @brief constructor from an ordered list of pairs
polynomial
(
std
::
list
<
std
::
pair
<
monomial
,
T
>
>
_vp
)
:
vp
(
_vp
){}
/// @brief get the list of terms
const
std
::
list
<
std
::
pair
<
monomial
,
T
>
>&
get_vp
()
const
{
explicit
polynomial
(
const
std
::
list
<
std
::
pair
<
monomial
,
T
>
>&
_vp
)
:
vp
(
_vp
)
{}
const
std
::
list
<
std
::
pair
<
monomial
,
T
>
>&
get_vp
()
const
{
return
vp
;
}
/// @brief orders the list of terms and merges terms with same monomials.
void
normalize
();
/// @brief set the polynomial to 0
void
clear
()
{
void
normalize
();
void
clear
()
{
vp
.
clear
();
}
/// @brief adds a term
/// @param m monomial part of the term
/// @param e field element
void
insert
(
monomial
m
,
T
e
)
{
vp
.
push_back
(
std
::
pair
<
monomial
,
T
>
(
m
,
e
));
void
insert
(
monomial
m
,
T
e
)
{
vp
.
push_back
(
std
::
pair
<
monomial
,
T
>
(
m
,
e
));
}
/// @brief get the leading monomial
const
monomial
&
LM
()
const
{
const
monomial
&
LM
()
const
{
assert
(
!
vp
.
back
().
second
.
is_zero
());
return
vp
.
back
().
first
;
}
/// @brief get the leading coefficient
const
T
&
LC
()
const
{
const
T
&
LC
()
const
{
return
vp
.
back
().
second
;
}
/// @brief scales the polynomial so that the leading coefficient is 1.
void
set_monic
();
unsigned
size
()
const
{
unsigned
size
()
const
{
return
vp
.
size
();
}
/// @brief tests if a normalized polynomial is zero.
bool
is_zero
()
const
{
bool
is_zero
()
const
{
return
vp
.
empty
();
}
/// @brief computes the degree, only works for degree orderings
/// @returns the sum of the exponents
unsigned
degree
()
const
{
//@todo extends for non-degree orderings
unsigned
degree
()
const
{
// TODO(pj): extends for non-degree orderings
return
LM
().
degree
();
}
#ifdef BILIN
/// @brief special degree for the selection of critpairs for bilinear systems
unsigned
degree_bilin
()
const
;
#endif
/// @brief top-reduce by a polynomial
/// @param g reductor
/// @returns a boolean indicating if the polynomial was topreduced
bool
topred
(
const
polynomial
&
g
);
/// @brief check if top-reducible by another polynomial
/// @param g reductor
/// @returns a boolean indicating if the polynomial was topreduced
bool
istopred
(
const
polynomial
&
g
)
const
;
/// @brief get the coefficient of a given monomial
/// @param m monomial whose coefficient is returned
/// @returns the corresponding coefficient
T
coeff
(
const
monomial
&
m
)
const
;
/****************************************/
...
...
@@ -139,17 +79,11 @@ class polynomial
void
operator
*=
(
const
T
&
);
void
operator
/=
(
const
T
&
);
/// @brief prints the list of pairs coeff/monomial
/// @param out output stream
void
print
(
std
::
ostream
&
out
)
const
;
/// @brief compares leading monomials.
/// @param P polynomial to be compared to.
inline
bool
operator
<
(
const
polynomial
<
T
>&
P
)
const
;
//human readable formatting
friend
std
::
ostream
&
operator
<<
<
T
>
(
std
::
ostream
&
,
const
polynomial
<
T
>&
);
};
#include "polynomial.tpp"
#endif
#endif
// POLYNOMIAL_H_
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