Open sritchie opened 2 years ago
@sritchie are the inputs to the metric comparable? For example, if we'll wrap the memoized metric with a function that ensures that metric x y
is always called with x>y
... would this do the trick?
Well, I tried this and I guess the answer is no?
ERROR in () (Numbers.java:259)
expected: (= (quote (/ (+ (* -8 G pi (expt (R t) 2) (rho t)) (* -1 Lambda (expt c 2) (expt (R t) 2)) (* 3 (expt c 2) k) (* 3 (expt ((D R) t) 2))) (expt (R t) 2))) (simplify ((((Einstein-field-equation spacetime-sphere K) g (quote Lambda) T_ij) d:dt d:dt) ((point spacetime-sphere) (up (quote t) (quote r) (quote theta) (quote phi))))))
actual: java.lang.ClassCastException: sicmutils.operator.Operator cannot be cast to java.lang.Number
at clojure.lang.Numbers.gt (Numbers.java:259)
sicmutils.calculus.connection$metric__GT_Christoffel_2$metric__34234.invoke (form-init7336172232703900265.clj:69)
I guess the original intention here was to replace the call to f/memoize
with something like f/symmetric-memoize
, which does not compare the arguments, but instead tries to find either (x, y)
or (y, x)
?
This would be a clever way to exploit symmetry...
The question is, how much performance can we gain (by measuring, say, Einstein's Field Equations) by making the
f/memoize
call here return a function that will symmetrically memoize? https://github.com/sicmutils/sicmutils/blob/c05f21aca265acd34b67b13d9337ce389d160961/src/sicmutils/calculus/connection.cljc#L67This means that if I call the two-arg function with
x
y
ory
x
I will always get the same value, so I should check the cache for BOTH entries in each call to the memoized function.