-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindicatorFunc.m2
More file actions
126 lines (107 loc) · 2.88 KB
/
indicatorFunc.m2
File metadata and controls
126 lines (107 loc) · 2.88 KB
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
-- indicator function for xi between a and b, in Fp
indicatorF= method()
indicatorF(ZZ,ZZ,ZZ,ZZ) := (a, b, i, p) -> (
R = ZZ/p[ value concatenate( "x", toString i) ];
QR = R / ideal apply(gens R, x -> x^p - x);
x := first gens R;
f := sum( (a..b), r -> (1 - (x - r)^(p-1)));
print toString f
)
--
simplify = method()
--simplify (String, ZZ, ZZ) := (input, p, n) -> (
-- R = ZZ/p[ apply( (1..n), i -> value concatenate( "x", toString i)) ];
-- QR = R / ideal apply(gens R, x -> x^p - x);
-- pol := value input;
-- print toString pol
--)
simplify (List, ZZ, ZZ) := (functionList, p, n) -> (
--print "calling simplify on List";
R = ZZ/p[ apply( (1..n), i -> value concatenate( "x", toString i)) ];
QR = R / ideal apply(gens R, x -> x^p - x);
scan( functionList, input -> (
pol := value input;
print toString pol
))
)
--L = {"x3", "x1"}
--p = 2
--vals = {0,1,0,1}
interpolate = method()
interpolate (List, ZZ, List) := (L, p, vals) -> (
params := select( vals, l -> ( class value toString l ) === Symbol );
R := ZZ/p[params / value][L / value ];
--R := ZZ/p[L];
n := #L;
QR := R / ideal apply( gens R, x -> x^p-x) ;
vals = apply(vals, l -> value toString l );
X := set (0..p-1);
inputs := sort toList X^**n;
--print toString L;
--print toString vals;
--print toString inputs;
pol := sum ( inputs, vals, (source, t) -> t* product( source, gens QR, (i, xi) -> 1 - (xi-i)^(p-1) ) );
print toString pol
)
--L = {"x3", "x1"}
--p = 2
--vals = {0,1,0,1}
interpolateContinuous = method()
interpolateContinuous (List, ZZ, List) := (L, p, vals) -> (
params := select( vals, l -> ( class value toString l ) === Symbol );
-- check for duplicate names of generators
if (#L != # unique L ) then (
print "<font color=red>Sorry, you are using the same variable name twice, the output variable should not be listed as one of the input variables for continuous models.</font>";
return
);
R := ZZ/p[params / value][ L / value ];
--R := ZZ/p[L];
n := #L;
QR := R / ideal apply( gens R, x -> x^p-x) ;
vals = apply(vals, l -> value toString l );
X := set (0..p-1);
inputs := sort toList X^**(n);
-- make a larger table
vals = flatten apply( vals, v -> (
apply( p, i ->
if (v < i) then i-1
else
if (v > i) then i+1
else i
)
));
--print toString L;
--print toString vals;
--print toString inputs;
pol := sum ( inputs, vals, (source, t) -> t* product( source, gens QR, (i, xi) -> 1 - (xi-i)^(p-1) ) );
print toString pol
)
end
p = 3
n = 3
R = ZZ/p[ apply( (1..n), i -> value concatenate( "x", toString i)) ];
QR = R / ideal apply(gens R, x -> x^p - x);
c = -x2^2*x3^2+x2^2*x3
f1 = x1 + c;
f2 = x2 - c;
f3 = x3 - 2*c;
print toString f1
print toString f2
print toString f3
end
x(t) y(t) y(t+1)
0 0 0
0 1 0
0 2 1
1 0 1
1 1 1
1 2 1
2 0 1
2 1 2
2 2 2
f_y = -x^2*y+x*y^2+x^2-y^2+y
x(t) y(t+1)
0 0
1 1
2 2
f_y = x