[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 | |
---|
| 32 | |
---|
| 33 | BEGIN_NAMESPACE_SINGULARXX BEGIN_NAMESPACE(SYZEXTRA) |
---|
| 34 | |
---|
[204092] | 35 | poly leadmonom(const poly p, const ring r); |
---|
[ff7993] | 36 | |
---|
[cd5fefc] | 37 | /// return the tail of a given polynomial or vector |
---|
| 38 | /// returns NULL if input is NULL, otherwise |
---|
| 39 | /// the result is a new polynomial/vector in the ring r |
---|
| 40 | poly p_Tail(const poly p, const ring r); |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | /// return the tail of a given ideal or module |
---|
| 44 | /// returns NULL if input is NULL, otherwise |
---|
| 45 | /// the result is a new ideal/module in the ring r |
---|
| 46 | /// NOTE: the resulting rank is autocorrected |
---|
| 47 | ideal id_Tail(const ideal id, const ring r); |
---|
| 48 | |
---|
[92992c] | 49 | /// inplace sorting of the module (ideal) id wrt <_(c,ds) |
---|
[204092] | 50 | void Sort_c_ds(const ideal id, const ring r); |
---|
| 51 | |
---|
| 52 | |
---|
[7088f18] | 53 | /** @class SchreyerSyzygyComputation syzextra.h |
---|
| 54 | * |
---|
| 55 | * Computing syzygies after Schreyer |
---|
| 56 | * |
---|
| 57 | * Storing/accumulating data during the computation requires some global |
---|
| 58 | * object, like this class. Ideally the above global functions should not |
---|
| 59 | * be used in favour of this class. |
---|
| 60 | * |
---|
| 61 | * @sa Schreyer Syzygy Computation Paper & Talk & Python prototype |
---|
| 62 | */ |
---|
| 63 | class SchreyerSyzygyComputation |
---|
| 64 | { |
---|
| 65 | public: |
---|
| 66 | /// Construct a global object for given input data (separated into leads & tails) |
---|
| 67 | SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ring rBaseRing): |
---|
| 68 | m_idLeads(idLeads), m_idTails(idTails), m_rBaseRing(rBaseRing), |
---|
| 69 | m_syzLeads(NULL), m_syzTails(NULL), m_LS(NULL) {} |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /// Construct a global object for given input data (separated into leads & tails) |
---|
| 73 | SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ideal syzLeads, const ring rBaseRing): |
---|
| 74 | m_idLeads(idLeads), m_idTails(idTails), m_rBaseRing(rBaseRing), |
---|
| 75 | m_syzLeads(NULL), m_syzTails(NULL), m_LS(syzLeads) {} |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | /// Destructor should not destruct the resulting m_syzLeads, m_syzTails. |
---|
| 79 | ~SchreyerSyzygyComputation(){ CleanUp(); } |
---|
| 80 | |
---|
| 81 | /// Read off the results while detaching them from this object |
---|
| 82 | /// NOTE: no copy! |
---|
| 83 | inline void ReadOffResult(ideal& syzL, ideal& syzT) |
---|
| 84 | { |
---|
| 85 | syzL = m_syzLeads; syzT = m_syzTails; |
---|
| 86 | |
---|
| 87 | m_syzLeads = m_syzTails = NULL; // m_LS ? |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /// The main driver function: computes |
---|
| 91 | void ComputeSyzygy(); |
---|
| 92 | |
---|
| 93 | /// Computes Syz(leads) or only LEAD of it. |
---|
| 94 | /// The result is stored into m_syzLeads |
---|
| 95 | void ComputeLeadingSyzygyTerms(bool bComputeSecondTerms = true); |
---|
| 96 | |
---|
[92992c] | 97 | // TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz? |
---|
[7088f18] | 98 | poly FindReducer(poly product, poly syzterm); |
---|
[92992c] | 99 | |
---|
[7088f18] | 100 | poly SchreyerSyzygyNF(poly syz_lead, poly syz_2); |
---|
[92992c] | 101 | |
---|
| 102 | // TODO: store m * @tail -.-^-.-^-.--> ? |
---|
[7088f18] | 103 | poly TraverseTail(poly multiplier, poly tail); |
---|
[92992c] | 104 | |
---|
| 105 | // TODO: save shortcut (syz: |-.->) LM(m) * "t" -> ? |
---|
[7088f18] | 106 | poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck); |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | protected: |
---|
| 110 | |
---|
| 111 | /// Clean up all the accumulated data |
---|
| 112 | void CleanUp() {} |
---|
| 113 | |
---|
| 114 | private: |
---|
| 115 | /// global base ring |
---|
| 116 | const ring m_rBaseRing; |
---|
| 117 | |
---|
| 118 | /// input leading terms |
---|
| 119 | const ideal m_idLeads; |
---|
| 120 | |
---|
| 121 | /// input tails |
---|
| 122 | const ideal m_idTails; |
---|
| 123 | |
---|
| 124 | /// output (syzygy) leading terms (+2nd terms?) |
---|
| 125 | ideal m_syzLeads; |
---|
| 126 | |
---|
| 127 | /// output (syzygy) tails |
---|
| 128 | ideal m_syzTails; |
---|
| 129 | |
---|
| 130 | /*mutable?*/ ideal m_LS; ///< leading syzygy terms used for reducing syzygy tails |
---|
| 131 | }; |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | // The following wrappers are just for testing separate functions on highest level (within schreyer.lib) |
---|
| 135 | |
---|
| 136 | static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const ring R) |
---|
| 137 | { |
---|
| 138 | SchreyerSyzygyComputation syz(L, T, R); |
---|
| 139 | syz.ComputeSyzygy(); |
---|
| 140 | syz.ReadOffResult(LL, TT); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const ring R) |
---|
| 144 | { |
---|
| 145 | SchreyerSyzygyComputation syz(L, NULL, R); |
---|
| 146 | syz.ComputeLeadingSyzygyTerms(false); |
---|
| 147 | ideal LL, TT; |
---|
| 148 | syz.ReadOffResult(LL, TT); |
---|
| 149 | return LL; // assume TT is NULL! |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const ring R) |
---|
| 153 | { |
---|
| 154 | SchreyerSyzygyComputation syz(L, NULL, R); |
---|
| 155 | syz.ComputeLeadingSyzygyTerms(true); |
---|
| 156 | ideal LL, TT; |
---|
| 157 | syz.ReadOffResult(LL, TT); |
---|
| 158 | return LL; // assume TT is NULL! |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | static inline poly FindReducer(poly product, poly syzterm, |
---|
| 162 | ideal L, ideal LS, const ring R) |
---|
| 163 | { |
---|
| 164 | SchreyerSyzygyComputation syz(L, NULL, LS, R); |
---|
| 165 | return syz.FindReducer(product, syzterm); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | static inline poly TraverseTail(poly multiplier, poly tail, |
---|
| 169 | ideal L, ideal T, ideal LS, const ring R) |
---|
| 170 | { |
---|
| 171 | SchreyerSyzygyComputation syz(L, T, LS, R); |
---|
| 172 | return syz.TraverseTail(multiplier, tail); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | static inline poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck, |
---|
| 176 | ideal L, ideal T, ideal LS, const ring R) |
---|
| 177 | { |
---|
| 178 | SchreyerSyzygyComputation syz(L, T, LS, R); |
---|
| 179 | return syz.ReduceTerm(multiplier, term4reduction, syztermCheck); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | static inline poly SchreyerSyzygyNF(poly syz_lead, poly syz_2, |
---|
| 184 | ideal L, ideal T, ideal LS, const ring R) |
---|
| 185 | { |
---|
| 186 | SchreyerSyzygyComputation syz(L, T, LS, R); |
---|
| 187 | return syz.SchreyerSyzygyNF(syz_lead, syz_2); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | END_NAMESPACE |
---|
| 193 | |
---|
| 194 | END_NAMESPACE_SINGULARXX |
---|
[ff7993] | 195 | |
---|
| 196 | #endif |
---|
| 197 | /* #ifndef SYZEXTRA_H */ |
---|
| 198 | |
---|
| 199 | // Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab |
---|
| 200 | |
---|