-
-
Notifications
You must be signed in to change notification settings - Fork 69
FDG chapter 9, fix manifold and field equation bug #384
Conversation
b418a94
to
13b3507
Compare
Codecov Report
@@ Coverage Diff @@
## master #384 +/- ##
==========================================
+ Coverage 84.60% 85.18% +0.58%
==========================================
Files 97 97
Lines 12887 12934 +47
Branches 692 694 +2
==========================================
+ Hits 10903 11018 +115
+ Misses 1292 1222 -70
- Partials 692 694 +2
Continue to review full report at Codecov.
|
(Here's my email describing the big bug and its fix. I was writing to GJS so translated everything to scheme and scmutils files.) Hey, moving to this thread... I managed to get my bug fixed! The upshot is:
Pretty quick! I'm sure this is benefitting from some memoization I added during investigation. That would be nice to talk about; it saves a bunch of duplicate calls, but I suspect that it is wiser to try and reduce the duplicate calls at the source. Let me know if you want to chat, or if you would like me to write up where I was able to save time. If you are curious what the solution was, the problem was quite subtle: In (up t r theta phi) in the COORDINATE-REPS mapping. The representation of the point "as it actually is on the manifold" is in rectangular 4D coordinates: (up t
(* r (sin theta) (cos phi))
(* r (sin theta) (sin phi))
(* r (cos theta))) In fact, if you ever try and use (up t
(sqrt (+ (expt (* r (sin theta) (cos phi)) 2)
(expt (* r (sin theta) (sin phi)) 2)
(expt (* r (cos theta)) 2)))
(acos (/ (* r (cos theta))
(sqrt (+ (expt (* r (sin theta) (cos phi)) 2)
(expt (* r (sin theta) (sin phi)) 2)
(expt (* r (cos theta)) 2)))))
(atan (* r (sin theta) (sin phi))
(* r (sin theta) (cos phi)))) But that does not matter (in scmutils) because MAKE-MANIFOLD-POINT stashes a mapping of spacetime-spherical => In my port, I (cleverly, I thought) removed almost all mutation, and changed SET-COORDINATE-PROTOTYPE! to WITH-COORDINATE-PROTOTYPE, which takes an immutable coordinate system and prototype and returns a NEW one. But this breaks the COORDINATE-REPS cache, since now my coordinate system does not match the old one. What does WITH-COORDINATE-PROTOTYPE have to do with Einstein's Field Equations?? Well, my tests were using my equivalent of USING-COORDINATES; but I structured my tests so there were TWO separate wrappings of USING-COORDINATES. Because of this, my field equations code was working with points that reported their spacetime-spherical coordinate representation as that crazy mess above, instead of a reasonable (up t r theta phi) The simplifier was not pleased. |
This PR ports all code listings from chapter 9 of FDG over to tests, and gets Einstein's Field Equations working! I had a super tough bugfix here. I sent GJS an email that I will paste in as a response to this PR. But IT ALL WORKS!!
From the CHANGELOG:
FDG chapter 9, fix manifold and field equation bug #384:
Adds
sicmutils.fdg.ch9-test
, with tests for all forms from FDG's 9thchapter.
Tests from
sicmutils.fdg.einstein-test
now all work, and quite fast. Thefunctions in this namespace comprise some of the exercises from FDG chapter
9. (Einstein's Field Equations hung until this PR... getting these working
is a huge achievement for me, and, in some sense, the final milestone of the
Big Port from scmutils.)
Adds
sicmutils.function/memoize
, a metadata-and-function-arity preservingversion of
clojure.core/memoize
.in
sicmutils.calculus.indexed
,with-argument-types
andwith-index-types
now both correctly set the arity of the returnedfunction, in addition to the argument types or indices.
sicmutils.function/arity
will now work correctly with indexed or typedfunctions.
Adds new
manifold?
andmanifold-family?
functions insicmutils.env
andsicmutils.calculus.manifold
. These are enabled by new:type :sicmutils.calculus.manifold/{manifold,manifold-family}
keys in theappropriate structures in the manifold namespace. Manifolds and manifold
families will now respond with these keywords to
sicmutils.value/kind
.The
sicmutils.calculus.manifold/ICoordinateSystem
now has auuid
function, for internal comparison of coordinate systems. This is here so
that points can cache coordinate system representations by UUID. Before this
change, changing the coordinate prototype, or attaching metadata to a
coordinate system would break its cache entry in manifold points. (This was
the killer for the Einstein Field Equations!)
sicmutils.calculus.manifold/{coordinate-prototype,with-coordinate-prototype}
now store and retrieve the coordinate prototype from metadata. This plus
the previous change allows manifold points to correctly cache their
coordinate representations.
sicmutils.calculus.manifold/manifold
acts as identity on manifolds now.Previously it only worked on coordinate systems.