openwebwork / pg

Problem rendering engine for WeBWorK
http://webwork.maa.org/wiki/Category:Authors
Other
45 stars 76 forks source link

answer array breaks other answers #603

Open Alex-Jordan opened 3 years ago

Alex-Jordan commented 3 years ago

Consider this problem code:

DOCUMENT();
loadMacros(  "PGstandard.pl",  "MathObjects.pl",  "PGML.pl");

Context("Vector");
$vector = Vector("<1,0,0>");

Context("Matrix");
$matrix = Matrix("[[1,0],[0,1]]");

BEGIN_PGML

a. What vector in [`\mathbb{R}^3`] is the unit vector along the [`x`]-axis?  
   [_]{$vector}{10}

a. What is the [`2\times2`] identity matrix?  
   [_]{$matrix}{10}

a. What vector in [`\mathbb{R}^3`] is the unit vector along the [`x`]-axis?  
   [_]*{$vector}{1}

a. What is the [`2\times2`] identity matrix?  
   [_]*{$matrix}{1}

END_PGML
ENDDOCUMENT();

When I submit the answers:

Screen Shot 2021-09-07 at 8 25 55 PM Screen Shot 2021-09-07 at 8 21 16 PM

Somehow the answers I submit to the first two answer fields are interpreted as first entries of the vector or matrix object instead of the entire vector or matrix.

If I remove the third and fourth questions that use an answer input array, then the first two answer blanks behave. Or if I just remove one of the last two questions, then the corresponding question from the first half behaves, but still not the other one.

It is as if using the answer input array is doing something to these mathobjects that persists longer than it should, and then later during an answer check, that breaks the answer checking.

drgrice1 commented 3 years ago

It seems that the ans_array method modifies the object used for the answer itself. If you use a different object for the two answers this problem does not occur. So if you change your code to the following this is not a problem:

DOCUMENT();

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

Context("Vector");
$vector1 = Vector("<1,0,0>");
$vector2 = Vector("<1,0,0>");

Context("Matrix");
$matrix1 = Matrix("[[1,0],[0,1]]");
$matrix2 = Matrix("[[1,0],[0,1]]");

BEGIN_PGML
a. What vector in [`\mathbb{R}^3`] is the unit vector along the [`x`]-axis?
   [_]{$vector1}{10}

a. What is the [`2\times2`] identity matrix?
   [_]{$matrix1}{10}

a. What vector in [`\mathbb{R}^3`] is the unit vector along the [`x`]-axis?
   [_]*{$vector2}{1}

a. What is the [`2\times2`] identity matrix?
   [_]*{$matrix2}{1}
END_PGML

ENDDOCUMENT();
Alex-Jordan commented 3 years ago

But should it be considered a bug that the ans_array method does that?

drdrew42 commented 3 years ago

It seems highly unlikely that the same Matrix would be used as an answer multiple times in the same problem -- so I'd say we look into fixing it, but it seems low priority?

drgrice1 commented 3 years ago

Yeah, I think it is a bug that should be fixed, but I agree that its priority is not high. For now, use a different answer object for this.

somiaj commented 2 years ago

I ran across this in one of my problems and was going to file an issue when I found this. My test case is slightly different, so here it is in case it can help track down the cause.

DOCUMENT();
loadMacros(
   "PGstandard.pl",
   "PGML.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

Context('Matrix');
$v1 = Matrix([[1],[2]]);

BEGIN_PGML

Enter in the two vector [``\vec{\bf v}_1=[$v1]``].

a) First Answer:

        [__]*{$v1}

b) Second Answer:

        [__]*{$v1}

END_PGML
ENDDOCUMENT();

In this case, what is entered in the second part of the ans_array gets used in both answers, but the first part isn't changed.

image