WeBWorK Problems

Scientific notation and Math Quill

Scientific notation and Math Quill

by Robin Cruz -
Number of replies: 30

I am trying out using Math Quill for entering answers this semester for the first time.  Our problems involving the contextScientificNotation.pl are giving errors. I'm including a picture of the error and the problem code at the end of this note.  Perhaps I'm just not using Math Quill correctly? I typed the answer in with the small x for the times.

--rac

webwork error message

-------Problem code---------

DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(

  "PGstandard.pl",

  "MathObjects.pl",

  "PGchoicemacros.pl",

  "contextScientificNotation.pl",

  "contextLimitedNumeric.pl"

);


TEXT(beginproblem());


######################################

#  Setup


$num0 = random(1.1,9,0.001);

$exp0 = random(2,4,1);

$num[0] = $num0 * 10**$exp0;


$num1 = random(1.1,9,0.001);

$exp1 = random(-3,-1,1);

$num[1] = $num1 * 10**$exp1;


$num2 = random(-9.5,-1.5,0.001);

$exp2 = random(2,4,1);

$num[2] = $num2 * 10**$exp2;


$num3 = random(-9.5,-1.5,0.001);

$exp3 = 0;

$num[3] = $num3 * 10**$exp3;


Context("LimitedNumeric");

$dec[0] = Compute("$num[0]")->reduce;

$dec[1] = Compute("$num[1]")->reduce;

$dec[2] = Compute("$num[2]")->reduce;

$dec[3] = Compute("$num[3]")->reduce;


Context("ScientificNotation");

$sn[0] = ScientificNotation($num[0]);

$sn[1] = ScientificNotation($num[1]);

$sn[2] = ScientificNotation($num[2]);

$sn[3] = ScientificNotation($num[3]);


($a,$b) = NchooseK(4,2);


######################################

#  Main text


Context()->texStrings;

BEGIN_TEXT

Convert:

$PAR

a) Write in decimal form: \( $sn[$a] \) =  \{ ans_rule(10) \}

$PAR

b) Write in scientific notation: \( $dec[$b]\) =  \{ ans_rule(10) \}

END_TEXT

Context()->normalStrings;


######################################

#  Answers


$ans_a = $dec[$a];

ANS($ans_a->cmp);

$ans_b = $sn[$b];

ANS($ans_b->cmp);


$showPartialCorrectAnswers = 1;


######################################

# Solutions


Context()->texStrings;

BEGIN_SOLUTION

$PAR Solution: $BR $BR

a) Write in decimal form: \( $sn[$a] \)\( $dec[$a] \) 

$PAR

b) Write in scientific notation: \( $dec[$b]\)\( $sn[$b] \) 

$BR

END_SOLUTION

Context()->normalStrings;


ENDDOCUMENT();   

In reply to Robin Cruz

Re: Scientific notation and Math Quill

by Glenn Rice -

You are using MathQuill correctly.  Unfortunately, you have found another case where MathQuill doesn't quite work right.  MathQuill adds the parentheses around the exponent that you are seeing in the answer.  This is needed for answers where the exponent involves more than a single number.  Unfortunately MathQuill is not a mathematical parser.  So it can't tell the difference between an exponent of "5x+3" or "3".  So adding the parentheses is pretty much an all or nothing thing.  Originally we had it set not to add the parentheses for a single digit exponent (that much can be checked at least), but even in that case there are times when the parentheses are needed to have WeBWorK correctly interpret the answer as it is displayed in the "display math" format of MathQuill to the student.  Furthermore, that wouldn't fix the problem in this case.   It would still add the parenthesis for something like 5x10^-5.

I have been trying to find a way for contexts (like the scientific notation one you are using) to change the way that MathQuill behaves for answers in that context.  So for example, the scientific notation context would add a flag to the context that would disable the addition of the parentheses around the exponent.  Unfortunately, I haven't had much time to work on it recently.


In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Robin Cruz -

Glenn,

Thanks for the quick reply.  I think our best bet is to turn off Math Quill for now.  I found several other situations in our problem sets that are causing similar errors.  Too bad. I liked the way it displayed the answers.

Thanks again for the information--rac

In reply to Robin Cruz

Re: Scientific notation and Math Quill

