Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various naming convention changes in the engine #2769

Merged
merged 6 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/engine.dd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declarations "// IWYU pragma: private, include \"engine-includes.hpp\"";
use gmp;

-- types
export RawMonomial := Pointer "const struct Monomial *";
export RawMonomial := Pointer "const struct EngineMonomial *";
export RawMonomialArray := array(RawMonomial);
export RawMonomialOrNull := RawMonomial or null;
export RawArrayInt := array(int);
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/equality.dd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ header "// required for equality checks
#include <interface/monomial-ideal.h> // for IM2_MonomialIdeal_is_equal
#include <interface/ringelement.h> // for IM2_RingElement_is_equal
#include <interface/ringmap.h> // for IM2_RingMap_is_equal
#include <monomial.hpp> // for Monomial"; -- TODO: remove this one
#include <monomial.hpp> // for EngineMonomial"; -- TODO: remove this one

equal(lhs:Expr,rhs:Expr):Expr;

Expand Down
10 changes: 5 additions & 5 deletions M2/Macaulay2/d/interface.dd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ header "// TODO: remove the following headers
#include <error.h> // for ERROR
#include <ZZp.hpp> // for Z_mod
#include <exceptions.hpp> // for engine_error, CATCH, TRY
#include <monomial.hpp> // for Monomial
#include <monomial.hpp> // for EngineMonomial
#include <relem.hpp> // for RingElement";

-- debugging:
Expand Down Expand Up @@ -75,7 +75,7 @@ setupfun("rawRandomCC",rawRandomCC);
-- monomials

rawVarMonomial(v:int,e:int):RawMonomialOrNull := Ccode(returns,"
try { return Monomial::make(v,e); }
try { return EngineMonomial::make(v,e); }
catch (const exc::engine_error& m) { ERROR(m.what()); return NULL; }");
export rawVarMonomial(a:Expr):Expr := (
when a
Expand Down Expand Up @@ -112,7 +112,7 @@ export rawSparseListFormMonomial(e:Expr):Expr := (
setupfun("rawSparseListFormMonomial",rawSparseListFormMonomial);

-- rawMakeMonomial(m:array(int)):RawMonomialOrNull := Ccode(returns,"
-- try { return Monomial::make(m); }
-- try { return EngineMonomial::make(m); }
-- catch (const exc::engine_error& e) { ERROR(e.what()); return NULL; }
-- "
-- -- /* Takes an array of the form [n, v1, e1, v2, e2, ..., vn, en]
Expand All @@ -130,7 +130,7 @@ export rawMakeMonomial(e:Expr):Expr := (
else (
ret := RawMonomialOrNull(null());
Ccode(void, "
try { ",ret," = Monomial::make(",getReverseSequenceOfPairsOfSmallIntegers(l.v),"); }
try { ",ret," = EngineMonomial::make(",getReverseSequenceOfPairsOfSmallIntegers(l.v),"); }
catch (const exc::engine_error& e) { ERROR(e.what()); }");
toExpr(ret)))
else WrongArg("a list of pairs of integers"));
Expand Down Expand Up @@ -304,7 +304,7 @@ export rawSaturate(e:Expr):Expr := (
setupfun("rawSaturate",rawSaturate);

rawSyzygy(a:RawMonomial,b:RawMonomial):RawMonomialPairOrNull := Ccode(returns,"
try { struct Monomial *aa, *bb;
try { struct EngineMonomial *aa, *bb;
a->monsyz(*b, aa, bb);
engine_RawMonomialPair result = new engine_RawMonomialPair_struct;
result->a = aa;
Expand Down
17 changes: 9 additions & 8 deletions M2/Macaulay2/e/Eschreyer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Eschreyer.hpp"
#include "matrix.hpp"
#include "monoid.hpp"
#include "text-io.hpp"
#include "gbring.hpp"
#include "matrix-con.hpp"
Expand Down Expand Up @@ -112,7 +113,7 @@ GBMatrix *GBKernelComputation::get_syzygies()
// Private routines //
//////////////////////
gbvector *GBKernelComputation::make_syz_term(ring_elem c,
const int *m,
const_monomial m,
int comp) const
// c is an element of GR->get_flattened_coefficients()
// (m,comp) is a Schreyer encoded monomial in Fsyz
Expand Down Expand Up @@ -173,9 +174,9 @@ void GBKernelComputation::new_pairs(int i)

if (R->is_skew_commutative())
{
int *find_pairs_exp = newarray_atomic(int, M->n_vars());
exponents_t find_pairs_exp = newarray_atomic(int, M->n_vars());

varpower::to_ntuple(M->n_vars(), vp.raw(), find_pairs_exp);
varpower::to_expvector(M->n_vars(), vp.raw(), find_pairs_exp);
for (int w = 0; w < R->n_skew_commutative_vars(); w++)
if (find_pairs_exp[R->skew_variable(w)] > 0)
{
Expand Down Expand Up @@ -226,7 +227,7 @@ void GBKernelComputation::new_pairs(int i)

MonomialIdeal *new_mi = new MonomialIdeal(R, elems);

int *m = M->make_one();
monomial m = M->make_one();
for (Bag& a : *new_mi)
{
M->from_varpower(a.monom().raw(), m);
Expand All @@ -242,7 +243,7 @@ void GBKernelComputation::new_pairs(int i)
// S-pairs and reduction ////////////////////
//////////////////////////////////////////////

bool GBKernelComputation::find_ring_divisor(const int *exp,
bool GBKernelComputation::find_ring_divisor(const_exponents exp,
const gbvector *&result)
// If 'exp' is divisible by a ring lead term, then 1 is returned,
// and result is set to be that ring element.
Expand All @@ -257,7 +258,7 @@ bool GBKernelComputation::find_ring_divisor(const int *exp,
}

int GBKernelComputation::find_divisor(const MonomialIdeal *this_mi,
const int *exp,
const_exponents exp,
int &result)
{
// Find all the possible matches, use some criterion for finding the best...
Expand Down Expand Up @@ -297,7 +298,7 @@ int GBKernelComputation::find_divisor(const MonomialIdeal *this_mi,
gbvector *GBKernelComputation::s_pair(gbvector *gsyz)
{
gbvector *result = NULL;
int *si = M->make_one();
monomial si = M->make_one();
for (gbvector *f = gsyz; f != 0; f = f->next)
{
SG->schreyer_down(f->monom, f->comp - 1, si);
Expand All @@ -313,7 +314,7 @@ void GBKernelComputation::wipe_unneeded_terms(gbvector *&f)
{
// Remove every term of f (except the lead term)
// which is NOT divisible by an element of mi.
int *exp = newarray_atomic(int, GR->n_vars());
exponents_t exp = newarray_atomic(int, GR->n_vars());
// int nterms = 1;
// int nsaved = 0;
gbvector *g = f;
Expand Down
3 changes: 2 additions & 1 deletion M2/Macaulay2/e/Eschreyer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "gbring.hpp"
#include "schorder.hpp"
#include "matrix.hpp"
#include "monoid.hpp"
#include "comp.hpp"

struct GBMatrix : public our_new_delete
Expand Down Expand Up @@ -53,7 +54,7 @@ class GBKernelComputation : public Computation
void strip_gb(const VECTOR(gbvector *) & m);
void strip_gb(const GBMatrix *m);

gbvector *make_syz_term(ring_elem c, const int *monom, int comp) const;
gbvector *make_syz_term(ring_elem c, const_monomial monom, int comp) const;
// This routine grabs 'c', and 'monom' should be the total monomial.

bool find_ring_divisor(const_exponents exp, const gbvector *&result);
Expand Down
8 changes: 4 additions & 4 deletions M2/Macaulay2/e/ExponentVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ class ExponentVector
};

// Legacy specialization
using ntuple = ExponentVector<int, true>;
typedef ntuple::Exponents exponents_t;
typedef ntuple::ConstExponents const_exponents;
using exponents = ExponentVector<int, true>;
using exponents_t = exponents::Exponents;
using const_exponents = exponents::ConstExponents;

// TODO: compare with ntuple_monomials in e/f4/
template <>
inline ntuple::HashExponent ntuple::mask(int nvars, ConstExponents exp)
inline exponents::HashExponent exponents::mask(int nvars, ConstExponents exp)
{
HashExponent result = 0, bit = 1;
for (int i = nvars - 1; i >= 0; i--)
Expand Down
18 changes: 7 additions & 11 deletions M2/Macaulay2/e/M2FreeAlgebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,13 @@ void M2FreeAlgebra::debug_display(const ring_elem ff) const
debug_display(f);
}

void M2FreeAlgebra::makeTerm(Poly& result, const ring_elem a, const int* monom) const
// 'monom' is in 'varpower' format
// [2n+1 v1 e1 v2 e2 ... vn en], where each ei > 0, (in 'varpower' format)
void M2FreeAlgebra::makeTerm(Poly& result, const ring_elem a, const_varpower monom) const
{
result.getCoeffInserter().push_back(a);
monoid().fromMonomial(monom, result.getMonomInserter());
}

ring_elem M2FreeAlgebra::makeTerm(const ring_elem a, const int* monom) const
// 'monom' is in 'varpower' format
// [2n+1 v1 e1 v2 e2 ... vn en], where each ei > 0, (in 'varpower' format)
ring_elem M2FreeAlgebra::makeTerm(const ring_elem a, const_varpower monom) const
{
auto result = new Poly;
makeTerm(*result, a, monom);
Expand Down Expand Up @@ -377,7 +373,7 @@ engine_RawArrayPairOrNull M2FreeAlgebra::list_form(const Ring *coeffR, const rin
vp.resize(0);
monoid().getMonomialReversed(i.monom(), vp); // should this instead reverse the monomial?
coeffs->array[next] = RingElement::make_raw(coeffR, c);
monoms->array[next] = Monomial::make(vp); // reverses the monomial
monoms->array[next] = EngineMonomial::make(vp); // reverses the monomial
}

return result;
Expand Down Expand Up @@ -426,20 +422,20 @@ bool M2FreeAlgebra::is_homogeneous(const Poly* f) const
return freeAlgebra().is_homogeneous(*f);
}

void M2FreeAlgebra::degree(const ring_elem f, int *d) const
void M2FreeAlgebra::degree(const ring_elem f, monomial d) const
{
multi_degree(f, d);
}

bool M2FreeAlgebra::multi_degree(const ring_elem g, int *d) const
bool M2FreeAlgebra::multi_degree(const ring_elem g, monomial d) const
{
const Poly* f = reinterpret_cast<const Poly*>(g.get_Poly());
return multi_degree(f, d);
}

bool M2FreeAlgebra::multi_degree(const Poly* f, int *result) const
bool M2FreeAlgebra::multi_degree(const Poly* f, monomial d) const
{
return freeAlgebra().multi_degree(*f,result);
return freeAlgebra().multi_degree(*f, d);
}

SumCollector* M2FreeAlgebra::make_SumCollector() const
Expand Down
16 changes: 7 additions & 9 deletions M2/Macaulay2/e/M2FreeAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class M2FreeAlgebraOrQuotient : public Ring

virtual ring_elem from_coefficient(const ring_elem a) const = 0;

virtual ring_elem makeTerm(const ring_elem a, const int* monom) const = 0;
virtual ring_elem makeTerm(const ring_elem a, const_varpower monom) const = 0;

// casting functions
virtual const M2FreeAlgebraOrQuotient * cast_to_M2FreeAlgebraOrQuotient() const { return this; }
Expand Down Expand Up @@ -120,8 +120,8 @@ class M2FreeAlgebra : public M2FreeAlgebraOrQuotient
const ring_elem f) const;

virtual bool is_homogeneous(const ring_elem f) const;
virtual void degree(const ring_elem f, int *d) const;
virtual bool multi_degree(const ring_elem f, int *d) const;
virtual void degree(const ring_elem f, monomial d) const;
virtual bool multi_degree(const ring_elem f, monomial d) const;

virtual SumCollector *make_SumCollector() const;

Expand All @@ -131,7 +131,7 @@ class M2FreeAlgebra : public M2FreeAlgebraOrQuotient

// returns true if f is homogeneous, and sets already_allocated_degree_vector
// to be the LCM of the exponent vectors of the degrees of all terms in f.
virtual bool multi_degree(const Poly* f, int *already_allocated_degree_vector) const;
virtual bool multi_degree(const Poly* f, monomial already_allocated_degree_vector) const;

// lead coefficient, monomials and terms.
ring_elem lead_coefficient(const Ring* coeffRing, const Poly* f) const;
Expand All @@ -141,7 +141,7 @@ class M2FreeAlgebra : public M2FreeAlgebraOrQuotient
}

#if 0
// lead_monomial: returns an allocated Monomial meant for the front end of M2.
// lead_monomial: returns an allocated EngineMonomial meant for the front end of M2.
const int* lead_monomial(const Poly* f) const;
const int* lead_monomial(const ring_elem f) const { return lead_monomial reinterpret_cast<const Poly*>((f.get_Poly())); }
#endif
Expand All @@ -164,11 +164,9 @@ class M2FreeAlgebra : public M2FreeAlgebraOrQuotient
void debug_display(const Poly* f) const;
void debug_display(const ring_elem ff) const;

ring_elem makeTerm(const ring_elem a, const int* monom) const;
ring_elem makeTerm(const ring_elem a, const_varpower monom) const;

void makeTerm(Poly& result, const ring_elem a, const int* monom) const;
// 'monom' is in 'varpower' format
// [2n+1 v1 e1 v2 e2 ... vn en], where each ei > 0, (in 'varpower' format)
void makeTerm(Poly& result, const ring_elem a, const_varpower monom) const;
};

PolyList copyPolyVector(const M2FreeAlgebraOrQuotient* A,
Expand Down
14 changes: 6 additions & 8 deletions M2/Macaulay2/e/M2FreeAlgebraQuotient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,13 @@ void M2FreeAlgebraQuotient::debug_display(const ring_elem ff) const
debug_display(f);
}

void M2FreeAlgebraQuotient::makeTerm(Poly& result, const ring_elem a, const int* monom) const
void M2FreeAlgebraQuotient::makeTerm(Poly& result, const ring_elem a, const_varpower monom) const
{
m2FreeAlgebra().makeTerm(result, a, monom);
freeAlgebraQuotient().normalizeInPlace(result);
}

ring_elem M2FreeAlgebraQuotient::makeTerm(const ring_elem a, const int* monom) const
// 'monom' is in 'varpower' format
// [2n+1 v1 e1 v2 e2 ... vn en], where each ei > 0, (in 'varpower' format)
ring_elem M2FreeAlgebraQuotient::makeTerm(const ring_elem a, const_varpower monom) const
{
Poly* f = new Poly;
makeTerm(*f, a, monom);
Expand Down Expand Up @@ -350,20 +348,20 @@ bool M2FreeAlgebraQuotient::is_homogeneous(const Poly* f) const
return freeAlgebraQuotient().is_homogeneous(*f);
}

void M2FreeAlgebraQuotient::degree(const ring_elem f, int *d) const
void M2FreeAlgebraQuotient::degree(const ring_elem f, monomial d) const
{
multi_degree(f, d);
}

bool M2FreeAlgebraQuotient::multi_degree(const ring_elem g, int *d) const
bool M2FreeAlgebraQuotient::multi_degree(const ring_elem g, monomial d) const
{
const Poly* f = reinterpret_cast<const Poly*>(g.get_Poly());
return multi_degree(f, d);
}

bool M2FreeAlgebraQuotient::multi_degree(const Poly* f, int *result) const
bool M2FreeAlgebraQuotient::multi_degree(const Poly* f, monomial d) const
{
return freeAlgebraQuotient().multi_degree(*f,result);
return freeAlgebraQuotient().multi_degree(*f, d);
}

SumCollector* M2FreeAlgebraQuotient::make_SumCollector() const
Expand Down
8 changes: 4 additions & 4 deletions M2/Macaulay2/e/M2FreeAlgebraQuotient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class M2FreeAlgebraQuotient : public M2FreeAlgebraOrQuotient
const ring_elem f) const;

virtual bool is_homogeneous(const ring_elem f) const;
virtual void degree(const ring_elem f, int *d) const;
virtual bool multi_degree(const ring_elem f, int *d) const;
virtual void degree(const ring_elem f, monomial d) const;
virtual bool multi_degree(const ring_elem f, monomial d) const;

virtual SumCollector *make_SumCollector() const;

Expand All @@ -99,7 +99,7 @@ class M2FreeAlgebraQuotient : public M2FreeAlgebraOrQuotient

// returns true if f is homogeneous, and sets already_allocated_degree_vector
// to be the LCM of the exponent vectors of the degrees of all terms in f.
virtual bool multi_degree(const Poly* f, int *already_allocated_degree_vector) const;
virtual bool multi_degree(const Poly* f, monomial already_allocated_degree_vector) const;

// lead coefficient, monomials and terms.
ring_elem lead_coefficient(const Ring* coeffRing, const Poly* f) const;
Expand All @@ -109,7 +109,7 @@ class M2FreeAlgebraQuotient : public M2FreeAlgebraOrQuotient
}

#if 0
// lead_monomial: returns an allocated Monomial meant for the front end of M2.
// lead_monomial: returns an allocated EngineMonomial meant for the front end of M2.
const int* lead_monomial(const Poly* f) const;
const int* lead_monomial(const ring_elem f) const { return lead_monomial reinterpret_cast<const Poly*>((f.get_Poly())); }
#endif
Expand Down
1 change: 0 additions & 1 deletion M2/Macaulay2/e/Makefile.files
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ NAMES_H = \
style \
util \
hash \
ntuple \
f4/ntuple-monomial \
res-a0-pair

Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/e/NAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ int SLP<Field>::poly_to_horner_slp(int n,
return cur_p;
}

void monomials_to_conventional_exponent_vectors(int n, Nterm* f) // auxiliary
void monomials_to_conventional_expvectors(int n, Nterm* f) // auxiliary
/* "unpack" monomials */
{
for (; f != NULL; f = f->next)
Expand Down Expand Up @@ -312,7 +312,7 @@ SLP<Field> /* or null */* SLP<Field>::make(const PolyRing* R, ring_elem e)
how to remove the pieces afterwards?
R->remove(...) is an empty function */
Nterm* f = e.get_poly();
monomials_to_conventional_exponent_vectors(n, f);
monomials_to_conventional_expvectors(n, f);
int out = res->poly_to_horner_slp(n, prog, consts, f);
if (out == ZERO_CONST)
{
Expand Down
6 changes: 3 additions & 3 deletions M2/Macaulay2/e/NCAlgebras/FreeAlgebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,15 @@ bool FreeAlgebra::is_homogeneous(const Poly& f) const
return result;
}

void FreeAlgebra::degree(const Poly& f, int *d) const
void FreeAlgebra::degree(const Poly& f, monomial d) const
{
multi_degree(f, d);
}

bool FreeAlgebra::multi_degree(const Poly& f,
int *already_allocated_degree_vector) const
monomial already_allocated_degree_vector) const
{
int* degVec = already_allocated_degree_vector;
monomial degVec = already_allocated_degree_vector;
bool ishomog = true;
auto i = f.cbegin();
monoid().multi_degree(i.monom(), degVec);
Expand Down
Loading