Update units context to include differentiation #1177
+238
−62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main purpose of this PR is to add the ability to differentiate formulas with units.
I also made a pass over the documentation, and corrected some errors, moved the section on removing units from a context to earlier (right after adding them), and added a section on the new differentiation features.
In the past, the$d\over dx^2 dy^3$ , and is equivalent to
D()
method provided for multiple derivatives likeD(2)
orD(2, "x")
, but only allowed one to be specified. I have extended theD()
method to allow more than one numeric repeat operation, so$f->D(2, "x", 3, "y")
would be$f->D("x", "x", "y", "y", "y")
or$f->D(2, "x")->D(3, "y")
. This should not affect existing problems, as it is an extension of the syntax, not a change.While working on this, I noticed that I had handled
abs()
for arguments that are numbers with units, but didn't handle the|...|
syntax for that. So I've added that here. That also required adding another option to thecontextExtensions.pl
extension mechanism to override the list classes (|...|
are handled using the list delimiters infrastructure).Finally, I fixed an error with
abs()
with number-with-units arguments where formula comparisons would fail (the type was not being set properly), simplified the evaluation of trig functions with angle units by removing unneeded tests that are already made in the_check()
function, and added aquantity
method to the Formula-with-Units class to match the one in the Number-with-Units class.