-
-
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
Add new contextUnits.pl implementing units as true MathObject classes #1107
base: develop
Are you sure you want to change the base?
Conversation
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.
There are a couple of typos and POD issues noted.
This looks good, and will be a nice MathObject addition.
I did note one issue in testing that is related to issue #1092. If you use the Units
context in a List
it works nicely. However, if you use the LimitedUnits
context with a List
it does not. If Compute("3 deg, 4 deg")
is called, the error "Can't use ',' in this context" is thrown. You can force it to work for creating the answer by calling List("3 deg", "4 deg")
, but then if a student enters the answer "3 deg, 4 deg" the student gets the above error message. Perhaps there is some way to accomplish this using the contextExtension.pl
macro? Although, it would be nice to not need additional steps for this.
Yes, that is because the One would be to leave it as is and document the fact that $context->operators->redefine(','); will make the comma available again. Alternatively, this could be added to the Which route do you all think should be taken? |
I've fixed the typos you identified. Thanks! |
I should have thought of that. I think you mentioned that before somewhere in a related setting. It works for me to add |
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.
Thanks for fixing the typos and pod issues, and thanks for this pull request to begin with!
I've updated this PR to include the changes to |
@dpvc Just tried one of your examples from the POD:
I got the error
I think this is because of the second squared in the bottom. I had set the context to:
BTW, the shorthand |
Sometimes there is a question where the answer is like
I'm just thinking openly and not requesting these things. I'm interested in your assessment of how the structure you have here already could support these things, or if it would involve more. |
Argh. This was due to a last-minute reorganization of the initialization of the context, and it caused the |
It wasn't but is now with the latest commit.
You could add it using Context("Units")->withUnitsFor("time")->addUnits("%" => {factor => .01, "%" => 1}); for example. Then you could do I don't think using Context(context::Units::extending("Percent")->withUnitsFor("time")); would allow You are right that you can't do just |
@dpvc The latest commit fixed my other errors. Also testing your other example in the POD
isn't working for me. It all makes sense to me, but not getting the expected results. |
There was a typo in a variable name (when removing the |
Trying to test this out and running into some issues. First seems the category velocity isn't working directly.
This gives me the error that Also in the TeX output, should units be wrapped in a Last, is there a way to add all units to a problem, for if I write a problem and don't add all possible units I think a student might input as an answer, students who enter in units I didn't add to the context get the message, "foo is not defined in this context", which I don't think is that useful for students. Though having an message like "Answer is dimensionally incorrect" that could be toggled via some |
Just to clarify my previous comment about MathQuill, it works just fine with units, I'm mostly talking about the formatting of units in the answer. Should they be italicized variables or not, and unsure if entering 'm/s' should show a slash, vs turn that into a fraction in the answer. |
Also regarding TeX output, further testing seems to suggest that some times units are wrapped in |
All the units already should be in
I can't reproduce that; the TeX output is
It is actually doing what it is supposed to, as the various categories add the named units for that category, not all possible ways of obtaining compound units for that category. You are right that Context("Units")->withUnitsFor("velocity", "length", "time");
$v = Compute("5 m/s"); It would be possible to define the velocity => [{m => 1, s => -1}, {m => 1}, {s => 1}] to get length and time as well, or to have Context("Units")->withUnitsFor("length", "volume"); so that you could do it is possible that the category idea needs better handling. If there are other ideas about how to specify the units to be included, that would be worth a discussion.
You could do Context("Units")->addUnitsNotAliases(keys %context::Units::Context::UNITS); but I would not recommend it. One reason is that there are a number of single-letter units (
Yes, that is correct, just as they would if they typed in some other letter that is not defined in the context. There is no way for the MathObject parser to know that the student might have been thinking about a unit rather than a function or variable or some other thing when it sees a letter that it doesn't have a definition for. I'm not sure how this could be handled better.
Perhaps in the Note that you do get a message about units being wrong if you enter units (that are defined) but are not correct, in case that is a help. |
I did find a typo in the definition for the temperature category, and pushed a commit to fix it. |
With some more testing, I find that this is due to processing with inputted answers, as I was looking at the student preview answer TeX when typing answers into the answer box. If I do |
This makes sense, as I was considering a case where I just wanted a numerical answer with correct units, and didn't want to give students hints as to what the units might be, so I thought having a quick way to add all units would be nice.
Yes, the case I was thinking of would be best done with some LimitedUnits context where I'm not expecting variables but want to be able to control if or if not hints are given to students who enter in dimensionally incorrect units. |
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.
Spell checking...
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
@somiaj, I'm pretty sure it is, but I don't have an installation running MathQuill to try it out. I'm not able to reproduce the problem without it, but don't have any idea why it would be producing this result. Does the MathQuill code set the |
This seems to be caused by the different precedence that is used when MathQuill is enabled. When MathQuill is enabled, then the precedence of the ' *' operator is 2.9 instead of 3. |
This PR adds the file
contextUnits.pl
to themacros/contexts
directory. It implements units as true MathObject classes, so that you can use units and numbers with units as you would any other MathObject. With this context, you can dorather than having to use
NumberWithUnit()
to create them.It also means you can do things like
or even
Since units are now MathObjects, even without a number, you can use
and ask a student what are the units for accelleration, without the need for a number in front of the units.
The
contextUnits.pl
file is based on thecontextExtensions.pl
framework for extending a context to include new features. That means you can add units to existing contexts. For example, you could add units to theMatrix
context to allow the entries of a matrix to have units.See the POD documentation at the top of the file for more details about how to use the Units contexts.
Note that the
contextExtension.pl
is included in this PR, even though I made a separate PR for that file. Because the branch for that PR isn't in the PG repository, I can't target this PR to that one. If that PR is merged, thecontextExtensions.pl
file should disappear from this PR.