WeBWorK Problems

LimitedRadicals context

LimitedRadicals context

by Alex Jordan -
Number of replies: 3
Earlier this week I posted a reply to a topic in these forums and included a file contextLimitedRadical.pl.

In the past few days it has been altered (improved I hope) to its current form, which is attached.

I am having a few problems with it.
  • In the problem below (created for testing this context - you would need to download the attached context file) there is one blank expecting sqrt(50)-sqrt(32) to be simplified to sqrt(2). If I enter "sqrt(50)-sqrt(32)", I get the message "Can't generate enough valid points for comparison". I don't understand this message because I think I understand where the comparison happens, and the comparison is of two constant Formulas. So why should there be any issue with finding valid points?
  • Possibly related, if I try something like "sqrt(50)-sqrt(32)+x-x", I get the error message "The domain of your function doesn't match that of the correct answer"
  • The same situation happens in a later answer that is expecting (1+sqrt(2))/2 if I enter "-1/(2-sqrt(2))".
  • In each case, if the subsequent answer is supposed to have some kind of feedback message, that message is suppressed. Somehow whatever badness is happening with regard to domain issues in the first two bullets is seeping into the next answer checker.
  • Lastly, and unrelated (I think), one of these answer blanks expects 1+sqrt(2)+sqrt(3). It properly rejects root(3,1)+sqrt(2)+sqrt(3), but accepts sqrt(1)+sqrt(2)+sqrt(3). I don't understand this because the mechanism that prevents root(3,1) is basically identical to the one that should be preventing sqrt(1).
If anyone can help, I'd be very thankful. This has been driving me a little crazy. And if we can hammer down these last issues, this context will be used a lot in an intermediate algebra library we are creating.

##############################################
DOCUMENT();
loadMacros(
 "PGstandard.pl",
 "MathObjects.pl",
 "PGML.pl",
 "contextLimitedRadical.pl",
);

##############################################
Context("LimitedRadical");
##############################################
TEXT(beginproblem());

BEGIN_PGML

##Square Roots (use sqrt(x))
[`\sqrt{16}=`] [________________]{Formula("4")}
[`\sqrt{27}=`] [________________]{Formula("3*sqrt(3)")}
[`\sqrt{x^3}=`] [________________]{Formula("abs(x)*sqrt(x)")}
[`\sqrt{12x^5}=`] [________________]{Formula("2x^2*sqrt(3x)")}
[`\sqrt{2}+\sqrt{2}=`] [________________]{Formula("2 sqrt(2)")}
[`\sqrt{50}-\sqrt{32}=`] [________________]{Formula("sqrt(2)")}
[`1+\sqrt{2}+\sqrt{3}=`] [________________]{Formula("1+sqrt(2)+sqrt(3)")}
[`\frac{1+\sqrt{2}}{2}=`] [________________]{Formula("(1+sqrt(2))/2")}
##Other Roots (use root(n,x))
[`\sqrt[3]{27}=`] [________________]{Formula("3")}
[`\sqrt[3]{-64}=`] [________________]{Formula("-4")}
[`\sqrt[3]{x^9}=`] [________________]{Formula("x^3")}
[`\sqrt[3]{8x^2}=`] [________________]{Formula("2root(3,x^2)")}
[`\frac{\sqrt{49x}}{\sqrt[3]{x^2}}=`] [________________]{Formula("7/root(6,x)")}
[`\sqrt{\sqrt[3]{(3x)^2}}=`] [________________]{Formula("root(6,(3x)^2)")}
END_PGML
##############################################
ENDDOCUMENT();
In reply to Alex Jordan

Re: LimitedRadicals context

by Davide Cervone -
There are two issues with your code; the first causes the first 3 bullet points, and the second the last one. The fourth I haven't looked into, but I'm hoping it will no longer be an issue.

The first issue is that your subtract class is missing the call method that is required to handle the isCommand property that is set in the context. That is causing your formula to fail to be able to be evaluated, and that is the source of the message about not being able to generate enough points to check it (every point fails to be in its domain).

The second problem is that the code for sqrt is looking for a flag setSqrt, which you haven't set, so it never uses the bizzaro version. You either want to use setRoot here, or add setSqrt in the checker that is part of the context.

One other item: you are using parser::Root, but I'd recommend that you use my::Function. That is because I am planning to add the parserRoot.pl file that I sent you earlier to the main macros directory, and it will use parser::Root, so it would be best if you don't use that yourself.

Davide
In reply to Alex Jordan

Re: LimitedRadicals context

by Davide Cervone -
One other thing: in the root code, the values of $x and $n are MathObjects, not perl reals, so the equality and inequality tests that you do in the code are "fuzzy" ones. That means something like $n == 0 is actually a test that uses the zeroLevel and zeroLevelTol values to decide if the value is zero.

Since all your values are likely to be integers, this should not be a problem, but I just thought I'd point out that these tests are controlled by the tolerances set in the problem. If you want to use the pure perl values, you could use $x->value to get at that.

Davide
In reply to Alex Jordan

Re: LimitedRadicals context

by Alex Jordan -
Here is the contextLimitedRadical.pl file after the edits Davide points out, and with some updating to the comments. Thanks Davide for your help; those two errors are really things that I should have caught.

Now setSqrt and setRoot can be set by the problem author, with default values of exp(1)/ln(2).

I was not able to make the root(n,x) function treat its inputs as perl reals rather than Math Objects as Davide suggests. My attempts to do so led to "Can't generate enough valid points for comparison" errors. So be careful with n or x very close to 0.