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

spielwiese
Last change on this file since c93fda was c7d29b, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
final removal of old _INTERNAL_ functions and corresp. wrappers TODO/Q?: eliminate "const BOOLEAN __DEBUG__ = attributes.__DEBUG__;" by inheriting SchreyerSyzygyComputation from SchreyerSyzygyComputationFlags?
  • Property mode set to 100644
File size: 7.1 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 basic definitions
20#include "singularxx_defs.h"
21
22struct  spolyrec;
23typedef struct spolyrec    polyrec;
24typedef polyrec *          poly;
25
26struct ip_sring;
27typedef struct ip_sring *         ring;
28
29struct sip_sideal;
30typedef struct sip_sideal *       ideal;
31
32class idrec;
33typedef idrec *   idhdl;
34
35BEGIN_NAMESPACE_SINGULARXX    BEGIN_NAMESPACE(SYZEXTRA)
36
37poly 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
42poly 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
49ideal id_Tail(const ideal id, const ring r);
50
51/// inplace sorting of the module (ideal) id wrt <_(c,ds)
52void Sort_c_ds(const ideal id, const ring r);
53
54
55
56
57
58/// Computation attribute storage
59struct 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 */
92class 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    /// just leading terms
142    ideal Compute1LeadingSyzygyTerms();
143
144    /// leading + second terms
145    ideal Compute2LeadingSyzygyTerms();
146   
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
168
169    const SchreyerSyzygyComputationFlags m_atttributes;
170};
171
172
173// The following wrappers are just for testing separate functions on highest level (within schreyer.lib)
174
175static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const ring R, const SchreyerSyzygyComputationFlags A)
176{
177  SchreyerSyzygyComputation syz(L, T, R, A);
178  syz.ComputeSyzygy();
179  syz.ReadOffResult(LL, TT);
180}
181
182static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A)
183{
184  SchreyerSyzygyComputation syz(L, NULL, R, A);
185  syz.ComputeLeadingSyzygyTerms(false);
186  ideal LL, TT;
187  syz.ReadOffResult(LL, TT);
188  return LL; // assume TT is NULL!
189}
190
191static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A)
192{
193  SchreyerSyzygyComputation syz(L, NULL, R, A);
194  syz.ComputeLeadingSyzygyTerms(true);
195  ideal LL, TT;
196  syz.ReadOffResult(LL, TT);
197  return LL; // assume TT is NULL!
198}
199
200static inline poly FindReducer(poly product, poly syzterm,
201                               ideal L, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
202{
203  SchreyerSyzygyComputation syz(L, NULL, LS, R, A);
204  return syz.FindReducer(product, syzterm);
205}
206
207static inline poly TraverseTail(poly multiplier, poly tail, 
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.TraverseTail(multiplier, tail);
212}
213
214static inline poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
215                              ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
216{
217  SchreyerSyzygyComputation syz(L, T, LS, R, A);
218  return syz.ReduceTerm(multiplier, term4reduction, syztermCheck);
219}
220
221
222static inline poly SchreyerSyzygyNF(poly syz_lead, poly syz_2,
223                                    ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
224{
225  SchreyerSyzygyComputation syz(L, T, LS, R, A);
226  return syz.SchreyerSyzygyNF(syz_lead, syz_2);
227}
228
229END_NAMESPACE
230   
231END_NAMESPACE_SINGULARXX
232
233#endif
234/* #ifndef SYZEXTRA_H */
235
236// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
237
Note: See TracBrowser for help on using the repository browser.