## WeBWorK Problems

### tool(s) to simplify sqrt(integer) ### tool(s) to simplify sqrt(integer)

by Dick Lane -
Number of replies: 0
While designing a problem involving lattice points, I sought a tool to simplify display of distances, e.g., sqrt(360) = 6 sqrt(10).  After quick searches found nothing, I wrote the following (the attached file demonstrates this code in a WeBWorK problem).

####    simplify square root of integer, e.g., sqrt(300) = 10 sqrt(3)
sub sqrtReduce {
my @Sqrt = (1,@_);
foreach my $p (2,3,5,7,11,13,17,19) { while ($Sqrt % ($p*$p) == 0 ) {
$Sqrt *=$p ;
$Sqrt /= ($p*$p) ; } } return @Sqrt } #### LaTeX formatting for output of sqrtReduce sub sqrtShow { my @Root = sqrtReduce(@_) ; if ($Root == 1) {
return $Root ; } elsif ($Root == 1) {
return "\sqrt{$Root}" ; } else { return "$Root \, \sqrt{\$Root}" ;
}
}

a)  I will welcome suggestions to improve this code.
b)  Does WeBWorK 2.#.# already have a library file with a similar tool?
c)  If not(b), could WW 3.# include a new file to contain tools not already in PGauxililaryFunctions.pl?  I would renew my proposal of an extended gcd discussed in http://webwork.maa.org/moodle/mod/forum/discuss.php?d=2286