WeBWorK Problems

Evaluate Multiline, Full Solution

Evaluate Multiline, Full Solution

by Chris Pinto -
Number of replies: 6

I teach high school science, and use WebWork extensively for Chemistry and Physics problems. My students have found it to be a valuable resource, but I would like to take it one step further. Currently, only a final answer is evaluated, but students in high school need to develop a good procedure for approaching problems that I would like to setup WebWork to evaluate (i.e. Givens, Unknowns, Formula, Substitution, and a Solution).


For instance, take a typical problem I might ask: 

How much current passes through a $R ohm resistor that has a $V V potential difference across it?


Typical WebWork solution:
DOCUMENT();
...
  $R = random(50,1000,10);
  $V= random(2,10,0.1);
  $I= NumberWithUnits("$V/$R", "amp");
...
BEGIN_TEXT
How much current passes through a $R ohm resistor that has a $V V potential difference across it?
END_TEXT
ANS( $I->cmp() );
ENDDOCUMENT();

On paper, I would have my students answer as follows:

R = 220 ohm
V = 5 V
I = ?
I = V/R
I = 5/220
I = 0.023 A

I would like to setup a multi-line response where they can enter that online and have it evaluated by the system (I don't foresee an issue doing most of the programming myself, but I would appreciate any guidance in how to approach the problem). I had the following in mind:


  1. All variables used in a response must be defined/declared before use (the givens/unknown) - to me, this is basically a list - type answer. I would like to make it more flexible over time, but initially, I know how many lines should be givens/unknowns, and can simply split on the line break (and somehow evaluate lines 1 to 3 as a list). I want them to use specific variables - e.g. I for current, not allow them to make up their own variables.
  2. check the equation - I can use ImplicitEquation for this
  3. check the substitution - I don't need units here (but would like to accept them), I don't want a mathematically equivalent answer to be valid (i.e. I want the actual substitution in the right order, not the final answer)
  4. final answer - I can use the normal answer evaluator for this
If done as 4 separate inputs, I don't see the above as being too difficult to evaluate. I would, however, like to do it as one input (basically to make it more 'realistic' with less prompting).

Problems:

  1. Parsing - I have seen some references to multiline problems on the forums where the parsing creates an array. I don't think I would have too much difficulty with this.
  2. Passing to the correct evaluator - I think I would start with 4 inputs initially, and then try to move to one input. The issue I would have is that I want to allow a little flexibility in the number of lines. Which somewhat implies determining what type of response is on each line if everything is in one input. For example, to account for the following: 
    1. some students might miss a step - I would like to be able to identify which step is missed and not just mark the entire problem incorrect. e.g. the following should say something like 'variables V and R used without being defined' (like a programming language)

      I = V/R
      I = 5/220
      I = 0.023 A

    2. some students might do some steps in multiple lines (especially a formula/substitution step) - e.g. someone might write:

      R = 220 ohm
      V = 5 V
      I = ?
      V = I*R
      I = V/R
      I = 5/220
      I = 0.023 A

      OR

      R = 220 ohm
      V = 5 V
      I = ?
      V = I*R
      5 = I*220
      5/220 = I
      I = 0.023 A

  3. The equation like structure is something I haven't used WebWork to grade previously (e.g. a normal answer would be 0.023A, not I = 0.023A) - but I don't expect this is that difficult to resolve.

I don't think it is an easy problem - or that it has an easy solution - but it is one I would like to work on over the next few months, and any advice on tackling it would be much appreciated.

In reply to Chris Pinto

Re: Evaluate Multiline, Full Solution

by Alex Jordan -
I have some comments that might help.
  • If the equations you are looking for are all like I=V/R, in that the left side will always consist of one variable, I would recommend looking at parserAssignment.pl rather than using an ImplicitEquation. ImplicitEquations require lots of care, especially (in my experience) if division is part of the equation.

  • We have developed a macro file we call bizarroDivision.pl (with lots of help from David Cervone) which may help with your desire to have "I=5/220".

    First, let's just talk about "5/220". With bizarroDivision, the student's answer for"5/220" would first be checked as a Math Object Formula. If it doesn't even match that, some kind of appropriate feedback can be sent to the student. If it does, the checker moves on.

    At this point, the checker changes the meaning of whichever of the arithmetic symbols +, -, *, /, and ^ you would like it to change. It changes them in a way so that if you changed them all, you have a system where all the rules of arithmetic still hold. But these bizarro arithmetic symbols do different things than the usual symbols do. So the correct answer can be "5/220", but under bizarro division, that evaluates to a different decimal than 0.0227... In this way the checker detects if the form of the expression is the same as what the problem author used.

    bizarroDivision.pl is attached. It's not perfect. One issue we have noticed has to do with test points. Domains of functions can be different under the two arithmetic systems, so attempts to control the test points for one system can sometimes cause trouble with the answer checking in the other system. To use bizarroArithmetic, read the commented documentation.

  • To move on to "I=5/220" is possible, but complicated. It involves using parserAssignment.pl and sort of splicing it with bizarroArithmetic. You would break down the Formula object "I=5/220" into its left and right parts, and then customize a bizarroArithmetic checker on the right part after doing the usual check on the left part.

Units is a whole different issue though, and this approach and the current Units module are not well-suited to each other.

In reply to Alex Jordan

Re: Evaluate Multiline, Full Solution

by Chris Pinto -
Firstly thank you for the quick and detailed response.
The equations do get a bit more complex than I = V / R.For instance:
  • 1/f = 1 / do + 1 / di 
  • n1 sin(i) = n2 sin(R) 

For these equations, I really am looking for two things:

  1. they have the correct variables and
  2. their equation equals the original equation(i.e.correct equation selected, and any rearrangement is mathematically correct)

bizzaroDivision.pl looks great - that was definitely a step I was unsure how to approach, and I think I can come up with something from your recommendations.


The final answer should always be a single variable assignment - so parserAssignment.pl will be perfect for that. 


As a more complex example (i.e. a grade 10 question), I commonly ask:

An object is placed 15cm away from a concave mirror which has a focal length of 10cm.How far from the mirror does the image form?

Breaking down the answer I would want:

  1. Givens / Unknowns(input field 1, for now) :

    do = 15cm
    f = 10cm
    di = ?

    I can create a list and use StringsInContext and parserAssignment.pl to define my three variables.

  2. Formula (input field 2, for now):

    1 / di = 1 / f - 1 / do 

    I would also want to accept

    di = 1/ (1 / f - 1 / do)
    or
    1 / f = 1 / di + 1 / do 

    I don't think that bizzaroArithmetic would work for this (since the left side can change, and I am looking for mathematical equality not a specific response). implicitEquation might be my only other option here. The equations used are typically fairly easy - but division is common and the equations almost always have 3 or more variables.

  3. Substitution (input field 3, for now):

    1 / di = 1 / 10 - 1 / 15 

    I think for this I need to generate the answer in response to the student's answer (in the vein of a MultiPart question). Essentially, the answer here should be the formula from the last line of input field 3, with the numbers filled in for the known variables. Assuming the left side has the unknown, I can use bizzaroArithmetic to evaluate the right side.

  4. Solve (input field 4, for now):

    1 / di = 1 / 30 

    This could be many steps, or just one, or omitted - but I basically want to just verify that there are no math errors (so the statement on each line should be mathematically equal to the one in the substitution field).

  5. Solution (input field 5, for now):

    di = 30 cm 

    Final answer - I think parserAssignment together with numberWithUnits would work here.

It is always harder than expected to go from the basic ideas to a working product - but so far, I think this looks promising and doable (about on par with getting WebWork to balance a chemical equation). Once again, thanks for the comments.
In reply to Chris Pinto

Re: Evaluate Multiline, Full Solution

by Alex Jordan -
Sounds like you've got some interesting coding in store. One more thing that may help is parserOneOf.pl. If you have a small finite list of versions of answers, you can list them all as a OneOf list. For example

$ans = OneOf(
Formula("V=IR"),
Formula("I=V/R"),
Formula("R=V/I"));
In reply to Alex Jordan

Re: Evaluate Multiline, Full Solution

by Chris Pinto -
Just to follow up here, I have made some progress, but find the solution to be a little fragile at present. Also, I have not yet managed to work units into the mix.

For the question: A 220 ohm resistor is connected to a 5V power supply. How much current flows across the resistor? 

Givens and Unknowns are working well - I can accept I = ? V = 5 R = 220 in any order, one per line.
I added the '?' to the context strings, but had to use a custom grader for splitting the string and identifying which unknown/givens were incorrect.
I believe there should be a way to change the delimiter used by 'list' but haven't found that yet. 
Also, I am looking to retrieve the left and right hand sides of the 'Assignment' type, and haven't been successful so far.

I am using OneOf/Compute for my formula, and that seems to work reasonably for now.
I used BizzaroArithmetic for the substitution, one problem I have is that the 'preview' (the 'entered' column) shows a random number (i.e. I enter I = 5/220 and see I = 0.00524624 (instead of I = 0.0227273) - the latex preview looks good though).

I am using Compute for the final answer (which I would like to change to 'NumberWithUnits' but the 'Assignment' type is giving me some issues with that). 

The current issues I have with the Assignment type relate to units:
a) the variable check conflicts with some units (e.g. the 'symbol' for voltage is 'V' and the unit (volts) also has the same symbol - so an answer like V = 5V is failing with same variable on both sides. If the precedence of the units was above that of the Assignment check I think it would work. 
b) the Assignment type doesn't recognize units as far as I can tell - but I manually parse the input (split on equal sign) I could probably set the right hand side to a NumberWithUnits without issue.

Overall, I think it has been good progress, but there is more to go.

As an aside, the 'OneOf' came in handy for another problem (I have my students enter element names for some symbols - and was having difficulty with Sulfur/Sulphur and Aluminum/Aluminium - I could only accept one answer - the OneOf solved that nicely).
In reply to Chris Pinto

Re: Evaluate Multiline, Full Solution

by Alex Jordan -
Here are some things to help with some of your issues.
  • If $a is a Formula object that's of Assignment type, then I believe $a->value will return an array of the left and right sides.
  • You can change the context flag formatStudentAnswer to parsed if you want the Preview field to show the result before any operations are carried out.
In reply to Alex Jordan

Re: Evaluate Multiline, Full Solution

by Chris Pinto -
Was able to use $a->data and that worked reasonably. formatStudentAnswer worked perfectly. Getting there - but I just don't have as much time to focus on it as I would like (hence, it is a longer term project - if I can get it working for April, I will be quite happy).