PREP 2014 Question Authoring - Archived

ImplicitEquation - still want to know if it is worth the time

ImplicitEquation - still want to know if it is worth the time

by Murphy Waggoner -
Number of replies: 2
I have been working on this problem off and on for 4 days. Some advice that I got from our mentors on another post helped resolved my last problems.

The issues, mostly, are in how ImplicitEquation checks answers. Since it randomly generates points numerically searches for zeros for f_lhs - f_rhs = F(x,y) when the student is supposed to input an equation equivalent to f_lhs = f_rhs, there are inherent problems. The search might not converge to the same zero for both equations (student's and instructor's), the search might not result in a zero because of the shape of F(x,y), the zero of F(x,y) might not occur in the default domain of ImplicitEquation, etc., etc.

It seems from on-line discussions of ImplicitEquation that either implicit equations of circles are most problematic or that this context is used most often when the answer is the equation of a circle. Regardless, setting the limits dynamically based on the parameters of the problem, especially when randomized, and providing solution points for the algorithms to work with resolve some problems.

The final issue I had was by trying to 'fix' the ImplicitEquation context so that I could use z and i in the question. Somehow by adding those variables to the context I created some problems in the context and was getting "Can't compute the log of zero" errors. This is a lesson I need to remember as I continue writing questions - it is best to use the Contexts in their pure state unless I am sure the changes I make are not going to corrupt anything.

