[ff7993] | 1 | // -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
---|
| 2 | /*****************************************************************************\ |
---|
| 3 | * Computer Algebra System SINGULAR |
---|
| 4 | \*****************************************************************************/ |
---|
| 5 | /** @file syzextra.h |
---|
| 6 | * |
---|
| 7 | * Computation of Syzygies |
---|
| 8 | * |
---|
| 9 | * ABSTRACT: Computation of Syzygies due to Schreyer |
---|
| 10 | * |
---|
| 11 | * @author Oleksandr Motsak |
---|
| 12 | * |
---|
| 13 | **/ |
---|
| 14 | /*****************************************************************************/ |
---|
| 15 | |
---|
| 16 | #ifndef SYZEXTRA_H |
---|
| 17 | #define SYZEXTRA_H |
---|
| 18 | |
---|
| 19 | // include basic definitions |
---|
| 20 | #include "singularxx_defs.h" |
---|
| 21 | |
---|
| 22 | struct spolyrec; |
---|
| 23 | typedef struct spolyrec polyrec; |
---|
| 24 | typedef polyrec * poly; |
---|
| 25 | |
---|
| 26 | struct ip_sring; |
---|
| 27 | typedef struct ip_sring * ring; |
---|
| 28 | |
---|
| 29 | struct sip_sideal; |
---|
| 30 | typedef struct sip_sideal * ideal; |
---|
| 31 | |
---|
[4eba3ad] | 32 | class idrec; |
---|
| 33 | typedef idrec * idhdl; |
---|
[ff7993] | 34 | |
---|
| 35 | BEGIN_NAMESPACE_SINGULARXX BEGIN_NAMESPACE(SYZEXTRA) |
---|
| 36 | |
---|
[204092] | 37 | poly leadmonom(const poly p, const ring r); |
---|
[ff7993] | 38 | |
---|
[cd5fefc] | 39 | /// return the tail of a given polynomial or vector |
---|
| 40 | /// returns NULL if input is NULL, otherwise |
---|
| 41 | /// the result is a new polynomial/vector in the ring r |
---|
| 42 | poly p_Tail(const poly p, const ring r); |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /// return the tail of a given ideal or module |
---|
| 46 | /// returns NULL if input is NULL, otherwise |
---|
| 47 | /// the result is a new ideal/module in the ring r |
---|
| 48 | /// NOTE: the resulting rank is autocorrected |
---|
| 49 | ideal id_Tail(const ideal id, const ring r); |
---|
| 50 | |
---|
[92992c] | 51 | /// inplace sorting of the module (ideal) id wrt <_(c,ds) |
---|
[204092] | 52 | void Sort_c_ds(const ideal id, const ring r); |
---|
| 53 | |
---|
| 54 | |
---|
[4eba3ad] | 55 | |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | /// Computation attribute storage |
---|
| 59 | struct SchreyerSyzygyComputationFlags |
---|
| 60 | { |
---|
| 61 | SchreyerSyzygyComputationFlags(idhdl rootRingHdl); |
---|
| 62 | |
---|
| 63 | /// output all the intermediate states |
---|
| 64 | const bool __DEBUG__; // DebugOutput; |
---|
| 65 | |
---|
| 66 | /// ? |
---|
| 67 | const bool __SYZCHECK__; // CheckSyzygyProperty; |
---|
| 68 | |
---|
| 69 | /// ? |
---|
| 70 | const bool __LEAD2SYZ__; // TwoLeadingSyzygyTerms; |
---|
| 71 | |
---|
| 72 | /// Reduce syzygy tails wrt the leading syzygy terms |
---|
| 73 | const bool __TAILREDSYZ__; // TailReducedSyzygies; |
---|
| 74 | |
---|
| 75 | /// Use the usual NF's S-poly reduction while dropping lower order terms |
---|
| 76 | const bool __HYBRIDNF__; // UseHybridNF |
---|
| 77 | |
---|
| 78 | }; |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
[7088f18] | 82 | /** @class SchreyerSyzygyComputation syzextra.h |
---|
| 83 | * |
---|
| 84 | * Computing syzygies after Schreyer |
---|
| 85 | * |
---|
| 86 | * Storing/accumulating data during the computation requires some global |
---|
| 87 | * object, like this class. Ideally the above global functions should not |
---|
| 88 | * be used in favour of this class. |
---|
| 89 | * |
---|
| 90 | * @sa Schreyer Syzygy Computation Paper & Talk & Python prototype |
---|
| 91 | */ |
---|
| 92 | class SchreyerSyzygyComputation |
---|
| 93 | { |
---|
| 94 | public: |
---|
| 95 | /// Construct a global object for given input data (separated into leads & tails) |
---|
[4eba3ad] | 96 | SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ring rBaseRing, const SchreyerSyzygyComputationFlags attribues): |
---|
| 97 | m_rBaseRing(rBaseRing), |
---|
| 98 | m_idLeads(idLeads), m_idTails(idTails), |
---|
| 99 | m_syzLeads(NULL), m_syzTails(NULL), m_LS(NULL), m_atttributes(attribues) {} |
---|
[7088f18] | 100 | |
---|
| 101 | |
---|
| 102 | /// Construct a global object for given input data (separated into leads & tails) |
---|
[4eba3ad] | 103 | SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ideal syzLeads, const ring rBaseRing, const SchreyerSyzygyComputationFlags attribues): |
---|
| 104 | m_rBaseRing(rBaseRing), |
---|
| 105 | m_idLeads(idLeads), m_idTails(idTails), |
---|
| 106 | m_syzLeads(NULL), m_syzTails(NULL), m_LS(syzLeads), m_atttributes(attribues) {} |
---|
[7088f18] | 107 | |
---|
| 108 | |
---|
| 109 | /// Destructor should not destruct the resulting m_syzLeads, m_syzTails. |
---|
| 110 | ~SchreyerSyzygyComputation(){ CleanUp(); } |
---|
| 111 | |
---|
| 112 | /// Read off the results while detaching them from this object |
---|
| 113 | /// NOTE: no copy! |
---|
| 114 | inline void ReadOffResult(ideal& syzL, ideal& syzT) |
---|
| 115 | { |
---|
| 116 | syzL = m_syzLeads; syzT = m_syzTails; |
---|
| 117 | |
---|
| 118 | m_syzLeads = m_syzTails = NULL; // m_LS ? |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /// The main driver function: computes |
---|
| 122 | void ComputeSyzygy(); |
---|
| 123 | |
---|
| 124 | /// Computes Syz(leads) or only LEAD of it. |
---|
| 125 | /// The result is stored into m_syzLeads |
---|
| 126 | void ComputeLeadingSyzygyTerms(bool bComputeSecondTerms = true); |
---|
| 127 | |
---|
[92992c] | 128 | // TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz? |
---|
[4eba3ad] | 129 | poly FindReducer(poly product, poly syzterm) const; |
---|
[92992c] | 130 | |
---|
[4eba3ad] | 131 | poly SchreyerSyzygyNF(poly syz_lead, poly syz_2) const; |
---|
[92992c] | 132 | |
---|
| 133 | // TODO: store m * @tail -.-^-.-^-.--> ? |
---|
[4eba3ad] | 134 | poly TraverseTail(poly multiplier, poly tail) const; |
---|
[92992c] | 135 | |
---|
| 136 | // TODO: save shortcut (syz: |-.->) LM(m) * "t" -> ? |
---|
[4eba3ad] | 137 | poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck) const; |
---|
[7088f18] | 138 | |
---|
| 139 | protected: |
---|
[c7d29b] | 140 | |
---|
| 141 | /// just leading terms |
---|
| 142 | ideal Compute1LeadingSyzygyTerms(); |
---|
| 143 | |
---|
| 144 | /// leading + second terms |
---|
| 145 | ideal Compute2LeadingSyzygyTerms(); |
---|
| 146 | |
---|
[7088f18] | 147 | |
---|
| 148 | /// Clean up all the accumulated data |
---|
| 149 | void CleanUp() {} |
---|
| 150 | |
---|
| 151 | private: |
---|
| 152 | /// global base ring |
---|
| 153 | const ring m_rBaseRing; |
---|
| 154 | |
---|
| 155 | /// input leading terms |
---|
| 156 | const ideal m_idLeads; |
---|
| 157 | |
---|
| 158 | /// input tails |
---|
| 159 | const ideal m_idTails; |
---|
| 160 | |
---|
| 161 | /// output (syzygy) leading terms (+2nd terms?) |
---|
| 162 | ideal m_syzLeads; |
---|
| 163 | |
---|
| 164 | /// output (syzygy) tails |
---|
| 165 | ideal m_syzTails; |
---|
| 166 | |
---|
| 167 | /*mutable?*/ ideal m_LS; ///< leading syzygy terms used for reducing syzygy tails |
---|
[4eba3ad] | 168 | |
---|
| 169 | const SchreyerSyzygyComputationFlags m_atttributes; |
---|
[7088f18] | 170 | }; |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | // The following wrappers are just for testing separate functions on highest level (within schreyer.lib) |
---|
| 174 | |
---|
[4eba3ad] | 175 | static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 176 | { |
---|
[4eba3ad] | 177 | SchreyerSyzygyComputation syz(L, T, R, A); |
---|
[7088f18] | 178 | syz.ComputeSyzygy(); |
---|
| 179 | syz.ReadOffResult(LL, TT); |
---|
| 180 | } |
---|
| 181 | |
---|
[4eba3ad] | 182 | static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 183 | { |
---|
[4eba3ad] | 184 | SchreyerSyzygyComputation syz(L, NULL, R, A); |
---|
[7088f18] | 185 | syz.ComputeLeadingSyzygyTerms(false); |
---|
| 186 | ideal LL, TT; |
---|
| 187 | syz.ReadOffResult(LL, TT); |
---|
| 188 | return LL; // assume TT is NULL! |
---|
| 189 | } |
---|
| 190 | |
---|
[4eba3ad] | 191 | static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 192 | { |
---|
[4eba3ad] | 193 | SchreyerSyzygyComputation syz(L, NULL, R, A); |
---|
[7088f18] | 194 | syz.ComputeLeadingSyzygyTerms(true); |
---|
| 195 | ideal LL, TT; |
---|
| 196 | syz.ReadOffResult(LL, TT); |
---|
| 197 | return LL; // assume TT is NULL! |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | static inline poly FindReducer(poly product, poly syzterm, |
---|
[4eba3ad] | 201 | ideal L, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 202 | { |
---|
[4eba3ad] | 203 | SchreyerSyzygyComputation syz(L, NULL, LS, R, A); |
---|
[7088f18] | 204 | return syz.FindReducer(product, syzterm); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | static inline poly TraverseTail(poly multiplier, poly tail, |
---|
[4eba3ad] | 208 | ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 209 | { |
---|
[4eba3ad] | 210 | SchreyerSyzygyComputation syz(L, T, LS, R, A); |
---|
[7088f18] | 211 | return syz.TraverseTail(multiplier, tail); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | static inline poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck, |
---|
[4eba3ad] | 215 | ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 216 | { |
---|
[4eba3ad] | 217 | SchreyerSyzygyComputation syz(L, T, LS, R, A); |
---|
[7088f18] | 218 | return syz.ReduceTerm(multiplier, term4reduction, syztermCheck); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | static inline poly SchreyerSyzygyNF(poly syz_lead, poly syz_2, |
---|
[4eba3ad] | 223 | ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
[7088f18] | 224 | { |
---|
[4eba3ad] | 225 | SchreyerSyzygyComputation syz(L, T, LS, R, A); |
---|
[7088f18] | 226 | return syz.SchreyerSyzygyNF(syz_lead, syz_2); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | END_NAMESPACE |
---|
| 230 | |
---|
| 231 | END_NAMESPACE_SINGULARXX |
---|
[ff7993] | 232 | |
---|
| 233 | #endif |
---|
| 234 | /* #ifndef SYZEXTRA_H */ |
---|
| 235 | |
---|
| 236 | // Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab |
---|
| 237 | |
---|