Trigonometric Identities

Trigonometric identities

Complete Code

Download file: TrigIdentities.pg

PG problem file

Explanation

DOCUMENT();

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

Preamble

These standard macros need to be loaded.
$ans = Compute('sin(x)')->cmp(
    checker => sub {
        my ($correct, $student, $ansHash) = @_;
        my $stu_ans = $student->reduce;
        Value->Error('There is a simpler answer')
            if $stu_ans->string eq 'cos(x)*tan(x)'
            || $stu_ans->string eq 'tan(x)*cos(x)';
        return $student == $correct ? 1 : 0;
    }
);

Setup

To prevent the student from just entering the given expression, a custom answer checker is used, which 1) calls reduce on the student answer which will do some small simplification, 2) returns an error if the original expression is entered and 3) then checks if the answer is correct.

A better method for doing this is demonstrated in Proving Identities. Don’t use the method demonstrated in this example as it will fail in many cases. A student can enter tan(x)*cos(x)*2/2 and it will be counted as correct because the reduce call does not simplify that to tan(x)*cos(x). Instead it reduces it to [2*tan(x)*cos(x)]/2. In general using string comparison is not what you should do with MathObjects. It completely subverts what MathObjects were designed to do.

BEGIN_PGML
Simplify the expression as much as possible.

[`\tan(x)\cos(x) =`] [_]{$ans}{15}
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.