by Glenn Rice -
I have to add that I think it is wrong that the scientific notation context does not allow parenthesis around the exponent.

One thing that you could do is add:

Context()->parens->add('(' => {close => ')', type => 'Real', removable => 1});

to the problem after you switch to the ScientificNotation context.  This will add parenthesis back to the context, and then the MathQuill answer will work.

That is if you don't have to many problems, so that it isn't to much work.

What other situations in your problem sets are causing errors?
In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Sean Fitzpatrick -

This would be a very imperfect workaround, but would scientific notation work if you use the MathQuill text mode? I know that's the only way my students were able to enter units.

The problem is that even if it works you'd have to communicate instructions to all students (and have them read/remember those instructions). 

In reply to Sean Fitzpatrick

Re: Scientific notation and Math Quill

by Glenn Rice -

Using the MathQuill text mode should always work as a fall back.  Nothing is added in text mode.  Of course nothing is displayed in the nice "display math" type way in text mode either.  Using text mode basically turns the MathQuill input box into a standard html input box.

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Alex Jordan -

Is it possible to put something in course config that essentially says:

if the problem set is this one particular problem set
then change $pg{specialPGEnvironmentVars}{entryAssist} to something else

?

I played around with this, but at the level of course.conf, I can't work out if it's possible to access the problem set's name. Later on, it would be $envir{setNumber}. But while a config file is being loaded, %envir does not yet exist. And maybe while a config file is being loaded, there is not yet any problem set information anywhere. But if it is somewhere in a hash that can be accessed, then this would be a hack to turn off MathQuill for individual problem sets. (And then you'd need to be careful that simple.conf doesn't override course.conf.)




In reply to Alex Jordan

Re: Scientific notation and Math Quill

by Ping-Shun Chan -
I love the MathQuill feature, but I think it might be useful to be able to override the MathQuill option for individual answer banks within a single multianswer problem.

Might it be possible to adjust the ans_rule routine so that it can accept optional arguments, e.g. "exemptFromMathQuill".  I noticed that ans_rule in the PG library is basically a wrapper for NAMED_ANS_RULE, which does accept an %options argument.

Could MathQuill then be made to skip touching those answer banks which has the attribute " aria-label = 'excemptFromMathQuill' " (or maybe some other attribute name can be used) in the corresponding <input> tag?
In reply to Ping-Shun Chan

Re: Scientific notation and Math Quill

by Glenn Rice -
I have a patch that can turn off MathQuill for an answer group, but I have not found a way to do so for individual answer rules within a MultiAnswer. You wouldn't use the aria-label for this though.
In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Ping-Shun Chan -
At least for an ans_rule, a cheap hack that apparently works is to edit NAMED_ANS_RULE in PGbasicmacros.pl in the PG library to accept an "mq_exempt" argument (just like how it is coded to accept an "aria_label" argument), and also add an %options argument to sub ans_rule. Then, edit mqeditor.js so that one forcibly *unhides* each input element which has an 'mq-exempt' attribute that is set to 'true'.

mathquill mixed mode
In reply to Ping-Shun Chan

Re: Scientific notation and Math Quill

by Nathan Wallach -

I like Ping-Shun's suggestion of expanding the use of an options hash as used by NAMED_ANS_RULE, and making more things (like ans_rule()) accept it and pass it on. That would also seem to make it more practical to provide customized aria-label values, and potentially strings for hidden HTML labels. 

For the purpose of disabling MQ for a specific element - would it be suitable to allow adding additional class names (in addition to the standard codeshard)  to input elements, and have the MQ code avoid replacing input boxes which also have the class "bypassMQ" or whatever we choose to call it?

See:  https://webwork.maa.org/moodle/mod/forum/discuss.php?d=4694  and https://github.com/openwebwork/pg/issues/444 for related discussions.

In reply to Nathan Wallach

Re: Scientific notation and Math Quill

by Glenn Rice -

This approach does have some problems though.  One is that you would need to ensure that all of the different ans_rule methods deal with the options, and do so consistently.  Another is to make sure that PGML is set to pass these options to the ans_rule methods when it calls them.

