## WeBWorK Problems

### Student entering nth roots (dev math) ### Student entering nth roots (dev math)

by Bruce Yoshiwara -
Number of replies: 4

Hello again. (It’s been quite a few years since I last posted.)

I’d like to have WeBWorK exercises asking (developmental math) students to translate expressions with rational exponents (such as “x^(1/n)”) into equivalent expressions with radicals, what LaTeX would show for “\sqrt[n]{x}”).

In the xyzhomework.com system (an implementation of the MyOpenMath homework system), we could ask students to input the “radical form” via either MathQuill (an online math expression editor) or by entering “root(n)(x)”. How can I code a similar WeBWorK exercise?

I’m looking for fairly direct translations, not simplifications, so that “1/sqrt(3)” is the expected acceptable expression for “3^(-1/2)”. But I don’t want the student to get credit for simply copying the expression with rational exponents—s/he needs to designate the appropriate radical.

Cheers.

Bruce Yoshiwara ### Re: Student entering nth roots (dev math)

by Alex Jordan -
Hi Bruce,

If you want a palette style answer entry, the ones that I know of currently would *look* like \sqrt[n]{x}, but would actually submit x^(1/n) to WeBWorK for evaluation. Which would mean they could just type x^(1/n) too. So until that behavior of the available palette tools is changed, I think you can't get what you want. But keep reading.

If you are OK with typed-in answers, then you can load parserRoot.pl. Then something like root(3,x) is understood. You want to disallow things like x^(1/3) and exp(1/3 ln(x)). So one option is to disable the exponentiation operator and functions, then re-enable root. So with the caveat that I haven't tried it out:

"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserRoot.pl",
);

Context("Numeric");
parser::Root->Enable;
Context()->operators->undefine("^","**");
Context()->functions->disable("All");
Context()->functions->enable("sqrt");
Context()->functions->enable("root"); #possibly not needed, if root is not a "function" but rather a "funciton2" as a function of 2 variables

BEGIN_PGML

[7^{1/3} = ][_______________]{Formula("root(3,7)")}

END_PGML

Now, one palette tool is WIRIS, which has a pull request to develop right now, and is likely to be available in WBWK 2.14. Presently, it handles things like I mentioned above, secretly passing things like x^(1/3). I'm working on convincing them to maybe pass root(3,x) instead. So maybe the future will have a working palette tool for this too.

Lastly, watch out that if the answer is like root(4, x), that you set the domain to be something appropriate. The default is [-2, 2], and every once in a while a student will get all their test points in [-2,0), and the problem won't work for them. ### Re: Student entering nth roots (dev math)

by Bruce Yoshiwara -
Dear Alex,

Terrific, thanks!

Your code seems to do exactly what I was hoping to get. I did remove the Context()->functions->enable("root"), and I also removed "Formula" in the answer, which works with just the "root(3,7)".

Cheers.

Bruce ### Re: Student entering nth roots (dev math)

by Alex Jordan -
Great, but something more occurred to me. If the answer is just a number (like root(3,7)) as opposed to an expression with variables (like root(3, x)), then students will still be able to enter 1.913 and get credit (it is within the default tolerance). You could disable decimals, but then they could still enter 1913/1000.

So...if you are sure you don't want an answer like root(3,4/5), where you would want the division slash, an easy thing to do is to basically turn off everything except integers and the root function.

So replace Context("Numeric") by Context("LimitedNumeric"). And disallow decimals with Parser::Number::NoDecimals();

If you did want the division slash, you could bring it back with Context()->operators->redefine("/"); ### Re: Student entering nth roots (dev math)

by Bruce Yoshiwara -
Dear Alex,

Thanks again!

I've decided to go with adding Parser::Number::NoDecimals(); and living with the possibility that some enterprising students might enter approximations as fractions.

I fiddled with using Context("LimitedNumeric"), but then WeBWorK complained about my using parentheses in expressions like "root(n,k)"

I didn't try to remove the "/" operator because I will also be writing exercises where the appropriate answer is "1/sqrt(x)"

Bruce