source: git/dyn_modules/syzextra/syzextra.h @ 495328

spielwiese
Last change on this file since 495328 was 495328, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
made all classes inherit from SchreyerSyzygyComputationFlags chg: moved the base ring into attributes (no need in extra ring argument) chg: removed __SYZCHECK__ (only relevant for schreyer.lib)
  • Property mode set to 100644
File size: 8.9 KB
Line 
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 <vector>
20#include <map>
21
22// include basic definitions
23#include "singularxx_defs.h"
24
25struct  spolyrec;
26typedef struct spolyrec    polyrec;
27typedef polyrec *          poly;
28
29struct ip_sring;
30typedef struct ip_sring *         ring;
31
32struct sip_sideal;
33typedef struct sip_sideal *       ideal;
34
35class idrec;
36typedef idrec *   idhdl;
37
38BEGIN_NAMESPACE_SINGULARXX    BEGIN_NAMESPACE(SYZEXTRA)
39
40poly leadmonom(const poly p, const ring r);
41
42/// return the tail of a given polynomial or vector
43/// returns NULL if input is NULL, otherwise
44/// the result is a new polynomial/vector in the ring r
45poly p_Tail(const poly p, const ring r);
46
47
48/// return the tail of a given ideal or module
49/// returns NULL if input is NULL, otherwise
50/// the result is a new ideal/module in the ring r
51/// NOTE: the resulting rank is autocorrected
52ideal id_Tail(const ideal id, const ring r);
53
54/// inplace sorting of the module (ideal) id wrt <_(c,ds)
55void Sort_c_ds(const ideal id, const ring r);
56
57
58
59
60
61/// Computation attribute storage
62struct SchreyerSyzygyComputationFlags
63{
64  SchreyerSyzygyComputationFlags(idhdl rootRingHdl);
65  SchreyerSyzygyComputationFlags(const SchreyerSyzygyComputationFlags& attr):
66      __DEBUG__(attr.__DEBUG__),
67//      __SYZCHECK__(attr.__SYZCHECK__),
68      __LEAD2SYZ__(attr.__LEAD2SYZ__),  __TAILREDSYZ__(attr.__TAILREDSYZ__),
69      __HYBRIDNF__(attr.__HYBRIDNF__),  m_rBaseRing(attr.m_rBaseRing)
70  {}
71     
72
73  /// output all the intermediate states
74  const bool __DEBUG__; // DebugOutput;
75
76//  const bool __SYZCHECK__; // CheckSyzygyProperty: never tested here...
77
78  /// ?
79  const bool __LEAD2SYZ__; // TwoLeadingSyzygyTerms;
80
81  /// Reduce syzygy tails wrt the leading syzygy terms
82  const bool __TAILREDSYZ__; // TailReducedSyzygies;
83
84  /// Use the usual NF's S-poly reduction while dropping lower order terms
85  const bool __HYBRIDNF__; // UseHybridNF
86
87  /// global base ring
88  const ring m_rBaseRing;
89
90};
91
92class SchreyerSyzygyComputation;
93
94class CLCM: public SchreyerSyzygyComputationFlags, public std::vector<bool>
95{
96  public:
97    CLCM(const SchreyerSyzygyComputation& data);
98
99    bool Check(const poly m) const;
100   
101  private:
102    const SchreyerSyzygyComputation& m_data;
103
104    bool m_compute;
105};
106
107
108class CReducerFinder: public SchreyerSyzygyComputationFlags
109{
110  private:
111    class CLeadingTerm
112    {
113      public: 
114        CLeadingTerm(unsigned int id,  const poly p, const ring);
115
116      private:
117        CLeadingTerm();
118
119      public:
120
121        const unsigned long m_sev; ///< not short exp. vector
122        // NOTE/TODO: either of the following should be enough:
123        const unsigned int  m_label; ///< index in the main L[] + 1
124        const poly          m_lt; ///< the leading term itself L[label-1]
125    };
126
127    typedef long TComponentKey;
128    typedef std::vector<const CLeadingTerm*> TReducers;
129    typedef std::map< TComponentKey, TReducers> CReducersHash;
130   
131  public:
132
133    /// goes over all leading terms
134    CReducerFinder(const SchreyerSyzygyComputation& data);
135
136    ~CReducerFinder();
137
138    // TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz?   
139    poly FindReducer(const poly product, const poly syzterm) const;
140
141  private:
142    const SchreyerSyzygyComputation& m_data;
143
144    CReducersHash m_hash; // can also be replaced with a vector indexed by components
145};
146
147
148
149/** @class SchreyerSyzygyComputation syzextra.h
150 *
151 * Computing syzygies after Schreyer
152 *
153 * Storing/accumulating data during the computation requires some global
154 * object, like this class. Ideally the above global functions should not
155 * be used in favour of this class.
156 *
157 * @sa Schreyer Syzygy Computation Paper & Talk & Python prototype
158 */
159class SchreyerSyzygyComputation: public SchreyerSyzygyComputationFlags
160{
161  friend class CLCM;
162  friend class CReducerFinder;
163 
164  public:
165
166    /// Construct a global object for given input data (separated into leads & tails)
167    SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const SchreyerSyzygyComputationFlags setting):
168        SchreyerSyzygyComputationFlags(setting),
169        m_idLeads(idLeads), m_idTails(idTails), 
170        m_syzLeads(NULL), m_syzTails(NULL), m_LS(NULL),
171        m_lcm(*this), m_div(*this)
172    {
173    }
174
175
176    /// Construct a global object for given input data (separated into leads & tails)
177    SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ideal syzLeads, const SchreyerSyzygyComputationFlags setting):
178        SchreyerSyzygyComputationFlags(setting),
179        m_idLeads(idLeads), m_idTails(idTails), 
180        m_syzLeads(NULL), m_syzTails(NULL), m_LS(syzLeads), 
181        m_lcm(*this), m_div(*this)
182    {
183    }
184
185   
186    /// Destructor should not destruct the resulting m_syzLeads, m_syzTails.
187    ~SchreyerSyzygyComputation(){ CleanUp(); }
188
189    /// Read off the results while detaching them from this object
190    /// NOTE: no copy!
191    inline void ReadOffResult(ideal& syzL, ideal& syzT)
192    {
193      syzL = m_syzLeads; syzT = m_syzTails; 
194
195      m_syzLeads = m_syzTails = NULL; // m_LS ?
196    }
197   
198    /// The main driver function: computes
199    void ComputeSyzygy();
200
201    /// Computes Syz(leads) or only LEAD of it.
202    /// The result is stored into m_syzLeads
203    void ComputeLeadingSyzygyTerms(bool bComputeSecondTerms = true);
204
205    poly SchreyerSyzygyNF(poly syz_lead, poly syz_2) const;
206
207    // TODO: store m * @tail -.-^-.-^-.--> ?
208    poly TraverseTail(poly multiplier, poly tail) const;
209
210    // TODO: save shortcut (syz: |-.->) LM(m) * "t" -> ?
211    poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck) const;
212
213  public:
214    /// just for testing via the wrapper below
215    inline poly _FindReducer(const poly product, const poly syzterm) const
216        { return m_div.FindReducer(product, syzterm); } 
217   
218  protected:
219
220    /// just leading terms
221    ideal Compute1LeadingSyzygyTerms();
222
223    /// leading + second terms
224    ideal Compute2LeadingSyzygyTerms();
225
226    /// Clean up all the accumulated data
227    void CleanUp() {}
228
229  private:
230    /// input leading terms
231    const ideal m_idLeads;
232
233    /// input tails
234    const ideal m_idTails;
235
236    /// output (syzygy) leading terms (+2nd terms?)
237    ideal m_syzLeads;
238
239    /// output (syzygy) tails
240    ideal m_syzTails;
241
242    /*mutable?*/ ideal m_LS; ///< leading syzygy terms used for reducing syzygy tails
243
244    /// Bitmask for variables occuring in leading terms
245    const CLCM m_lcm;
246
247    /// Divisor finder
248    const CReducerFinder m_div;
249};
250
251
252// The following wrappers are just for testing separate functions on highest level (within schreyer.lib)
253
254static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const SchreyerSyzygyComputationFlags A)
255{
256  SchreyerSyzygyComputation syz(L, T, A);
257  syz.ComputeSyzygy();
258  syz.ReadOffResult(LL, TT);
259}
260
261static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const SchreyerSyzygyComputationFlags A)
262{
263  SchreyerSyzygyComputation syz(L, NULL, A);
264  syz.ComputeLeadingSyzygyTerms(false);
265  ideal LL, TT;
266  syz.ReadOffResult(LL, TT);
267  return LL; // assume TT is NULL!
268}
269
270static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const SchreyerSyzygyComputationFlags A)
271{
272  SchreyerSyzygyComputation syz(L, NULL, A);
273  syz.ComputeLeadingSyzygyTerms(true);
274  ideal LL, TT;
275  syz.ReadOffResult(LL, TT);
276  return LL; // assume TT is NULL!
277}
278
279static inline poly FindReducer(poly product, poly syzterm,
280                               ideal L, ideal LS, const SchreyerSyzygyComputationFlags A)
281{
282  SchreyerSyzygyComputation syz(L, NULL, LS, A);
283  return syz._FindReducer(product, syzterm);
284}
285
286static inline poly TraverseTail(poly multiplier, poly tail, 
287                                ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
288{
289  SchreyerSyzygyComputation syz(L, T, LS, A);
290  return syz.TraverseTail(multiplier, tail);
291}
292
293static inline poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
294                              ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
295{
296  SchreyerSyzygyComputation syz(L, T, LS, A);
297  return syz.ReduceTerm(multiplier, term4reduction, syztermCheck);
298}
299
300
301static inline poly SchreyerSyzygyNF(poly syz_lead, poly syz_2,
302                                    ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
303{
304  SchreyerSyzygyComputation syz(L, T, LS, A);
305  return syz.SchreyerSyzygyNF(syz_lead, syz_2);
306}
307
308END_NAMESPACE
309   
310END_NAMESPACE_SINGULARXX
311
312#endif
313/* #ifndef SYZEXTRA_H */
314
315// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
316
Note: See TracBrowser for help on using the repository browser.