On another note, I think that this particular thread has been derailed.  I don't think the issue this thread was started about is really one that MathQuill needs to fixed for.  Rather the scientific notation context should be fixed.  There is no real need to disable parentheses in that context.  There is no reason why -2.716x10^(0) should be not allowed regardless of if it came from MathQuill or if a student typed that directly into the input box.  In fact for negative exponents it looks better to add the parentheses. 5x10^(-5) looks better to me than 5x10^-5.

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Ping-Shun Chan -

Dear All,

Thank you very much for the thoughtful and detailed discussion. I have learned a lot reading all your comments. There are legitimate concerns which I had not even thought of (like the idea of "future proof" mentioned by Alex). From the Github thread mentioned by Nathan, it appears a lot of the relevant issues have already been discussed in great depth early last year. If I have any more suggestions (mainly in my capacity as a webwork user/instructor) in this context, I will perhaps start a new thread under "New Features and Development Ideas".  Thank you very much!

Best regards,
Ping-Shun

In reply to Alex Jordan

Re: Scientific notation and Math Quill

by Glenn Rice -

Yeah, I am not sure if you would have access to what is needed in course.conf to accomplish this.

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Nathan Wallach -

There was a discussion of providing the need for an ability to turn off MathQuill at the problem level or the level of specific input elements back in the discussion thread at https://github.com/openwebwork/webwork2/pull/920 .

I still think that a problem author should have some capability to disable MathQuill to some extent for entire problems  /or specific answer blanks (groups?).

Several participants (including me) felt that providing local overrides to MQ is probably most feasibly done at the PG level. Alex Jordan had proposed that this somehow be handled at the problem configuration level in webwork2 and not at the PG level.

I think that we are rediscovering the need to provide some feature for this so that use of specific problems which do not work well with MQ do not require turning it off course-wide or forcing students to do something special. 

contextScientificNotation.pl might be a case where the context itself could by default disable MQ for its input box. Davide has written "Using the context to send hints to MQ about the editing might be possible, but would take some work.".

In reply to Nathan Wallach

Re: Scientific notation and Math Quill

by Alex Jordan -

> Alex Jordan had proposed that this somehow be handled at the problem configuration level in webwork2 and not at the PG level.

I'm not sure that's what I meant to say. I generally object to these things at the .pg problem file level, but not at the PG level (which also includes macro libraries and larger PG modules). For instance, if a MathObjects context held information about which MathObjects were safe for something like MathQuill, that could go into an answer blank attribute that MQ could look for. That's a bit of a mash between PG and webwork2.

My attitude towards problem files is they should be future proof. Coding in stuff that specifically address MQ usage does not feel future proof. For example maybe MQ will evolve to become smarter and there is no need to turn it off in these cases. Or maybe MQ becomes obsolete and something else replaces it. These things can happen and you have derelict code in the .pg file.

You might be thinking of another rant I make occasionally, that configuration of problem instances in a particular problem set would be a good thing. And not unprecedented, looking at other online homework systems. That's an abstract approach that could control MathQuill too, but in this case I lean toward something that automates it all using MathObjects, as Davide mentioned.

This is one of the higher level items on my WW wish list. I can't make promises, but I will probably take a stab at it in the coming year. I'm on sabbatical until late March, so I may get some things done.

In reply to Alex Jordan

Re: Scientific notation and Math Quill

by Bianca Sosnovski -

I don't know if anyone brought up a similar issue in evaluating answers that  are rational expression entered with MathQuill. 

Issue with MathQuill


Text mode in MQ

After some of my colleagues contacted me about the issue, I changed the default for assistive tool for helping students to enter their answer to WIRIS.

Both WIRIS and MathView don't present any issue with answers with expressions with exponents and rational expressions.


In reply to Bianca Sosnovski

Re: Scientific notation and Math Quill

by Glenn Rice -

I use MathQuill for all of my classes.  I have never seen that problem.

I suspect there is an issue with that problem that is causing this and not MathQuill, based on the errors that are being displayed, i.e., "the evaluated answer is not an answer hash".  Could you post the PG source for that problem?

Just out of curiosity, what happens if you type in "(3/(x-3))", either in text mode in MathQuill, or directly into a text box?

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Bianca Sosnovski -
Hi Glenn,

Here is the result when I type in "(3/(x-3))" in text mode:

