File: singular.rules

package info (click to toggle)
polymake 4.15-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,892 kB
  • sloc: cpp: 168,945; perl: 43,410; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (229 lines) | stat: -rw-r--r-- 8,371 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#  Copyright (c) 1997-2024
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

# @category Singular interface
# An intermediate object wrapping the ideal on the Singular side and providing its methods.
declare property_type SingularIdeal : c++ (include => ["polymake/ideal/singularIdeal.h"]) {

   # @category Constructors
   # Construct a Singular ideal with monomial ordering given by a matrix.
   method construct(Array<Polynomial>, Matrix<Int>) : c++;

   # @category Constructors
   # Construct a Singular ideal with monomial ordering given by a vector.
   method construct(Array<Polynomial>, Vector<Int>) : c++;

   # @category Constructors
   # Construct a Singular ideal with monomial ordering given by its name (in the Singular notation).
   method construct(Array<Polynomial>, String) : c++;

   # @category Singular interface
   # Compute the Groebner basis.
   method groebner() : c++ ;

   # Compute the dimension of the ideal.
   method dim() : c++ ;

   # Check via saturation whether the ideal contains a monomial.
   method contains_monomial() : c++ ;

   # Compute the initial ideal. Depends on monomial ordering.
   method initial_ideal() : c++;

   # Compute the radical of the ideal.
   method radical() : c++ ;

   # Compute the saturation of the ideal.
   method saturation(Array<Polynomial>) : c++ ;

   method division(Polynomial) : c++;

   method solve() : c++;

   # Reduce a polynomial modulo the ideal, i.e. check ideal membership.
   method reduce(Polynomial) : c++;
   
   # Reduce a polynomial modulo the ideal, i.e. check ideal membership.
   method reduce(Array<Polynomial>) : c++;

   method polynomials() : c++;

   # Compute the primary decomposition of the ideal.
   method primary_decomposition() : c++;

}

object Groebner {

   # @category Singular interface
   # Intermediate object wrapping the Singular objects, i.e. the ring with the monomial ordering and the ideal.
   property SINGULAR_IDEAL : SingularIdeal : non_storable;

   # Reduce a [[Polynomial]] //p// with respect to the Groebner basis.
   # @param Polynomial p
   # @return Polynomial
   user_method reduce(Polynomial) {
      my ($self, $p) = @_;
      $self->parent->N_VARIABLES == $p->n_vars() or croak ("incompatible rings");
      return $self->SINGULAR_IDEAL->reduce($p);
   }
   
   # Reduce an [[Ideal]] //I// with respect to the Groebner basis.
   # @param Ideal I
   # @return Array<Polynomial>
   user_method reduce(Ideal) {
      my ($self, $I) = @_;
      $self->parent->N_VARIABLES == $I->N_VARIABLES or croak ("incompatible rings");
      return $self->SINGULAR_IDEAL->reduce($I->GENERATORS);
   }

   user_method division(Polynomial) {
      my ($self, $p) = @_;
      $self->parent->N_VARIABLES == $p->n_vars() or croak ("incompatible rings");
      return $self->SINGULAR_IDEAL->division($p);
   }

}

object Ideal {

   rule GROEBNER.INITIAL_IDEAL : GROEBNER.SINGULAR_IDEAL, N_VARIABLES {
      my $i = $this->GROEBNER->SINGULAR_IDEAL->initial_ideal();
      $this->GROEBNER->INITIAL_IDEAL = new Ideal(GENERATORS=>$i->polynomials(), N_VARIABLES=>$this->N_VARIABLES);
   }

   rule GROEBNER.SINGULAR_IDEAL : GENERATORS, GROEBNER.ORDER_MATRIX {
      $this->GROEBNER->SINGULAR_IDEAL = new SingularIdeal($this->GENERATORS, $this->GROEBNER->ORDER_MATRIX);
      $this->GROEBNER->SINGULAR_IDEAL->groebner();
   }
   precondition : !ZERO;

   rule GROEBNER.SINGULAR_IDEAL : GENERATORS, GROEBNER.ORDER_VECTOR {
      $this->GROEBNER->SINGULAR_IDEAL = new SingularIdeal($this->GENERATORS, $this->GROEBNER->ORDER_VECTOR);
      $this->GROEBNER->SINGULAR_IDEAL->groebner();
   }
   precondition : !ZERO;

   rule GROEBNER.SINGULAR_IDEAL : GENERATORS, GROEBNER.ORDER_NAME {
      $this->GROEBNER->SINGULAR_IDEAL = new SingularIdeal($this->GENERATORS, $this->GROEBNER->ORDER_NAME);
      $this->GROEBNER->SINGULAR_IDEAL->groebner();
   }
   precondition : !ZERO;

   rule GROEBNER.BASIS : GROEBNER.SINGULAR_IDEAL, N_VARIABLES{
      $this->GROEBNER->BASIS = $this->GROEBNER->SINGULAR_IDEAL->polynomials();
   }

