WeBWorK Problems

Summation notation answer checker

Summation notation answer checker

by Paul Pearson -
Number of replies: 0
Hi all,

I would like to be able to evaluate student answers such as \sum_{k=1}^3 x^k and \sum_{k=1}^\infty x^k. I have written some code (see below my signature) that has minimal working functionality by doing the following:

1. Adding an integer valued variable k to the context.

2. Removing the string infinity (and variations) from the context and then adding "inf" as a variable to the context.

3. Defining a function Sum( f(x,k), a, b ) whose first argument is a function f(x,k) for the kth term of the sum, second argument is the starting index a, and third argument is the stopping index. This function does not actually compute the sum, but instead uses a strange formula that depends on x, k, f(x,k), a, and b that the student is not likely to enter. Then, the answer checking happens behind the scenes by interpreting the student answer and the correct answer using the same strange formula and comparing them. In the case of a finite sum, I used ParserOneOf.pl to allow for multiple correct answers.

Limitations:

For #2 above: Students can no longer enter "infinity", "INF", or "INFINITY" and have it interpreted as "inf".

For #3 above: If the students choose a different indexing scheme (say zero-based indexing instead of 1-based indexing), this answer checker will mark their answer incorrect, which is a major limitation. The students do not get to specify the index name (k), which is minor. In the case of a finite sum, I had to use ParserOneOf.pl to allow for multiple correct answers, which allows for the problem author to choose whether they want to require the Sum() function to be used.

Ideal situation:

We would not need to remove the strings for infinity and add a variable inf to the context, because the Sum() function would be allowed to have a and b be infinite. The answer checker would work with an arbitrary choice of indexing. The answer checker would either check the (finite) partial sum for correctness (instead of using a strange formula behind the scenes), or possibly check several terms for correctness. If the answer is a finite sum, then if the student enters the finite sum directly instead of using the Sum() function their answer will be marked correct. In the case where a = - infinity or b = infinity, the answer checker would still just check some (finite) partial sums or randomly chosen terms for correctness, and also separately verify that a and/or b is -/+ infinity. Also, should there be an option to have the answer preview be either plain text Sum(...) or TeX \sum...? Perhaps a second version of the function would be something like Sum( f(x,k), k, a, b), where students can choose the name k for the index (e.g., maybe students prefer n to k).

Questions: Is there a good way to use answerPreFilters


as a way to deal with allowing infinity as an input to the Sum() function?

Also, it would be useful to extend these ideas to a function Integral(f,a,b) that would be able to check if students have set up an integral formula correctly.

Thanks!

Paul Pearson


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

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserFunction.pl",
"parserOneOf.pl",
"PGcourse.pl",
);
TEXT(beginproblem());

Context("Numeric")->variables->add(k => ['Real', limits=>[1,10], resolution=>1]);
Context()->strings->remove("inf","infinity","INF","INFINITY");
Context()->variables->add('inf'=>['Real', TeX=>'\infty']);

parserFunction("Sum(f,a,b)" => "(6.9281 *(b+1.42)) * x * f^(0.8273 (a+0.37)) / (1.27 k)");

BEGIN_PGML
Note: In this problem [`\infty`] must be entered as [|inf|] because we have removed the strings [|inf|], [|infinity|], [|INF|], and [|INFINITY|] from the context and then added [|inf|] as a variable in the context.

Enter [``\sum_{k=1}^3 x^k``] by typing [`Sum(x^k,1,3)`] or [`x+x^2+x^3`]: [______________]{OneOf("Sum(x^k,1,3)","x+x^2+x^3")}.

Enter [``\sum_{k=1}^\infty x^k``] by typing [`Sum(x^k,1,inf)`]: [______________]{"Sum(x^k,1,inf)"}.

END_PGML

ENDDOCUMENT();