WeBWorK Problems

Answers in terms of functions

Re: Answers in terms of functions

by Davide Cervone -
Number of replies: 0
What you are asking for is somewhat difficult to accomplish in WeBWorK. This is because WeBWorK compares functions by evaluation, not by algebraic structure, so there would have to be a means of evaluating f(n) before WeBWorK would be able to handle it.

It is possible to use the parserFunction.pl macro library to do this, though it does present some possible (but unlikely) ways to get the answer marked correct without it being what you want.

Here is a sample code snippet that may do what you are after:


    parserFunction(f => "sin(pi^n)+e");  # something student is unlikely to type by hand
    $f = Formula("3 f(n-1) + 2");

    \(f(n)\) = \{ans_rule(20)\}.


Note that this defines f(n) to be something obscure that a student is unlikely to type by hand so that WeBWorK can evaluate the formula. It would be difficult to get a formula that matched without writing it using f (though if the definition of f is chosen badly, it might be able to be written in several ways using f).

Unfortunately, you can't include the f(n)= as part of the answer, even using the parserAssignment.pl macros, as they don't allow recursive definitions.

Alternatively, you could write a custom checker that looks for the specific algebraic structure you are using, but that would limit the form that the student could use to enter the answer (e.g., 3 f(n-1)+1+1 might not be accepted if you weren't careful about how you code your checker). This approach is difficult, and I wouldn't recommend it.