Skip to content

Commit

Permalink
More cleanup of the sample problems and addition of complex samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
pstaabp committed Jun 28, 2023
1 parent 2fe3622 commit 60a7446
Show file tree
Hide file tree
Showing 72 changed files with 1,082 additions and 784 deletions.
84 changes: 40 additions & 44 deletions doc/sample-problems/Algebra/AlgebraicFractionAnswer.pg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## MO(1)
## KEYWORDS('algebra', 'algebraic fraction answer')

#:% name = Fraction Answer
#:% name = Algebraic Fraction Answer
#:% type = Sample
#:% subject = [algebra, precalculus]
#:% categories = [fraction]
Expand All @@ -27,27 +27,31 @@ loadMacros(
);

#:% section = setup
#: We define a string `$fraction` that will be displayed in TeX mode. We define MathObjects
#: formulas `$num` and `$den` that are the correct numerator and denominator for the answer,
#: as well as some bogus answers `$numbogus` and `$denbogus` that result from not finding a
#: common denominator. We use MultiAnswer to manipulate both student answers at the same
#: time. In `$multians` we allow for answers to be left blank, which requires one of two
#: things: either we disable the error message or do type checking on the students input
#: by using `ref($f1) eq ref($f1stu)` to see if the correct numerator `$f1` and the student
#: numerator `$f1stu` have the same type. We used the code
#: `Context()->{error}{msg}{"Operands of '*' can't be words"} = ' ';` to disable the
#: error message because this method allows the "Simplify your answer" feature to
#: work more reliably. We also allow for the student to enter the fraction as either
#: `(6y-3)/(y-2)` or `(3-6y)/(2-y)`, since both are correct and it is not clear that
#: one is preferable to the other, which requires that we check
#: `$f1 == $f1stu || -$f1 == $f1stu`. Here `||` is perl's "or" operator. We provide
#: some custom answer hints by testing for bogus numerators and denominators and
#: displaying answer messages via `$self->setMessage(1, "Simplify your answer further");`,
#: We define MathObjects formulas `$num` and `$den` that are the correct
#: numerator and denominator for the answer, as well as some bogus answers
#: `$numbogus` and `$denbogus` that result from not finding a common
#: denominator. We use `MultiAnswer` to manipulate both student answers at
#: the same time. In `$multians` we allow for answers to be left blank,
#: which requires one of two things: either we disable the error message or
#: do type checking on the students input by using `ref($f1) eq ref($f1stu)`
#: to see if the correct numerator `$f1` and the student numerator `$f1stu`
#: have the same type. We used the code
#: `Context()->{error}{msg}{"Operands of '*' can't be words"} = ' ';` to
#: disable the error message because this method allows the
#: "Simplify your answer" feature to work more reliably. We also allow for
#: the student to enter the fraction as either
#: `(6y-3)/(y-2)` or `(3-6y)/(2-y)`, since both are correct and it is not
#: clear that one is preferable to the other, which requires that we check
#: `$f1 == $f1stu || -$f1 == $f1stu`. Here `||` is perl's "or" operator. We
#: provide some custom answer hints by testing for bogus numerators and
#: denominators and displaying answer messages via
#: `$self->setMessage(1, "Simplify your answer further");`,
#: where the 1 stands for the first answer blank.
#:
#: The fraction answer is created using a `LayoutTable` from `niceTables.pl`.
#: This is just a one-column table with the first row with a horizontal line.
#: The padding is changed to improve the look of the fraction.
#: The outer `LayoutTable` has a single row with the mathematical expression
#: and then another `LayoutTable` that formats the fraction with a bottom
#: horizontal line. The padding is changed to improve the look of the fraction.
Context()->variables->are(y => 'Real');
Context()->{error}{msg}{"Operands of '*' can't be words"} = ' ';

Expand All @@ -57,8 +61,6 @@ do {
$c = random(1, 9, 1);
} until ($a*$c != $b);

$fraction = "\frac{$a y}{y-$c} + \frac{$b}{$c - y} ";

$num = Formula("$a y - $b");
$den = Formula("y - $c");

Expand Down Expand Up @@ -97,40 +99,34 @@ $multians = MultiAnswer($num, $den)->with(
}
);

# Display the fraction and answer blanks nicely
# Context()->texStrings;
# if ($displayMode eq 'TeX') {
# $showfraction =
# "\[ $fraction = "
# . $multians->ans_rule(10)
# . $multians->ans_rule(10) . " \]";
# } else {
# $showfraction = ColumnTable(
# "\( \displaystyle $fraction = \)",
# $multians->ans_rule(20) . $BR . $HR . $multians->ans_rule(20),
# separation => 10,
# );
# }
# Context()->normalStrings;

