## 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 Show exact form (do not evaluate square roots) topic started 9/3/2006; 12:13:56 PMlast post 9/5/2006; 10:41:01 AM Michal Charemza - Show exact form (do not evaluate square roots) 9/3/2006; 12:13:56 PM (reads: 339, responses: 2) Hi, 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? Thanks, Michal. <| Post or View Comments |> Davide P. Cervone - Re: Show exact form (do not evaluate square roots) 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)"); or $V = Compute(""); 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  Context()->flags->set(reduceConstants=>0,reduceConstantFunctions=>0); 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:  Context()->flags->set(reduceConstants=>0,reduceConstantFunctions=>0);$sq2 = Formula("sqrt(2)"); Context()->texStrings; BEGIN_TEXT $$sq2$$ = \{ans_rule(10)\} END_TEXT Context()->normalStrings; ANS(Compute($sq2)->cmp); 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 |> Michal Charemza - Re: Show exact form (do not evaluate square roots) 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) Michal. <| Post or View Comments |>
{"ft_lang_label":"__label__en","ft_lang_prob":0.85520303,"math_prob":0.93420494,"size":2118,"snap":"2022-27-2022-33","text_gpt3_token_len":524,"char_repetition_ratio":0.12440871,"word_repetition_ratio":0.0,"special_character_ratio":0.25779036,"punctuation_ratio":0.11881188,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9926296,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-17T08:27:03Z\",\"WARC-Record-ID\":\"<urn:uuid:595c4327-9c8c-4e98-b560-3acc1eee1d37>\",\"Content-Length\":\"70784\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:38d3ceee-28a0-4fb5-b6c2-d2561372b82c>\",\"WARC-Concurrent-To\":\"<urn:uuid:820da458-a454-4abb-b36b-cca57c48eb87>\",\"WARC-IP-Address\":\"34.204.106.157\",\"WARC-Target-URI\":\"https://webwork.maa.org/moodle/mod/forum/discuss.php?d=1887\",\"WARC-Payload-Digest\":\"sha1:P5CRVYK2NOCWDQWXPLO5V4R7OU2MO3JX\",\"WARC-Block-Digest\":\"sha1:VU3ZOSUIVWB5JYFVAO6F6GHS7BNM76KT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882572870.85_warc_CC-MAIN-20220817062258-20220817092258-00457.warc.gz\"}"}