public function test_stack_maxima_int_feedback_2()
 {
     $at = new stack_answertest_general_cas('((5*%e^7*x-%e^7)*%e^(5*x))', '((5*%e^7*x-%e^7)*%e^(5*x))/25+c', 'ATInt', true, '[x,x*%e^(5*x+7)]', null, true, true);
     $this->assertFalse($at->do_test());
     $this->assertEquals(0, $at->get_at_mark());
     $fbt = 'stack_trans(\'ATInt_generic\' , !quot!\\[x\\cdot e^{5\\cdot x+7}\\]!quot!  , !quot!\\(x\\)!quot!  , ' . '!quot!\\[5\\cdot e^{5\\cdot x+7}+5\\cdot \\left(5\\cdot e^7\\cdot x-e^7\\right) \\cdot e^{5\\cdot x}\\]!quot! );';
     $this->assertEquals($fbt, $at->get_at_feedback());
     $fbt = 'The derivative of your answer should be equal to the expression that you were asked to integrate, that was: ' . '\\[x\\cdot e^{5\\cdot x+7}\\]  In fact, the derivative of your answer, with respect to \\(x\\) is: ' . '\\[5\\cdot e^{5\\cdot x+7}+5\\cdot \\left(5\\cdot e^7\\cdot x-e^7\\right) \\cdot e^{5\\cdot x}\\] ' . 'so you must have done something wrong!';
     $this->assertEquals($fbt, stack_maxima_translate($at->get_at_feedback()));
 }
 public static function run_test($test)
 {
     // Note: What we would really like to do is the following.
     // $el = stack_input_factory::make('algebraic', 'sans1', 'x');
     // $el->set_parameter('insertStars', 1);
     // $el->set_parameter('strictSyntax', false);
     // $el->set_parameter('sameType', false);
     // $cs = $el->validate_student_response($test->rawstring);
     // However, we want to pull apart the bits to expose where the various errors occur.
     $cs = new stack_cas_casstring($test->rawstring);
     $cs->get_valid('s', false, 1);
     $cs->set_cas_validation_casstring('sans1', true, true, false, null);
     $phpvalid = $cs->get_valid();
     if ($phpvalid) {
         // Trim off stack_validate_typeless([..], true, true).
         $phpcasstring = $cs->get_casstring();
         $phpcasstring = substr($phpcasstring, 25);
         $phpcasstring = substr($phpcasstring, 0, strlen($phpcasstring) - 12);
         $outputphpcasstring = $phpcasstring;
     } else {
         $phpcasstring = '';
         $outputphpcasstring = 'N/A...';
     }
     $errors = $cs->get_errors();
     $passed = true;
     if ('php_true' === $test->phpvalid) {
         $expected = true;
     } else {
         $expected = false;
     }
     if ($phpvalid != $expected) {
         $passed = false;
         $errors .= ' ' . stack_string('phpvalidatemismatch');
     }
     if ($phpvalid && $phpcasstring != $test->phpcasstring) {
         $passed = false;
         $errors .= ' ' . stack_maxima_format_casstring($phpcasstring) . ' \\(\\neq \\) ' . stack_maxima_format_casstring($test->phpcasstring);
     }
     $casvalid = '';
     $caserrors = '';
     $casvalue = '';
     $casdisplay = '';
     if ($cs->get_valid()) {
         $options = new stack_options();
         $options->set_option('simplify', false);
         $session = new stack_cas_session(array($cs), $options, 0);
         $session->instantiate();
         $session = $session->get_session();
         $cs = $session[0];
         $caserrors = stack_maxima_translate($cs->get_errors());
         $casvalue = stack_maxima_format_casstring($cs->get_value());
         if ('cas_true' == $test->casvalid) {
             $casexpected = true;
         } else {
             $casexpected = false;
         }
         if ('' == $cs->get_value()) {
             $casvalid = false;
         } else {
             $casvalid = true;
         }
         if ($casexpected != $casvalid) {
             $passed = false;
             $caserrors .= ' ' . stack_string('casvalidatemismatch');
         }
         $casdisplay = $cs->get_display();
     }
     $answernote = $cs->get_answernote();
     if ($answernote != $test->ansnotes) {
         $passed = false;
         $errors .= ' ' . stack_string('ansnotemismatch');
     }
     return array($passed, $phpvalid, $phpcasstring, $errors, $casvalid, $caserrors, $casdisplay, $casvalue, $answernote);
 }
 /**
  * Validate any attempts at this question.
  *
  * @param array $response the student response to the question.
  * @param stack_options $options CAS options to use when validating.
  * @param string $teacheranswer the teachers answer as a string representation of the evaluated expression.
  * @return stack_input_state represents the current state of the input.
  */
 public function validate_student_response($response, $options, $teacheranswer, $forbiddenkeys)
 {
     if (!is_a($options, 'stack_options')) {
         throw new stack_exception('stack_input: validate_student_response: options not of class stack_options');
     }
     $localoptions = clone $options;
     // The validation field should always come back through as a single RAW Maxima expression for each input.
     if (array_key_exists($this->name . '_val', $response)) {
         $validator = $response[$this->name . '_val'];
     } else {
         $validator = '';
     }
     $contents = $this->response_to_contents($response);
     if (array() == $contents or $this->is_blank_response($contents)) {
         return new stack_input_state(self::BLANK, array(), '', '', '', '', '');
     }
     // This method actually validates any CAS strings etc.
     list($valid, $errors, $modifiedcontents) = $this->validate_contents($contents, $forbiddenkeys);
     // If we can't get a "displayed value" back from the CAS, show the student their original expression.
     $display = stack_maxima_format_casstring($this->contents_to_maxima($contents));
     $interpretedanswer = $this->contents_to_maxima($modifiedcontents);
     $answer = new stack_cas_casstring($interpretedanswer);
     $lvarsdisp = '';
     // Send the string to the CAS.
     if ($valid) {
         if (!$this->get_parameter('sameType')) {
             $teacheranswer = null;
         }
         $singlevarchars = false;
         if (2 == $this->get_parameter('insertStars', 0)) {
             $singlevarchars = true;
         }
         // Generate an expression from which we extract the list of variables in the student's answer.
         $lvars = new stack_cas_casstring('ev(listofvars(' . $interpretedanswer . '),simp)');
         $lvars->get_valid('t', $this->get_parameter('strictSyntax', true), $this->get_parameter('insertStars', 0), $this->get_parameter('allowWords', ''));
         $answer->set_cas_validation_casstring($this->name, $this->get_parameter('forbidFloats', false), $this->get_parameter('lowestTerms', false), $singlevarchars, $teacheranswer, $this->get_parameter('allowWords', ''));
         $localoptions->set_option('simplify', false);
         $session = new stack_cas_session(array($answer, $lvars), $localoptions, 0);
         $session->instantiate();
         $session = $session->get_session();
         $answer = $session[0];
         $lvars = $session[1];
         $errors = stack_maxima_translate($answer->get_errors());
         if ('' != $errors) {
             $valid = false;
         }
         if ('' == $answer->get_value()) {
             $valid = false;
         } else {
             $display = '\\[ ' . $answer->get_display() . ' \\]';
             $interpretedanswer = $answer->get_value();
             if (!($lvars->get_value() == '[]')) {
                 $lvarsdisp = '\\( ' . $lvars->get_display() . '\\) ';
             }
         }
     }
     $note = $answer->get_answernote();
     // Answers may not contain the ? character.  CAS-strings may, but answers may not.
     // It is very useful for teachers to be able to add in syntax hints.
     if (!(strpos($interpretedanswer, '?') === false)) {
         $valid = false;
         $errors .= stack_string('qm_error');
     }
     if (!$valid) {
         $status = self::INVALID;
     } else {
         if ($this->get_parameter('mustVerify', true) && $validator != $this->contents_to_maxima($contents)) {
             $status = self::VALID;
         } else {
             $status = self::SCORE;
         }
     }
     return new stack_input_state($status, $contents, $interpretedanswer, $display, $errors, $note, $lvarsdisp);
 }
 /**
  *
  *
  * @return string
  * @access public
  */
 public function get_at_feedback()
 {
     return stack_maxima_translate($this->at->get_at_feedback());
 }