$frac = LayoutTable([[[ans_rule(10), rowbottom => 1]],[ans_rule(10)]],
center => 0, allcellcss => {padding => '4pt'});
$frac = LayoutTable(
[[
"\(\displaystyle\frac{$a y}{y-$c} + \frac{$b}{$c - y}=\)",
LayoutTable(
[
[[ans_rule(4), bottom => 1]],
[ans_rule(4)],
],
padding => [0.5, 0],
)
]],
padding => [0, 0.5],
valign => 'middle',
);

#:% section = statement
#: Everything is as usual. Insert the fraction and answer blanks using `$showfraction`.
BEGIN_PGML
Perform the indicated operations.
Express your answer in reduced form.
Perform the indicated operations. Express your answer in reduced form.

[``[$fraction]=``][$frac]***
[$frac]*

END_PGML

#:% section = answer
#: It is necessary to install the answer evaluator with `ANS`, since
#: It is necessary to use the answer evaluator `ANS` since
#: `ans_rule` was used to produce answer blanks.
ANS($multians->cmp());
# ANS($multians->cmp());

#:% section = solution
BEGIN_PGML_SOLUTION
Expand Down
7 changes: 5 additions & 2 deletions doc/sample-problems/Algebra/FunctionDecomposition.pg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'answerComposition.pl', 'PGcourse.pl');

#:% section = setup
#: We will ask the students for a function `f(u)` and and function `g(x)` such
#: that `f(g(x))` is a given function. Therefore, we need to make `u` a
#: variable and define `$f` and `$g`.
Context()->variables->add(u => 'Real');

$a = random(2, 9);
Expand All @@ -46,8 +49,8 @@ END_PGML

#:% section = answer
#: We use the `COMPOSITION_ANS()` routine to evaluate both answer blanks. It is
#: possible to use the same variable for both answer blanks. See PODLINK('answerComposition.pl')
#: for more options and details.
#: possible to use the same variable for both answer blanks. See
#: PODLINK('answerComposition.pl') for more options and details.
COMPOSITION_ANS($f, $g, vars => [ 'u', 'x' ], showVariableHints => 1);

#:% section = solution
Expand Down
2 changes: 1 addition & 1 deletion doc/sample-problems/Algebra/GraphToolCustomChecker.pg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#:% section = preamble
#: This example shows how to get student input in the form of a graph (a circle)
#: by using interactive graphing tools, and demonstrates the usage of a custom
#: checker. Load the parserGraphTool.pl macro for this.
#: checker. Load the `parserGraphTool.pl` macro for this.
DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
Expand Down
2 changes: 1 addition & 1 deletion doc/sample-problems/Algebra/GraphToolPoints.pg
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $gt = GraphTool("{point, ($x1, $y1)}", "{point, ($x2, $y2)}")->with(
showCoordinateHints => 0,
);

#:% section = statement.
#:% section = statement
#: The code `[_]{$gt}` inserts the GraphTool.
BEGIN_PGML
Graph the points [`([$x1], [$y1])`] and [`([$x2], [$y2])`].
Expand Down
9 changes: 3 additions & 6 deletions doc/sample-problems/Algebra/InequalityAnswer.pg
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ Context('Inequalities-Only');
Context()->flags->set(formatStudentAnswer => 'parsed');

$a = random(3, 9);

$ineq = "-$a x \leq 10"; # TeX

$answer = Compute("x >= -10 / $a");
$ans = Compute("x >= -10 / $a");

#:% section = statement
BEGIN_PGML
Solve the inequality [`\displaystyle [$ineq]`].
Solve the inequality [``-[$a]x \leq 10``].
Enter your answer using inequality notation.

[_]{$answer}{20}
[_]{$ans}

[@ helpLink('inequalities') @]*
END_PGML
Expand Down
3 changes: 2 additions & 1 deletion doc/sample-problems/Algebra/StringOrOtherType.pg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#:% type = Sample
#:% subject = [algebra, precalculus]
#:% categories = [strings]
#:% see_also = [StringsInContext.pg]

#:% section = preamble
DOCUMENT();
Expand All @@ -23,7 +24,7 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

#:% section = setup
#: There are several predefined strings, such as NONE, DNE, INF, INFINITY. If you
#: need another string added to the context, see strings in context.
#: need another string added to the context, see PROBLINK('StringsInContext.pg').
#:
#: When `$answer = Formula('2x')` and a student enters the string `NONE`, they will
#: not get any error message because when the answer checker expects a formula and
Expand Down
2 changes: 0 additions & 2 deletions doc/sample-problems/Algebra/UnorderedAnswers.pg
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ END_PGML
#: possible to withhold feedback and credit until everything is correct by using
#: the standard problem grader, which awards no partial credit and full credit
#: only when everything is correct.

$showPartialCorrectAnswers = 0;
install_problem_grader(~~&std_problem_grader);

UNORDERED_ANS($answer1->cmp, $answer2->cmp, $answer3->cmp);

Expand Down
68 changes: 68 additions & 0 deletions doc/sample-problems/Complex/ComplexOperations.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## DESCRIPTION
## This demonstrates basic operations with complex numbers.
## ENDDESCRIPTION

