-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCreateSubs.cpp
138 lines (123 loc) · 5.7 KB
/
CreateSubs.cpp
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
/*********************************************************************/
/*** FILE : CreateSubs.c ***/
/*** AUTHOR: David P Jacobs ***/
/*** PROGRAMMER:Sekhar Muddana ***/
/*** PUBLIC ROUTINES: ***/
/*** int CreateSubs() ***/
/*** PRIVATE ROUTINES: ***/
/*** int DoCreateSubs() ***/
/*** MODULE DESCRIPTION: ***/
/*** Given a set partitioning, we create substitution records ***/
/*** by selecting basis elements of the type given in set ***/
/*** partition. ***/
/*** ***/
/*** e.g. ***/
/*** ***/
/*** If Set partitions are : ***/
/*** ***/
/*** x y ***/
/*** --------------- ***/
/*** u | 1 0 0 | 1 0 0 | ***/
/*** --------------- ***/
/*** v | 0 2 0 | ***/
/*** ------- ***/
/*** w | 0 0 1 | ***/
/*** ------- ***/
/*** ***/
/*** and the generators are a, b and c then the ***/
/*** substitution record would be as follows: ***/
/*** ***/
/*** x y ***/
/*** --------------- ***/
/*** u | ab | a | ***/
/*** --------------- ***/
/*** v | b | ***/
/*** ------- ***/
/*** w | c | ***/
/*** ------- ***/
/*** ***/
/*** So the identity is linearized F(x,y) --> F(u,v,w,y). ***/
/*** We substiute basis elements in place of variables u,v,w,y.***/
/*** ***/
/*********************************************************************/
#include <vector>
using std::vector;
#include <stdio.h>
#include <stdlib.h>
#include "CreateSubs.h"
#include "Build_defs.h"
#include "Type_table.h"
#include "CreateMatrix.h"
#include "Memory_routines.h"
#include "PerformSub.h"
#include "Po_parse_exptext.h"
#include "Debug.h"
//static void BuildSubs(const Name *Set_partitions, const int *Deg_var, int row, int col, vector<Basis> &tmp, vector<vector<Basis> > &Substitutions);
#if DEBUG_SUBSTITUTION
static void PrintSubstitution(const vector<Basis> &Substitution);
#endif
int CreateSubs(Equations &equations, const struct polynomial *F, int nVars, int maxDegVar, const vector<vector<Basis> > &all_Substitutions, const int *Deg_var)
{
int status = OK;
int se = equations.size();
int as = all_Substitutions.size();
equations.resize(se + as);
//vector<vector<vector<Basis_pair> > > res(as);
{
vector<vector<vector<int> > > permutations;
int ps = 0;
{
BuildPermutationLists(nVars, Deg_var, permutations);
ps = permutations.size();
for(int i=0; i<as; i++) {
//res[i].resize(ps);
equations[se + i].resize(ps);
}
}
//printf("<%d %d %d>\n", all_Substitutions.size(), Substitutions.size(), permutations.size());
#pragma omp parallel for schedule(dynamic, 2) collapse(2)
for(int i=0; i<as; i++) {
for(int j=0; j<ps; j++) {
status = PerformSubs(all_Substitutions[i], F, maxDegVar, permutations[j], equations[se + i][j]);
}
}
}
//printf("se:%d ass:%d ", se, as);
#if 0
for(int i=0; i<as; i++) {
LocalListToEquation(res[i], equations[se + i]);
//AppendLocalListToTheList(res[i], equations);
}
#endif
return(status);
}
void BuildSubs(const vector<Name> &Set_partitions, int maxDegVar, const int *Deg_var, int row, int col, vector<Basis> &tmp, int nVars, vector<vector<Basis> > &Substitutions) {
if (row >= nVars) {
#if DEBUG_SUBSTITUTION
PrintSubstitution(tmp);
#endif
Substitutions.push_back(tmp);
} else if (col >= Deg_var[row])
BuildSubs(Set_partitions, maxDegVar, Deg_var, row+1, 0, tmp, nVars, Substitutions);
else {
Basis b = FirstBasis(Set_partitions[col*nVars + row]);
while (b != 0) {
tmp[row*maxDegVar + col] = b;
BuildSubs(Set_partitions, maxDegVar, Deg_var, row, col+1, tmp, nVars, Substitutions);
b = NextBasisSameType(b);
}
}
}
#if DEBUG_SUBSTITUTION
void PrintSubstitution(const vector<Basis> &Substitution)
{
int i,j;
static int count = 1;
printf("Substitution %d is \n",count++);
for (i=0;i<Num_vars;i++) {
for (j=0;j<Deg_var[i];j++)
printf("%d",Substitution[i*Max_deg_var + j]);
printf("\n");
}
}
#endif