Extra parenthesis in text mode.

The PG code is for this problem is below. We have a bunch of problems with similar PG code that has the same issue when using MathQuill.
---------------------------------------------------------

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "CofIdaho_macros.pl",
  "PGcourse.pl"
);

TEXT(beginproblem());

######################################
#  Setup
#  Form: a(x+b)/(x+b)(x+c)

$a= random(2,5,1);
$b= non_zero_random(-5,5,1);
$c = non_zero_random(-7,7,1);

$f = Formula("($a x + $a*$b)/(x^2 + ($b + $c)x + $b*$c)")->reduce->TeX;

######################################
#  Main text

BEGIN_TEXT
Simplify the rational expression.  
\[$f\]
Answer:  \{ ans_rule(30) \} 

$PAR
  ${BBOLD}Need Help?${EBOLD} 
  \{ htmlLink( "https://youtu.be/tJiz5rEktBs?t=2m23s", "Click the link to see a video example.", "TARGET='_blank'" ) \}
$BR
$PAR

END_TEXT

######################################
#  Answer

$answer = "$a/(x+$c)";
ANS(RationalExpEvaluator($answer,"x")); 

$showPartialCorrectAnswers = 1;

######################################


;
ENDDOCUMENT();
In reply to Bianca Sosnovski

Re: Scientific notation and Math Quill

by Bianca Sosnovski -
The other type of problems that don't accept the correct answer with Math Quill is the ones with exponents in factoring problems.
Here is an example:

with exponents

And here is the PG code:

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "CofIdaho_macros.pl"
);

TEXT(beginproblem());

######################################
#  Setup

@alphabet = ("a","b","s","t","x","y");
$n = random(0,4,2);
$var1 = $alphabet[$n];
$var2 = $alphabet[1+$n];
Context()->variables->are($var1=>'Real',$var2=>'Real');

$a= random(2,5,1);
do {$b= random(2,5,1);} until (gcd($a,$b)==1);
$c = random(3,9,1);
$m = random(2,7,1);

$poly = Formula("$a*$m $var1^2 $var2^4 + $b*$m $var1 $var2 - $c*$m $var1")->TeX;

######################################
#  Main text

BEGIN_TEXT
Factor out the greatest common factor: 
$PAR
\( $poly = \)  \{ ans_rule(30) \} 
END_TEXT

######################################
#  Answer

$answer = "$m * $var1 * ($a * $var1 * $var2^4 + $b * $var2 - $c )";
ANS(FactoringEvaluator($answer,[$var1,$var2])); 

$showPartialCorrectAnswers = 1;

######################################


COMMENT('MathObject version');
ENDDOCUMENT();
In reply to Bianca Sosnovski

Re: Scientific notation and Math Quill

by Glenn Rice -

So you have confirmed that this has nothing to do with MathQuill.  The problem is the incorrect design of these problems.  The pedagogy is completely incorrect.  An instructor should absolutely never count an answer incorrect for additional parentheses.  In fact, the usage of additional parenthesis should be encouraged.

The reason that this is happening is because MathQuill adds extra parenthesis to maintain correctness in order of operations as the answer is visually displayed when the student types the answer into the MathQuill answer box.  Those additional parentheses are mathematically correct, just as additional parentheses are when a student uses them.

When a student types 3/(x-3) as a vertical fraction (without typing any parentheses), then MathQuill passes the answer (3/(x-3)) to webwork.  In this case those additional parentheses are not needed, but MathQuill is not a mathematical program.  It doesn't know if there are other things typed before or after that might make those parentheses be necessary.  The answer is still mathematically correct, and no grader should count off for that.

The same thing is happening in this problem as well.  MathQuill is adding parentheses around the exponents to maintain correctness in that case as well.  You can see this in the "Entered" column of the results table.  WeBWorK removes most of these extra parentheses when it parses answers and this is why it shows up without those parentheses in the "Preview" column.  Without those parentheses there would be no difference between the answers x to the power of 23 and x to the power of 2 times 3 (for one example).  Both cases would be sent to webwork as x^23.  Again the answer is mathematically correct, and should not be counted off for even if this were what the student had entered in a text input (without MathQuill).

