Skip to content

Commit 1ef85ff

Browse files
authored
Merge pull request #920 from dlglin/master
Rewrite problem with MathObjects,PGML in order to disallow use of sqrt
2 parents 8a17b1b + d764378 commit 1ef85ff

File tree

1 file changed

+21
-17
lines changed
  • OpenProblemLibrary/Rochester/setAlgebra11ComplexNumbers

1 file changed

+21
-17
lines changed

OpenProblemLibrary/Rochester/setAlgebra11ComplexNumbers/Sqrt.pg

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,47 @@
22
## Complex Numbers
33
## ENDDESCRIPTION
44

5-
## Tagged by nhamblet
6-
75
## DBsubject(Complex analysis)
86
## DBchapter(Arithmetic)
97
## DBsection(Powers and roots)
108
## Institution(Rochester)
119
## Level(2)
10+
## MO(1)
1211
## KEYWORDS('Complex', 'Imaginary')
1312

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

1615

1716
loadMacros(
1817
"PGstandard.pl",
19-
"PGchoicemacros.pl",
20-
"PGcomplexmacros.pl",
18+
"MathObjects.pl",
19+
"PGML.pl",
2120
"PGcourse.pl"
2221
);
2322

2423
TEXT(beginproblem());
2524
$showPartialCorrectAnswers = 1;
2625

26+
Context("Complex");
27+
Context()->functions->disable('sqrt');
28+
Context()->operators->undefine('^', '**');
29+
Context()->{error}{msg}{"Can't use '^' in this context"}
30+
= "Exponents are disabled for this problem. Compute the result for yourself and resubmit your answer.";
31+
Context()->{error}{msg}{"Can't use '**' in this context"}
32+
= "Exponents are disabled for this problem. Compute the result for yourself and resubmit your answer.";
33+
Context()->{error}{msg}{"Function 'sqrt' is not allowed in this context"}
34+
= "Square roots are disabled for this problem. Compute the result for yourself and resubmit your answer.";
2735

28-
$z = random(-9,9,1) + non_zero_random(-9,9,1)*i;
29-
30-
TEXT(EV2(<<EOT));
31-
Find the square root of $z so that the real part of your answer is
32-
positive.
33-
$BR $BR
34-
The square root is \{ans_rule(10)\}.
36+
do {
37+
$z = non_zero_random(-5,5,1) + non_zero_random(-5,5,1)*i;
38+
$z2 = $z**2;
39+
} while (Re($z2) == 0);
40+
$ans = List($z,-$z);
3541

36-
EOT
42+
BEGIN_PGML
43+
Find the square roots of [:[$z2]:].
3744

38-
$ans1 = sqrt($z);
39-
$ans = Re($ans1) + Im($ans1)*i;
40-
ANS(cplx_cmp($ans));
45+
The square roots are [__________]{$ans}.
46+
END_PGML
4147

4248
ENDDOCUMENT(); # This should be the last executable line in the problem.
43-
44-

0 commit comments

Comments
 (0)