Skip to content
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

Using upToConstant with complex numbers #1013

Open
mikeshulman opened this issue Feb 13, 2024 · 4 comments
Open

Using upToConstant with complex numbers #1013

mikeshulman opened this issue Feb 13, 2024 · 4 comments

Comments

@mikeshulman
Copy link
Contributor

In Complex context, it appears that upToConstant still thinks that all constants are real. If the correct answer is 2xy and is checked upToConstant, then 2xy+1 is marked correct, but 2xy+i is marked incorrect.

@Alex-Jordan
Copy link
Contributor

I looked into this a little. The upToConstant checker option inserts an adaptive parameter. So the real issue is whether adaptive parameters handle complex numbers, and according to this comment, they don't:

# to the ORIGINAL correct answer. (This will have to be

I didn't keep thinking about it more though. Maybe they can be elevated to support complex contexts.

I'm not sure what your immediate needs are, but a custom checker could take the student answer and subtract 2xy, then see if both derivatives (wrt x, y) agree with the zero function. Not as nice as with upToConstant, and also might come with more gotchas. But it's what I would do.

@mikeshulman
Copy link
Contributor Author

As it turns out, I realized after submitting the bug report that I didn't actually need it right now. But it is still surprising that upToConstant doesn't allow complex constants.

@dpvc
Copy link
Member

dpvc commented Apr 11, 2024

As Alex points out, the upToConstant option currently uses adaptive parameters to handle the constant, and those are limited to real numbers. I've never been all that happy with the adaptive parameter setup, but that's how the original WeBWorK answer checkers worked before MathObjects, and when I developed MathObjects, I included the options available in the legacy answer checkers. The FormulaUpToConstant object was intended to be the better way to do this using MathObjects.

Unfortunately, FormulaUpToConstant also uses adaptive parameters, so has the same limitation. I have written a new version of parserFormulaUpToConstant.pl, attached below as parserFormulaUpToConstant2.pl, that uses a different method to compare the formulas. This works for complex as well as real-valued formulas, and works with multi-variable formulas, and even vector-valued formulas as well. There are some caveats, so do look at the POD documentation for details.

Note that the traditional FormulaUpToConstant object requires the student to explicitly give a +C (or whatever constant they choose), whereas the upToConstant option does not. This new FormulaUpToConstant() allows you to set a requireConstant => 0 on the cmp() method (or in the context flags) that determines whether the student must include +C or not (it is always allowed, but may or may not be required). So this can be used in the situation you had for upToConstant if you don't want to force the +C in the student answer.

parserFormulaUpToConstant2.pl.zip

@mikeshulman
Copy link
Contributor Author

Thanks! I didn't get a chance to try this out this semester, but I will the next time I teach complex. Do you plan to incorporate this into the main webwork distribution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants