/usr/include/linbox/blackbox/companion.h is in liblinbox-dev 1.1.6~rc0-4.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | /* linbox/blackbox/mapleBB.h
*
* Written by David Saunders <saunders@cis.udel.edu>
* See COPYING
*/
#ifndef __COMPANION_H
#define __COMPANION_H
#include <linbox/blackbox/blackbox-interface.h>
#include "linbox/blackbox/triplesbb.h"
#include <vector>
namespace LinBox {
/** \ingroup blackbox
\brief %Companion matrix of a monic polynomial.
*/
template<class _Field>
struct Companion: public TriplesBB<_Field> {
typedef _Field Field;
/// This is the n by n companion matrix of a given polynomial of degree n.
template<class Polynomial>
Companion(const Field& F =Field(), const Polynomial& P =Polynomial(1))
: TriplesBB<Field>(F, P.size()-1, P.size()-1)
{ size_t n = P.size() - 1;
const size_t indexbase = 1;
typename Field::Element one; F.init(one, 1);
for (size_t i = 1; i < n; ++i) addEntry(one, i+indexbase, i-1+indexbase);
for (size_t i = 0; i < n; ++i)
{ typename Field::Element x;
F.init(x, 0);
F.neg(x, P[i]);
addEntry(x, i+indexbase, n-1+indexbase);
}
}// Companion cstor
/**
* \brief This constructs a random companion matrix.
Builds n by n matrix from degree n monic poly with other coefficients random.
*/
Companion(const Field& F, size_t n,
typename Field::RandIter r )
: TriplesBB<Field>(F, n, n)
{
std::vector<typename Field::Element> p(n+1);
for (typename std::vector<typename Field::Element>::iterator i = p.begin(); i != p.end(); ++i)
r.random(*i); // we'll pretend p[n] == 1, ok?
const size_t indexbase = 1;
typename Field::Element one; F.init(one, 1);
for (size_t i = 1; i < n; ++i) addEntry(one, i+indexbase, i-1+indexbase);
for (size_t i = 0; i < n; ++i)
{ typename Field::Element x;
F.init(x, 0);
F.neg(x, p[i]);
addEntry(x, i+indexbase, n-1+indexbase);
}
}
Companion(const Field& F, size_t n) :TriplesBB<Field>(F,n,n)
{
typename Field::RandIter r(F);
std::vector<typename Field::Element> p(n+1);
for (typename std::vector<typename Field::Element>::iterator i = p.begin(); i != p.end(); ++i)
r.random(*i); // we'll pretend p[n] == 1, ok?
const size_t indexbase = 1;
typename Field::Element one; F.init(one, 1);
for (size_t i = 1; i < n; ++i) addEntry(one, i+indexbase, i-1+indexbase);
for (size_t i = 0; i < n; ++i)
{ typename Field::Element x;
F.init(x, 0);
F.neg(x, p[i]);
addEntry(x, i+indexbase, n-1+indexbase);
}
}
template<typename _Tp1>
struct rebind
{ typedef Companion<_Tp1> other; };
// companion would be faster if built direct, using one axpy per entry: y_i = x_i-1 + p_i*x_n
}; //Companion class
} //LinBox
#endif //__COMPANION_H
|