2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
template<class R> class mod_map;
|
2012-02-29 04:08:52 +01:00
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R> class mod_span;
|
2012-02-29 04:08:52 +01:00
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R> class free_submodule;
|
|
|
|
template<class R> class quotient_module;
|
2012-03-01 04:21:45 +01:00
|
|
|
template<class R> class direct_sum;
|
2012-02-29 04:08:52 +01:00
|
|
|
template<class R> class tensor_product;
|
|
|
|
template<class R> class hom_module;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
/* `module' is a bigraded module over a ring R. */
|
|
|
|
template<class R>
|
|
|
|
class module : public refcounted
|
|
|
|
{
|
2012-02-29 04:08:52 +01:00
|
|
|
private:
|
2012-05-03 21:27:05 +02:00
|
|
|
friend class reader;
|
|
|
|
friend class writer;
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
unsigned id;
|
|
|
|
|
|
|
|
static unsigned id_counter;
|
|
|
|
|
2012-05-21 16:09:17 +02:00
|
|
|
static map<unsigned, ptr<const module<R> > > reader_id_module;
|
2012-05-03 21:27:05 +02:00
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
static map<basedvector<unsigned, 1>,
|
2012-03-01 04:21:45 +01:00
|
|
|
ptr<const direct_sum<R> > > direct_sum_idx;
|
2012-02-29 04:08:52 +01:00
|
|
|
static map<basedvector<unsigned, 1>,
|
|
|
|
ptr<const tensor_product<R> > > tensor_product_idx;
|
|
|
|
static map<pair<unsigned, unsigned>,
|
|
|
|
ptr<const hom_module<R> > > hom_module_idx;
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
public:
|
2012-02-29 04:08:52 +01:00
|
|
|
module ()
|
|
|
|
{
|
|
|
|
id_counter ++;
|
2012-05-03 21:27:05 +02:00
|
|
|
id = id_counter;
|
2012-02-29 04:08:52 +01:00
|
|
|
}
|
2012-07-27 21:37:47 +02:00
|
|
|
module (const module &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
virtual ~module () { }
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
module &operator = (const module &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
// the number of generators; n
|
|
|
|
virtual unsigned dim () const = 0;
|
|
|
|
|
|
|
|
// r; 1 <= r <= n
|
|
|
|
virtual unsigned free_rank () const = 0;
|
|
|
|
|
|
|
|
virtual grading generator_grading (unsigned i) const = 0;
|
|
|
|
virtual void show_generator (unsigned i) const = 0;
|
|
|
|
|
|
|
|
// r < i <= n
|
|
|
|
virtual R generator_ann (unsigned i) const = 0;
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
set<grading> gradings () const;
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
bool is_free () const { return dim () == free_rank (); }
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
bool is_zero (R c, unsigned i) const
|
|
|
|
{
|
|
|
|
if (i <= free_rank ())
|
|
|
|
return c == 0;
|
|
|
|
else
|
|
|
|
return generator_ann (i) | c;
|
|
|
|
}
|
|
|
|
|
|
|
|
R annihilator (R c, unsigned i) const
|
|
|
|
{
|
|
|
|
R iann = generator_ann (i);
|
|
|
|
|
|
|
|
return iann.div (iann.gcd (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isomorphic (ptr<const module<R> > m) const;
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
ptr<const quotient_module<R> > quotient (const mod_span<R> &span) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
ptr<const quotient_module<R> > quotient (ptr<const free_submodule<R> > m) const;
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
ptr<const free_submodule<R> > submodule (const mod_span<R> &span) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2011-12-22 21:35:49 +01:00
|
|
|
multivariate_laurentpoly<Z> free_poincare_polynomial () const;
|
|
|
|
multivariate_laurentpoly<Z> free_delta_poincare_polynomial () const;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-03-01 04:21:45 +01:00
|
|
|
ptr<const direct_sum<R> >
|
|
|
|
add (basedvector<ptr<const module<R> >, 1> compound_summands) const;
|
|
|
|
|
|
|
|
ptr<const direct_sum<R> > add (ptr<const module<R> > m) const
|
|
|
|
{
|
|
|
|
basedvector<ptr<const module<R> >, 1> summands (2);
|
|
|
|
summands[1] = this;
|
|
|
|
summands[2] = m;
|
|
|
|
return add (summands);
|
|
|
|
}
|
|
|
|
|
|
|
|
// g -> (g, 0)
|
|
|
|
unsigned inject_1 (unsigned g, ptr<const module<R> > m) const
|
|
|
|
{
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
// g -> (0, g)
|
|
|
|
unsigned inject_2 (ptr<const module<R> > m, unsigned g) const
|
|
|
|
{
|
|
|
|
return dim () + g;
|
|
|
|
}
|
|
|
|
|
|
|
|
pair<unsigned, unsigned> project (ptr<const module<R> > m, unsigned g) const
|
|
|
|
{
|
|
|
|
if (g <= dim ())
|
|
|
|
return pair<unsigned, unsigned> (1, g);
|
|
|
|
else
|
|
|
|
return pair<unsigned, unsigned> (2, g - dim ());
|
|
|
|
}
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
ptr<const tensor_product<R> > tensor (ptr<const module<R> > m) const
|
|
|
|
{
|
|
|
|
basedvector<ptr<const module<R> >, 1> factors (2);
|
|
|
|
factors[1] = this;
|
|
|
|
factors[2] = m;
|
|
|
|
return tensor (factors);
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr<const hom_module<R> > hom (ptr<const module<R> > to) const;
|
|
|
|
|
|
|
|
pair<unsigned, unsigned>
|
|
|
|
generator_factors (ptr<const module<R> > m, unsigned g) const
|
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p ((g - 1) % dim () + 1,
|
|
|
|
(g - 1) / dim () + 1);
|
|
|
|
assert (g == tensor_generators (p.first, m, p.second));
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ptr<const tensor_product<R> > tensor (basedvector<ptr<const module<R> >, 1> compound_factors);
|
|
|
|
|
|
|
|
unsigned tensor_generators (unsigned i, ptr<const module<R> > m, unsigned j) const
|
|
|
|
{
|
|
|
|
return (i - 1) + (j - 1) * dim () + 1;
|
|
|
|
}
|
|
|
|
|
2012-03-01 04:21:45 +01:00
|
|
|
virtual void append_direct_summands (basedvector<ptr<const module<R> >, 1> &summands) const
|
|
|
|
{
|
|
|
|
summands.append (this);
|
|
|
|
}
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
virtual void append_tensor_factors (basedvector<ptr<const module<R> >, 1> &factors) const
|
|
|
|
{
|
|
|
|
factors.append (this);
|
|
|
|
}
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
ptr<const free_submodule<R> > graded_piece (grading hq) const;
|
|
|
|
|
|
|
|
void write_self (writer &w) const { w.write_mod<R> (this); }
|
2011-12-09 21:50:25 +01:00
|
|
|
void show_self () const;
|
|
|
|
void display_self () const;
|
|
|
|
};
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
template<class R> unsigned module<R>::id_counter = 0;
|
|
|
|
|
2012-05-21 16:09:17 +02:00
|
|
|
template<class R> map<unsigned, ptr<const module<R> > > module<R>::reader_id_module;
|
2012-03-01 04:21:45 +01:00
|
|
|
|
|
|
|
template<class R> map<basedvector<unsigned, 1>,
|
|
|
|
ptr<const direct_sum<R> > > module<R>::direct_sum_idx;
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
template<class R> map<basedvector<unsigned, 1>,
|
|
|
|
ptr<const tensor_product<R> > > module<R>::tensor_product_idx;
|
|
|
|
|
|
|
|
template<class R> map<pair<unsigned, unsigned>,
|
|
|
|
ptr<const hom_module<R> > > module<R>::hom_module_idx;
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class direct_sum : public module<R>
|
|
|
|
{
|
|
|
|
unsigned n;
|
|
|
|
basedvector<ptr<const module<R> >, 1> summands;
|
|
|
|
|
|
|
|
public:
|
|
|
|
direct_sum (basedvector<ptr<const module<R> >, 1> summands_)
|
|
|
|
: n(0),
|
2012-03-01 04:21:45 +01:00
|
|
|
summands(summands_)
|
2012-02-29 04:08:52 +01:00
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
2012-03-01 04:21:45 +01:00
|
|
|
for (unsigned i = 1; i <= summands.size (); i ++)
|
|
|
|
assert (summands[i]->is_free ());
|
2012-02-29 04:08:52 +01:00
|
|
|
#endif
|
|
|
|
|
2012-03-01 04:21:45 +01:00
|
|
|
for (unsigned i = 1; i <= summands.size (); i ++)
|
|
|
|
n += summands[i]->dim ();
|
2012-02-29 04:08:52 +01:00
|
|
|
}
|
2012-03-01 04:21:45 +01:00
|
|
|
~direct_sum () { }
|
2012-02-29 04:08:52 +01:00
|
|
|
|
|
|
|
unsigned dim () const { return n; }
|
|
|
|
unsigned free_rank () const { return n; }
|
|
|
|
|
2012-03-01 04:21:45 +01:00
|
|
|
grading generator_grading (unsigned i) const;
|
|
|
|
void show_generator (unsigned i) const;
|
|
|
|
R generator_ann (unsigned i) const { return R (0); }
|
|
|
|
|
|
|
|
void append_direct_summands (basedvector<ptr<const module<R> >, 1> &psummands) const
|
|
|
|
{
|
|
|
|
for (unsigned i = 1; i <= summands.size (); i ++)
|
|
|
|
psummands.append (summands[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned inject (unsigned i, unsigned g) const;
|
|
|
|
pair<unsigned, unsigned> project (unsigned g) const;
|
2012-02-29 04:08:52 +01:00
|
|
|
};
|
2012-03-01 04:21:45 +01:00
|
|
|
|
|
|
|
template<class R> grading
|
|
|
|
direct_sum<R>::generator_grading (unsigned i) const
|
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p = project (i);
|
|
|
|
return summands[p.first]->generator_grading (p.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
direct_sum<R>::show_generator (unsigned i) const
|
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p = project (i);
|
|
|
|
printf ("%d:", p.first);
|
|
|
|
return summands[p.first]->show_generator (p.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> unsigned
|
|
|
|
direct_sum<R>::inject (unsigned i, unsigned g) const
|
|
|
|
{
|
|
|
|
assert (i >= 1 && i <= summands.size ());
|
|
|
|
|
|
|
|
for (unsigned j = 1; j < i; j ++)
|
|
|
|
g += summands[j]->dim ();
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> pair<unsigned, unsigned>
|
|
|
|
direct_sum<R>::project (unsigned g) const
|
|
|
|
{
|
|
|
|
assert (g <= n);
|
|
|
|
|
|
|
|
unsigned g0 = g;
|
|
|
|
|
|
|
|
for (unsigned j = 1; j <= summands.size (); j ++)
|
|
|
|
{
|
|
|
|
if (g <= summands[j]->dim ())
|
|
|
|
{
|
|
|
|
assert (inject (j, g) == g0);
|
|
|
|
|
|
|
|
return pair<unsigned, unsigned> (j, g);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g -= summands[j]->dim ();
|
|
|
|
}
|
|
|
|
abort (); // shouldn't get here
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const direct_sum<R> >
|
|
|
|
module<R>::add (basedvector<ptr<const module<R> >, 1> compound_summands) const
|
|
|
|
{
|
|
|
|
basedvector<ptr<const module<R> >, 1> summands;
|
|
|
|
for (unsigned i = 1; i <= compound_summands.size (); i ++)
|
|
|
|
compound_summands[i]->append_direct_summands (summands);
|
|
|
|
|
|
|
|
basedvector<unsigned, 1> summand_ids (summands.size ());
|
|
|
|
for (unsigned i = 1; i <= summands.size (); i ++)
|
|
|
|
summand_ids[i] = summands[i]->id;
|
|
|
|
|
|
|
|
pair<ptr<const direct_sum<R> > &, bool> p = direct_sum_idx.find (summand_ids);
|
|
|
|
if (!p.second)
|
|
|
|
p.first = new direct_sum<R> (summands);
|
|
|
|
return p.first;
|
|
|
|
}
|
2012-02-29 04:08:52 +01:00
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class tensor_product : public module<R>
|
|
|
|
{
|
|
|
|
unsigned n;
|
|
|
|
basedvector<ptr<const module<R> >, 1> factors;
|
|
|
|
|
|
|
|
basedvector<unsigned, 1> generator_factors (unsigned g) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
tensor_product (basedvector<ptr<const module<R> >, 1> factors_)
|
|
|
|
: n(1),
|
|
|
|
factors(factors_)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
assert (factors[i]->is_free ());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
n *= factors[i]->dim ();
|
|
|
|
}
|
|
|
|
~tensor_product () { }
|
|
|
|
|
|
|
|
unsigned dim () const { return n; }
|
|
|
|
unsigned free_rank () const { return n; }
|
|
|
|
|
|
|
|
grading generator_grading (unsigned i) const;
|
|
|
|
void show_generator (unsigned i) const;
|
|
|
|
R generator_ann (unsigned i) const { return R (0); }
|
|
|
|
|
|
|
|
unsigned tensor_generators (basedvector<unsigned, 1> gs) const;
|
|
|
|
|
|
|
|
void append_tensor_factors (basedvector<ptr<const module<R> >, 1> &pfactors) const
|
|
|
|
{
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
pfactors.append (factors[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R> ptr<const tensor_product<R> >
|
|
|
|
module<R>::tensor (basedvector<ptr<const module<R> >, 1> compound_factors)
|
|
|
|
{
|
|
|
|
basedvector<ptr<const module<R> >, 1> factors;
|
|
|
|
for (unsigned i = 1; i <= compound_factors.size (); i ++)
|
|
|
|
compound_factors[i]->append_tensor_factors (factors);
|
|
|
|
|
|
|
|
basedvector<unsigned, 1> factor_ids (factors.size ());
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
factor_ids[i] = factors[i]->id;
|
|
|
|
|
|
|
|
pair<ptr<const tensor_product<R> > &, bool> p = tensor_product_idx.find (factor_ids);
|
|
|
|
if (!p.second)
|
|
|
|
p.first = new tensor_product<R> (factors);
|
|
|
|
return p.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> grading
|
|
|
|
tensor_product<R>::generator_grading (unsigned i) const
|
|
|
|
{
|
|
|
|
basedvector<unsigned, 1> gs = generator_factors (i);
|
|
|
|
assert (gs.size () == factors.size ());
|
|
|
|
|
|
|
|
grading gr;
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
gr += factors[i]->generator_grading (gs[i]);
|
|
|
|
|
|
|
|
return gr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
tensor_product<R>::show_generator (unsigned i) const
|
|
|
|
{
|
|
|
|
basedvector<unsigned, 1> gs = generator_factors (i);
|
|
|
|
assert (gs.size () == factors.size ());
|
|
|
|
|
|
|
|
printf ("o(");
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
{
|
|
|
|
if (i > 1)
|
|
|
|
printf (",");
|
|
|
|
factors[i]->show_generator (gs[i]);
|
|
|
|
}
|
|
|
|
printf (")");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> unsigned
|
|
|
|
tensor_product<R>::tensor_generators (basedvector<unsigned, 1> gs) const
|
|
|
|
{
|
|
|
|
assert (gs.size () == factors.size ());
|
|
|
|
|
|
|
|
unsigned r = gs[gs.size ()] - 1;
|
|
|
|
for (unsigned i = gs.size () - 1; i >= 1; i --)
|
|
|
|
{
|
|
|
|
r *= factors[i]->dim ();
|
|
|
|
r += gs[i] - 1;
|
|
|
|
}
|
|
|
|
r ++;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> basedvector<unsigned, 1>
|
|
|
|
tensor_product<R>::generator_factors (unsigned g) const
|
|
|
|
{
|
|
|
|
basedvector<unsigned, 1> r (factors.size ());
|
|
|
|
|
|
|
|
unsigned g0 = g;
|
|
|
|
|
|
|
|
g --;
|
|
|
|
for (unsigned i = 1; i <= factors.size (); i ++)
|
|
|
|
{
|
|
|
|
r[i] = (g % factors[i]->dim ()) + 1;
|
|
|
|
g /= factors[i]->dim ();
|
|
|
|
}
|
|
|
|
assert (g == 0);
|
|
|
|
assert (tensor_generators (r) == g0);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class hom_module : public module<R>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
unsigned n;
|
|
|
|
ptr<const module<R> > from;
|
|
|
|
ptr<const module<R> > to;
|
|
|
|
|
|
|
|
public:
|
|
|
|
hom_module (ptr<const module<R> > from_,
|
|
|
|
ptr<const module<R> > to_)
|
|
|
|
: from(from_), to(to_)
|
|
|
|
{
|
|
|
|
assert (from->is_free ()
|
|
|
|
&& to->is_free ());
|
|
|
|
n = from->dim () * to->dim ();
|
|
|
|
}
|
|
|
|
~hom_module () { }
|
|
|
|
|
|
|
|
// e_ij -> ij
|
|
|
|
pair<unsigned, unsigned> generator_indices (unsigned g) const
|
|
|
|
{
|
|
|
|
unsigned d = from->dim ();
|
|
|
|
unsigned g0 = g;
|
|
|
|
|
|
|
|
g --;
|
|
|
|
pair<unsigned, unsigned> p ((g % d) + 1,
|
|
|
|
(g / d) + 1);
|
|
|
|
|
|
|
|
assert (generator (p.first, p.second) == g0);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ij -> e_ij
|
|
|
|
unsigned generator (unsigned i, unsigned j) const
|
|
|
|
{
|
|
|
|
return (i - 1) + (j - 1) * from->dim () + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned dim () const { return n; }
|
|
|
|
unsigned free_rank () const { return n; }
|
|
|
|
|
|
|
|
grading generator_grading (unsigned i) const;
|
|
|
|
void show_generator (unsigned i) const;
|
|
|
|
R generator_ann (unsigned i) const { return R (0); }
|
|
|
|
|
|
|
|
linear_combination<R> map_as_element (const mod_map<R> &m) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R> ptr<const hom_module<R> >
|
|
|
|
module<R>::hom (ptr<const module<R> > to) const
|
|
|
|
{
|
|
|
|
pair<ptr<const hom_module<R> > &, bool> p = hom_module_idx.find (pair<unsigned, unsigned>
|
|
|
|
(id, to->id));
|
|
|
|
if (!p.second)
|
|
|
|
p.first = new hom_module<R> (this, to);
|
|
|
|
return p.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> grading
|
|
|
|
hom_module<R>::generator_grading (unsigned i) const
|
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p = generator_indices (i);
|
|
|
|
return (to->generator_grading (p.second)
|
|
|
|
- from->generator_grading (p.first));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
hom_module<R>::show_generator (unsigned i) const
|
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p = generator_indices (i);
|
|
|
|
|
|
|
|
printf ("(");
|
|
|
|
from->show_generator (p.first);
|
|
|
|
printf (" -> ");
|
|
|
|
to->show_generator (p.second);
|
|
|
|
printf (")");
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R, class G>
|
|
|
|
class base_module : public module<R>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
G g;
|
|
|
|
|
|
|
|
public:
|
2012-07-27 21:37:47 +02:00
|
|
|
base_module () = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
base_module (const G &g_) : g(g_) { }
|
|
|
|
~base_module () { }
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
base_module &operator = (const base_module &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
unsigned dim () const { return g.dim (); }
|
|
|
|
unsigned free_rank () const { return g.free_rank (); }
|
|
|
|
grading generator_grading (unsigned i) const { return g.generator_grading (i); }
|
|
|
|
void show_generator (unsigned i) const { g.show_generator (i); }
|
|
|
|
R generator_ann (unsigned i) const { return g.generator_ann (i); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class explicit_module : public module<R>
|
|
|
|
{
|
|
|
|
unsigned r;
|
|
|
|
basedvector<R, 1> ann;
|
|
|
|
basedvector<grading, 1> hq;
|
|
|
|
|
|
|
|
public:
|
2012-07-27 21:37:47 +02:00
|
|
|
explicit_module () = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
explicit_module (unsigned r_,
|
|
|
|
basedvector<R, 1> ann_,
|
|
|
|
basedvector<grading, 1> hq_)
|
|
|
|
: r(r_), ann(ann_), hq(hq_)
|
2012-05-21 16:09:17 +02:00
|
|
|
{
|
|
|
|
assert (hq.size () == r + ann.size ());
|
|
|
|
}
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
explicit explicit_module (unsigned r_, basedvector<grading, 1> hq_) : r(r_), hq(hq_) { }
|
|
|
|
~explicit_module () { }
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
explicit_module &operator = (const explicit_module &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
unsigned dim () const { return r + ann.size (); }
|
|
|
|
unsigned free_rank () const { return r; }
|
|
|
|
grading generator_grading (unsigned i) const { return hq[i]; }
|
|
|
|
void show_generator (unsigned i) const { printf ("%d", i); }
|
|
|
|
R generator_ann (unsigned i) const { return ann[i - r]; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class free_submodule : public module<R>
|
|
|
|
{
|
|
|
|
friend class module<R>;
|
|
|
|
|
|
|
|
ptr<const module<R> > parent;
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> gens;
|
2011-12-09 21:50:25 +01:00
|
|
|
basedvector<unsigned, 1> pivots;
|
|
|
|
|
|
|
|
public:
|
|
|
|
free_submodule (ptr<const module<R> > parent_,
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> gens_,
|
2011-12-09 21:50:25 +01:00
|
|
|
basedvector<unsigned, 1> pivots_)
|
|
|
|
: parent(parent_),
|
|
|
|
gens(gens_),
|
|
|
|
pivots(pivots_)
|
|
|
|
{ }
|
|
|
|
~free_submodule () { }
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
free_submodule &operator = (const free_submodule &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
ptr<const module<R> > parent_module () const { return parent; }
|
|
|
|
|
|
|
|
unsigned dim () const { return gens.size (); }
|
|
|
|
unsigned free_rank () const { return gens.size (); }
|
|
|
|
grading generator_grading (unsigned i) const { return gens[i].hq (); }
|
|
|
|
void show_generator (unsigned i) const { show (gens[i]); }
|
|
|
|
R generator_ann (unsigned i) const { abort (); }
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> inject_generator (unsigned i) const { return gens[i]; }
|
|
|
|
linear_combination<R> inject (linear_combination<R> v) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
mod_map<R> injection_map () const;
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> restrict (linear_combination<R> v0) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
ptr<const free_submodule<R> > restrict_submodule (ptr<const free_submodule<R> > m) const;
|
2012-05-03 21:27:05 +02:00
|
|
|
|
|
|
|
ptr<const free_submodule<R> > intersection (ptr<const free_submodule<R> > m) const;
|
|
|
|
ptr<const free_submodule<R> > plus (ptr<const free_submodule<R> > m) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class quotient_module : public module<R>
|
|
|
|
{
|
|
|
|
friend class module<R>;
|
|
|
|
|
|
|
|
ptr<const module<R> > parent;
|
|
|
|
|
|
|
|
// note: these get filled in by module::quotient
|
|
|
|
|
|
|
|
basedvector<R, 1> ann;
|
|
|
|
|
|
|
|
// parent lc representing i
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> rep;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
// map from parent generator to lc in quotient
|
|
|
|
basedvector<map<unsigned, R>, 1> pi;
|
|
|
|
|
|
|
|
public:
|
2012-07-27 21:37:47 +02:00
|
|
|
quotient_module (const quotient_module &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
quotient_module (ptr<const module<R> > parent_)
|
|
|
|
: parent(parent_)
|
|
|
|
{ }
|
|
|
|
~quotient_module () { }
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
quotient_module &operator = (const quotient_module &) = delete;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
ptr<const module<R> > parent_module () const { return parent; }
|
|
|
|
|
|
|
|
unsigned dim () const { return rep.size (); }
|
|
|
|
unsigned free_rank () const { return rep.size () - ann.size (); }
|
|
|
|
grading generator_grading (unsigned i) const { return rep[i].hq (); }
|
|
|
|
void show_generator (unsigned i) const
|
|
|
|
{
|
|
|
|
show (rep[i]);
|
|
|
|
printf ("/~");
|
|
|
|
}
|
|
|
|
|
|
|
|
R generator_ann (unsigned i) const
|
|
|
|
{
|
|
|
|
unsigned r = free_rank ();
|
|
|
|
assert (i > r);
|
|
|
|
return ann[i - r];
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> project_generator (unsigned i) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
assert (i >= 1 && i <= parent->dim ());
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r (this);
|
2011-12-09 21:50:25 +01:00
|
|
|
for (typename map<unsigned, R>::const_iter j = pi[i]; j; j ++)
|
|
|
|
r.muladd (j.val (), j.key ());
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> project (linear_combination<R> v) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
assert (v.m == parent);
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r (this);
|
|
|
|
for (linear_combination_const_iter<R> i = v; i; i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
r.muladd (i.val (), project_generator (i.key ()));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> generator_rep (unsigned i) const { return rep[i]; }
|
2011-12-09 21:50:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
2012-02-28 20:26:38 +01:00
|
|
|
class map_impl : public refcounted
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
public:
|
|
|
|
ptr<const module<R> > from;
|
|
|
|
ptr<const module<R> > to;
|
|
|
|
|
|
|
|
public:
|
2012-07-27 21:37:47 +02:00
|
|
|
map_impl (const map_impl &) = delete;
|
2012-02-28 20:26:38 +01:00
|
|
|
map_impl (ptr<const module<R> > fromto)
|
|
|
|
: from(fromto), to(fromto)
|
|
|
|
{ }
|
|
|
|
map_impl (ptr<const module<R> > from_, ptr<const module<R> > to_)
|
|
|
|
: from(from_), to(to_)
|
|
|
|
{ }
|
|
|
|
virtual ~map_impl () { }
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
map_impl &operator = (const map_impl &) = delete;
|
2012-02-28 20:26:38 +01:00
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
virtual const linear_combination<R> column (unsigned i) const = 0;
|
|
|
|
virtual const linear_combination<R> column_copy (unsigned i) const { return column (i); }
|
2012-02-28 20:26:38 +01:00
|
|
|
|
2012-03-19 03:55:56 +01:00
|
|
|
linear_combination<R> map (const linear_combination<R> &lc) const
|
2012-02-28 20:26:38 +01:00
|
|
|
{
|
2012-03-19 03:55:56 +01:00
|
|
|
linear_combination<R> r (this->to);
|
2012-02-28 20:26:38 +01:00
|
|
|
for (linear_combination_const_iter<R> i = lc; i; i ++)
|
|
|
|
r.muladd (i.val (), column (i.key ()));
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class explicit_map_impl : public map_impl<R>
|
|
|
|
{
|
|
|
|
basedvector<linear_combination<R>, 1> columns;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
public:
|
2012-02-28 20:26:38 +01:00
|
|
|
explicit_map_impl (ptr<const module<R> > fromto,
|
|
|
|
basedvector<linear_combination<R>, 1> columns_)
|
|
|
|
: map_impl<R>(fromto),
|
|
|
|
columns(columns_)
|
2011-12-09 21:50:25 +01:00
|
|
|
{ }
|
2012-02-28 20:26:38 +01:00
|
|
|
explicit_map_impl (ptr<const module<R> > from, ptr<const module<R> > to,
|
|
|
|
basedvector<linear_combination<R>, 1> columns_)
|
|
|
|
: map_impl<R>(from, to),
|
|
|
|
columns(columns_)
|
|
|
|
{ }
|
|
|
|
~explicit_map_impl () { }
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const { return columns[i]; }
|
|
|
|
const linear_combination<R> column_copy (unsigned i) const
|
|
|
|
{
|
|
|
|
return linear_combination<R> (COPY, columns[i]);
|
|
|
|
}
|
2012-02-28 20:26:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class zero_map_impl : public map_impl<R>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
zero_map_impl (ptr<const module<R> > fromto) : map_impl<R>(fromto) { }
|
|
|
|
zero_map_impl (ptr<const module<R> > from, ptr<const module<R> > to) : map_impl<R>(from, to) { }
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const { return linear_combination<R> (this->to); }
|
2012-02-28 20:26:38 +01:00
|
|
|
};
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
template<class R>
|
|
|
|
class id_map_impl : public map_impl<R>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
id_map_impl (ptr<const module<R> > fromto) : map_impl<R>(fromto) { }
|
|
|
|
id_map_impl (ptr<const module<R> > from, ptr<const module<R> > to) : map_impl<R>(from, to) { }
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const
|
2012-02-28 20:26:38 +01:00
|
|
|
{
|
|
|
|
linear_combination<R> r (this->to);
|
|
|
|
r.muladd (1, i);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class composition_impl : public map_impl<R>
|
|
|
|
{
|
|
|
|
// f(g(x))
|
2012-02-29 04:08:52 +01:00
|
|
|
ptr<const map_impl<R> > f, g;
|
2012-02-28 20:26:38 +01:00
|
|
|
|
|
|
|
public:
|
2012-02-29 04:08:52 +01:00
|
|
|
composition_impl (ptr<const map_impl<R> > f_, ptr<const map_impl<R> > g_)
|
2012-02-28 20:26:38 +01:00
|
|
|
: map_impl<R>(g_->from, f_->to),
|
|
|
|
f(f_),
|
|
|
|
g(g_)
|
|
|
|
{
|
|
|
|
assert (g->to == f->from);
|
|
|
|
}
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const
|
2012-02-28 20:26:38 +01:00
|
|
|
{
|
|
|
|
return f->map (g->column (i));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-01 04:21:45 +01:00
|
|
|
template<class R>
|
|
|
|
class direct_sum_impl : public map_impl<R>
|
|
|
|
{
|
|
|
|
// f\oplus g
|
|
|
|
ptr<const map_impl<R> > f, g;
|
|
|
|
|
|
|
|
public:
|
|
|
|
direct_sum_impl (ptr<const map_impl<R> > f_, ptr<const map_impl<R> > g_)
|
|
|
|
: map_impl<R>(f_->from->add (g_->from),
|
|
|
|
f_->to->add (g_->to)),
|
|
|
|
f(f_),
|
|
|
|
g(g_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const
|
2012-03-01 04:21:45 +01:00
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p = f->from->project (g->from, i);
|
|
|
|
|
|
|
|
linear_combination<R> r (this->to);
|
|
|
|
if (p.first == 1)
|
|
|
|
{
|
|
|
|
for (linear_combination_const_iter<R> j = f->column (p.second); j; j ++)
|
|
|
|
r.muladd (j.val (), f->to->inject_1 (j.key (), g->to));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert (p.first == 2);
|
|
|
|
for (linear_combination_const_iter<R> j = g->column (p.second); j; j ++)
|
|
|
|
r.muladd (j.val (), f->to->inject_2 (g->to, j.key ()));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
template<class R>
|
|
|
|
class tensor_impl : public map_impl<R>
|
|
|
|
{
|
|
|
|
// f\otimes g
|
|
|
|
ptr<const map_impl<R> > f, g;
|
|
|
|
|
|
|
|
public:
|
|
|
|
tensor_impl (ptr<const map_impl<R> > f_, ptr<const map_impl<R> > g_)
|
|
|
|
: map_impl<R>(f_->from->tensor (g_->from),
|
2012-03-19 03:55:56 +01:00
|
|
|
f_->to->tensor (g_->to)),
|
2012-02-29 04:08:52 +01:00
|
|
|
f(f_),
|
|
|
|
g(g_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const
|
2012-02-29 04:08:52 +01:00
|
|
|
{
|
|
|
|
pair<unsigned, unsigned> p = f->from->generator_factors (g->from, i);
|
|
|
|
|
|
|
|
// ??
|
|
|
|
return f->column (p.first).tensor (g->column (p.second));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
template<class R>
|
|
|
|
class map_builder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ptr<const module<R> > from, to;
|
|
|
|
basedvector<linear_combination<R>, 1> columns;
|
|
|
|
|
|
|
|
void init ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
map_builder (ptr<const module<R> > fromto) : from(fromto), to(fromto) { init (); }
|
|
|
|
map_builder (ptr<const module<R> > fromto, int i) : from(fromto), to(fromto)
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
if (i == 1)
|
|
|
|
{
|
|
|
|
for (unsigned i = 1; i <= from->dim (); i ++)
|
|
|
|
columns[i].muladd (1, i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
assert (i == 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map_builder (ptr<const module<R> > from_, ptr<const module<R> > to_)
|
|
|
|
: from(from_), to(to_)
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
linear_combination<R> &operator [] (unsigned i) { return columns[i]; }
|
|
|
|
const linear_combination<R> &operator [] (unsigned i) const { return columns[i]; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
map_builder<R>::init ()
|
|
|
|
{
|
|
|
|
columns.resize (from->dim ());
|
|
|
|
for (unsigned i = 1; i <= from->dim (); i ++)
|
|
|
|
columns[i] = linear_combination<R> (to);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class mod_map
|
|
|
|
{
|
2012-02-29 04:08:52 +01:00
|
|
|
// ???
|
|
|
|
enum impl_ctor { IMPL };
|
|
|
|
|
|
|
|
ptr<const map_impl<R> > impl;
|
2012-02-28 20:26:38 +01:00
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
mod_map (impl_ctor, ptr<const map_impl<R> > impl_) : impl(impl_) { }
|
2012-02-28 20:26:38 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
mod_map () { }
|
|
|
|
mod_map (const mod_map &m) : impl(m.impl) { }
|
|
|
|
|
|
|
|
mod_map (ptr<const module<R> > fromto) : impl(new zero_map_impl<R>(fromto)) { }
|
|
|
|
mod_map (ptr<const module<R> > fromto, int i)
|
|
|
|
{
|
|
|
|
if (i == 1)
|
|
|
|
impl = new id_map_impl<R> (fromto);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert (i == 0);
|
|
|
|
impl = new zero_map_impl<R> (fromto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_map (ptr<const module<R> > from, ptr<const module<R> > to)
|
|
|
|
: impl(new zero_map_impl<R> (from, to))
|
2011-12-09 21:50:25 +01:00
|
|
|
{ }
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
mod_map (ptr<const module<R> > fromto,
|
|
|
|
basedvector<linear_combination<R>, 1> columns)
|
|
|
|
: impl(new explicit_map_impl<R> (fromto, columns))
|
2011-12-09 21:50:25 +01:00
|
|
|
{ }
|
2012-02-28 20:26:38 +01:00
|
|
|
mod_map (ptr<const module<R> > from,
|
|
|
|
ptr<const module<R> > to,
|
|
|
|
basedvector<linear_combination<R>, 1> columns)
|
|
|
|
: impl(new explicit_map_impl<R> (from, to, columns))
|
|
|
|
{ }
|
|
|
|
mod_map (const map_builder<R> &b)
|
|
|
|
: impl(new explicit_map_impl<R> (b.from, b.to, b.columns))
|
|
|
|
{ }
|
2012-05-03 21:27:05 +02:00
|
|
|
|
|
|
|
mod_map (reader &r)
|
|
|
|
{
|
|
|
|
ptr<const module<R> > from = r.read_mod<R> ();
|
|
|
|
ptr<const module<R> > to = r.read_mod<R> ();
|
|
|
|
basedvector<linear_combination<R>, 1> columns (r);
|
|
|
|
impl = new explicit_map_impl<R> (from, to, columns);
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
~mod_map () { }
|
|
|
|
|
|
|
|
mod_map &operator = (const mod_map &m) { impl = m.impl; return *this; }
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
ptr<const module<R> > domain () const { return impl->from; }
|
|
|
|
ptr<const module<R> > codomain () const { return impl->to; }
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
bool operator == (const mod_map &m) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (impl->from == m.impl->from);
|
|
|
|
assert (impl->to == m.impl->to);
|
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
|
|
|
{
|
2012-02-29 04:08:52 +01:00
|
|
|
if (impl->column (i) != m.impl->column (i))
|
2012-02-28 20:26:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
2012-07-27 21:37:47 +02:00
|
|
|
bool operator != (const mod_map &m) const { return !operator == (m); }
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
bool operator == (int x) const
|
|
|
|
{
|
|
|
|
R c (x);
|
|
|
|
assert (c == 0);
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
if (impl->column (i) != 0)
|
2011-12-09 21:50:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (int x) const { return !operator == (x); }
|
|
|
|
|
2012-04-11 07:06:04 +02:00
|
|
|
const linear_combination<R> column (unsigned i) const { return impl->column (i); }
|
|
|
|
const linear_combination<R> operator [] (unsigned i) const { return impl->column (i); }
|
|
|
|
|
|
|
|
const linear_combination<R> column_copy (unsigned i) const { return impl->column_copy (i); }
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> map (const linear_combination<R> &lc) const { return impl->map (lc); }
|
2012-02-29 04:08:52 +01:00
|
|
|
mod_map compose (const mod_map &m) const
|
|
|
|
{
|
|
|
|
return mod_map (IMPL,
|
|
|
|
new composition_impl<R> (impl, m.impl));
|
|
|
|
}
|
|
|
|
|
2012-03-01 04:21:45 +01:00
|
|
|
// ??? in the sense of direct sum
|
|
|
|
mod_map add (const mod_map &m) const
|
|
|
|
{
|
|
|
|
return mod_map (IMPL,
|
|
|
|
new direct_sum_impl<R> (impl, m.impl));
|
|
|
|
}
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
mod_map tensor (const mod_map &m) const
|
|
|
|
{
|
|
|
|
return mod_map (IMPL,
|
|
|
|
new tensor_impl<R> (impl, m.impl));
|
|
|
|
}
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
// ?? add and other map operations should not be explicit
|
|
|
|
mod_map operator + (const mod_map &m) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
bool homogeneous () const;
|
|
|
|
void check_grading (grading delta) const;
|
|
|
|
|
|
|
|
// inj : ker -> from
|
|
|
|
ptr<const free_submodule<R> > kernel () const;
|
|
|
|
|
|
|
|
// inj : im -> to
|
|
|
|
ptr<const free_submodule<R> > image () const;
|
2012-05-21 16:09:17 +02:00
|
|
|
ptr<const free_submodule<R> > image (basedvector<linear_combination<R>, 1> vs) const;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
ptr<const quotient_module<R> > cokernel () const;
|
|
|
|
|
|
|
|
ptr<const quotient_module<R> > homology () const;
|
|
|
|
|
|
|
|
mod_map restrict_from (ptr<const free_submodule<R> > new_from) const;
|
|
|
|
mod_map restrict_to (ptr<const free_submodule<R> > new_to) const;
|
|
|
|
mod_map restrict (ptr<const free_submodule<R> > new_from,
|
|
|
|
ptr<const free_submodule<R> > new_to) const;
|
|
|
|
mod_map restrict (ptr<const free_submodule<R> > new_fromto) const
|
|
|
|
{
|
|
|
|
return restrict (new_fromto, new_fromto);
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_map induced_map_to (ptr<const quotient_module<R> > new_to);
|
|
|
|
mod_map induced_map (ptr<const quotient_module<R> > new_fromto);
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
// ???
|
|
|
|
basedvector<linear_combination<R>, 1> explicit_columns () const;
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
void write_self (writer &w) const
|
|
|
|
{
|
|
|
|
// write explicitly
|
|
|
|
write (w, *impl->from);
|
|
|
|
write (w, *impl->to);
|
|
|
|
write (w, explicit_columns ());
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
void show_self () const;
|
|
|
|
void display_self () const;
|
|
|
|
};
|
|
|
|
|
2012-02-29 04:08:52 +01:00
|
|
|
template<class R> linear_combination<R>
|
|
|
|
hom_module<R>::map_as_element (const mod_map<R> &m) const
|
|
|
|
{
|
|
|
|
assert (from == m.domain ()
|
|
|
|
&& to == m.codomain ());
|
|
|
|
|
|
|
|
linear_combination<R> r (this);
|
|
|
|
for (unsigned i = 1; i <= from->dim (); i ++)
|
|
|
|
{
|
|
|
|
for (linear_combination_const_iter<R> j = m.column (i); j; j ++)
|
|
|
|
r.muladd (j.val (), generator (i, j.key ()));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R>
|
|
|
|
class mod_span
|
|
|
|
{
|
|
|
|
public:
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> gens;
|
2011-12-09 21:50:25 +01:00
|
|
|
basedvector<unsigned, 1> pivots;
|
|
|
|
|
|
|
|
public:
|
2012-02-28 20:26:38 +01:00
|
|
|
mod_span (ptr<const module<R> > mod, basedvector<linear_combination<R>, 1> xs);
|
2011-12-09 21:50:25 +01:00
|
|
|
~mod_span () { }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class quotient_helper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ptr<const module<R> > mod;
|
|
|
|
|
|
|
|
// rows of the presentation matrix
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> rows;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> generators;
|
|
|
|
basedvector<linear_combination<R>, 1> generators_inv;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
bool improve_pivot_row (unsigned i, unsigned j, unsigned i2);
|
|
|
|
bool improve_pivot_column (unsigned i, unsigned j, unsigned j2);
|
|
|
|
void improve_pivot (unsigned i, unsigned j);
|
|
|
|
|
|
|
|
public:
|
2012-02-28 20:26:38 +01:00
|
|
|
quotient_helper (ptr<const module<R> > mod_, basedvector<linear_combination<R>, 1> rows);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
void normalize ();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R> bool
|
|
|
|
module<R>::isomorphic (ptr<const module<R> > m) const
|
|
|
|
{
|
|
|
|
if (dim () != m->dim ()
|
|
|
|
|| free_rank () != m->free_rank ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
set<grading> gradings;
|
|
|
|
for (unsigned i = 1; i <= dim (); i ++)
|
|
|
|
gradings += generator_grading (i);
|
|
|
|
|
|
|
|
for (set_const_iter<grading> i = gradings; i; i ++)
|
|
|
|
{
|
|
|
|
grading hq = i.val ();
|
|
|
|
|
|
|
|
unsigned hq_r = 0,
|
|
|
|
m_hq_r = 0;
|
|
|
|
basedvector<R, 1> hq_ann, m_hq_ann;
|
|
|
|
for (unsigned i = 1; i <= dim (); i ++)
|
|
|
|
{
|
|
|
|
if (generator_grading (i) == hq)
|
|
|
|
{
|
|
|
|
if (i <= free_rank ())
|
|
|
|
hq_r ++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hq_ann.append (generator_ann (i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m->generator_grading (i) == hq)
|
|
|
|
{
|
|
|
|
if (i <= free_rank ())
|
|
|
|
m_hq_r ++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_hq_ann.append (m->generator_ann (i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hq_r != m_hq_r)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (hq_ann.size () != m_hq_ann.size ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= hq_ann.size (); i ++)
|
|
|
|
{
|
|
|
|
R a = hq_ann[i],
|
|
|
|
m_a = m_hq_ann[i];
|
|
|
|
if (! (a | m_a && m_a | a))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
quotient_helper<R>::quotient_helper (ptr<const module<R> > mod_,
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> rows_)
|
2011-12-09 21:50:25 +01:00
|
|
|
: mod(mod_),
|
|
|
|
rows(rows_),
|
|
|
|
generators(mod->dim ()),
|
|
|
|
generators_inv(mod->dim ())
|
|
|
|
{
|
|
|
|
assert (mod->dim () == mod->free_rank ());
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= mod->dim (); i ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> v (mod);
|
2011-12-09 21:50:25 +01:00
|
|
|
v.muladd (1, i);
|
|
|
|
generators[i] = v;
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> vinv (mod);
|
2011-12-09 21:50:25 +01:00
|
|
|
vinv.muladd (1, i);
|
|
|
|
generators_inv[i] = vinv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> bool
|
|
|
|
quotient_helper<R>::improve_pivot_row (unsigned i, unsigned j, unsigned i2)
|
|
|
|
{
|
|
|
|
assert (i != i2);
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
const linear_combination<R> &r = rows[i],
|
2011-12-09 21:50:25 +01:00
|
|
|
&r2 = rows[i2];
|
|
|
|
R rc = r(j),
|
|
|
|
r2c = r2(j);
|
|
|
|
|
|
|
|
if (r2c == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (rc | r2c)
|
|
|
|
{
|
|
|
|
R q = r2c.div (rc);
|
|
|
|
rows[i2].mulsub (q, r);
|
|
|
|
|
|
|
|
assert (rows[i2](j) == 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
tuple<R, R, R> t = rc.extended_gcd (r2c);
|
|
|
|
assert (get<0> (t) == rc*get<1> (t) + get<2> (t)*r2c);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
rows[i] = r*get<1> (t) + r2*get<2> (t);
|
|
|
|
rows[i2] = (rc.div (get<0> (t)))*r2 - (r2c.div (get<0> (t)))*r;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
assert ((rc | r2c) == rc.divides (get<0> (t)));
|
|
|
|
assert (!rc.divides (get<0> (t)) || rows[i2](j) == 0);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
return !rc.divides (get<0> (t));
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> bool
|
|
|
|
quotient_helper<R>::improve_pivot_column (unsigned i, unsigned j, unsigned j2)
|
|
|
|
{
|
|
|
|
assert (j != j2);
|
|
|
|
|
|
|
|
#if 0
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> orig_row_image (rows.size ());
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned k = 1; k <= rows.size (); k ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r (mod);
|
|
|
|
for (linear_combination_const_iter<R> l = rows[k]; l; l ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
r.muladd (l.val (), generators[l.key ()]);
|
|
|
|
orig_row_image[k] = r;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
const linear_combination<R> &r = rows[i];
|
2011-12-09 21:50:25 +01:00
|
|
|
R rc = r(j),
|
|
|
|
rc2 = r(j2);
|
|
|
|
|
|
|
|
assert (rc != 0);
|
|
|
|
if (rc2 == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert (generators[j].hq () == generators[j2].hq ());
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (rc | rc2)
|
|
|
|
{
|
|
|
|
R q = rc2.div (rc);
|
|
|
|
for (unsigned k = 1; k <= rows.size (); k ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &rk = rows[k];
|
2011-12-09 21:50:25 +01:00
|
|
|
rk.mulsub (rk(j) * q, j2);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (r(j2) == 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
tuple<R, R, R> t = rc.extended_gcd (rc2);
|
|
|
|
assert (get<0> (t) == rc*get<1> (t) + get<2> (t)*rc2);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
for (unsigned k = 1; k <= rows.size (); k ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &rk = rows[k];
|
2011-12-09 21:50:25 +01:00
|
|
|
R rkc = rk(j),
|
|
|
|
rkc2 = rk(j2);
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
rk.set_coeff (rkc*get<1> (t) + rkc2*get<2> (t),
|
2011-12-14 19:32:28 +01:00
|
|
|
j);
|
2012-07-27 21:37:47 +02:00
|
|
|
rk.set_coeff (rkc2*(rc.div (get<0> (t))) - rkc*(rc2.div (get<0> (t))),
|
2011-12-14 19:32:28 +01:00
|
|
|
j2);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> g = generators[j],
|
2011-12-09 21:50:25 +01:00
|
|
|
g2 = generators[j2];
|
|
|
|
|
|
|
|
assert (g.hq () == g2.hq ());
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
generators[j] = (rc.div (get<0> (t))) * g + (rc2.div (get<0> (t))) * g2;
|
|
|
|
generators[j2] = get<1> (t) * g2 - get<2> (t) * g;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
for (unsigned k = 1; k <= rows.size (); k ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r2 (mod);
|
|
|
|
for (linear_combination_const_iter<R> l = rows[k]; l; l ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
r2.muladd (l.val (), generators[l.key ()]);
|
|
|
|
assert (r2 == orig_row_image[k]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (unsigned k = 1; k <= mod->dim (); k ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &ginv = generators_inv[k];
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
R d = ginv(j),
|
|
|
|
d2 = ginv(j2);
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
ginv.set_coeff (get<1> (t)*d + get<2> (t)*d2, j);
|
|
|
|
ginv.set_coeff (rc.div (get<0> (t)) * d2 - rc2.div (get<0> (t)) * d, j2);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
for (unsigned k = 1; k <= mod->dim (); k ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r (mod);
|
2011-12-09 21:50:25 +01:00
|
|
|
r.muladd (1, k);
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r2 (mod);
|
|
|
|
for (linear_combination_const_iter<R> l = generators_inv[k]; l; l ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
r2.muladd (l.val (), generators[l.key ()]);
|
|
|
|
|
|
|
|
assert (r == r2);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
assert ((rc | rc2) == rc.divides (get<0> (t)));
|
|
|
|
assert (!rc.divides (get<0> (t)) || r(j2) == 0);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
return !rc.divides (get<0> (t));
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
quotient_helper<R>::improve_pivot (unsigned i, unsigned j)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
bool changed = 0;
|
|
|
|
for (unsigned k = 1; k <= rows.size (); k ++)
|
|
|
|
{
|
|
|
|
if (k == i)
|
|
|
|
continue;
|
|
|
|
if (improve_pivot_row (i, j, k))
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned k = 1; k <= mod->dim (); k ++)
|
|
|
|
{
|
|
|
|
if (k == j)
|
|
|
|
continue;
|
|
|
|
if (improve_pivot_column (i, j, k))
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
L:
|
2012-02-28 20:26:38 +01:00
|
|
|
for (linear_combination_const_iter<R> k = rows[i]; k; k ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
if (k.key () != j)
|
|
|
|
{
|
|
|
|
if (improve_pivot_column (i, j, k.key ()))
|
|
|
|
changed = 1;
|
|
|
|
goto L;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!changed)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
quotient_helper<R>::normalize ()
|
|
|
|
{
|
|
|
|
for (unsigned i = 1; i <= rows.size (); i ++)
|
|
|
|
{
|
|
|
|
if (rows[i] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pair<unsigned, R> p = rows[i].head ();
|
|
|
|
improve_pivot (i, p.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= rows.size (); i ++)
|
|
|
|
{
|
|
|
|
if (rows[i] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert (rows[i].card () == 1);
|
|
|
|
pair<unsigned, R> p = rows[i].head ();
|
|
|
|
grading ihq = generators[p.first].hq ();
|
|
|
|
|
|
|
|
for (unsigned j = i; j <= rows.size (); j ++)
|
|
|
|
{
|
|
|
|
if (rows[j] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert (rows[j].card () == 1);
|
|
|
|
pair<unsigned, R> q = rows[j].head ();
|
|
|
|
grading jhq = generators[q.first].hq ();
|
|
|
|
|
|
|
|
if (ihq != jhq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (p.second | q.second)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rows[i] += rows[j];
|
|
|
|
improve_pivot (i, p.first);
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
assert (rows[i].card () == 1);
|
|
|
|
pair<unsigned, R> p2 = rows[i].head ();
|
|
|
|
assert (p2.first == p.first);
|
|
|
|
|
|
|
|
assert (rows[j].card () == 1);
|
|
|
|
pair<unsigned, R> q2 = rows[j].head ();
|
|
|
|
assert (q2.first == q.first);
|
|
|
|
|
|
|
|
assert (p2.second | q2.second);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const quotient_module<R> >
|
2012-02-28 20:26:38 +01:00
|
|
|
module<R>::quotient (const mod_span<R> &span) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
unsigned n = dim ();
|
|
|
|
|
|
|
|
quotient_helper<R> h (this, span.gens);
|
|
|
|
h.normalize ();
|
|
|
|
|
|
|
|
basedvector<R, 1> ann (n);
|
|
|
|
for (unsigned i = 1; i <= h.rows.size (); i ++)
|
|
|
|
{
|
|
|
|
if (h.rows[i] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert (h.rows[i].card () == 1);
|
|
|
|
|
|
|
|
pair<unsigned, R> p = h.rows[i].head ();
|
|
|
|
ann[p.first] = p.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr<quotient_module<R> > Q = new quotient_module<R> (this);
|
|
|
|
|
|
|
|
unsigned quot_r = 0;
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> quot_rep;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
basedvector<unsigned, 1> generator_quot_gen (n);
|
|
|
|
for (unsigned i = 1; i <= n; i ++)
|
|
|
|
generator_quot_gen[i] = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= n; i ++)
|
|
|
|
{
|
|
|
|
if (ann[i] == 0)
|
|
|
|
{
|
|
|
|
quot_r ++;
|
|
|
|
quot_rep.append (h.generators[i]);
|
|
|
|
generator_quot_gen[i] = quot_r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned quot_n = quot_r;
|
|
|
|
basedvector<R, 1> quot_ann;
|
|
|
|
for (unsigned i = 1; i <= n; i ++)
|
|
|
|
{
|
|
|
|
R a = ann[i];
|
|
|
|
if (a != 0 && !a.is_unit ())
|
|
|
|
{
|
|
|
|
quot_n ++;
|
|
|
|
quot_rep.append (h.generators[i]);
|
|
|
|
|
|
|
|
assert (generator_quot_gen[i] == 0);
|
|
|
|
generator_quot_gen[i] = quot_n;
|
|
|
|
quot_ann.append (a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
basedvector<map<unsigned, R>, 1> quot_pi (n);
|
|
|
|
for (unsigned i = 1; i <= n; i ++)
|
|
|
|
{
|
|
|
|
map<unsigned, R> v;
|
2012-02-28 20:26:38 +01:00
|
|
|
for (linear_combination_const_iter<R> j = h.generators_inv[i]; j; j ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
unsigned qg = generator_quot_gen[j.key ()];
|
|
|
|
if (qg)
|
|
|
|
v.push (qg, j.val ());
|
|
|
|
}
|
|
|
|
quot_pi[i] = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (quot_n >= quot_r);
|
|
|
|
assert (quot_rep.size () == quot_n);
|
|
|
|
assert (quot_ann.size () == quot_n - quot_r);
|
|
|
|
|
|
|
|
Q->rep = quot_rep;
|
|
|
|
Q->pi = quot_pi;
|
|
|
|
Q->ann = quot_ann;
|
|
|
|
|
|
|
|
assert (Q->dim () == quot_n);
|
|
|
|
assert (Q->free_rank () == quot_r);
|
|
|
|
|
|
|
|
return Q;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const quotient_module<R> >
|
|
|
|
module<R>::quotient (ptr<const free_submodule<R> > m) const
|
|
|
|
{
|
|
|
|
assert (m->parent_module () == this);
|
|
|
|
|
|
|
|
// ??? duplicate
|
|
|
|
mod_span<R> span (this, m->gens);
|
|
|
|
return quotient (span);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const free_submodule<R> >
|
2012-02-28 20:26:38 +01:00
|
|
|
module<R>::submodule (const mod_span<R> &span) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
assert (free_rank () == dim ());
|
|
|
|
return new free_submodule<R> (this,
|
|
|
|
span.gens,
|
|
|
|
span.pivots);
|
|
|
|
}
|
|
|
|
|
2011-12-22 21:35:49 +01:00
|
|
|
template<class R> multivariate_laurentpoly<Z>
|
2011-12-09 21:50:25 +01:00
|
|
|
module<R>::free_poincare_polynomial () const
|
|
|
|
{
|
2011-12-22 21:35:49 +01:00
|
|
|
multivariate_laurentpoly<Z> r;
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= free_rank (); i ++)
|
|
|
|
{
|
|
|
|
grading hq = generator_grading (i);
|
2011-12-22 21:35:49 +01:00
|
|
|
multivariate_laurent_monomial m;
|
|
|
|
m.push_exponent (1, hq.h);
|
|
|
|
m.push_exponent (2, hq.q);
|
|
|
|
r.muladdeq (1, m);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-12-22 21:35:49 +01:00
|
|
|
template<class R> multivariate_laurentpoly<Z>
|
2011-12-09 21:50:25 +01:00
|
|
|
module<R>::free_delta_poincare_polynomial () const
|
|
|
|
{
|
2011-12-22 21:35:49 +01:00
|
|
|
multivariate_laurentpoly<Z> r;
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= free_rank (); i ++)
|
|
|
|
{
|
|
|
|
grading hq = generator_grading (i);
|
2011-12-22 21:35:49 +01:00
|
|
|
multivariate_laurent_monomial m;
|
|
|
|
m.push_exponent (1, hq.q - 2*hq.h);
|
|
|
|
r.muladdeq (1, m);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
template<class R> set<grading>
|
|
|
|
module<R>::gradings () const
|
|
|
|
{
|
|
|
|
set<grading> gs;
|
|
|
|
for (unsigned i = 1; i <= dim (); i ++)
|
|
|
|
gs += generator_grading (i);
|
|
|
|
return gs;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
module<R>::graded_piece (grading hq) const
|
|
|
|
{
|
|
|
|
basedvector<linear_combination<R>, 1> s;
|
|
|
|
for (unsigned i = 1; i <= dim (); i ++)
|
|
|
|
{
|
|
|
|
grading ihq = generator_grading (i);
|
|
|
|
if (ihq.h == hq.h
|
|
|
|
&& ihq.q == hq.q)
|
|
|
|
{
|
|
|
|
linear_combination<R> v (this);
|
|
|
|
v.muladd (1, i);
|
|
|
|
s.append (v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_span<R> span (this, s);
|
|
|
|
return submodule (span);
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R> void
|
|
|
|
module<R>::show_self () const
|
|
|
|
{
|
|
|
|
printf ("module/");
|
|
|
|
R::show_ring ();
|
|
|
|
printf (" %p %d", this, dim ());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
module<R>::display_self () const
|
|
|
|
{
|
|
|
|
show_self (); newline ();
|
|
|
|
|
|
|
|
printf (" free_rank %d\n", free_rank ());
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= dim (); i ++)
|
|
|
|
{
|
|
|
|
printf (" %d ", i);
|
|
|
|
show (generator_grading (i));
|
|
|
|
printf (" ");
|
|
|
|
show_generator (i);
|
|
|
|
|
|
|
|
if (i > free_rank ())
|
|
|
|
{
|
|
|
|
printf (": ");
|
|
|
|
R iann = generator_ann (i);
|
|
|
|
if (iann.is_unit ())
|
|
|
|
printf ("0\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
R::show_ring ();
|
|
|
|
if (iann != 0)
|
|
|
|
{
|
|
|
|
printf ("/");
|
|
|
|
show (iann);
|
|
|
|
R::show_ring ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newline ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
template<class R> linear_combination<R>
|
|
|
|
free_submodule<R>::inject (linear_combination<R> v) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r (parent);
|
|
|
|
for (linear_combination_const_iter<R> i = v; i; i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
r.muladd (i.val (), gens[i.key ()]);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
|
|
|
free_submodule<R>::injection_map () const
|
|
|
|
{
|
|
|
|
return mod_map<R> (this, parent, gens);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
|
|
|
mod_map<R>::induced_map_to (ptr<const quotient_module<R> > new_to)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (new_to->parent_module () == impl->to);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (impl->from->dim ());
|
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
|
|
|
v[i] = new_to->project (column (i));
|
|
|
|
return new explicit_map_impl<R> (impl->from, new_to, v);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
|
|
|
mod_map<R>::induced_map (ptr<const quotient_module<R> > new_fromto)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (impl->from == new_fromto->parent_module ());
|
|
|
|
assert (impl->to == new_fromto->parent_module ());
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
// ??? doesn't check induced map is well-defined
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (new_fromto->dim ());
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= new_fromto->dim (); i ++)
|
2012-02-28 20:26:38 +01:00
|
|
|
v[i] = new_fromto->project (map (new_fromto->generator_rep (i)));
|
|
|
|
return new explicit_map_impl<R> (new_fromto, v);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
|
|
|
mod_map<R>::restrict_from (ptr<const free_submodule<R> > new_from) const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (new_from->parent_module () == impl->from);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (new_from->dim ());
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= new_from->dim (); i ++)
|
2012-02-28 20:26:38 +01:00
|
|
|
v[i] = map (new_from->inject_generator (i));
|
2012-05-03 21:27:05 +02:00
|
|
|
return mod_map (IMPL, new explicit_map_impl<R> (new_from, impl->to, v));
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
|
|
|
mod_map<R>::restrict_to (ptr<const free_submodule<R> > new_to) const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (new_to->parent_module () == impl->to);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (impl->from->dim ());
|
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
|
|
|
v[i] = new_to->restrict (column (i));
|
|
|
|
return new explicit_map_impl<R> (impl->from, new_to, v);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
|
|
|
mod_map<R>::restrict (ptr<const free_submodule<R> > new_from,
|
|
|
|
ptr<const free_submodule<R> > new_to) const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (new_from->parent_module () == impl->from);
|
|
|
|
assert (new_to->parent_module () == impl->to);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (new_from->dim ());
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= new_from->dim (); i ++)
|
2012-02-28 20:26:38 +01:00
|
|
|
v[i] = new_to->restrict (map (new_from->inject_generator (i)));
|
2012-05-03 21:27:05 +02:00
|
|
|
return mod_map (IMPL, new explicit_map_impl<R> (new_from, new_to, v));
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
template<class R> linear_combination<R>
|
|
|
|
free_submodule<R>::restrict (linear_combination<R> v0) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
assert (v0.m == parent);
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> v (COPY, v0);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> r (this);
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= gens.size (); i ++)
|
|
|
|
{
|
|
|
|
unsigned j = pivots[i];
|
|
|
|
R vc = v(j);
|
|
|
|
if (vc != 0)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
const linear_combination<R> &g = gens[i];
|
2011-12-09 21:50:25 +01:00
|
|
|
R gc = g(j);
|
|
|
|
|
|
|
|
assert (gc | vc);
|
|
|
|
R q = vc.div (gc);
|
|
|
|
|
|
|
|
v.mulsub (q, g);
|
|
|
|
r.muladd (q, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert (v == 0);
|
|
|
|
assert (inject (r) == v0);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
free_submodule<R>::restrict_submodule (ptr<const free_submodule<R> > m) const
|
|
|
|
{
|
|
|
|
assert (m->parent == parent);
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> span (m->dim ());
|
2011-12-09 21:50:25 +01:00
|
|
|
for (unsigned i = 1; i <= m->dim (); i ++)
|
|
|
|
span[i] = restrict (m->inject_generator (i));
|
|
|
|
|
|
|
|
mod_span<R> span2 (this, span);
|
2012-07-27 21:37:47 +02:00
|
|
|
return this->submodule (span2);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
free_submodule<R>::intersection (ptr<const free_submodule<R> > m) const
|
|
|
|
{
|
|
|
|
assert (parent == m->parent);
|
|
|
|
|
|
|
|
unsigned md = m->dim (),
|
|
|
|
d = dim ();
|
|
|
|
|
|
|
|
basedvector<linear_combination<R>, 1> intr;
|
|
|
|
|
|
|
|
basedvector<linear_combination<R>, 1> hperp,
|
|
|
|
hproj;
|
|
|
|
basedvector<unsigned, 1> hpivots;
|
|
|
|
for (unsigned i = 1; i <= md; i ++)
|
|
|
|
{
|
|
|
|
linear_combination<R> perp (COPY, m->gens[i]),
|
|
|
|
proj (parent);
|
|
|
|
|
|
|
|
for (unsigned j = 1; j <= d; j ++)
|
|
|
|
{
|
|
|
|
unsigned k = pivots[j];
|
|
|
|
if (perp % k)
|
|
|
|
{
|
|
|
|
const linear_combination<R> &g = gens[j];
|
|
|
|
R c = g(k);
|
|
|
|
R d = perp(k);
|
|
|
|
|
|
|
|
assert (c | d);
|
|
|
|
R q = d.div (c);
|
|
|
|
|
|
|
|
perp.mulsub (q, g);
|
|
|
|
proj.mulsub (q, g);
|
|
|
|
|
|
|
|
assert (! (perp % k));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned j = 1; j <= hpivots.size (); j ++)
|
|
|
|
{
|
|
|
|
unsigned k = hpivots[j];
|
|
|
|
if (perp % k)
|
|
|
|
{
|
|
|
|
const linear_combination<R> &h = hperp[j];
|
|
|
|
R c = h(k);
|
|
|
|
R d = perp(k);
|
|
|
|
|
|
|
|
assert (c | d);
|
|
|
|
R q = d.div (c);
|
|
|
|
|
|
|
|
perp.mulsub (q, h);
|
|
|
|
proj.mulsub (q, hproj[j]);
|
|
|
|
|
|
|
|
assert (! (perp % k));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (perp == 0)
|
|
|
|
intr.append (proj);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hperp.append (perp);
|
|
|
|
hproj.append (proj);
|
|
|
|
hpivots.append (perp.head ().first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_span<R> span (parent, intr);
|
|
|
|
return parent->submodule (span);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
free_submodule<R>::plus (ptr<const free_submodule<R> > m) const
|
|
|
|
{
|
|
|
|
assert (parent == m->parent);
|
|
|
|
|
|
|
|
basedvector<linear_combination<R>, 1> s;
|
|
|
|
for (unsigned i = 1; i <= dim (); i ++)
|
|
|
|
s.append (gens[i]);
|
|
|
|
|
|
|
|
for (unsigned i = 1; i <= m->dim (); i ++)
|
|
|
|
s.append (m->gens[i]);
|
|
|
|
|
|
|
|
mod_span<R> span (parent, s);
|
|
|
|
return parent->submodule (span);
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R> bool
|
|
|
|
mod_map<R>::homogeneous () const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
if (column (i) != 0)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
grading dhq = column (i).hq () - impl->from->generator_grading (i);
|
|
|
|
for (unsigned j = i + 1; j <= impl->from->dim (); j ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
if (column (j) != 0
|
|
|
|
&& dhq != column (j).hq () - impl->from->generator_grading (j))
|
2011-12-09 21:50:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
mod_map<R>::check_grading (grading delta) const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
if (column (i) != 0)
|
|
|
|
assert (column (i).hq () - impl->from->generator_grading (i) == delta);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class R> mod_map<R>
|
2012-02-28 20:26:38 +01:00
|
|
|
mod_map<R>::operator + (const mod_map &m) const
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
assert (impl->from == m.impl->from && impl->to == m.impl->to);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (impl->from->dim ());
|
|
|
|
for (unsigned i = 1; i <= m.impl->from->dim (); i ++)
|
2012-04-11 07:06:04 +02:00
|
|
|
v[i] = column (i) + m.column (i);
|
|
|
|
return mod_map (IMPL, new explicit_map_impl<R> (impl->from, impl->to, v));
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
mod_map<R>::kernel () const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
ptr<const module<R> > from = impl->from,
|
|
|
|
to = impl->to;
|
|
|
|
|
|
|
|
basedvector<linear_combination<R>, 1> from_xs (from->dim ());
|
2012-05-03 21:27:05 +02:00
|
|
|
for (unsigned i = 1; i <= from->dim (); i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> x (from);
|
2011-12-09 21:50:25 +01:00
|
|
|
x.muladd (1, i);
|
|
|
|
from_xs[i] = x;
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> to_xs (COPY2, explicit_columns ());
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
for (unsigned i = 1; i <= to->dim (); i ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> from_v (from),
|
2011-12-09 21:50:25 +01:00
|
|
|
to_v (to);
|
|
|
|
|
|
|
|
for (unsigned j = 1; j <= to_xs.size (); j ++)
|
|
|
|
{
|
|
|
|
R to_vc = to_v(i);
|
|
|
|
if (to_vc.is_unit ())
|
|
|
|
break;
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &to_x = to_xs[j],
|
2011-12-09 21:50:25 +01:00
|
|
|
&from_x = from_xs[j];
|
|
|
|
R to_xc = to_x(i);
|
|
|
|
if (! (to_vc | to_xc))
|
|
|
|
{
|
2012-07-27 21:37:47 +02:00
|
|
|
tuple<R, R, R> t = to_vc.extended_gcd (to_xc);
|
|
|
|
assert (get<0> (t) == to_vc*get<1> (t) + get<2> (t)*to_xc);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
to_v = get<1> (t)*to_v + get<2> (t)*to_x;
|
|
|
|
from_v = get<1> (t)*from_v + get<2> (t)*from_x;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
assert (to_v(i) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R to_vc = to_v(i);
|
|
|
|
if (to_vc != 0)
|
|
|
|
{
|
|
|
|
for (unsigned j = 1; j <= to_xs.size (); j ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &to_x = to_xs[j],
|
2011-12-09 21:50:25 +01:00
|
|
|
&from_x = from_xs[j];
|
|
|
|
R to_xc = to_x(i);
|
|
|
|
if (to_xc != 0)
|
|
|
|
{
|
|
|
|
assert (to_vc | to_xc);
|
|
|
|
|
|
|
|
R q = to_xc.div (to_vc);
|
|
|
|
to_x.mulsub (q, to_v);
|
|
|
|
from_x.mulsub (q, from_v);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (to_x(i) == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_span<R> span (from, from_xs);
|
|
|
|
return from->submodule (span);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
mod_map<R>::image () const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
mod_span<R> span (impl->to, explicit_columns ());
|
|
|
|
return impl->to->submodule (span);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
2012-05-21 16:09:17 +02:00
|
|
|
template<class R> ptr<const free_submodule<R> >
|
|
|
|
mod_map<R>::image (basedvector<linear_combination<R>, 1> vs) const
|
|
|
|
{
|
|
|
|
mod_span<R> span (impl->from, vs);
|
|
|
|
ptr<const free_submodule<R> > s = impl->from->submodule (span);
|
|
|
|
mod_map<R> r = restrict_from (s);
|
|
|
|
return r.image ();
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R> ptr<const quotient_module<R> >
|
|
|
|
mod_map<R>::cokernel () const
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
mod_span<R> span (impl->to, explicit_columns ());
|
|
|
|
return impl->to->quotient (span);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const quotient_module<R> >
|
|
|
|
mod_map<R>::homology () const
|
|
|
|
{
|
|
|
|
ptr<const free_submodule<R> > ker = kernel (),
|
|
|
|
im = image ();
|
|
|
|
|
|
|
|
// display ("ker:", *ker);
|
|
|
|
// display ("im:", *im);
|
|
|
|
|
|
|
|
ptr<const free_submodule<R> > im2 = ker->restrict_submodule (im);
|
|
|
|
|
|
|
|
// display ("im2:", *im2);
|
|
|
|
|
|
|
|
return ker->quotient (im2);
|
|
|
|
}
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
template<class R> basedvector<linear_combination<R>, 1>
|
|
|
|
mod_map<R>::explicit_columns () const
|
|
|
|
{
|
2012-03-19 03:55:56 +01:00
|
|
|
basedvector<linear_combination<R>, 1> v (impl->from->dim ());
|
2012-02-28 20:26:38 +01:00
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
|
|
|
v[i] = column (i);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2011-12-09 21:50:25 +01:00
|
|
|
template<class R>
|
|
|
|
mod_span<R>::mod_span (ptr<const module<R> > mod,
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> xs0)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
|
|
|
assert (mod->free_rank () == mod->dim ());
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
basedvector<linear_combination<R>, 1> xs (COPY2, xs0);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
for (unsigned i = 1; i <= mod->dim (); i ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> v (mod);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
for (unsigned j = 1; j <= xs.size (); j ++)
|
|
|
|
{
|
|
|
|
R vc = v(i);
|
|
|
|
if (vc.is_unit ())
|
|
|
|
break;
|
|
|
|
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &x = xs[j];
|
2011-12-09 21:50:25 +01:00
|
|
|
R xc = x(i);
|
|
|
|
|
|
|
|
if (! (vc | xc))
|
|
|
|
{
|
2012-07-27 21:37:47 +02:00
|
|
|
tuple<R, R, R> t = vc.extended_gcd (xc);
|
|
|
|
assert (get<0> (t) == vc*get<1> (t) + get<2> (t)*xc);
|
2011-12-09 21:50:25 +01:00
|
|
|
|
2012-07-27 21:37:47 +02:00
|
|
|
v = get<1> (t)*v + get<2> (t)*x;
|
2011-12-09 21:50:25 +01:00
|
|
|
|
|
|
|
assert (v(i) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R vc = v(i);
|
|
|
|
if (vc != 0)
|
|
|
|
{
|
|
|
|
for (unsigned j = 1; j <= xs.size (); j ++)
|
|
|
|
{
|
2012-02-28 20:26:38 +01:00
|
|
|
linear_combination<R> &x = xs[j];
|
2011-12-09 21:50:25 +01:00
|
|
|
R xc = x(i);
|
|
|
|
if (xc != 0)
|
|
|
|
{
|
|
|
|
assert (vc | xc);
|
|
|
|
|
|
|
|
R q = xc.div (vc);
|
|
|
|
x.mulsub (q, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (x(i) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pivots.append (i);
|
|
|
|
gens.append (v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
mod_map<R>::show_self () const
|
|
|
|
{
|
|
|
|
printf ("mod_map ");
|
2012-02-28 20:26:38 +01:00
|
|
|
show (*impl->from);
|
2011-12-09 21:50:25 +01:00
|
|
|
printf (" -> ");
|
2012-02-28 20:26:38 +01:00
|
|
|
show (*impl->to);
|
2011-12-09 21:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
mod_map<R>::display_self () const
|
|
|
|
{
|
|
|
|
show_self (); newline ();
|
2012-02-28 20:26:38 +01:00
|
|
|
for (unsigned i = 1; i <= impl->from->dim (); i ++)
|
2011-12-09 21:50:25 +01:00
|
|
|
{
|
2012-02-29 04:08:52 +01:00
|
|
|
printf (" %d ", i);
|
|
|
|
impl->from->show_generator (i);
|
2012-04-11 08:25:27 +02:00
|
|
|
printf (" ");
|
|
|
|
show (impl->from->generator_grading (i));
|
2012-02-29 04:08:52 +01:00
|
|
|
printf (": ");
|
2012-02-28 20:26:38 +01:00
|
|
|
show (column (i));
|
2011-12-09 21:50:25 +01:00
|
|
|
newline ();
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 21:27:05 +02:00
|
|
|
|
|
|
|
// ??? io
|
|
|
|
|
|
|
|
template<class R> void
|
|
|
|
writer::write_mod (ptr<const module<R> > m)
|
|
|
|
{
|
2012-05-04 14:27:09 +02:00
|
|
|
pair<unsigned &, bool> p = aw->id_io_id.find (m->id);
|
2012-05-03 21:27:05 +02:00
|
|
|
if (p.second)
|
|
|
|
{
|
|
|
|
write_int ((int)p.first);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++ aw->io_id_counter;
|
|
|
|
unsigned io_id = aw->io_id_counter;
|
|
|
|
|
|
|
|
p.first = io_id;
|
|
|
|
|
|
|
|
write_int (- (int)io_id);
|
|
|
|
|
|
|
|
unsigned n = m->dim (),
|
|
|
|
r = m->free_rank ();
|
|
|
|
write_unsigned (n);
|
|
|
|
write_unsigned (r);
|
|
|
|
for (unsigned i = 1; i <= n; i ++)
|
|
|
|
write (*this, m->generator_grading (i));
|
|
|
|
for (unsigned i = r + 1; i <= n; i ++)
|
|
|
|
write (*this, m->generator_ann (i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class R> ptr<const module<R> >
|
|
|
|
reader::read_mod ()
|
|
|
|
{
|
|
|
|
int io_id = read_int ();
|
|
|
|
if (io_id < 0)
|
|
|
|
{
|
|
|
|
unsigned n = read_unsigned ();
|
|
|
|
unsigned r = read_unsigned ();
|
|
|
|
basedvector<grading, 1> gr (n);
|
|
|
|
for (unsigned i = 1; i <= n; i ++)
|
|
|
|
gr[i] = grading (*this);
|
|
|
|
basedvector<R, 1> ann (n - r);
|
|
|
|
for (unsigned i = r + 1; i <= n; i ++)
|
|
|
|
ann[i - r] = R (*this);
|
|
|
|
|
|
|
|
ptr<const module<R> > m = new explicit_module<R> (r, ann, gr);
|
|
|
|
ar->io_id_id.push ((unsigned)(-io_id), m->id);
|
2012-05-21 16:09:17 +02:00
|
|
|
module<R>::reader_id_module.push (m->id, m);
|
|
|
|
|
2012-05-03 21:27:05 +02:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned id = ar->io_id_id(io_id);
|
2012-05-21 16:09:17 +02:00
|
|
|
return module<R>::reader_id_module(id);
|
2012-05-03 21:27:05 +02:00
|
|
|
}
|
|
|
|
}
|