## DBsubject(WeBWorK)
## DBchapter(WeBWorK tutorial)
## DBsection(Problem Techniques)
## Date(06/01/2023)
## Institution(Fitchburg State University)
## Author(Peter Staab)
## MO(1)
## KEYWORDS('complex','addition','subtraction','absolute value')

#:% name = Basic Operations of Complex numbers
#:% type = [technique]
#:% subject = [complex]

#:% section = preamble
DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

#:% section = setup
#: To use complex numbers, we need to switch context with `Context('Complex')`.
#: There are many ways to create a complex number. Notice on the 4th one
#: `i` is defined and can be used naturally.
#:
#: Also, the standard operations go through as expected.
#: Notice that for the first two questions, we give the store the answer in
#: a variable.
Context('Complex');

$z0 = Complex(non_zero_random(-5,4), non_zero_random(-5,5));
$z1 = Complex([-1,4]);
$z2 = Complex("2-4i");
$z3 = 3-4*i;

$ans1 = $z0+$z1;
$a0 = non_zero_random(-4,4);
$a1 = random(1,5);
$ans2 = Compute("$a0*$z1-$a1*$z2");

#:% section = statement
#: Note that in the last three answer blanks, the correct answer is
#: in the `{}` instead of stored as a variable, like the first two.
#: Either method is correct and it varies on which to use.
#: Recall that the perl power `**` is used in the last one.
BEGIN_PGML
Let [`z_0=[$z0]`], [`z_1=[$z1]`], [`z_2=[$z2]`] and [`z_3=[$z3]`]. Find

[`z_0+z_1=`] [___]{$ans1}

[`[$a0]z_1-[$a1]z_2=`] [_____]{$ans2}

[`z_1z_2=`] [___]{$z1*$z2}

[``\frac{z_3}{z_0}= ``] [___]{$z3/$z0}

[`` z_2^2=``] [__]{$z2**2}
END_PGML

#:% section = solution
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION


ENDDOCUMENT();
77 changes: 77 additions & 0 deletions doc/sample-problems/Complex/LimitedComplex.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
## DESCRIPTION
## This shows the capabilities of the LimitedComplex context.
## ENDDESCRIPTION

## DBsubject(WeBWorK)
## DBchapter(WeBWorK tutorial)
## DBsection(Problem Techniques)
## Date(06/01/2023)
## Institution(Fitchburg State University)
## Author(Peter Staab)
## MO(1)
## KEYWORDS('complex','addition','subtraction','absolute value')

#:% name = Complex Numbers, Limited Input
#:% type = [technique]
#:% subject = [complex]

#:% section = preamble
#: This problems shows the capabilities of the `contextLimitedComplex.pl` macro
#: so it must be loaded.
DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'contextLimitedComplex.pl', 'PGcourse.pl');

#:% section = setup
#: If we ask students to do operations with complex numbers, often we don't
#: want those operations to be allowed in the answer. In this case we set the
#: `Context('LimitedComplex')`. If we define complex numbers, then perl operations
#: will be allowed, but not operations in `Compute` functions.
#:
#: `LimitedComplex` will allow a single number entered (technically only one
#: value of `i`) in either cartesian or polar form. This problem gives the
#: answer in polar to check that form.
#:
#: If you only want complex numbers to be entered in cartesian form you can use
#: `Context('LimitedComplex-cartesian')` and if you only want students to
#: enter numbers in polar form use `Context('LimitedComplex-polar')`.
Context('LimitedComplex');

$x0 = non_zero_random(-5,5);
$y0 = non_zero_random(-5,5);
$x1 = non_zero_random(-5,5);
$y1 = non_zero_random(-5,5);

$z0 = Complex($x0,$y0);
$z1 = Complex($x1,$y1);

$ans1 = $z0+$z1;
$ans2 = $z0*$z1;

# Determine the polar form of the answer to give a hint. Since in
# LimitedComplex, most functions are diasbled, so we work on the components.
$arg0 = atan($y0/$x0) + ($x0 > 0 ? ($y0>0 ? 0 : 2*pi): pi);
$arg1 = atan($y1/$x1) + ($x1 > 0 ? ($y1>0 ? 0 : 2*pi): pi);
$abs0 = sqrt($x0**2+$y0**2);
$abs1 = sqrt($x1**2+$y1**2);

#:% section = statement
BEGIN_PGML
Let [`z_0=[$z0]`] and [`z_1=[$z1]`]. Find

[`z_0+z_1=`] [___]{$ans1}

[`z_0z_1=`] [___]{$ans2}

You may not enter operations between numbers for these answers. However,
if you want the polar form (the second answer is [`[@ $abs0*$abs1 @] e^{[@ $arg0+$arg1 @]i}`])

END_PGML

#:% section = solution
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION


ENDDOCUMENT();
Loading

0 comments on commit 60a7446

Please sign in to comment.