Here is an example of what I have done in the past for this issue.
Say the problem asks to find dy/dx for x^4+y^2+y=7.
Consider this code:
Context() -> variables -> add(y=>'Real');
$dydx = Formula("-4x^3/(2y+1)");
@y = (random(-2,2,0.2), random(-2,2,0.2), random(-2,2,0.2), random(-2,2,0.2), random(-2,2,0.2));
@x = map{(7-($_)-($_)**2)**(1/4)*(-1)**(random(-1,1,2))} (@y);
@xy = map{[$x[$_], $y[$_]]} (0..4);
$dydx -> {test_points} = ~~@xy;
Explanation:
- Add y to the context (this assumes x is there to start).
- Make the canonical correct answer formula. This will display as "the" correct answer.
- Make some random y-values coming from an interval where 7 - y - y^2 is positive. This part means you need to consider the specifics of the original curve.
- Find x-values that pair with those y-values on the curve. This was doable with this curve because x can essentially be solved for. Note it is randomly choosing positive or negative fourth roots. In other settings, it may make more sense to randomize x-values and solve for y-values. In yet other settings, this approach just isn't quite doable.
- Make an array where each element is an array reference to an x,y-pair that is on the curve.
- Set the test points for the answer to be this array.
So during a check, instead of choosing a bunch of random x and y-values to plug in to -4x^3/(2y+1), it is forced to only choose (x,y) pairs that are on the curve. Therefore if a student uses an expression that has made use of the defining relationship between x and y, it won't matter. With this example, it is OK to answer with:
-4x^3/(2y+1)
or with:
-4x^4/[x(2y+1)]
or with:
-4(7 - y - y^2)/[x(2y+1)]
etc.