Forum archive 2000-2006

Michal Charemza - Show exact form (do not evaluate square roots)

Michal Charemza - Show exact form (do not evaluate square roots)

by Arnold Pizer -
Number of replies: 0
inactiveTopicShow exact form (do not evaluate square roots) topic started 9/3/2006; 12:13:56 PM
last post 9/5/2006; 10:41:01 AM
userMichal Charemza - Show exact form (do not evaluate square roots)  blueArrow
9/3/2006; 12:13:56 PM (reads: 339, responses: 2)

When using a Formula object, say Formula("sqrt(2)"), is there a way to show this in exact form (i.e. not evaluate it to 1.41421), both in the question and in the correct answer box?



<| Post or View Comments |>

userDavide P. Cervone - Re: Show exact form (do not evaluate square roots)  blueArrow
9/4/2006; 8:55:49 AM (reads: 422, responses: 0)
There are several different ways to accomplish.

If you are creating a constant rather than a formula, you can use

   $r = Compute("sqrt(2)");
  $V = Compute("<sqrt(2)+1,1/5>");
and the resulting object will use whatever string you originally entered as its version of the "correct answer". (However, if you use $V to generate its string version, it will still use the computed form.)

For formulas, the Parser usually reduces constant operations and function calls to their results, you could do something like Formula("$n x^($n-1)") and obtain Formula("3 x^2") when $n is 3, for example. To prevent this, use

which will turn off reducing operations between constants (like $n-1 in the previous example), and function calls with constant parameters (like your sqrt(2)).

Note that this works only with formulas, since the constant objects don't retain a parsed form, and so only keep the computed value. But you have to be a bit careful about using Formulas for storing constants, because the error messages a student will receive will say that the answer is looking for a formula, and that could be confusing. You really want to have the answer checker use the Real() answer checker, not the Formula() one. Here's one way to do it:


$sq2 = Formula("sqrt(2)");

\($sq2\) = \{ans_rule(10)\}


Here, $sq2 will be a formula that retains the sqrt, and so when it is inserted into the BEGIN_TEXT/END_TEXT block, it will produce \sqrt{2} rather than 1.41421. But, since you want the answer checked as a Real(), not a Formula(), you call Compute() to turn the result into the actual constant, but the string used to specify the value is retained and shown as the correct answer by the answer checker. Since you have passed $sq2 to Compute(), it gets converted to a string, and then is computed, so the effect is the same as Compute("sqrt(2)"), which is what you wanted.

<| Post or View Comments |>

userMichal Charemza - Re: Show exact form (do not evaluate square roots)  blueArrow
9/5/2006; 10:41:01 AM (reads: 419, responses: 0)
>> Context()->flags->set(reduceConstants=>0,reduceConstantFunctions=>0);

Thanks, this works. (and thank you for your detailed answer)


<| Post or View Comments |>