## WeBWorK Problems

### Using reduce results in incorrect display with complex numbers

by Murphy Waggoner -
Number of replies: 2
Hi,

I tried to capture this error once before, but must not have done it correctly.  I'm trying again.

When I write a polynomial with complex coefficient and I use reduce to simplify it, if there is a negative before the constant term, reduce eliminates the parenthesis around the constant term but does not negate the imaginary part.  So that

z - (1 + i) is displayed as z - 1 + i.

Last night I had to debug two problems for students because my seed did not cause a problem, but they got seeds that did.

The code is below.  A file with screen shots is attached, with images of what happens with and without reduce.

Thanks.

## DESCRIPTION
##   Complex Variables
## ENDDESCRIPTION

## KEYWORDS('Complex')
## Tagged by mewaggoner

## DBsubject('Complex Analysis')
## DBchapter('Functions')
## DBsection('Limits')
## Date('14Jun2014')
## Author('Murphy Waggoner')
## Institution('Simpson')

DOCUMENT();        # This should be the first executable line in the problem.

######################################
#  Preamble

"PG.pl",
"PGbasicmacros.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"PGauxiliaryFunctions.pl",
"PGcomplexmacros.pl"
);

TEXT(beginproblem());

######################################
#  Setup

Context("Complex");

# Create two different exponents in the range of 2 to 5
# These will be the exponents in the denominators

$exp1 = Real(random(2, 5, 1)); do {$exp2 = random(2,5,1); } until ( $exp2 !=$exp1 );

# Create an exponent for numerator that is less than the denominator
$exp3 =$exp1 - random(1,$exp1- 1,1);$exp4 = $exp2 - random(1,$exp2,1);

# Generate some random complex numbers to use below
# Choose all coefficients to be non-zero

$a = Complex(random( -5, 5, 1 ) , non_zero_random( -5, 5, 1 ) );$b = Complex( non_zero_random( -5, 5, 1 ) , random( -5, 5, 1 ) );
$c = Complex( non_zero_random( -5, 5, 1 ), 0);$d = Complex( 0, non_zero_random( -5, 5, 1) );

#  Create the expressions to take limits of
#  The reduce eliminates 0 exponents, combines constants, etc.
#  The TeX makes the fractions horizontal and eliminates * by
#  creating TeX commands for the formulas

$f1 = Compute("($a z^$exp1 +$b)/($b z^$exp3 + $d )")->reduce->TeX;$f2 = Compute("($c z^$exp2 + $b)/($d z^$exp4 +$a )")->reduce->TeX;

######################################
#  Calculate Solutions
# reciprocate both the function and the variable

$soln1 = Formula("($b z^(-$exp3) +$d )/($a z^(-$exp1) + $b)");$soln2 = Formula("($d z^(-$exp4) + $a )/($c z^(-$exp2) +$b)");

######################################
#  Question text

BEGIN_TEXT

Using the formal theorems for evaluating limits at and of infinity, fill in the blank with the appropriate function.
$PAR$PAR
$$\text{Question 1: }\ \ \ \displaystyle\lim_{z \to \infty}f1 \ = \infty\ \ \text{if and only if}$$$BR$BR
$$\ \ \ \ \ \ \displaystyle\lim_{z \to 0}\$$\{ans_rule(30)\} $$\ = \ 0$$

$PAR $$\text{Question 2: }\ \ \ \displaystyle\lim_{z \to \infty}f2 \ = \infty\ \ \text{if and only if}$$$BR$BR $$\ \ \ \ \ \ \displaystyle\lim_{z \to 0}\$$\{ans_rule(30)\} $$\ = \ 0$$$PAR

END_TEXT

$showHint=2; BEGIN_HINT Beware of negative signs in front of the fraction. END_HINT ###################################### # End game #Checking solutions ANS($soln1->cmp);
ANS($soln2->cmp); #Show the students which answers were correct$showPartialCorrectAnswers = 1;

######################################
#  Done

ENDDOCUMENT();        # This should be the last executable line in the problem.