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 | class idrec; |
---|
33 | typedef idrec * idhdl; |
---|
34 | |
---|
35 | BEGIN_NAMESPACE_SINGULARXX BEGIN_NAMESPACE(SYZEXTRA) |
---|
36 | |
---|
37 | poly leadmonom(const poly p, const ring r); |
---|
38 | |
---|
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 | |
---|
51 | /// inplace sorting of the module (ideal) id wrt <_(c,ds) |
---|
52 | void Sort_c_ds(const ideal id, const ring r); |
---|
53 | |
---|
54 | |
---|
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 | |
---|
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) |
---|
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) {} |
---|
100 | |
---|
101 | |
---|
102 | /// Construct a global object for given input data (separated into leads & tails) |
---|
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) {} |
---|
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 | |
---|
128 | // TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz? |
---|
129 | poly FindReducer(poly product, poly syzterm) const; |
---|
130 | |
---|
131 | poly SchreyerSyzygyNF(poly syz_lead, poly syz_2) const; |
---|
132 | |
---|
133 | // TODO: store m * @tail -.-^-.-^-.--> ? |
---|
134 | poly TraverseTail(poly multiplier, poly tail) const; |
---|
135 | |
---|
136 | // TODO: save shortcut (syz: |-.->) LM(m) * "t" -> ? |
---|
137 | poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck) const; |
---|
138 | |
---|
139 | protected: |
---|
140 | |
---|
141 | /// Clean up all the accumulated data |
---|
142 | void CleanUp() {} |
---|
143 | |
---|
144 | private: |
---|
145 | /// global base ring |
---|
146 | const ring m_rBaseRing; |
---|
147 | |
---|
148 | /// input leading terms |
---|
149 | const ideal m_idLeads; |
---|
150 | |
---|
151 | /// input tails |
---|
152 | const ideal m_idTails; |
---|
153 | |
---|
154 | /// output (syzygy) leading terms (+2nd terms?) |
---|
155 | ideal m_syzLeads; |
---|
156 | |
---|
157 | /// output (syzygy) tails |
---|
158 | ideal m_syzTails; |
---|
159 | |
---|
160 | /*mutable?*/ ideal m_LS; ///< leading syzygy terms used for reducing syzygy tails |
---|
161 | |
---|
162 | const SchreyerSyzygyComputationFlags m_atttributes; |
---|
163 | }; |
---|
164 | |
---|
165 | |
---|
166 | // The following wrappers are just for testing separate functions on highest level (within schreyer.lib) |
---|
167 | |
---|
168 | static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
169 | { |
---|
170 | SchreyerSyzygyComputation syz(L, T, R, A); |
---|
171 | syz.ComputeSyzygy(); |
---|
172 | syz.ReadOffResult(LL, TT); |
---|
173 | } |
---|
174 | |
---|
175 | static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
176 | { |
---|
177 | SchreyerSyzygyComputation syz(L, NULL, R, A); |
---|
178 | syz.ComputeLeadingSyzygyTerms(false); |
---|
179 | ideal LL, TT; |
---|
180 | syz.ReadOffResult(LL, TT); |
---|
181 | return LL; // assume TT is NULL! |
---|
182 | } |
---|
183 | |
---|
184 | static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
185 | { |
---|
186 | SchreyerSyzygyComputation syz(L, NULL, R, A); |
---|
187 | syz.ComputeLeadingSyzygyTerms(true); |
---|
188 | ideal LL, TT; |
---|
189 | syz.ReadOffResult(LL, TT); |
---|
190 | return LL; // assume TT is NULL! |
---|
191 | } |
---|
192 | |
---|
193 | static inline poly FindReducer(poly product, poly syzterm, |
---|
194 | ideal L, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
195 | { |
---|
196 | SchreyerSyzygyComputation syz(L, NULL, LS, R, A); |
---|
197 | return syz.FindReducer(product, syzterm); |
---|
198 | } |
---|
199 | |
---|
200 | static inline poly TraverseTail(poly multiplier, poly tail, |
---|
201 | ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
202 | { |
---|
203 | SchreyerSyzygyComputation syz(L, T, LS, R, A); |
---|
204 | return syz.TraverseTail(multiplier, tail); |
---|
205 | } |
---|
206 | |
---|
207 | static inline poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck, |
---|
208 | ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
209 | { |
---|
210 | SchreyerSyzygyComputation syz(L, T, LS, R, A); |
---|
211 | return syz.ReduceTerm(multiplier, term4reduction, syztermCheck); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | static inline poly SchreyerSyzygyNF(poly syz_lead, poly syz_2, |
---|
216 | ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A) |
---|
217 | { |
---|
218 | SchreyerSyzygyComputation syz(L, T, LS, R, A); |
---|
219 | return syz.SchreyerSyzygyNF(syz_lead, syz_2); |
---|
220 | } |
---|
221 | |
---|
222 | END_NAMESPACE |
---|
223 | |
---|
224 | END_NAMESPACE_SINGULARXX |
---|
225 | |
---|
226 | #endif |
---|
227 | /* #ifndef SYZEXTRA_H */ |
---|
228 | |
---|
229 | // Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab |
---|
230 | |
---|