-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpbma.m
196 lines (171 loc) · 6.4 KB
/
pbma.m
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
function [polysys,a,b]=pbma(root,varargin)
% [polysys,a,b]=pbma(root) or pbma(root,mult)
% -------------------------------------------
% Projective Buchberger-Moller algorithm. For a given set of projective roots and their
% multiplicity structures, this algorithm returns a mimimal reduced Grobner
% basis.
%
% polysys = cell containing coefficients and monomials exponents of the
% reduced Grobner basis.
%
% a = vector, indices of monomials which are leading monomials
% that can be reached in C_d^n.
%
% b = vector, indices of standard monomials.
%
% root = matrix, each row corresponds with a projetive root.
%
% mult = cell, mult{i} contains a matrix T that defines the
% multiplicit structure of root(i,:). The matrix T is such
% that the canonical kernel K = D*T, with D the matrix of
% differential functionals obtained via getKSB.m. Optional,
% default is no multiplicities.
%
% CALLS
% -----
%
% getKSB.m, fite.m, getM.m
%
% Kim Batselier, 2014-03
[m,n] = size(root);
if isempty(varargin)
mult=cell(1,m);
% no multiplicities
for i=1:m
mult{i}=1;
end
else
mult=varargin{1};
end
a=[];
b=[2,3]; % 2 pure powers that are connected, hence stop condition not satisfied
polysys=[];
d=0;
while ~canstop(b,n)
d=d+1;
% construct kernel K
% for now, make whole K everytime
K=[];
for i=1:m % for each root
% determine order of differentiation
ddiff=0;
while nchoosek(ddiff+n,n) < size(mult{i},1)
ddiff=ddiff+1;
end
D=getKSB(d,ddiff,root(i,:));
K=[K D*mult{i}];
end
indices = nchoosek(d-1+n,n)+1:nchoosek(d+n,n); % indices of all monomials of degree d
% remove multiples of A from indices
for i=1:length(indices) % for each new monomial
for j=1:length(a) % check whether it is multiple of a(j)
if sum((fite(indices(i),n)-fite(a(j),n)) >= 0) == n
% we found a multiple
indices(i) = 0;
end
end
end
indices(indices==0)=[];
b=[];
% canonical decomposition
for i=1:length(indices)
[U, S,Z]=svd(full(K([b indices(i)],:)'));
if size(S,2)==1
S=S(1,1);
else
S=diag(S);
end
tol=m*S(1)*eps;
rs=sum(S > tol);
if (S(end) < tol) || (rs < length([b indices(i)]))
temp=zeros(1,nchoosek(d+n,n));
temp([b indices(i)])=Z(:,end);
temp(abs(temp)<tol)=0; % remove numerically zero coefficients
% check whether new polynomial g_i lies in <g_1,..,g_{i-1}>
if ~isempty(polysys)
M=getM(polysys,d); % construct Macaulay matrix
M=M(:,nchoosek(d-1+n,n)+1:end); % only need monomials of degree d
if rank([M;temp(nchoosek(d-1+n,n)+1:end)]) > rank(M)
% g_i does not lie in <g_1,..,g_{i-1}>
polysys=[polysys;vec2polysys(temp,n)];
a=[a indices(i)];
end
else
polysys=[polysys;vec2polysys(temp,n)];
a=[a indices(i)];
end
else
b=[b indices(i)];
end
end
end
function satisfied = canstop(b,n)
satisfied=1;
% determine indices pure powers in B
exponents=fite(b,n);
dd=sum(exponents(1,:));
ppindices=zeros(1,n);
for ii=1:size(exponents,1) % for each monomial in B
if length(find(exponents(ii,:)))==1
ppindices(find(exponents(ii,:)))=ii;
end
end
for ii=1:length(ppindices)
if ppindices(ii) ~= 0
% determine connected components for each pure power in B
connected = b(ppindices(ii));
index=ppindices(ii);
% going up in indices
if connected < nchoosek(dd+n,n)
for jj=[index+1:length(b)]
if isconnected(connected,b(jj),n)
connected = [connected b(jj)];
end
end
end
% going down in indices
if connected > nchoosek(dd-1+n,n)+1
for jj=[index-1:-1:1]
if isconnected(connected,b(jj),n)
connected = [connected b(jj)];
end
end
end
% check divisibility of connected set by x_i
allexponents=fite(connected,n);
if ~isempty(find(allexponents(:,ii)==0))
satisfied=0;
break;
end
end
end
function isc=isconnected(connected,index,n)
isc=0; % is 1 if index is connected
checkexponents=fite(index,n);
for iii=1:length(connected)
bexponents=fite(connected(iii),n);
% check where there are nonzero exponents in connected(i)
nzexpindices= find(bexponents >0);
for jjj=1:length(nzexpindices) % for each nonzero exponent
% other exponents
otherexponents=1:n;
otherexponents(nzexpindices(jjj))=[];
% construct multiply and divide exponents
mdexponents=zeros(n-1,n);
mdexponents(:,nzexpindices(jjj))=-1;
for k=1:n-1
mdexponents(k,otherexponents(k))=1;
end
% check reach of bexponents
for k=1:n-1
if sum(bexponents+mdexponents(k,:) == checkexponents)==n
% the monomial is connected to pure power
isc=1;
break;
end
end
end
end
end
end
end