Created
December 31, 2020 13:30
-
-
Save sritchie/1ea590d72d142fc8402fc1e4a0e0a17f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define ((replace-differential-tag oldtag newtag) object) | |
(cond ((differential? object) | |
(terms->differential | |
(map (lambda (term) | |
(let ((terms (differential-tags term))) | |
(cond ((and (memv oldtag terms) | |
(memv newtag terms)) | |
(make-differential-term | |
(remove-differential-tag newtag (remove-differential-tag oldtag terms)) | |
:zero)) | |
((memv oldtag terms) | |
(make-differential-term | |
(insert-differential-tag newtag (remove-differential-tag oldtag terms)) | |
(differential-coefficient term))) | |
(else term)))) | |
(differential-term-list object)))) | |
((structure? object) | |
(s:map/r (replace-differential-tag oldtag newtag) object)) | |
((matrix? object) | |
((m:elementwise (replace-differential-tag oldtag newtag)) object)) | |
((quaternion? object) | |
(let ((r (replace-differential-tag oldtag newtag))) | |
(quaternion | |
(r (quaternion-ref object 0)) | |
(r (quaternion-ref object 1)) | |
(r (quaternion-ref object 2)) | |
(r (quaternion-ref object 3))))) | |
((series? object) | |
(make-series (g:arity object) | |
(map-stream (replace-differential-tag oldtag newtag) | |
(series->stream object)))) | |
((function? object) | |
((replace-dx-function newtag oldtag) object)) | |
((operator? object) | |
((replace-dx-operator newtag oldtag) object)) | |
(else object))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment