WeBWorK Problems

How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Jan Hlavacek -
Number of replies: 9
I have a problem where students are required to enter the exact value of square root of 3, that is sqrt(3), in the answer box. My problem is that when they preview or submit their answer, the "Entered" column shows 1.73205, which is not the exact value and it is not what they entered. I assumed that setting formatStudentAnswer to 'parsed' would take care of this, but it does not seem to work. I think this is important because in this course we stress the difference between an exact value and an approximation, and then WeBWorK seems to be telling them that there is no difference. This is what I tried:
loadMacros(↲                                                                                                                                       
    "PGstandard.pl",↲                                                                                                                                
    "PGML.pl",↲                                                                                                                                      
    "MathObjects.pl",↲                                                                                                                               
    "PGcourse.pl"↲                                                                                                                                   
  );↲                                                                                                                                                
  ↲                                                                                                                                                  
TEXT(beginproblem());↲                                                                                                                             
                                                                                                                                       
$a = list_random(2,3,5,6,7,8,10,11,12,13,14,15);↲                                                                                                  
  ↲                                                                                                                                                  
Context("Numeric");↲                                                                                                                               
  ↲                                                                                                                                                  
Context()->flags->set(↲                                                                                                                            
      formatStudentAnswers => 'parsed',↲                                                                                                             
      reduceConstants => 0,↲                                                                                                                         
      reduceConstantFunctions => 0,↲                                                                                                                 
      );↲                                                                                                                                            
↲                                                                                                                                                  
$sqrt1 = Formula("sqrt($a)");↲                                                                                                                     
↲                                                                                                                                                  
BEGIN_PGML↲                                                                                                                                        
Enter the exact value of [`[$sqrt1]`]: [__________]{$sqrt1}↲                                                                                       
END_PGML↲                                                                                                                                          
  ↲                                                                                                                                                  
ENDDOCUMENT();
In reply to Jan Hlavacek

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Danny Glin -
I'm not sure about changing the display of the "Entered" column, but there is another issue: there is nothing in your code preventing a student from entering a numerical answer.

Since you are using the default answer checker, it will accept any answer which is within the default tolerance numerically, so for sqrt(8), a student would be able to type 2.828, and it would be marked as correct.

I don't immediately see a good way to force students to type sqrt(8). You could tighten the tolerance so at least answers that were rounded to a few decimal places were marked wrong. Another approach would be to request the answer as a string, but I don't like this because it would require the student to type exactly what you have. For example, you would want any of "sqrt(8)", "sqrt 8", "2sqrt(2)", "2*sqrt(2)", "2sqrt 2", etc. to be marked right, but "2.828" to be marked wrong. Perhaps there is some way of doing this using MathObjects that I am not aware of.
In reply to Danny Glin

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Jan Hlavacek -

Sorry, my actual problem had

Parser::Number::NoDecimals();

but I forgot to include it in the minimal working example.

That takes care of entering the decimal approximation, but the "Entered" column still shows the approximation.

I would expect that the "Entered" column contains the exact text that the student entered.

In reply to Jan Hlavacek

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Michael Gage -
The answer preview column does show a typeset square root of 3. The entered column shows how WW has evaluated the students answer which is as 1.73205.
As Danny says if you type sqrt(3) to 5 decimal places WW will also evaluate it as correct.

There is a switch in the code (in the attemptsResult file) that allows you to hide the entered column completely. (You can still get the numerical result in the popover attached to the answer preview column). Last time I hid the Entered column to save space there was an overwhelming vote to bring it back. :-)

WW uses numerical comparisons for the most part. Algebraic reductions would require a CAS, lots of time and memory and even then it would not be reliable since algebraic "simplifications" in general have been proven to not be solvable.
In reply to Michael Gage

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Jan Hlavacek -

I think I misunderstood what the "Entered" column means. I expected it to show the exact text that the student entered. It must be available somewhere, because:

  1. The Parser::Number::NoDecimals checks that it is not a decimal

  2. The Preview column displays the square root, so it knows that a square root was entered.

It seems to me that the Formula flags reduceConstants and reduceConstantFunctions are not applied when parsing student answer, and so the parsed version is reduced. It would be helpful to have similar flags for the student answer, or have another value, e.g. "asis", for the formatStudentAnswer flag, that would use the student's answer verbatim.

In reply to Jan Hlavacek

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Jan Hlavacek -

I am digging into AnswerChecker.pm, trying to figure out where is the numerical value that appears in the "Entered" column calculated. I am not sure I am unraveling this right, but it seems that $ans->{student_formula}->TeX has the TeX version of the actual entered answer, while $ans->{student_formula}->string seems to have the evaluated numerical version.

Also, in cmpContextFlags, both reduceConstants and reduceConstantFunctions are set to 0, so I am now completely confused.

Is there some way how to disable the "Entered" column on per course basis? I found the showAttemptAnswers flag in AttemptsTable.pm, but I am not sure where to set it and if it is possible to set it for individual courses.

In reply to Jan Hlavacek

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Michael Gage -
It turns out there is a way to suppress the "Entered" column on a course by course basis. I'd forgotten that I'd created this option and it's actually pretty easy to change.

Go the Course Configuration page.
Click on the tab "PG- problem Display/Answer checking"
Change the value of "Display the evaluated student answer" to False.
Save the page

See if this achieves the required affect.

If you can have someone give you "admin" (higher than prof) permissions in your course you will have access to several other check boxes, in addition to "show correct answers", that reveal the data calculated by the answer evaluators. The "AnswerHashInfo" checkbox is probably the first one to use.


In reply to Jan Hlavacek

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Alex Jordan -
You could use contextLimitedRadical.pl, and activate Context("LimitedRadical"). If you ask for Formula("sqrt(3)") then it should do what you want.

This relies on bizarroArithmetic.pl, which changes the meaning of sqrt. IIRC, you have to make Formula objects, not Reals. So Compute("sqrt(3)") or Real("sqrt(3)") probably doesn't work.

Also, note that Formula("sqrt(8)") and Formula("2sqrt(2)") are not equal in this context.
In reply to Alex Jordan

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Jan Hlavacek -

Thank you! This does exactly what I need it to do, at least for radicals. I still think students in my remedial class will be confused when they enter something like 2^3 and WeBWorK will claim that they entered 8, but at least these are actually equal.

In reply to Jan Hlavacek

Re: How to show "sqrt(3)" in the Entered column when previewing or submiting answers?

by Davide Cervone -
Note that the flag name is formatStudentAnswer not formatStudentAnswers (singular not plural). If you set that to 'parsed', that should show the unevaluated student answer in the "Entered" column. You don't need to set the reduceConstants or reduceConstantFunctions flags unless you want to affect the correct answer, as these are set automatically during processing of student answers.