   rule GROEBNER.INITIAL_IDEAL.GENERATORS, GROEBNER.INITIAL_IDEAL.N_VARIABLES, GROEBNER.BASIS : GENERATORS, GROEBNER.ORDER_MATRIX , N_VARIABLES {
      my $si;
      unless ( defined($si = $this->lookup("GROEBNER.SINGULAR_IDEAL"))) {
         $si = new SingularIdeal($this->GENERATORS, $this->GROEBNER->ORDER_MATRIX);
         $si->groebner();
      }
      $this->GROEBNER->BASIS = $si->polynomials();
      my $i = $si->initial_ideal();
      $this->GROEBNER->INITIAL_IDEAL->GENERATORS = $i->polynomials();
      $this->GROEBNER->INITIAL_IDEAL->N_VARIABLES = $this->N_VARIABLES;
   }
   precondition : !ZERO;


	rule GROEBNER.SINGULAR_IDEAL : GROEBNER.BASIS , GROEBNER.ORDER_MATRIX {
  	   $this->GROEBNER->SINGULAR_IDEAL = new SingularIdeal($this->GROEBNER->BASIS, $this->GROEBNER->ORDER_MATRIX);
  	   $this->GROEBNER->SINGULAR_IDEAL->groebner();
  	}

  	rule MONOMIAL : GENERATORS {
  	   my $si;
  	   unless (defined($si = $this->lookup("GROEBNER"))) {
  	      $si = $this->GROEBNER(ORDER_NAME=>"dp",temporary);
  	   }
  	   my $result = 1;
  	   # One can easily show that it suffices to check whether the generators
  	   # of the initial ideal are contained in the ideal.
  	   foreach my $mon (@{$si->INITIAL_IDEAL->GENERATORS}){
  	      $result &&= ($si->reduce($mon)->trivial);
  	   }
  	   $this->MONOMIAL = $result;
  	}

  	rule DIM : GENERATORS {
  	   my $si;
  	   unless (defined($si = $this->lookup("GROEBNER.SINGULAR_IDEAL"))) {
  	      $si = $this->GROEBNER(ORDER_NAME=>"dp",temporary)->SINGULAR_IDEAL;
  	   }

  	   $this->DIM = $si->dim();
  	}

	user_method SOLVE : N_VARIABLES, GENERATORS {
  	  my $this = shift;
  	  my $si;
  	  unless (defined($si = $this->lookup("GROEBNER.SINGULAR_IDEAL"))) {
  	      $si = $this->GROEBNER(ORDER_NAME=>"dp",temporary)->SINGULAR_IDEAL;
  	  }
  	  $si->solve();
  	}

  	rule PRIMARY_DECOMPOSITION : N_VARIABLES, GENERATORS {
  	   my $n_vars = $this->N_VARIABLES;
  	   my $si;
  	   unless (defined($si = $this->lookup("GROEBNER.SINGULAR_IDEAL"))) {
  	      $si = $this->GROEBNER(ORDER_NAME=>"dp",temporary)->SINGULAR_IDEAL;
  	   }
  	   my @pd = $si->primary_decomposition();
  	   my @res;
  	   foreach my $id (@pd) {
  	      push @res, new Ideal(GENERATORS=>$id->polynomials(),N_VARIABLES=>$n_vars,PRIMARY=>1);
  	   }
  	   $this->PRIMARY_DECOMPOSITION = \@res;
  	}

  	rule RADICAL : N_VARIABLES, GENERATORS {
  	   my $si;
  	   unless (defined($si = $this->lookup("GROEBNER.SINGULAR_IDEAL"))) {
  	      $si = $this->GROEBNER(ORDER_NAME=>"dp",temporary)->SINGULAR_IDEAL;
  	   }
  	   my $radical = $si->radical();
  	   $this->RADICAL = new Ideal(GENERATORS=>$radical->polynomials(),N_VARIABLES=>$this->N_VARIABLES);
  	}

   user_method SATURATION(Array<Polynomial>) : N_VARIABLES, GENERATORS {
      my ($this, $polys) = @_;
      my $si;
      unless (defined($si = $this->lookup("GROEBNER.SINGULAR_IDEAL"))) {
         $si = $this->GROEBNER(ORDER_NAME=>"dp",temporary)->SINGULAR_IDEAL;
      }
      my $saturation = $si->saturation($polys);
      return new Ideal(GENERATORS=>$saturation->polynomials(),N_VARIABLES=>$this->N_VARIABLES);
   }

  	# Check via saturation whether the ideal contains a monomial.
  	# Returns a monomial from the ideal or the trivial monomial if there is none.
  	# @param String s Optional term order (see [[ORDER_NAME]]) for intermediate Groebner bases, default: "dp"
  	# @return Polynomial
  	user_method contains_monomial(;$="dp") {
  	   my ($I,$order) = @_;
  	   return $I->GROEBNER(ORDER_NAME=>$order)->SINGULAR_IDEAL->contains_monomial();
  	}
}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: