File: ideal.rules

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (147 lines) | stat: -rw-r--r-- 4,383 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
#  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.
#-------------------------------------------------------------------------------

object Ideal {

   rule initial : GENERATORS {
      my $gens = $this->GENERATORS;
      my $nvars = $gens->[0]->n_vars();
      foreach my $p (@$gens){
         if($p->n_vars() != $nvars){
            croak("\ninvalid input: Number of variables needs to be the same for all GENERATORS");
            return;
         }
      }
   }
   precondition : !exists(N_VARIABLES);
   precondition : exists(GENERATORS);
	precondition : GENERATORS {
		$this->GENERATORS->size() > 0;
	}

   rule initial : GENERATORS, N_VARIABLES {
      my $gens = $this->GENERATORS;
      my $nvars = $this->N_VARIABLES;
      foreach my $p (@$gens){
         if($p->n_vars() != $nvars){
            croak("\ninvalid input: N_VARIABLES does not agree with the number of variables of the GENERATORS");
            return;
         }
      }
   }
   precondition : exists(N_VARIABLES);
   precondition : exists(GENERATORS);

   rule PRIMARY : {
      $this->PRIMARY = 1;
   }
   precondition : PRIME;
   weight 0.10;

   rule PRIMARY : RADICAL.PRIME {
      $this->PRIMARY = $this->RADICAL->PRIME;
   }
   weight 0.10;

   rule ZERO : GENERATORS {
      foreach my $p (@{$this->GENERATORS}){
         if(!$p->trivial){
            $this->ZERO = 0;
            return;
         }
      }
      $this->ZERO = 1;
   }
   weight 1.10;

	rule N_VARIABLES : GENERATORS {
		$this->N_VARIABLES = $this->GENERATORS->[0]->n_vars();
	}
	precondition : GENERATORS {
		$this->GENERATORS->size() > 0;
	}
	weight 0.10;

    rule GENERATORS = GROEBNER.BASIS;

}

object Groebner {

   rule initial :  {
      if (my $order = $this->lookup("ORDER_NAME")) {
         $order =~ /^(dp|Dp|lp|Lp|rp|ls|rs|ds|Ds)$/ or croak ("unknown term order");
      } elsif ( ! defined($this->lookup("ORDER_VECTOR | ORDER_MATRIX"))) {
         croak ("no term order specified");
      }
   }

   rule INITIAL_FORMS : BASIS, ORDER_VECTOR {
      $this->INITIAL_FORMS = [ map { $_->initial_form($this->ORDER_VECTOR) } @{$this->BASIS} ];
   }
   weight 1.10;

   rule INITIAL_FORMS : BASIS, ORDER_MATRIX {
      $this->INITIAL_FORMS = [ map { $_->initial_form($this->ORDER_MATRIX->row(0)) } @{$this->BASIS} ];
   }
   weight 1.10;

}

object_specialization Ideal::Binomial {

   rule N_VARIABLES : BINOMIAL_GENERATORS {
      $this->N_VARIABLES = $this->BINOMIAL_GENERATORS->cols;
   }

   rule GENERATORS : BINOMIAL_GENERATORS {
      my $binomials = $this->BINOMIAL_GENERATORS;
      my @gens;
      my $coef = new Vector<Rational>(1, -1);
      foreach my $binomial (@$binomials){
         my $positivePart = new Vector<Int>(map($_>0 ? $_ : 0, @$binomial));
         my $negativePart = new Vector<Int>(map($_<0 ? -$_ : 0, @$binomial));
         my $expmat = new Matrix<Int>([$positivePart, $negativePart]);
         push @gens, new Polynomial($coef, $expmat);
      }
      $this->GENERATORS(temporary) = \@gens;
   }

   property GROEBNER {

        rule BASIS : BINOMIAL_BASIS {
             my $binomials = $this->BINOMIAL_BASIS;
             my @gens;
             my $coef = new Vector<Rational>(1, -1);
             foreach my $binomial (@$binomials){
                my $positivePart = new Vector<Int>(map($_>0 ? $_ : 0, @$binomial));
                my $negativePart = new Vector<Int>(map($_<0 ? -$_ : 0, @$binomial));
                my $expmat = new Matrix<Int>([$positivePart, $negativePart]);
                push @gens, new Polynomial($coef, $expmat);
             }
             $this->BASIS(temporary) = \@gens;
        }

   }

   rule BINOMIAL_GENERATORS = GROEBNER.BINOMIAL_BASIS;
}

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