-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcurtest.java
More file actions
320 lines (310 loc) · 12.1 KB
/
Copy pathcurtest.java
File metadata and controls
320 lines (310 loc) · 12.1 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package commandui;
import core.functions.GeneralFunction;
import core.functions.endpoint.Placeholder;
import core.functions.unitary.specialcases.Exp;
import static core.tools.defaults.DefaultFunctions.*;
import tensors.*;
import static tensors.TensorTools.prettyString;
import static tensors.TensorTools.product;
import static tensors.TensorTools.wrap;
public class curtest {
public static void main(String[] args) {
System.out.println("hi");
String[] genericVariables = new String[10];
for (int i = 0; i < 3; ++i) {
genericVariables[i] = ((char) ('x' + i)) + "";
}
for (int i = 3; i < genericVariables.length; ++i) {
genericVariables[i] = ((char) ('z' - i)) + "";
}
{
String[] vars = new String[2];
for (int i = 0; i < vars.length; ++i) {
vars[i] = genericVariables[i];
}
// var genericMetrics = TensorTools.placeholderMetrics(vars);
var genericMetrics = TensorTools.placeholderDiagonalMetrics(vars);
Tensor genericMetric = genericMetrics.getFirst();
Tensor genericInverseMetric = genericMetrics.getSecond();
// GeneralFunction conformalScale = new Placeholder("M", vars);
GeneralFunction conformalScale = new Exp(new Placeholder("w", vars));
Tensor conformalMetric = TensorTools
.magicTensor(product(wrap(conformalScale), genericMetric.index("a", "b")));
Tensor conformalInverseMetric = TensorTools
.magicTensor(product(wrap(reciprocal(conformalScale)), genericInverseMetric.index("a", "b")));
Space conformalSpace = new Space(vars, conformalMetric, conformalInverseMetric);
System.out.println("Conformal Space: " + conformalSpace
+ "\nConformal Metric: " + prettyString(conformalMetric, conformalSpace, "a", "b")
+ "\nConformal Inverse Metric: " + prettyString(conformalInverseMetric, conformalSpace, "a", "b"));
System.out.println("Conformal Christoffel: "
+ prettyString(conformalSpace.christoffel, conformalSpace, "a", "b", "c"));
// System.out.println("Conformal Riemann Tensor: "
// + prettyString(conformalSpace.riemannTensor, conformalSpace, vars));
System.out.println("Conformal Ricci Tensor: "
+ prettyString(conformalSpace.ricciTensor, conformalSpace, "a", "b"));
// System.out.println("Conformal Ricci Scalar: "
// + prettyString(conformalSpace.ricciScalar, conformalSpace, vars));
}
// {
// String[] vars = { "t", "r", "h", "f", "s" };
// GeneralFunction[] diag = {
// NEGATIVE_ONE,
// new Pow(TWO, new Placeholder("a", "t")),
// new Pow(TWO, new Sinh(new Variable(vars[1]))),
// new Pow(TWO, new Sin(new Variable(vars[2]))),
// new Pow(TWO, new Sin(new Variable(vars[3]))),
// };
// for (int i = 2; i < diag.length; ++i) {
// diag[i] = new Product(diag[i], diag[i]).simplifyPull();
// }
// System.out.println(Space.fromDiagonalMetric(vars, diag).ricciScalar);
// }
// // {
// String[] vars = { "t", "r", "h", "f" };
// Variable[] variables =
// Arrays.stream(vars).map(Variable::new).toArray(Variable[]::new);
// var radial = new Variable("r");
// // var integration_constant = new Variable("C");
// // var placeholder_f = new Placeholder("f", "r");
// var integration_constant = ONE;
// var mass = new Variable("M");
// var charge = new Variable("q");
// var placeholder_f = new Sum(ONE, new Product(NEGATIVE_TWO, mass,
// reciprocal(radial)),
// square(new Product(charge, reciprocal(radial))));
// GeneralFunction[] diag = {
// negative(placeholder_f),
// new Product(integration_constant, reciprocal(placeholder_f)),
// square(radial),
// new Product(square(radial), square(new Sin(new Variable(vars[2]))))
// };
// Space space = Space.fromDiagonalMetric(vars, diag);
// System.out.println(prettyString(space.christoffel, space, new String[] { "a",
// "b", "c" }));
// // System.out.println(prettyString(space.riemannTensor, space, new String[] {
// // "a", "b", "c", "d" }));
// // System.out.println(prettyString(space.einsteinTensor, space, new String[]
// {
// // "a", "b" }));
// Tensor einsteinDownUp = magicTensor(
// product(space.einsteinTensor.index("\\alpha", "\\beta"),
// space.inverseMetric.index("\\gamma", "\\beta")));
// System.out.println(prettyString(einsteinDownUp, space, new String[] {
// "a", "b" }));
// // }
// var curt = DefaultSpaces.s3.ricciTensor;
// var curtm = curt.modifyWithTensor(MiscTools::trigForSinners);
// System.out.println(
// TensorTools.prettyString(curtm,
// DefaultSpaces.s3, new String[] { "a", "b" }));
}
/**
* @BeforeAll
* static void beforeAll() {
* DefaultSpaces.initialize();
* }
*
* @Test
* void undirectedTest() {
* NestedArray<?, Integer> test = NestedArray.nest(new Object[][] {
* { 1, 2 },
* { 3, 4 }
* });
* System.out.println(test);
* assertEquals(2, test.getAtIndex(0, 1));
* assertEquals(2, test.getRank());
* test.setAtIndex(-1, 0, 0);
* assertEquals(-1, test.getAtIndex(0, 0));
* Nested<?, Integer> test2 = test.modifyWith(i -> -2 * i);
* assertEquals(-4, test2.getAtIndex(0, 1));
* }
*
* @Test
* void directedTest() {
* DirectedNested<?, Integer> test = DirectedNestedArray.direct(
* new Object[][] {
* { 1, 2 },
* { 3, 4 }
* }, new boolean[] { true, false });
* System.out.println(test);
* assertEquals(2, test.getAtIndex(0, 1));
* assertTrue(test.getDirection());
* }
*
* @Test
* void tensorTest() {
* Tensor test = ArrayTensor.tensor(
* new Object[][] {
* { ONE, TWO },
* { new Constant(3), new Product(TWO, E) }
* },
* true, false);
* System.out.println(test);
* assertEquals(TWO, test.getAtIndex(0, 1));
* assertTrue(test.getDirection());
* DirectedNested<?, GeneralFunction> test2d =
* DirectedNestedArray.direct(NestedArray.nest(
* new Object[][] {
* { ONE, ONE },
* { ONE, TWO }
* }), new boolean[] { true, false });
* Tensor test2 = ArrayTensor.tensor(test2d);
* DirectedNested<?, ?> sum = TensorTools.createFrom(
* List.of("a", "b"),
* new boolean[] { true, false },
* 2,
* new ElementSum(indexTensor(test, "a", "b"), indexTensor(test2, "a",
* "b")));
* assertEquals(sum.getAtIndex(1, 0), new Constant(4));
* System.out.println(sum);
* }
*
* @Test
* void elementTest() {
* Tensor id2u = ArrayTensor.tensor(
* new Object[][] {
* { ZERO, ONE },
* { ONE, ZERO }
* },
* false, false);
* Tensor id2d = ArrayTensor.tensor(
* new Object[][] {
* { ZERO, ONE },
* { ONE, ZERO }
* },
* true, true);
* System.out.println(createFrom(List.of("a", "b"), new boolean[] { true,
* false }, 2,
* new ElementProduct(new ElementWrapper(id2u, "a", "m"), new
* ElementWrapper(id2d, "m", "b"))));
* }
*
* @Test
* void scalarTest1() {
* Tensor C = ArrayTensor.tensor(
* new Object[] {
* ONE,
* TWO
* },
* true);
* Tensor R = ArrayTensor.tensor(
* new Object[] {
* TEN, ONE
* },
* false);
* System.out.println(createFrom(List.of(), new boolean[] {}, 2,
* new ElementProduct(new ElementWrapper(R, "\\mu"), new ElementWrapper(C,
* "\\mu"))));
* }
*
* @Test
* void scalarTest2() {
* Tensor C = ArrayTensor.tensor(
* new Object[] {
* TEN, ONE
* },
* true);
* Tensor metric = ArrayTensor.tensor(
* new Object[][] {
* { NEGATIVE_ONE, ZERO },
* { ZERO, ONE }
* },
* false, false);
* System.out.println(createFrom(List.of("\\nu"), new boolean[] { false },
* 2,
* new ElementProduct(new ElementWrapper(C, "\\mu"), new
* ElementWrapper(metric, "\\mu", "\\nu"))));
* }
*
* @Test
* void christoffel() {
* Space space = DefaultSpaces.s2;
* System.out.println(space.christoffel);
* }
*
* @Test
* void cov1() {
* Space space = DefaultSpaces.cartesian2d;
* Tensor tensor = ArrayTensor.tensor(
* new Object[] { square(new Variable("x")), new Product(TWO, new
* Variable("y")) },
* true);
* assertEquals(space.covariantDerivative("a", tensor, "b"),
* ArrayTensor.tensor(
* new Object[][] {
* { new Product(TWO, new Variable("x")), ZERO },
* { ZERO, TWO }
* },
* false, true));
*
* }
*
* @Test
* void cov2() {
* Space space = DefaultSpaces.spherical;
* Tensor tensor = ArrayTensor.tensor(
* new Object[] {
* new Product(new Variable("k"), new Variable("q"), new Pow(NEGATIVE_TWO,
* new Variable("r"))),
* ZERO, ZERO },
* true);
* Tensor expected = ArrayTensor.tensor(
* new Object[][] {
* { new Product(NEGATIVE_TWO, new Variable("k"), new Variable("q"),
* new Pow(new Constant(-3), new Variable("r"))), ZERO, ZERO },
* { ZERO, new Product(new Variable("k"), new Variable("q"),
* new Pow(new Constant(-3), new Variable("r"))), ZERO },
* { ZERO, ZERO,
* new Product(new Variable("k"), new Variable("q"),
* new Pow(new Constant(-3), new Variable("r"))) }
* },
* false, true);
* assertEquals(expected, space.covariantDerivative("\\mu", tensor,
* "\\nu"));
* }
*
* @Test
* void cov3() {
* Space space = DefaultSpaces.cartesian2d;
* Tensor tensor = ArrayTensor.tensor(
* new Object[][] {
* { square(new Variable("x")), new Product(TWO, new Variable("y")) },
* { ZERO, new Sin(new Variable("x")) }
* },
* true, false);
* assertEquals(space.covariantDerivative("a", tensor, "b", "c"),
* ArrayTensor.tensor(
* new Object[][][] {
* {
* { new Product(TWO, new Variable("x")), ZERO },
* { ZERO, new Cos(new Variable("x")) }
* },
* {
* { ZERO, TWO },
* { ZERO, ZERO }
* }
* },
* false, true, false));
*
* }
*
* @Test
* void access1() {
* Tensor vector = ArrayTensor.tensor(
* new Object[] {
* new Product(new Variable("k"), new Variable("q"), new Pow(NEGATIVE_TWO,
* new Variable("r"))),
* ZERO, ZERO },
* true);
* System.out.println(TensorTools.createFrom(
* List.of("\\beta", "a"),
* new boolean[] { false, true },
* 3,
* new ElementProduct(
* TensorTools.indexTensor(vector, "\\alpha"),
* TensorTools.indexTensor(DefaultSpaces.spherical.christoffel, "\\alpha",
* "a", "\\beta"))));
* }
*
**/
}