WeBWorK Main Forum

multianswer typechecking and point promotion to vectors

multianswer typechecking and point promotion to vectors

by Gavin LaRose -
Number of replies: 2
I'm considering something like the following.
DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
);

Context("Vector");
# Context()->flags->set( promotePoints => 1 );

$v = Vector("<1,1,1>");
$zchk = MultiAnswer( $v, -$v )->with(
  singleResult => 0,
  # checkTypes => 0,
  checker => sub {
    my ( $cor, $stu, $self ) = @_;
    warn( "in checker" );
    @ret = ( 0, 0 );
    $ret[0] = ( $v->isParallel($stu->[0]) );
    $ret[1] = ( $stu->[0] != $stu->[1] && $v->isParallel($stu->[1]) );
    return [@ret];
} );

Context()->texStrings;
BEGIN_TEXT
Enter two vectors paralell to \(\vec v = $v\). $BR
\( \vec z_1 = \) \{ $zchk->ans_rule(25) \} $BR
\( \vec z_2 = \) \{ $zchk->ans_rule(25) \}
END_TEXT
Context()->normalStrings;

ANS( $zchk->cmp() );
ENDDOCUMENT();

It appears that the checker is not checking student answers given as points (that is, (1,1,1) instead of <1,1,1>). I've tried adding the promotePoints flag to the Context, as suggested by the commented out line, and setting checkTypes=>0, also as suggested. However, with or without these when I enter an answer in point format the warn in the checker doesn't fire, and I get the informational message "Your answer isn't a vector (it looks like a point)."

Any help clarifying why this is would be welcome. This is on WeBWorK 2.13, installed late August.

Thanks,
Gavin

In reply to Gavin LaRose

Re: multianswer typechecking and point promotion to vectors

by Davide Cervone -
You are on the right track, but the problem is that promotePoints is not a context flag, it is an answer-checker flag. Normally, you would use something like
ANS($ans->cmp(promotePoints => 1));
but unfortunately, the MultiAnswer object doesn't pass the flags on to the individual checkers, so you can't do that if $ans is a MultiAnswer object.

Instead, you have to set the default cmp flags for the desired MathObject type, as in

Context()->{cmpDefaults}{Vector}{promotePoints} = 1;
This, together with checkTypes => 0 should do the trick. Note that even with checkTypes => 0, the standard type checking is performed (so you will get a warning if you enter a number rather than a vector or point, for example). That means you will only get something that you could normally compare to a Vector. Unfortunately, that does mean you could get one of the context strings (like NONE or DNE), since you don't usually want those to cause an error message. So you still do need to do a type check of your own to make sure you have a point or vector.

So I'd recommend the following:

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "parserMultiAnswer.pl",
);

Context("Vector");
Context()->{cmpDefaults}{Vector}{promotePoints} = 1;

$v = Vector("");
$zchk = MultiAnswer($v, -$v)->with(
  singleResult => 0,
  checkTypes => 0,
  checker => sub {
    my ($cor, $stu, $self) = @_;
    @ret = (0, 0);
    $ret[0] = $v->isParallel($stu->[0]) if $stu->[0]->classMatch("Vector","Point");
    $ret[1] = $stu->[0] != $stu->[1] && $v->isParallel($stu->[1])
        if $stu->[1]->classMatch("Vector","Point");
    return @ret;
});

Context()->texStrings;
BEGIN_TEXT
Enter two vectors paralell to \(\vec v = $v\). $BR
\( \vec z_1 = \) \{ $zchk->ans_rule(25) \} $BR
\( \vec z_2 = \) \{ $zchk->ans_rule(25) \}
END_TEXT
Context()->normalStrings;

ANS($zchk->cmp);

ENDDOCUMENT();
In reply to Davide Cervone

Re: multianswer typechecking and point promotion to vectors

by Gavin LaRose -
Perfect. As one would expect, that works like a charm. Thanks, Davide.