By taking the advice of Paul, I changed contexts from Complex, where I created the question, to ImplicitEquation for the solution and the student input. Thanks, Paul! (See http://webwork.maa.org/moodle/mod/forum/discuss.php?d=3358 for details.)

Here is the most recent (working!) code. I also put this in the Problem Testing problem set. Feel free to try to break it.

Enjoy!

## DESCRIPTION
## Complex Variables
## ENDDESCRIPTION

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

## DBsubject('Complex Analysis')
## DBchapter('Complex Variables')
## DBsection('Point Sets')
## Date('22Jun2014')
## Author('Murphy Waggoner')
## Institution('Simpson')


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

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

loadMacros(
"PGstandard.pl",
"PGbasicmacros.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"PGcomplexmacros.pl",
"parserImplicitEquation.pl" # to allow input of non-linear implicit equation
);



TEXT(beginproblem());

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

# Set Context to Complex for the question - will change later
Context("Complex");

# Generate some random numbers to use below

$r1 = random( 2, 8, 1 ) ; # radius
$x1 = random( 1, 6, 1 ); # positive center abscissa
$y1 = random( -8, -1, 1 ); # negative center ordinate

# Create the LHS of the equation in complex variables
# standard complex equation of a circle

$f1 = Compute("abs(z - $x1 - $y1 i)")->reduce->TeX;

######################################
# Calculate Solutions = Cartesian equation of a circle

# Set Context to ImplicitEquation for solution and student input
# Eliminate error messages that will have no meaning for students

Context("ImplicitEquation");
Context()->{error}{msg}{
"Can't find any solutions to your equation"} = " ";
Context()->{error}{msg}{
"Can't generate enough valid points for comparison"} = " ";

# Set limits for evaluation = center +/- radius in both directions

$xmax = $x1 + $r1 ;
$xmin = $x1 - $r1 ;
$ymax = $y1 + $r1 ;
$ymin = $y1 - $r1 ;

# Generate 7 random points on the circle to send to ImplicitEquation
for my $i (0..6) {
$xtest[$i] = random($xmin,$xmax,0.01);
$ytest[$i] = $y1 + random(-1,1,2)*sqrt(($r1)**2 - ($xtest[$i]-$x1)**2);
}

# Create the implicit equation solution
# Make sure limits define a box including the circle

$soln1 = ImplicitEquation("(x-$x1)**2 + (y-$y1)**2 -( ($r1)**2)=0",
limits=>[[$xmin-1,$xmax+1],[$ymin-1,$ymax+1]],
tolerance=>0.001,
solutions=>[[$xtest[0],$ytest[0]],
[$xtest[1],$ytest[1]],
[$xtest[2],$ytest[2]],
[$xtest[3],$ytest[3]],
[$xtest[4],$ytest[4]],
[$xtest[5],$ytest[5]],
[$xtest[6],$ytest[6]]] );


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

BEGIN_TEXT

Displaying values of xmax, xmin, ymax, ymin, xtest[0], and ytest[0] for debugging purposes

$BR
$xmax; $xmin ; $ymax ; $ymin ; $xtest[0]; $ytest[0];
$BR
$BR


Convert the following equation in the complex variable \(z\) to an implicit equation in real variables \(x\) and \(y\).

$BR


$PAR
The set of points described by the complex equation \( $f1 = $r1\) is the same as the set of points describe by the real equation
\{ans_rule(25)\}


$PAR
END_TEXT

######################################
# End game

#Checking solutions
ANS($soln1->cmp);


#Show the students which answers were correct
$showPartialCorrectAnswers = 1;

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

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

In reply to Murphy Waggoner

Re: ImplicitEquation - still want to know if it is worth the time

by Gavin LaRose -
Hi Murphy,

Davide can correct me on this, but I think the best description of ImplicitEquation is that it's a tool that in a few cases will be very useful, but which has some significant shortcomings. Some of those are unavoidable mathematical artifacts of trying to check implicitly defined functions.

You have probably seen and been working with it, but the Problem Techniques page http://webwork.maa.org/wiki/EquationEvaluators has some discussion of the issues.

So, if one can use implicitPlane instead, do. there are some cases where implicitEquation may allow one to do things that aren't otherwise possible, but I think Davide will say that it's not a well-refined tool.

Gavin

In reply to Murphy Waggoner

Re: ImplicitEquation - still want to know if it is worth the time

by Davide Cervone -
Thanks for posting your working code, and comments. I did want to respond to a few of the comments, and make some suggestions about your code.

The search might not converge to the same zero for both equations (student's and instructor's)

That is not a problem, since the comparison doesn't compare the zeros obtained from the two equations to each other, but rather plugs the zeros located for one equation into the other one to see if they are also zeros there. That is, the zeros of one equation must also be the zeros of the other.

the search might not result in a zero because of the shape of F(x,y)

That is certainly possible, and something that needs to be taken into consideration. One of the keys is getting the domain right so that the search for zeros will be more likely to find them.

the zero of F(x,y) might not occur in the default domain of ImplicitEquation,

Right. Again, setting the domain appropriately is important.

It seems from on-line discussions of ImplicitEquation that either implicit equations of circles are most problematic or that this context is used most often when the answer is the equation of a circle.

Circles are no more problematic than other equations, but they are fairly frequently used, so come up often.

setting the limits dynamically based on the parameters of the problem, especially when randomized, and providing solution points for the algorithms to work with resolve some problems.

These are good practices.

The final issue I had was by trying to 'fix' the ImplicitEquation context so that I could use z and i in the question. Somehow by adding those variables to the context I created some problems in the context and was getting "Can't compute the log of zero" errors.

The ImplicitEquation object uses the variables in the context to specify the domain of the formula, so if you add more variables, the dimension of the domain goes up. If the variables in the context are x, y, and z, then the ImplicitEquation will look for points in (x,y,z)-space that are zeros of the formula.

It turns out that the algorithm used in the ImplicitEquation object requires the variables to be real-valued, and that complex-valued variables cause the problem you see. The algorithm takes the distance between two test points, and if some of the coordinates are complex, then the distance is computed incorrectly, and it leads to the log of zero problem.

The take-away is that you can add real variables to the ImplicitEquation context, but not complex ones. Your use of the Complex context separately is the better approach.


Here are some comments on the code:

Context("ImplicitEquation");
Context()->{error}{msg}{"Can't find any solutions to your equation"} = " ";
Context()->{error}{msg}{"Can't generate enough valid points for comparison"} = " ";
I would not disable these messages, as they alert you to problems that are occurring with the answer checking. They indicate that the checking will not be properly performed, and so the correct/incorrect result is not necessarily reliable.

for my $i (0..6) {
  $xtest[$i] = random($xmin,$xmax,0.01);
  $ytest[$i] = $y1 + random(-1,1,2)*sqrt(($r1)**2 - ($xtest[$i]-$x1)**2);
}
It is customary to use foreach rather than for here, but apparently both work.

$soln1 = ImplicitEquation("(x-$x1)**2 + (y-$y1)**2 -( ($r1)**2)=0",
   limits=>[[$xmin-1,$xmax+1],[$ymin-1,$ymax+1]],
   ...
Since your radius can be as large as 8, the extra 1 on either side might be a little small (since the circle will be relatively close to the edge of the domain). Perhaps using $xmin-$r1/2 and $xmax+$r1/2 might be better, as this gives a better chance of finding zeros.

Anyway, glad you got the problem to run. Good work!