# [LON-CAPA-users] square roots in formula response

**Gerd Kortemeyer
**
lon-capa-users@mail.lon-capa.org

*Tue, 4 Sep 2007 07:23:17 -0400*

Hi,
On Sep 3, 2007, at 9:53 PM, Justin Gray wrote:
>* Are you sure that Maxima does not simplify expressions when
*>* comparing them? I was under the impression that Maxima tries to
*>* simplify the difference of two equivalent expressions and verify
*>* that it is zero.
*
Well, here's the actual code of what it does in <formularesponse>:
sub compareterms {
my ($socket,$terma,$termb)=@_;
my $difference=$terma.'-('.$termb.')';
if (&blacklisted($difference)) { return 'Error: blacklisted'; }
my $reply=&maximareply($socket,'trigsimp(trigreduce('.
$difference.'));');
if ($reply=~/^\s*0\s*$/) { return 'true'; }
if ($reply=~/^Error\:/) { return $reply; }
return 'false';
}
- so it would do simplification. But I think Peter's idea might work
if you do it by hand inside of <mathresponse>.
It's a very common problem for us, for which I don't know any good
answer: you want students to modify or simplify a term, but you don't
want the original answer (or a trivial variant of it) back.
For example, if you want them to factor out
a^2+2ab+b^2
it should be
(a+b)^2 - okay
(a+b)(a+b) - okay
(a+b)(b+a) - okay
1*(a+b)(a+b) - ???
a*(1+b/a)(a+b) - ???
a^2+2ab+b^2 - not okay
2ab+a^2+b^2 - not okay
a*a+a*b+b*a+b*b - not okay
a^2+2ab+b^2+a-a - not okay
- I don't know how any system should manage this in a generalizable way.
In the above case, <customresponse> might do the trick. You could do
regular expressions to
* look for '(', which should be in there
* look for '^2', which should not be in there
* look for 'a*a', 'b*b', or 'a*b', which should not be in there
* finally do a &cas()-call to figure out mathematical equivalency
... sort of stinks, though.
- Gerd.