-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update units context to include differentiation #1177
base: develop
Are you sure you want to change the base?
Conversation
…with absolute value
Overall, this looks great. I was testing the higher-order derivatives with the non-realistic function
and the result was 6x * 24y kg/(m ft^3) as expected. I was thinking that using |
@pstaabp Assuming implicit multiplication has higher precedence than explicit, I think that There is a relatively new reduction rule: Note that if implicit and explicit multiplication had the same precedence, then maybe you have: |
It doesn't. In fact, the MathQuill settings have implicit multiplication as lower precedence than explicit multiplication, if I recall correctly. The actual result from the differentiation is Also note that differentiation does a
You are right, the Number-with-Units object does not have a |
Note that MathQuill precedence is only used when parsing student answers. |
I seem to recall a discussion where we considered making this the precedence all the time. And one could certainly take derivatives of student answers, although I know that isn't what Peter was doing. In any case, I was only trying to say that Alex's assumption about the precedences wasn't true, and that it is more likely to be the other way around, if anything. |
It turns out that reducing formulas that return number-with-unit objects already works fine, and that the actual NumberWithUnit object doesn't need a |
I know, I was just pointing out that the MathQuill precedence wouldn't have had effect in @pstaabp's calls. |
I've pushed the changes requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good.
The new units context and the context extensions stuff in general is really awesome. So much new potential. Thanks so much for doing this.
There is one minor detail that seems to have been missed in previous pull requests. On line 171 of contextUnits.pl, C<limited => 1>
should be C<< limited => 1 >>
. I noticed that is not displayed correctly in the generated HTML for the POD.
Thanks! I had wanted to do a real units object since the very beginning (the old I agree, that this opens up a lot of new possibilities. I've made the POD change you requested. Thanks! |
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.