The problem comes down to lines 417 - 432 of the file CollegeOfIdaho/CofIdaho_macros.pl from the OPL that this file is using.  Those lines should not be in that file.  Those lines check for extra parentheses and count off for it.  Bad!

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Bianca Sosnovski -
Hi Glenn,

Thank you so much to take a look at the issue.

Our College Algebra Template course has a lot of problems that use that macro. These problems are from the OPL and a colleague of mine modified the PG code to include links to explanation for each problem.

I will adjust the code of these problems in our template to exclude the use of the macro because we would like to continue using MathQuill and not have so many students complaining about it.

Meanwhile, I changed the default in the system to MathView since WIRIS requires students to use a separate pop up window to enter their answers and we are concern that may be blocked by settings in the students' web browsers. Unfortunately, WIRIS also seems not show to the students the last recorded answer in the system.

Thank you so much for your time in looking at the issue.
In reply to Bianca Sosnovski

Re: Scientific notation and Math Quill

by Alex Jordan -

First, my apologies for not reading the full thread here. I hope what I am posting is relevant.

If you have problems that want basic algebra expressions in "simplified", "factored", "expanded" form, etc., try using contextFrom.pl (which is in the OPL, in the PCC macros folder). For example, here is a minimal problem file. Then two screenshots with MathQuill in use. One with correct answers accepted, and one showing what happens if the form is not right. The context is flexible in certain senses, like (x+1)(x+2) is counted equivalent to (2+x)(x+1), etc. But it catches the things that math teachers are trying to catch.

If this works for you, it /might/ be as easy as visiting each problem, loading contextForm.pl, and activating Context("Form") immediately prior to the declaration of the answer formula.


DOCUMENT();
loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "PGML.pl",
  "contextForm.pl",
  "PGcourse.pl",
);
##############################################
Context("Form");
$display = Formula("(3x+9)/(x^2-9)");
$answer = Formula("3/(x-3)");
$display2 = Formula("x^2+3x+2");
$answer2 = Formula("(x+2)(x+1)");
##############################################
TEXT(beginproblem());
BEGIN_PGML
a. Simplify [` [$display] `].
   [_]{$answer}{20}

a. Factor [` [$display2] `].
   [_]{$answer2}{20}
END_PGML
##############################################
ENDDOCUMENT();




demonstrating correct is accepted



demonstrating incorrect is not accepted
In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Andras Balogh -

Hi Glenn,

This was an old and very long thread and I might have missed something. I don't understand why it is alright to prohibit extra parentheses in scientific notations. For me MathQuill is not doing anything wrong neither in the CofIdaho_macros case nor in the contextScientificNotation case.


In reply to Andras Balogh

Re: Scientific notation and Math Quill

by Glenn Rice -

I am not sure what you mean by "it is alright to prohibit extra parentheses in scientific notation".  Can you clarify?

With the scientific notation context, if you enter 5x10^(-3) it will be counted wrong, even if that is correct.  That is assuming that you are not using MathQuill. If you are using MathQuill it adds the parentheses, and so is graded as incorrect.

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Andras Balogh -

Why is it counted incorrect to enter 5x10^(-3) in the scientific notation context ?

In reply to Andras Balogh

Re: Scientific notation and Math Quill

by Glenn Rice -

I suppose this is a very long thread.  Read the post by Robin that started the whole thing.  The contextScientificNotation.pl macro removes "parens" from the context, making it so that entering such an answer will be counted correct and give the message "'(' is not allowed in scientific notation".

In reply to Glenn Rice

Re: Scientific notation and Math Quill

by Andras Balogh -

I think you meant that the answer will be counted INCORRECT.

Shouldn't it be counted correct? I want to encourage students to use parentheses, not discourage them.

In reply to Andras Balogh

Re: Scientific notation and Math Quill

by Glenn Rice -

Yeah, I meant incorrect.

I agree that this should be counted correct.  I also want to encourage the correct usage of parenthesis.

Note that you can add:

    Context()->parens->add('(' => {close => ')', type => 'Real', removable => 1});

to the problem to allow parenthesis again.  Add this line in the problem after the call to Context("ScientificNotation").

See https://webwork.maa.org/moodle/mod/forum/discuss.php?d=4877#p14643 earlier in this thread.