{"id":3651,"date":"2015-09-14T17:56:27","date_gmt":"2015-09-14T08:56:27","guid":{"rendered":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=3651"},"modified":"2016-10-17T08:17:29","modified_gmt":"2016-10-17T08:17:29","slug":"stack3-3-3%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=3651","title":{"rendered":"STACK3.3.3\u3092\u5229\u7528\u3059\u308b"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>ubuntu14.04 \u3067 STACK 3.3.3 \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u307f\u305f\u3089\u3001\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002maxima\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092ubuntu14.04\u306e\u3082\u306e\u3088\u308a\u4e0a\u3052\u308b\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u3067\u3001maxima 5.36.0 \u306b\u4e0a\u3052\u308b\u3068\u3001STACK\u304c\u6b63\u5e38\u306b\u52d5\u304d\u307e\u3057\u305f\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u65b0\u3057\u3044 maxima \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u306f\u3001\u4ee5\u524d\u306b\u66f8\u3044\u305f \u6570\u5f0f\u81ea\u52d5\u63a1\u70b9\u7528\u306e\u30b3\u30fc\u30c9\uff08STACK \u306e\u30b3\u30fc\u30c9\u3092\u5229\u7528\u3057\u3066\u3044\u308b\uff09\u304c\u52d5\u4f5c\u3057\u306a\u3044\u3053\u3068\u304c\u6700\u8fd1\u5206\u304b\u308a\u307e\u3057\u305f\u3002\u3064\u307e\u308a\u3001\u6b21\u306e ubuntu \uff08\u591a\u5206 ubuntu 16.04\uff09\u3067\u306f\u3001maxima \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c 5.36.0 \u4ee5\u4e0a\u3068\u306a\u308b\u306e\u3067\u3001\u73fe\u5728\u306e\u81ea\u52d5\u63a1\u70b9\u306e\u30b3\u30fc\u30c9\u304c\u52d5\u4f5c\u3057\u306a\u304f\u306a\u308a\u305d\u3046\u3067\u3059\u3002maxima \u306e\u4ed5\u69d8\u306b\u5de6\u53f3\u3055\u308c\u308b\u306e\u306f\u3001\u3053\u306e\u5148\u304b\u306a\u308a\u5384\u4ecb\u3067\u3059\u304c\u3001\u3068\u306b\u304b\u304f\u5bfe\u5fdc\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u4ee5\u4e0b\u3001\u4f5c\u696d\u3092\u8a18\u9332\u3057\u307e\u3059\u3002 maxima 5.360 \u306f\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002\u305d\u3046\u3059\u308b\u3068\u3001maxima\u306e\u5834\u6240\u304c\u5909\u66f4\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u307e\u3067 \/usr\/bin\/maxima\u3060\u3063\u305f\u306e\u304c\uff0c \/usr\/local\/bin\/maxima\u306b\u306a\u308a\u307e\u3059\u3002\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u4e0a\u3052\u3066\u4e0a\u624b\u304f\u884c\u3063\u305f\u7406\u7531\u306b\u306f\u3001LISP\u306e\u9055\u3044\u3082\u3042\u308b\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/healthcheck1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3774\" title=\"healthcheck1\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/healthcheck1-300x263.png\" alt=\"\" width=\"300\" height=\"263\" \/><\/a><\/p>\n<p>\u4e0a\u56f3\u306e\u3088\u3046\u306a\u3001STACK \u306e\u52d5\u4f5c\u78ba\u8a8d\u3092\u3059\u308b\u30da\u30fc\u30b8\u304c\u3042\u308a\u307e\u3059\u3002moodle\/question\/type\/stack\/healthcheck.php \u304c\u4f5c\u6210\u3057\u3066\u3044\u308b\u30da\u30fc\u30b8\u3067\u3059\u3002\u3053\u308c\u306e\u4e2d\u7a0b\u306b\u300cCAS\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u307e\u305b\u3093\u300d\u3068\u66f8\u304b\u308c\u305f\u3068\u3053\u308d\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/healthcheck2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3775\" title=\"healthcheck2\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/healthcheck2-300x263.png\" alt=\"\" width=\"300\" height=\"263\" \/><\/a><\/p>\n<p>\u305d\u306e\u5185\u5bb9\u306f\u30b3\u30fc\u30c9\u4e2d\u306e\u4e0b\u8a18\u306e\u7b87\u6240\u304c\u95a2\u9023\u3057\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\/\/ Test an *uncached* call to the CAS.\u00a0 I.e. a genuine call to the process.<\/span><br \/>\n<span style=\"color: #666699;\"> echo $OUTPUT-&gt;heading(stack_string(&#8216;healthuncached&#8217;), 3);<\/span><br \/>\n<span style=\"color: #666699;\"> echo html_writer::tag(&#8216;p&#8217;, stack_string(&#8216;healthuncachedintro&#8217;));<\/span><br \/>\n<span style=\"color: #666699;\"> list($message, $genuinedebug, $result) = stack_connection_helper::stackmaxima_genuine_connect();<\/span><br \/>\n<span style=\"color: #666699;\"> $summary[] = array($result, $message);<\/span><br \/>\n<span style=\"color: #666699;\"> echo html_writer::tag(&#8216;p&#8217;, $message);<\/span><br \/>\n<span style=\"color: #666699;\"> echo output_debug(stack_string(&#8216;debuginfo&#8217;), $genuinedebug);<\/span><br \/>\n<span style=\"color: #666699;\"> $genuinecascall = $result;<\/span><\/p>\n<p>\u3053\u306e\u4e2d\u3067\u3001 stack_connection_helper \u306f\u3001\u5b9a\u7fa9\u304c\u00a0connectorhelper.class.php \u306b\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u3046\u3061\u3001 stackmaxima_genuine_connect() \u3092\u4e0b\u8a18\u306b\u629c\u304d\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\u00a0\/**<\/span><br \/>\n<span style=\"color: #666699;\"> * Really exectue a CAS command, regardless of the cache settings.<\/span><br \/>\n<span style=\"color: #666699;\"> *\/<\/span><br \/>\n<span style=\"color: #666699;\"> public static function stackmaxima_genuine_connect() {<\/span><br \/>\n<span style=\"color: #666699;\"> self::ensure_config_loaded();<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\/\/ Put something non-trivial in the call.<\/span><br \/>\n<span style=\"color: #666699;\"> $date = date(&#8220;Y-m-d H:i:s&#8221;);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$command = &#8216;cab:block([],print(&#8220;[TimeStamp= [ 0 ], Locals= [ 0=[ error= [&#8220;), &#8216; .<\/span><br \/>\n<span style=\"color: #666699;\"> &#8216;cte(&#8220;CASresult&#8221;,errcatch(diff(x^n,x))), print(&#8220;1=[ error= [&#8220;), &#8216; .<\/span><br \/>\n<span style=\"color: #666699;\"> &#8216;cte(&#8220;STACKversion&#8221;,errcatch(stackmaximaversion)), print(&#8220;2=[ error= [&#8220;), &#8216; .<\/span><br \/>\n<span style=\"color: #666699;\"> &#8216;cte(&#8220;MAXIMAversion&#8221;,errcatch(MAXIMA_VERSION)), print(&#8220;3=[ error= [&#8220;), &#8216; .<\/span><br \/>\n<span style=\"color: #666699;\"> &#8216;cte(&#8220;CAStime&#8221;,errcatch(CAStime:&#8221;&#8216;.$date.'&#8221;)), print(&#8220;] ]&#8221;), return(true));&#8217; .<\/span><br \/>\n<span style=\"color: #666699;\"> &#8220;\\n&#8221;;<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\/\/ Really make sure there is no cache.<\/span><br \/>\n<span style=\"color: #666699;\"> list($results, $debug) = self::stackmaxima_nocache_call($command);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$success = true;<\/span><br \/>\n<span style=\"color: #666699;\"> $message = &#8221;;<\/span><br \/>\n<span style=\"color: #666699;\"> if (empty($results)) {<\/span><br \/>\n<span style=\"color: #666699;\"> $message = stack_string(&#8216;stackCas_allFailed&#8217;);<\/span><br \/>\n<span style=\"color: #666699;\"> $success = false;<\/span><br \/>\n<span style=\"color: #666699;\"> } else {<\/span><br \/>\n<span style=\"color: #666699;\"> foreach ($results as $result) {<\/span><br \/>\n<span style=\"color: #666699;\"> if (&#8216;CASresult&#8217; === $result[&#8216;key&#8217;]) {<\/span><br \/>\n<span style=\"color: #666699;\"> if ($result[&#8216;value&#8217;] != &#8216;n*x^(n-1)&#8217;) {<\/span><br \/>\n<span style=\"color: #666699;\"> $success = false;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> } else if (&#8216;CAStime&#8217; === $result[&#8216;key&#8217;]) {<\/span><br \/>\n<span style=\"color: #666699;\"> if ($result[&#8216;value&#8217;] != &#8216;&#8221;&#8216;.$date.'&#8221;&#8216;) {<\/span><br \/>\n<span style=\"color: #666699;\"> $success = false;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> } else if (&#8216;STACKversion&#8217; !== $result[&#8216;key&#8217;] &amp;&amp; &#8216;MAXIMAversion&#8217; !== $result[&#8216;key&#8217;]) {<\/span><br \/>\n<span style=\"color: #666699;\"> $success = false;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if ($success) {<\/span><br \/>\n<span style=\"color: #666699;\"> $message = stack_string(&#8216;healthuncachedstack_CAS_ok&#8217;);<\/span><br \/>\n<span style=\"color: #666699;\"> } else {<\/span><br \/>\n<span style=\"color: #666699;\"> $message .= stack_string(&#8216;healthuncachedstack_CAS_not&#8217;);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">return array($message, $debug, $success);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p>\u00a0$command \u3068\u3044\u3046\u5909\u6570\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u4e2d\u8eab\u306f Maxima \u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002\u3053\u306e\u5185\u5bb9\u3092\u8a08\u7b97\u3057\u3066\u753b\u9762\u306b\u51fa\u529b\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p><span style=\"color: #3366ff;\">\uff08 cte() \u95a2\u6570\u306f\u3001stackmaxima.mac \u306e\u4e2d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002errcatch() \u95a2\u6570\u306f Maxima \u306e\u95a2\u6570\u3067\u3001\u30ab\u30c3\u30b3\u5185\u306e\u5f0f\u3092\u9806\u306b\u8a55\u4fa1\u3057\u3066\u3001\u3082\u3057\u30a8\u30e9\u30fc\u304c\u751f\u3058\u306a\u3051\u308c\u3070\u7d50\u679c\u306e\u30ea\u30b9\u30c8\u3092\u8fd4\u3057\u3001\u9014\u4e2d\u3067\u30a8\u30e9\u30fc\u304c\u751f\u3058\u305f\u3089\u7a7a\u306e\u30ea\u30b9\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002cte() \u95a2\u6570\u306e\u4e2d\u8eab\u306f\u4e0b\u8a18\u3002<\/span><\/p>\n<p style=\"padding-left: 30px;\">\/* This function executes ex, which is assumed to be a stack expression\u00a0 *\/<br \/>\n\/* which is surrounded by errcatch.\u00a0 Hence we end up with a list.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *\/<br \/>\ncte(var,ex) := block([str],<br \/>\nprint(&#8220;], key= [&#8220;),<br \/>\nprint(var),<br \/>\nprint(&#8220;]&#8221;),<br \/>\nif ex = [] then block(<br \/>\nex:STACKERROR,<br \/>\nprint(&#8220;, value = [], display = []&#8221;)<br \/>\n)<br \/>\nelse block(<br \/>\nprint(&#8220;, value = [&#8220;),<br \/>\nprint(string(ex[1])),<br \/>\nprint(&#8220;], display = [&#8220;),<br \/>\nprint(StackDISP(ex[1], &#8220;&#8221;)),<br \/>\nprint(&#8220;]&#8221;),<br \/>\nex:ex[1]<br \/>\n),<br \/>\nprint(&#8220;], &#8220;),<br \/>\nreturn(ex)<br \/>\n)$<\/p>\n<p><span style=\"color: #3366ff;\">\uff09<\/span><\/p>\n<p>\u3053\u3053\u304b\u3089\u6b21\u306b\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u3067<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\/\/ Really make sure there is no cache.<\/span><br \/>\n<span style=\"color: #666699;\"> list($results, $debug) = self::stackmaxima_nocache_call($command);<\/span><\/p>\n<p>\u304a\u306a\u3058\u30af\u30e9\u30b9\u5185\u306e stackmaxima_nocache_call($command) \u306b\u79fb\u308a\u307e\u3059\u3002\u3059\u3050\u4e0a\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5185\u5bb9\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\u00a0\/**<\/span><br \/>\n<span style=\"color: #666699;\"> * Exectue a CAS command, without any caching.<\/span><br \/>\n<span style=\"color: #666699;\"> *\/<\/span><br \/>\n<span style=\"color: #666699;\"> private static function stackmaxima_nocache_call($command) {<\/span><br \/>\n<span style=\"color: #666699;\"> self::ensure_config_loaded();<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$configcache = self::$config-&gt;casresultscache;<\/span><br \/>\n<span style=\"color: #666699;\"> $casdebugging = self::$config-&gt;casdebugging;<\/span><br \/>\n<span style=\"color: #666699;\"> self::$config-&gt;casresultscache = &#8216;none&#8217;;<\/span><br \/>\n<span style=\"color: #666699;\"> self::$config-&gt;casdebugging = true;<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$connection = self::make();<\/span><br \/>\n<span style=\"color: #666699;\"> $results = $connection-&gt;compute($command);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">self::$config-&gt;casresultscache = $configcache;<\/span><br \/>\n<span style=\"color: #666699;\"> self::$config-&gt;casdebugging = $casdebugging;<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$debug = $connection-&gt;get_debuginfo();<\/span><br \/>\n<span style=\"color: #666699;\"> return array($results, $debug);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p>\u3053\u3053\u304b\u3089\u3001 compute($command) \u304c\u547c\u3073\u51fa\u3055\u308c\u3066\u3001\u3053\u308c\u306e\u5b9a\u7fa9\u306f connector.class.php \u306b\u3042\u3063\u3066\u3001\u4e0b\u8a18\u306e\u5185\u5bb9\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\u00a0\/* @see stack_cas_connection::compute() *\/<\/span><br \/>\n<span style=\"color: #666699;\"> public function compute($command) {<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$context = &#8220;Platform: &#8220;. stack_connection_helper::get_platform() . &#8220;\\n&#8221;;<\/span><br \/>\n<span style=\"color: #666699;\"> $context .= &#8220;Maxima shell command: &#8220;. $this-&gt;command . &#8220;\\n&#8221;;;<\/span><br \/>\n<span style=\"color: #666699;\"> $context .= &#8220;Maxima initial command: &#8220;. $this-&gt;initcommand . &#8220;\\n&#8221;;<\/span><br \/>\n<span style=\"color: #666699;\"> $context .= &#8220;Maxima timeout: &#8220;. $this-&gt;timeout;<\/span><br \/>\n<span style=\"color: #666699;\"> $this-&gt;debug-&gt;log(&#8216;Context used&#8217;, $context);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$this-&gt;debug-&gt;log(&#8216;Maxima command&#8217;, $command);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$rawresult = $this-&gt;call_maxima($command);<\/span><br \/>\n<span style=\"color: #666699;\"> $this-&gt;debug-&gt;log(&#8216;CAS result&#8217;, $rawresult);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$unpackedresult = $this-&gt;unpack_raw_result($rawresult);<\/span><br \/>\n<span style=\"color: #666699;\"> $this-&gt;debug-&gt;log(&#8216;Unpacked result as&#8217;, print_r($unpackedresult, true));<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if (!stack_connection_helper::check_stackmaxima_version($unpackedresult)) {<\/span><br \/>\n<span style=\"color: #666699;\"> stack_connection_helper::warn_about_version_mismatch($this-&gt;debug);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">return $unpackedresult;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p>\u305d\u308c\u3089\u3057\u3044\u3001\u6587\u5b57\u5217\u304c\u4e26\u3093\u3067\u3044\u307e\u3059\u3002\u753b\u9762\u306b\u51fa\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u3068\u540c\u3058\u3067\u3059\u3002\u305d\u306e\u5f8c\u3001\u3053\u308c\u81ea\u8eab\u306e call_maxima($command) \u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u5b9f\u969b\u306e\u4e2d\u8eab\u306f connector.unix.class.php \u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u5185\u5bb9\u3092\u4e0b\u8a18\u306b\u3042\u3052\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">\u00a0\/* @see stack_cas_connection_base::call_maxima() *\/<\/span><br \/>\n<span style=\"color: #666699;\"> protected function call_maxima($command) {<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$ret = false;<\/span><br \/>\n<span style=\"color: #666699;\"> $err = &#8221;;<\/span><br \/>\n<span style=\"color: #666699;\"> $cwd = null;<\/span><br \/>\n<span style=\"color: #666699;\"> $env = array(&#8216;why&#8217; =&gt; &#8216;itworks&#8217;);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$descriptors = array(<\/span><br \/>\n<span style=\"color: #666699;\"> 0 =&gt; array(&#8216;pipe&#8217;, &#8216;r&#8217;),<\/span><br \/>\n<span style=\"color: #666699;\"> 1 =&gt; array(&#8216;pipe&#8217;, &#8216;w&#8217;),<\/span><br \/>\n<span style=\"color: #666699;\"> 2 =&gt; array(&#8216;pipe&#8217;, &#8216;w&#8217;));<\/span><br \/>\n<span style=\"color: #666699;\"> $casprocess = proc_open($this-&gt;command, $descriptors, $pipes, $cwd, $env);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if (!is_resource($casprocess)) {<\/span><br \/>\n<span style=\"color: #666699;\"> throw new stack_exception(&#8216;stack_cas_connection: could not open a CAS process&#8217;);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if (!fwrite($pipes[0], $this-&gt;initcommand)) {<\/span><br \/>\n<span style=\"color: #666699;\"> throw new stack_exception(&#8216;stack_cas_connection: could not write to the CAS process.&#8217;);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> fwrite($pipes[0], $command);<\/span><br \/>\n<span style=\"color: #666699;\"> fwrite($pipes[0], &#8216;quit();&#8217;.&#8221;\\n\\n&#8221;);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$ret = &#8221;;<\/span><br \/>\n<span style=\"color: #666699;\"> \/\/ Read output from stdout.<\/span><br \/>\n<span style=\"color: #666699;\"> $starttime = microtime(true);<\/span><br \/>\n<span style=\"color: #666699;\"> $continue\u00a0\u00a0 = true;<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if (!stream_set_blocking($pipes[1], false)) {<\/span><br \/>\n<span style=\"color: #666699;\"> $this-&gt;debug-&gt;log(&#8221;, &#8216;Warning: could not stream_set_blocking to be FALSE on the CAS process.&#8217;);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">while ($continue and !feof($pipes[1])) {<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$now = microtime(true);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if (($now &#8211; $starttime) &gt; $this-&gt;timeout) {<\/span><br \/>\n<span style=\"color: #666699;\"> $procarray = proc_get_status($casprocess);<\/span><br \/>\n<span style=\"color: #666699;\"> if ($procarray[&#8216;running&#8217;]) {<\/span><br \/>\n<span style=\"color: #666699;\"> proc_terminate($casprocess);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> $continue = false;<\/span><br \/>\n<span style=\"color: #666699;\"> } else {<\/span><br \/>\n<span style=\"color: #666699;\"> $out = fread($pipes[1], 1024);<\/span><br \/>\n<span style=\"color: #666699;\"> if (&#8221; == $out) {<\/span><br \/>\n<span style=\"color: #666699;\"> \/\/ Pause.<\/span><br \/>\n<span style=\"color: #666699;\"> usleep(1000);<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> $ret .= $out;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">}<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">if ($continue) {<\/span><br \/>\n<span style=\"color: #666699;\"> fclose($pipes[0]);<\/span><br \/>\n<span style=\"color: #666699;\"> fclose($pipes[1]);<\/span><br \/>\n<span style=\"color: #666699;\"> $this-&gt;debug-&gt;log(&#8216;Timings&#8217;, &#8220;Start: {$starttime}, End: {$now}, Taken = &#8221; .<\/span><br \/>\n<span style=\"color: #666699;\"> ($now &#8211; $starttime));<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">} else {<\/span><br \/>\n<span style=\"color: #666699;\"> \/\/ Add sufficient closing ]&#8217;s to allow something to be un-parsed from the CAS.<\/span><br \/>\n<span style=\"color: #666699;\"> \/\/ WARNING: the string &#8216;The CAS timed out&#8217; is used by the cache to search for a timeout occurrence.<\/span><br \/>\n<span style=\"color: #666699;\"> $ret .= &#8216; The CAS timed out. ] ] ] ]&#8217;;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">return $ret;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p>proc_open($this-&gt;command, $descriptors, $pipes, $cwd, $env) \u304c Maxima \u3092\u8d77\u52d5\u3057\u3066\u3001\u30b3\u30de\u30f3\u30c9\u3092\u53d7\u3051\u4ed8\u3051\u308b\u72b6\u614b\u306b\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\uff08proc_open \u306f php \u306e\u30b3\u30de\u30f3\u30c9\uff09\u3002\u305d\u306e\u4e2d\u306b\u3001\u4e00\u90e8 if \u6587\u306b\u57cb\u3082\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">fwrite($pipes[0], $this-&gt;initcommand)<\/span><br \/>\n<span style=\"color: #666699;\"> fwrite($pipes[0], $command)<\/span><br \/>\n<span style=\"color: #666699;\"> fwrite($pipes[0], &#8216;quit();&#8217;.&#8221;\\n\\n&#8221;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>$pipes[0] \u3068\u306f\u3001\u5148\u306b\u8d77\u52d5\u3057\u3066\u958b\u3044\u305f Maxima \u306e\u30d1\u30a4\u30d7\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u304c Maxima \u306b\u547d\u4ee4\u3092\u9001\u3063\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002\u5185\u5bb9\u3092\u30e2\u30cb\u30bf\u30fc\u3057\u3066\u307f\u308b\u3068\u3001$this-&gt;initcommand \u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067 moodledata\/stackmaximalocal.mac \u3092\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3057\u305f\u3002<\/p>\n<pre style=\"padding-left: 30px;\" dir=\"ltr\"><span style=\"color: #cc0000;\">load(\"\/var\/www\/moodledata\/stack\/maximalocal.mac\"); <\/span><\/pre>\n<p>\u6b21\u306e $command \u306f\u5148\u306e cab:block([],\u00a0 . . . \u3000\u3067\u59cb\u307e\u308b Maxima \u306e\u30b3\u30de\u30f3\u30c9\u3067\u3059\u3002\u6700\u5f8c\u306f\u30d1\u30a4\u30d7\u3092\u9589\u3058\u3066\u3044\u307e\u3059\u3002\u4f9d\u3063\u3066\u3001\u7aef\u672b\u304b\u3089 Maxima \u3092\u8d77\u52d5\u3057\u3066\u3001\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3092 Maxima \u306b\u9001\u308a\u8fbc\u3080\u3068\u540c\u3058\u51fa\u529b\u304c\u5f97\u3089\u308c\u307e\u3059(\u30c0\u30d6\u30eb\u30af\u30aa\u30fc\u30c8\u304c\u5909\u306a\u6587\u5b57\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u4fee\u6b63\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059)\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">load(&#8220;\/var\/www\/moodledata\/stack\/maximalocal.mac&#8221;);<\/span><br \/>\n<span style=\"color: #666699;\"> cab:block([],print(&#8220;[TimeStamp= [ 0 ], Locals= [ 0=[ error= [&#8220;), cte(&#8220;CASresult&#8221;,errcatch(diff(x^n,x))), print(&#8220;1=[ error= [&#8220;), cte(&#8220;STACKversion&#8221;,errcatch(stackmaximaversion)), print(&#8220;2=[ error= [&#8220;), cte(&#8220;MAXIMAversion&#8221;,errcatch(MAXIMA_VERSION)), print(&#8220;3=[ error= [&#8220;), cte(&#8220;CAStime&#8221;,errcatch(CAStime:&#8221;2015-10-01 17:03:01&#8243;)), print(&#8220;] ]&#8221;), return(true));<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\u51fa\u529b\u306f\u4e0b\u8a18\u3002\u9577\u3059\u304e\u3066\u5165\u308a\u304d\u3063\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3796\" title=\"term3\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term3-184x300.png\" alt=\"\" width=\"184\" height=\"300\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>cab:block([],\u00a0 . . . \u3000\u3067\u59cb\u307e\u308b\u30b3\u30de\u30f3\u30c9\u306f\u30c7\u30fc\u30bf\u30fc\u30d9\u30fc\u30b9\u306b\u8a18\u9332\u3055\u308c\u3066\u3044\u307e\u3059\u3002<code> mdl_qtype_stack_cas_cache <\/code>\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb\u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u3092\u691c\u7d22\u3057\u3066\u3001\u8a72\u5f53\u306e\u3082\u306e\u304c\u3042\u308c\u3070\u3001\u51e6\u7406\u305b\u305a\u306b\u8fd4\u4e8b\u3092\u8fd4\u3059\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001cab:block([],\u00a0 . . . \u3000\u3067\u59cb\u307e\u308b\u30b3\u30de\u30f3\u30c9\u306e\u4f5c\u6210\u306e\u3068\u3053\u308d\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/algequiv.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3659\" title=\"algequiv\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/algequiv-300x194.png\" alt=\"\" width=\"300\" height=\"194\" \/><\/a><\/p>\n<p>\u4e0a\u56f3\u306f\u3001\u8a55\u4fa1\u95a2\u6570\u306e\u52d5\u4f5c\u3092\u8a66\u3059\u30da\u30fc\u30b8\u3067\u3001 moodle\/question\/type\/stack\/answertests.php \u304c\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u30b3\u30fc\u30c9\u304b\u3089\u305f\u3069\u3063\u3066\u307f\u307e\u3059\u3002\u4e0b\u8a18\u304c\u8a55\u4fa1\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u7b87\u6240\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">list($passed, $error, $rawmark, $feedback, $ansnote) = stack_answertest_test_data::run_test($test);<\/span><\/p>\n<p>\u3053\u306e stack_answertest_test_data \u30af\u30e9\u30b9\u306e\u5b9a\u7fa9\u304c answertestfixtures.class.php \u306b\u3042\u3063\u3066\u3001run_test \u306e\u4e2d\u3067\u3001\u3055\u3089\u306b<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$anst = new stack_ans_test_controller($test-&gt;name, $test-&gt;studentanswer,<\/span><br \/>\n<span style=\"color: #666699;\"> $test-&gt;teacheranswer, new stack_options(), $test-&gt;options);<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$result\u00a0\u00a0 = $anst-&gt;do_test();<\/span><\/p>\n<p>$test \u3068\u3044\u3046\u306e\u304c\u30011\u500b1\u500b\u306e\u8a55\u4fa1\u30c6\u30b9\u30c8\u306e\u6750\u6599\u3067\u3001answertestfixtures.class.php \u81ea\u8eab\u306b\u5024\u304c\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">array(&#8216;AlgEquiv&#8217;, &#8216;x-1&#8217;, &#8216;(x^2-1)\/(x+1)&#8217;, 1, &#8221;, &#8221;)<\/span><\/p>\n<p>\u3053\u306e\u5024\u3092\u5143\u306b\u3057\u3066\u3001\u5148\u306e cab:block([],\u00a0 . . . \u3000\u3067\u59cb\u307e\u308b\u30b3\u30de\u30f3\u30c9\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>stack_ans_test_controller \u30af\u30e9\u30b9\u306e\u5b9a\u7fa9\u304c\u3001controller.class.php \u306b\u3042\u3063\u3066\u3001\u521d\u671f\u5316\u306b\u304a\u3044\u3066\u4e0b\u8a18\u306e\u30af\u30e9\u30b9\u304c\u5f15\u7528\u3055\u308c\u3066\u3001<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$this-&gt;at = new stack_answertest_general_cas($sans, $tans, &#8216;ATAlgEquiv&#8217;, false, $casoption, $options);<\/span><\/p>\n<p>do_test \u306b\u304a\u3044\u3066\u3001<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">public function do_test() {<\/span><br \/>\n<span style=\"color: #666699;\"> $result = $this-&gt;at-&gt;do_test();<\/span><br \/>\n<span style=\"color: #666699;\"> return $result;<\/span><br \/>\n<span style=\"color: #666699;\"> }<\/span><\/p>\n<p>\u4f9d\u3063\u3066\u3001\u6b21\u306b stack_answertest_general_cas \u30af\u30e9\u30b9\u3067\u3059\u304c\u3001\u3053\u308c\u306f at_general_cas.class.php \u306b\u3042\u3063\u3066\u3001 do_test \u306b\u304a\u3044\u3066<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$session = new stack_cas_session($cts, $this-&gt;options, 0);<\/span><\/p>\n<p>\u3053\u306e\u5f15\u6570\u306b\u3042\u308b $cts \u306e\u4e2d\u8eab\u306f\u3001\u8981\u7d203\u500b\u306e\u914d\u5217\u3067\u3001\u305d\u308c\u305e\u308c <em>stack_cas_casstring<\/em> \u3068\u3044\u3046\u30af\u30e9\u30b9\u3067\u3001\u4f8b\u3048\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5185\u5bb9\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\">array (size=3)<br \/>\n0 =&gt;<br \/>\nobject(stack_cas_casstring)[910]<br \/>\nprivate &#8216;rawcasstring&#8217; =&gt; string &#8216;STACKSA:1\/0&#8217; (length=11)<br \/>\nprivate &#8216;casstring&#8217; =&gt; string &#8216;1\/0&#8217; (length=3)<br \/>\nprivate &#8216;valid&#8217; =&gt; boolean true<br \/>\nprivate &#8216;key&#8217; =&gt; string &#8216;STACKSA&#8217; (length=7)<br \/>\nprivate &#8216;errors&#8217; =&gt; null<br \/>\nprivate &#8216;value&#8217; =&gt; null<br \/>\nprivate &#8216;display&#8217; =&gt; null<br \/>\nprivate &#8216;answernote&#8217; =&gt;<br \/>\narray (size=0)<br \/>\nempty<br \/>\nprivate &#8216;feedback&#8217; =&gt; null<br \/>\n1 =&gt;<br \/>\nobject(stack_cas_casstring)[913]<br \/>\nprivate &#8216;rawcasstring&#8217; =&gt; string &#8216;STACKTA:0&#8217; (length=9)<br \/>\nprivate &#8216;casstring&#8217; =&gt; string &#8216;0&#8217; (length=1)<br \/>\nprivate &#8216;valid&#8217; =&gt; boolean true<br \/>\nprivate &#8216;key&#8217; =&gt; string &#8216;STACKTA&#8217; (length=7)<br \/>\nprivate &#8216;errors&#8217; =&gt; null<br \/>\nprivate &#8216;value&#8217; =&gt; null<br \/>\nprivate &#8216;display&#8217; =&gt; null<br \/>\nprivate &#8216;answernote&#8217; =&gt;<br \/>\narray (size=0)<br \/>\nempty<br \/>\nprivate &#8216;feedback&#8217; =&gt; null<br \/>\n2 =&gt;<br \/>\nobject(stack_cas_casstring)[914]<br \/>\nprivate &#8216;rawcasstring&#8217; =&gt; string &#8216;result:StackReturn(ATEqualComAss(STACKSA,STACKTA))&#8217; (length=50)<br \/>\nprivate &#8216;casstring&#8217; =&gt; string &#8216;StackReturn(ATEqualComAss(STACKSA,STACKTA))&#8217; (length=43)<br \/>\nprivate &#8216;valid&#8217; =&gt; boolean true<br \/>\nprivate &#8216;key&#8217; =&gt; string &#8216;result&#8217; (length=6)<br \/>\nprivate &#8216;errors&#8217; =&gt; null<br \/>\nprivate &#8216;value&#8217; =&gt; null<br \/>\nprivate &#8216;display&#8217; =&gt; null<br \/>\nprivate &#8216;answernote&#8217; =&gt;<br \/>\narray (size=0)<br \/>\nempty<br \/>\nprivate &#8216;feedback&#8217; =&gt; null<\/p>\n<p>\u305d\u308c\u305e\u308c\u3001\u5b66\u751f\u306e\u89e3\u7b54\u3001\u5148\u751f\u306e\u6e96\u5099\u3057\u305f\u7b54\u3048\u3001STACK\u306e\u8fd4\u4e8b\uff1f\u306b\u95a2\u3059\u308b\u3082\u306e\u306e\u3088\u3046\u3067\u3059\u3002$this-&gt;options \u306e\u4e2d\u8eab\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3057\u305f\u3002<\/p>\n<p style=\"padding-left: 30px;\">object(stack_options)[912]<br \/>\nprivate &#8216;options&#8217; =&gt;<br \/>\narray (size=9)<br \/>\n&#8216;display&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;list&#8217; (length=4)<br \/>\n&#8216;value&#8217; =&gt; string &#8216;LaTeX&#8217; (length=5)<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=3)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;OPT_OUTPUT&#8217; (length=10)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;string&#8217; (length=6)<br \/>\n&#8216;multiplicationsign&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;list&#8217; (length=4)<br \/>\n&#8216;value&#8217; =&gt; string &#8216;dot&#8217; (length=3)<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=3)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;make_multsgn&#8217; (length=12)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;fun&#8217; (length=3)<br \/>\n&#8216;complexno&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;list&#8217; (length=4)<br \/>\n&#8216;value&#8217; =&gt; string &#8216;i&#8217; (length=1)<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=4)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;make_complexJ&#8217; (length=13)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;fun&#8217; (length=3)<br \/>\n&#8216;inversetrig&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;list&#8217; (length=4)<br \/>\n&#8216;value&#8217; =&gt; string &#8216;cos-1&#8217; (length=5)<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=3)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;make_arccos&#8217; (length=11)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;fun&#8217; (length=3)<br \/>\n&#8216;floats&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;boolean&#8217; (length=7)<br \/>\n&#8216;value&#8217; =&gt; int 1<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=0)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;OPT_NoFloats&#8217; (length=12)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;ex&#8217; (length=2)<br \/>\n&#8216;sqrtsign&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;boolean&#8217; (length=7)<br \/>\n&#8216;value&#8217; =&gt; boolean true<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=0)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;sqrtdispflag&#8217; (length=12)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;ex&#8217; (length=2)<br \/>\n&#8216;simplify&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;boolean&#8217; (length=7)<br \/>\n&#8216;value&#8217; =&gt; boolean false<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=0)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;simp&#8217; (length=4)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;ex&#8217; (length=2)<br \/>\n&#8216;assumepos&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;boolean&#8217; (length=7)<br \/>\n&#8216;value&#8217; =&gt; boolean false<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=0)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;assume_pos&#8217; (length=10)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;ex&#8217; (length=2)<br \/>\n&#8216;matrixparens&#8217; =&gt;<br \/>\narray (size=6)<br \/>\n&#8216;type&#8217; =&gt; string &#8216;list&#8217; (length=4)<br \/>\n&#8216;value&#8217; =&gt; string &#8216;[&#8216; (length=1)<br \/>\n&#8216;strict&#8217; =&gt; boolean true<br \/>\n&#8216;values&#8217; =&gt;<br \/>\narray (size=5)<br \/>\n&#8230;<br \/>\n&#8216;caskey&#8217; =&gt; string &#8216;lmxchar&#8217; (length=7)<br \/>\n&#8216;castype&#8217; =&gt; string &#8216;exs&#8217; (length=3)<\/p>\n<p>STACK \u306e\u30bb\u30c3\u30c6\u30a3\u30f3\u30b0\u306b\u95a2\u3059\u308b\u3082\u306e\u306e\u3088\u3046\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u30da\u30fc\u30b8\u306e\u4e0b\u65b9\u3067\u8a2d\u5b9a\u3059\u308b\u5185\u5bb9\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/setting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3832\" title=\"setting\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/setting-300x263.png\" alt=\"\" width=\"300\" height=\"263\" \/><\/a><\/p>\n<p>\u4e0a\u8a18\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u306e\u8a2d\u5b9a\u306b\u95a2\u9023\u3059\u308b\u3082\u306e\u306f\u3001\/var\/www\/html\/moodle\/question\/type\/stack\/settings.php \u3084 \/var\/www\/html\/moodle\/question\/type\/stack\/stack\/options.class.php \u3067\u3059\u3002\u3053\u306e\u8fba\u306f\u5f8c\u3067\u307e\u305f\u5229\u7528\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u8a71\u3092<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #666699;\">$session = new stack_cas_session($cts, $this-&gt;options, 0);<\/span><\/p>\n<p>\u306b\u623b\u3057\u307e\u3059\u3002\u3082\u3046\u5c11\u3057\u5f15\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">$session = new stack_cas_session($cts, $this-&gt;options, 0);\r\n$session-&gt;instantiate();\r\n$this-&gt;debuginfo = $session-&gt;get_debuginfo();\r\n<\/code><\/pre>\n<p>stack_cas_session \u306f cassession.class.php \u306b\u5b9a\u7fa9\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u305f\u5f8c\uff0cinstantiate()\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\uff0c\u3053\u306einstantiate()\u306e\u4e2d\u3092\u898b\u308b\u3068\uff0c<\/p>\n<pre><code style=\"color:midnightblue;\">$connection = stack_connection_helper::make();\r\n$results = $connection-&gt;compute($this-&gt;construct_maxima_command());\r\n$this-&gt;debuginfo = $connection-&gt;get_debuginfo();\r\n<\/code><\/pre>\n<p>\u3053\u306e\u4e2d\u306b\u3042\u308b\u3001construct_maxima_command()\u306e\u5185\u5bb9\u306f\u4e0b\u8a18\u3067\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">private function construct_maxima_command() {\r\n\/\/ Ensure that every command has a valid key.\r\n\r\n$casoptions = $this-&gt;options-&gt;get_cas_commands();\r\n\r\n$csnames = $casoptions['names'];\r\n$csvars = $casoptions['commands'];\r\n$cascommands = '';\r\n$caspreamble = '';\r\n\r\n$cascommands .= ', print(\"-1=[ error= [\"), cte(\"__stackmaximaversion\",errcatch(__stackmaximaversion:stackmaximaversion)) ';\r\n\r\n$i = 0;\r\nforeach ($this-&gt;session as $cs) {\r\nif ('' == $cs-&gt;get_key()) {\r\n$label = 'dumvar'.$i;\r\n} else {\r\n$label = $cs-&gt;get_key();\r\n}\r\n\r\n\/\/ Replace any ?'s with a safe value.\r\n$cmd = str_replace('?', 'QMCHAR', $cs-&gt;get_casstring());\r\n\/\/ Strip off any []s at the end of a variable name.\r\n\/\/ These are used to assign elements of lists and matrices, but this breaks Maxima's block command.\r\nif (false === strpos($label, '[')) {\r\n$cleanlabel = $label;\r\n} else {\r\n$cleanlabel = substr($label, 0, strpos($label, '['));\r\n}\r\n\r\n\/\/ Now we do special things if we have a command to re-order expressions.\r\nif (false !== strpos($cmd, 'ordergreat') || false !== strpos($cmd, 'orderless')) {\r\n\/\/ These commands must be in a separate block, and must only appear once.\r\n$caspreamble = $cmd.\"$\\n\";\r\n$cmd = '0';\r\n}\r\n\r\n$csnames .= \", $cleanlabel\";\r\n$cascommands .= \", print(\\\"$i=[ error= [\\\"), cte(\\\"$label\\\",errcatch($label:$cmd)) \";\r\n$i++;\r\n\r\n}\r\n\r\n$cass = $caspreamble;\r\n$cass .= 'cab:block([ RANDOM_SEED';\r\n$cass .= $csnames;\r\n$cass .= '], stack_randseed(';\r\n$cass .= $this-&gt;seed.')'.$csvars;\r\n$cass .= \", print(\\\"[TimeStamp= [ $this-&gt;seed ], Locals= [ \\\") \";\r\n$cass .= $cascommands;\r\n$cass .= \", print(\\\"] ]\\\") , return(true) ); \\n \";\r\n\r\nreturn $cass;\r\n}\r\n<\/code><\/pre>\n<p>\u3053\u3053\u3067\u3001Maxima \u306e\u30b3\u30de\u30f3\u30c9\u304c\u7d44\u307f\u7acb\u3066\u3089\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u4ee5\u4e0b\u3001\u7e70\u308a\u8fd4\u3057\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u306e\u4e2d\u3067\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u5909\u6570\u306a\u3069\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002\u307e\u305a\u3001\u6700\u521d\u306e\u65b9\u306e\u3001<\/p>\n<p><span style=\"color: #666699;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $casoptions = $this-&gt;options-&gt;get_cas_commands();<\/span><br \/>\n<span style=\"color: #666699;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $csnames = $casoptions[&#8216;names&#8217;];<\/span><br \/>\n<span style=\"color: #666699;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $csvars\u00a0 = $casoptions[&#8216;commands&#8217;];<\/span><\/p>\n<p>$csnames \u306e\u5185\u5bb9\u306f\u3001\u4f8b\u3048\u3070<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #000000;\">, OPT_NoFloats, sqrtdispflag, simp, assume_pos, lmxchar<\/span><\/p>\n<p>$csvars \u306e\u5185\u5bb9\u306f<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #000000;\">, make_multsgn(&#8220;dot&#8221;), make_complexJ(&#8220;i&#8221;), make_arccos(&#8220;cos-1&#8221;), OPT_NoFloats:true, sqrtdispflag:true, simp:false, assume_pos:false, lmxchar:&#8221;[&#8220;<\/span><\/p>\n<p>\u3067\u3059\u3002\u3053\u308c\u306f options.class.php \u3067\u4f5c\u3089\u308c\u308b\u3082\u306e\u3067\u3001$this-&gt;options \u3068\u306f stack_options \u30af\u30e9\u30b9\u3067\u3059\u3002\u3053\u308c\u306f\u7c21\u5358\u306b\u5229\u7528\u3067\u304d\u305d\u3046\u3067\u3001\u554f\u984c\u306a\u3057\u3002<\/p>\n<p>\u6b21\u306b\u3001\u30eb\u30fc\u30d7\u306b\u306a\u3063\u3066\u3044\u308b\u90e8\u5206\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e<\/p>\n<p><span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $i = 0;<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 foreach ($this-&gt;session as $cs) {<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (&#8221; == $cs-&gt;get_key()) {<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $label = &#8216;dumvar&#8217;.$i;<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } else {<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $label = $cs-&gt;get_key();<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Replace any ?&#8217;s with a safe value.<\/span><br \/>\n<span style=\"color: #333399;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $cmd = str_replace(&#8216;?&#8217;, &#8216;QMCHAR&#8217;, $cs-&gt;get_casstring());<\/span><\/p>\n<p>\u3053\u306e\u4e2d\u306e $this-&gt;session \u3067\u3059\u304c\u3001\u305d\u3053\u304b\u3089\u53d6\u308a\u51fa\u3057\u305f $cs \u306b\u95a2\u3059\u308b $cs-&gt;get_key() \u306e\u5024\u306f\u3001&#8221;STACKSA&#8221; \u3084 &#8220;STACKTA&#8221; \u3084 &#8220;result&#8221; \u3067\u3059\u3002\u3064\u307e\u308a\u3001\u3053\u306e $this-&gt;session \u306f\u3001at_general_cas.class.php \u306e do_test \u306b\u304a\u3044\u3066 \u4f5c\u3089\u308c\u308b $cts \u3067\u3059\uff08$cs \u306f <em>stack_cas_casstring<\/em> \u30af\u30e9\u30b9\uff09\u3002\u3053\u306e $cts \u306b\u76f8\u5f53\u3059\u308b\u3082\u306e\u306f\u3001\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ed6\u3001\u3053\u306e construct_maxima_command() \u306e\u4e2d\u3067\u3001\u554f\u984c\u306b\u306a\u308a\u305d\u3046\u306a\u5909\u6570\u306f\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u307e\u3059\u3002<\/p>\n<p>\u8a71\u3092 at_general_cas.class.php \u306e do_test() \u307e\u3067\u623b\u3057\u307e\u3059\u3002\u3068\u308a\u3042\u3048\u305a do_test() \u3092\u5168\u90e8\u4e0b\u8a18\u306b\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/**\r\n*\r\n*\r\n* @return bool\r\n* @access public\r\n*\/\r\npublic function do_test() {\r\n\r\nif ('' == trim($this-&gt;sanskey)) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptySA\")));\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptySA\")));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'TEST_FAILED:Empty SA.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\nif ('' == trim($this-&gt;tanskey)) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptyTA\")));\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptyTA\")));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'TEST_FAILED:Empty TA.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\nif ($this-&gt;processcasoptions) {\r\nif (null == $this-&gt;atoption or '' == $this-&gt;atoption) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_MissingOptions\")));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = 'STACKERROR_OPTION.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n} else {\r\n\/\/ Validate with teacher privileges, strict syntax &amp; no automatically adding stars.\r\n$ct\u00a0 = new stack_cas_casstring($this-&gt;atoption);\r\n\r\nif (!$ct-&gt;get_valid('t', true, 1)) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; ''));\r\n$this-&gt;atfeedback\u00a0 .= stack_string('AT_InvalidOptions', array('errors' =&gt; $ct-&gt;get_errors()));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = 'STACKERROR_OPTION.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n}\r\n$atopt = $this-&gt;atoption;\r\n$ta\u00a0\u00a0 = \"[$this-&gt;tanskey,$atopt]\";\r\n} else {\r\n$ta = $this-&gt;tanskey;\r\n}\r\n\r\n\/\/ Sort out options.\r\nif (null === $this-&gt;options) {\r\n$this-&gt;options = new stack_options();\r\n}\r\nif (!(null === $this-&gt;simp)) {\r\n$this-&gt;options-&gt;set_option('simplify', $this-&gt;simp);\r\n}\r\n\r\n$cascommands = array();\r\n$cascommands[] = \"STACKSA:$this-&gt;sanskey\";\r\n$cascommands[] = \"STACKTA:$ta\";\r\n$cascommands[] = \"result:StackReturn({$this-&gt;casfunction}(STACKSA,STACKTA))\";\r\n\r\n$cts = array();\r\nforeach ($cascommands as $com) {\r\n$cs\u00a0\u00a0\u00a0 = new stack_cas_casstring($com);\r\n$cs-&gt;get_valid('t', true, 0);\r\n$cts[] = $cs;\r\n}\r\n\r\n$session = new stack_cas_session($cts, $this-&gt;options, 0);\r\n$session-&gt;instantiate();\r\n$this-&gt;debuginfo = $session-&gt;get_debuginfo();\r\n\r\nif ('' != $session-&gt;get_errors_key('STACKSA')) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; $session-&gt;get_errors_key('STACKSA')));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'_STACKERROR_SAns.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\nif ('' != $session-&gt;get_errors_key('STACKTA')) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; $session-&gt;get_errors_key('STACKTA')));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'_STACKERROR_TAns.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\n$sessionvars = $session-&gt;get_session();\r\n$result = $sessionvars[2];\r\n\r\nif ('' != $result-&gt;get_errors()) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\nif ('' != trim($result-&gt;get_feedback())) {\r\n$this-&gt;atfeedback = $result-&gt;get_feedback();\r\n} else {\r\n$this-&gt;atfeedback = stack_string('TEST_FAILED', array('errors' =&gt; $result-&gt;get_errors()));\r\n}\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = trim($result-&gt;get_answernote());\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\n$this-&gt;atansnote\u00a0 = trim($result-&gt;get_answernote());\r\n\r\n\/\/ Convert the Maxima string 'true' to PHP true.\r\nif ('true' == $result-&gt;get_value()) {\r\n$this-&gt;atmark = 1;\r\n} else {\r\n$this-&gt;atmark = 0;\r\n}\r\n$this-&gt;atfeedback = $result-&gt;get_feedback();\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0 = $result-&gt;get_valid();\r\n\r\nif ($this-&gt;atmark) {\r\nreturn true;\r\n} else {\r\nreturn false;\r\n}\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>stack_string() \u306f locallib.php \u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u3066\u3001\u629c\u304d\u51fa\u3059\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/**\r\n* Equivalent to get_string($key, 'qtype_stack', $a), but this method ensure that\r\n* any equations in the string are displayed properly.\r\n* @param string $key the string name.\r\n* @param mixed $a (optional) any values to interpolate into the string.\r\n* @return string the language string\r\n*\/\r\nfunction stack_string($key, $a = null) {\r\nreturn stack_maths::process_lang_string(get_string($key, 'qtype_stack', $a));\r\n}\r\n\r\n<\/code><\/pre>\n<p>\u57fa\u672c\u7684\u306b\u306f\u3001moodle \u306e get_string() \u95a2\u6570\u3067\u3059\u3002\u3053\u308c\u306f\u7279\u5b9a\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8fd4\u3059\u3082\u306e\u3067\u3001\u305d\u306e\u8fd4\u3059\u5185\u5bb9\u306f\u4e0b\u8a18\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\/var\/www\/html\/moodle\/question\/type\/stack\/lang\/en\/qtype_stack.php<\/p>\n<p>\u3053\u306e\u65e5\u672c\u8a9e\u7248\u304c\u3001moodledata\/lang\/ja\/qtype_stack.php \u306b\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u66f8\u304d\u63db\u3048\u308b\u306e\u306f\u5bb9\u6613\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001$ct\u00a0 = new stack_cas_casstring($this-&gt;atoption); \u306a\u3069\u306b\u3042\u308b stack_cas_casstring() \u306f\u5384\u4ecb\u3067\u3059\u3002\u3053\u306e\u5b9a\u7fa9\u306f casstring.class.php \u306b\u3042\u308a\u307e\u3059\u3002 \u305d\u306e\u5185\u5bb9\u306f\u3001\u5b66\u751f\u3084\u6559\u5e2b\u306e\u89e3\u7b54\u3084\u6b63\u89e3\u306e\u5185\u5bb9\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3082\u306e\u306e\u3088\u3046\u3067\u3059\u3002\u5229\u7528\u3057\u305f\u3044\u5185\u5bb9\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u52d5\u304b\u3059\u306b\u306f\u95a2\u9023\u3059\u308b\u30b3\u30fc\u30c9\u304c\u591a\u304f\u3066\u304b\u306a\u308a\u5927\u5909\u3067\u3059\u3002\u3086\u304f\u3086\u304f\u306f\u5229\u7528\u3059\u308b\u3068\u3057\u3066\u3001\u4eca\u56de\u306f\u3053\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30fc\u95a2\u4fc2\u306e\u6a5f\u80fd\u3092\u30ab\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u9577\u304f\u306a\u308a\u307e\u3059\u304c maxima \u306b\u9001\u308b\u30b3\u30de\u30f3\u30c9\u3092\u7d44\u307f\u7acb\u3066\u308b php \u3092\u4e0b\u8a18\u306b\u6319\u3052\u307e\u3059\u3002casstring.class.php \u3068\u00a0options.class.php \u3082\u542b\u3081\u305fzip \u30d5\u30a1\u30a4\u30eb\u306f<span style=\"color: #0000ff;\"><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/command.zip\"><span style=\"color: #0000ff;\">\u3053\u3053<\/span><\/a><\/span>\u3067\u3059\u3002\u3053\u306e2\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u591a\u5c11\u66f8\u304d\u63db\u3048\u307e\u3057\u305f\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">&lt;?php\r\n\r\nrequire_once('casstring.class.php');\r\n\r\nrequire_once('options.class.php');\r\n\r\n\/\/ \u4e0b\u8a18\u306e\u30c7\u30fc\u30bf\u306f answertestfixtures.class.php \u304b\u3089\r\n\r\n\/\/$rawdata = array('AlgEquiv', 'a^b*a^c', 'a^(b+c)', 1, '', '');\r\n\r\n\/\/$rawdata = array('AlgEquiv', 'integerp(3.1)', 'true', 0, '', '');\r\n\r\n\/\/$rawdata = array('AlgEquiv', 'abs(x)', 'sqrt(x^2)', 1, '', '');\r\n\r\n\/\/$rawdata = array('EqualComAss', '2\/4', '1\/2', 0, '', 'Numbers');\r\n\r\n$rawdata = array('FacForm', '24*(x-1\/4)', '24*x-6', 1, 'x', 'Factors over other fields');\r\n\r\n$test = new stdClass();\r\n$test-&gt;name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $rawdata[0];\r\n$test-&gt;studentanswer = $rawdata[1];\r\n$test-&gt;teacheranswer = $rawdata[2];\r\n$test-&gt;expectedscore = $rawdata[3];\r\n$test-&gt;options\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $rawdata[4];\r\n$test-&gt;notes\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $rawdata[5];\r\n\r\n$options = null;\r\n$expectedscore = $test-&gt;expectedscore;\r\n$seed = 0;\r\n$notes = $test-&gt;notes;\r\n\r\n$param = ATconstruct($test-&gt;name, $test-&gt;studentanswer, $test-&gt;teacheranswer, $test-&gt;options, $options);\r\n\r\n$sanskey = $param-&gt;sans;\r\n$tanskey = $param-&gt;tans;\r\n$casfunction = $param-&gt;casfunction;\r\n$processcasoptions = $param-&gt;processcasoptions;\r\n$options = $param-&gt;options;\r\n$casoption = $param-&gt;casoption;\r\n$simp = $param-&gt;simp;\r\n$requiredoptions = $param-&gt;requiredoptions;\r\n\r\nif ($processcasoptions) {\r\n$ta\u00a0\u00a0 = \"[$tanskey,$casoption]\";\r\n} else {\r\n$ta = $tanskey;\r\n}\r\n\r\n\/\/ Sort out options.\r\n\r\nif (null === $options) {\r\n$options = new stack_options();\r\n}\r\n\r\nif (!(null === $simp)) {\r\n$options-&gt;set_option('simplify', $simp);\r\n}\r\n\r\n$cascommands = array();\r\n$cascommands[] = \"STACKSA:$sanskey\";\r\n$cascommands[] = \"STACKTA:$ta\";\r\n$cascommands[] = \"result:StackReturn({$casfunction}(STACKSA,STACKTA))\";\r\n\r\n$keys = array();\r\n$keys[] = \"STACKSA\";\r\n$keys[] = \"STACKTA\";\r\n$keys[] = \"result\";\r\n\r\n$casstring = array();\r\n$casstring[] = $sanskey;\r\n$casstring[] = $ta;\r\n$casstring[] = \"StackReturn({$casfunction}(STACKSA,STACKTA))\";\r\n\r\n$cts = array();\r\n$i = 0;\r\n\r\nforeach ($cascommands as $com) {\r\n\r\n$cs\u00a0\u00a0\u00a0 = new stack_cas_casstring($com);\r\n\r\n\/\/$cs-&gt;get_valid('t', true, 0); \/\/ \u3053\u306e\u6a5f\u80fd\u306f\u524a\u9664\u3057\u305f\r\n\r\n$cs-&gt;set_key($keys[$i]);\r\n\r\n$cs-&gt;set_casstring($casstring[$i]);\r\n\r\n$cts[] = $cs;\r\n\r\n$i++;\r\n}\r\n\r\n$str = construct_maxima_command($cts, $options, $seed);\r\n\r\necho $str.\"\\n\";\r\n\r\nfunction ATconstruct($anstest = null, $sans = null, $tans = null, $casoption = null, $options = null) {\r\n\r\n\/\/ ($anstest = null, $sans = null, $tans = null, $options = null, $casoption = null)\r\n\r\nswitch($anstest) {\r\ncase 'AlgEquiv':\r\nreturn new parameter_constract($sans, $tans, 'ATAlgEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\n\/\/ \u4fee\u6b63\u3057\u305f\u3068\u3053\u308d Dimension \u7528\u306e\u90e8\u5206\r\n\r\ncase 'Dimension':\r\nreturn new parameter_constract($sans, $tans, 'ATAlgEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'EqualComAss':\r\nreturn new parameter_constract($sans, $tans, 'ATEqualComAss', false, $casoption, $options, false);\r\nbreak;\r\n\r\ncase 'CasEqual':\r\nreturn new parameter_constract($sans, $tans, 'ATCASEqual', false, $casoption, $options, false);\r\nbreak;\r\n\r\ncase 'SameType':\r\nreturn new parameter_constract($sans, $tans, 'ATSameType', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'SubstEquiv':\r\nreturn new parameter_constract($sans, $tans, 'ATSubstEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'Expanded':\r\nreturn new parameter_constract($sans, $tans, 'ATExpanded', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'FacForm':\r\nreturn new parameter_constract($sans, $tans, 'ATFacForm', true, $casoption, $options, false, true);\r\nbreak;\r\n\r\ncase 'SingleFrac':\r\nreturn new parameter_constract($sans, $tans, 'ATSingleFrac', false, $casoption, $options, false);\r\nbreak;\r\n\r\ncase 'PartFrac':\r\nreturn new parameter_constract($sans, $tans, 'ATPartFrac',\r\ntrue, $casoption, $options, true, false, true);\r\nbreak;\r\n\r\ncase 'CompSquare':\r\nreturn new parameter_constract($sans, $tans, 'ATCompSquare',\r\ntrue, $casoption, $options, true, false, true);\r\nbreak;\r\n\r\ncase 'String':\r\n\/\/require_once(__DIR__ . '\/atstring.class.php');\r\n\/\/return new stack_anstest_atstring($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'StringSloppy':\r\n\/\/require_once(__DIR__ . '\/stringsloppy.class.php');\r\n\/\/return new stack_anstest_stringsloppy($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'RegExp':\r\n\/\/require_once(__DIR__ . '\/atregexp.class.php');\r\n\/\/return new stack_anstest_atregexp($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'Diff':\r\nreturn new parameter_constract($sans, $tans, 'ATDiff', true, $casoption, $options, false, true);\r\nbreak;\r\n\r\ncase 'Int':\r\nreturn new parameter_constract($sans, $tans, 'ATInt', true, $casoption, $options, false, true);\r\nbreak;\r\n\r\ncase 'GT':\r\nreturn new parameter_constract($sans, $tans, 'ATGT', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'GTE':\r\nreturn new parameter_constract($sans, $tans, 'ATGTE', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'NumAbsolute':\r\nif (trim($casoption) == '') {\r\n$casoption = '0.05';\r\n}\r\nreturn new parameter_constract($sans, $tans, 'ATNumAbsolute', true, $casoption, $options, true, true);\r\nbreak;\r\n\r\ncase 'NumRelative':\r\nif (trim($casoption) == '') {\r\n$casoption = '0.05';\r\n}\r\nreturn new parameter_constract($sans, $tans, 'ATNumRelative', true, $casoption, $options, true, true);\r\nbreak;\r\n\r\ncase 'NumSigFigs':\r\nreturn new parameter_constract($sans, $tans, 'ATNumSigFigs', true, $casoption, $options, true, true);\r\nbreak;\r\n\r\ncase 'NumDecPlaces':\r\n\/\/require_once(__DIR__ . '\/atdecplaces.class.php');\r\n\/\/$this-&gt;at = new stack_anstest_atdecplaces($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'LowestTerms':\r\nreturn new parameter_constract($sans, $tans, 'ATLowestTerms', false, $casoption, $options, 0);\r\nbreak;\r\n\r\ncase 'SysEquiv':\r\nreturn new parameter_constract($sans, $tans, 'ATSysEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\ndefault:\r\nreturn 'stack_ans_test_controller: called with invalid answer test name: '.$anstest;\r\nbreak;\r\n}\r\n}\r\n\r\n\/\/ \u5143\u306f\u3001class stack_answertest_general_cas\r\n\r\nclass parameter_constract {\r\n\r\npublic $sans;\r\npublic $tans;\r\n\r\n\/**\r\n* @var string The name of the cas function this answer test uses.\r\n*\/\r\npublic $casfunction;\r\n\r\n\/**\r\n* $var bool Are options processed by the CAS.\r\n*\/\r\npublic $processcasoptions;\r\n\r\npublic $casoption;\r\npublic $options;\r\n\r\n\/**\r\n* $var bool If this variable is set to true or false we override the\r\n*\u00a0\u00a0\u00a0\u00a0\u00a0 simplification options in the CAS variables.\r\n*\/\r\npublic $simp;\r\n\r\n\/**\r\n* $var bool Are options required for this test.\r\n*\/\r\npublic $requiredoptions;\r\n\r\n\/**\r\n* @param\u00a0 string $sans\r\n* @param\u00a0 string $tans\r\n* @param\u00a0 string $casoption\r\n*\/\r\npublic function __construct($sans, $tans, $casfunction, $processcasoptions = false, $casoption = null, $options = null, $simp = false, $requiredoptions = false) {\r\n\r\n$this-&gt;sans\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $sans;\r\n$this-&gt;tans\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $tans;\r\n\r\n$this-&gt;casfunction\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $casfunction;\r\n$this-&gt;processcasoptions = $processcasoptions;\r\n\r\n$this-&gt;casoption\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $casoption;\r\n$this-&gt;options\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $options;\r\n\r\n$this-&gt;simp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = (bool) $simp;\r\n\r\n$this-&gt;requiredoptions\u00a0\u00a0 = $requiredoptions;\r\n}\r\n}\r\n\r\n\/**\r\n* Creates the string which Maxima will execute\r\n*\r\n* @return string\r\n*\/\r\nfunction construct_maxima_command($cts, $options, $seed) {\r\n\/\/ Ensure that every command has a valid key.\r\n\r\n$casoptions = $options-&gt;get_cas_commands();\r\n\r\n$csnames = $casoptions['names'];\r\n$csvars\u00a0 = $casoptions['commands'];\r\n$cascommands = '';\r\n$caspreamble = '';\r\n\r\n$cascommands .= ', print(\"-1=[ error= [\"), cte(\"__stackmaximaversion\",errcatch(__stackmaximaversion:stackmaximaversion)) ';\r\n\r\n$i = 0;\r\nforeach ($cts as $cs) {\r\nif ('' == $cs-&gt;get_key()) {\r\n$label = 'dumvar'.$i;\r\n} else {\r\n$label = $cs-&gt;get_key();\r\n}\r\n\r\n\/\/ Replace any ?'s with a safe value.\r\n$cmd = str_replace('?', 'QMCHAR', $cs-&gt;get_casstring());\r\n\/\/ Strip off any []s at the end of a variable name.\r\n\/\/ These are used to assign elements of lists and matrices, but this breaks Maxima's block command.\r\nif (false === strpos($label, '[')) {\r\n$cleanlabel = $label;\r\n} else {\r\n$cleanlabel = substr($label, 0, strpos($label, '['));\r\n}\r\n\r\n\/\/ Now we do special things if we have a command to re-order expressions.\r\nif (false !== strpos($cmd, 'ordergreat') || false !== strpos($cmd, 'orderless')) {\r\n\/\/ These commands must be in a separate block, and must only appear once.\r\n$caspreamble = $cmd.\"$\\n\";\r\n$cmd = '0';\r\n}\r\n\r\n$csnames\u00a0\u00a0 .= \", $cleanlabel\";\r\n$cascommands .= \", print(\\\"$i=[ error= [\\\"), cte(\\\"$label\\\",errcatch($label:$cmd)) \";\r\n$i++;\r\n\r\n}\r\n\r\n$cass\u00a0 = $caspreamble;\r\n$cass .= 'cab:block([ RANDOM_SEED';\r\n$cass .= $csnames;\r\n$cass .= '], stack_randseed(';\r\n$cass .= $seed.')'.$csvars;\r\n$cass .= \", print(\\\"[TimeStamp= [ $seed ], Locals= [ \\\") \";\r\n$cass .= $cascommands;\r\n$cass .= \", print(\\\"] ]\\\") , return(true) ); \\n \";\r\n\r\nreturn $cass;\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u74b0\u5883\u306e\u9055\u3044\u3067\u52d5\u304b\u306a\u3044\u3053\u3068\u3082\u8003\u3048\u3089\u308c\u307e\u3059\u304c\u3001\u305d\u306e\u3078\u3093\u306f\u5f8c\u3067\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001\u4f5c\u6210\u3057\u305f Maxima \u30b3\u30de\u30f3\u30c9\u3092\u9001\u308b\u3068\u3053\u308d\u3067\u3059\u3002 connector.unix.class.php \u306b\u3042\u308b call_maxima( ) \u3092\u5229\u7528\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u307b\u3068\u3093\u3069\u304c\u5148\u306e\u30b3\u30fc\u30c9\u3068\u91cd\u306a\u308b\u306e\u3067\u3001\u4e0b\u8a18\u306b Maxima \u306b\u30b3\u30de\u30f3\u30c9\u3092\u9001\u308b\u95a2\u6570\u306e\u6240\u3060\u3051\u3092\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/\/ connector.unix.class.php \u304b\u3089\u4f5c\u6210\r\n\r\nfunction call_maxima($initcommand, $command, $debug, $timeout) {\r\n\r\n$ret = false;\r\n$err = '';\r\n$cwd = null;\r\n$env = array('why' =&gt; 'itworks');\r\n\r\n$descriptors = array(\r\n0 =&gt; array('pipe', 'r'),\r\n1 =&gt; array('pipe', 'w'),\r\n2 =&gt; array('pipe', 'w'));\r\n\r\n$casprocess = proc_open('\/usr\/local\/bin\/maxima', $descriptors, $pipes, $cwd, $env);\r\n\r\nfwrite($pipes[0], $initcommand);\r\nfwrite($pipes[0], $command);\r\nfwrite($pipes[0], 'quit();'.\"\\n\\n\");\r\n\r\n$ret = '';\r\n\/\/ Read output from stdout.\r\n$starttime = microtime(true);\r\n$continue\u00a0\u00a0 = true;\r\n\r\nif (!stream_set_blocking($pipes[1], false)) {\r\n$debug-&gt;log('', 'Warning: could not stream_set_blocking to be FALSE on the CAS process.');\r\n}\r\n\r\nwhile ($continue and !feof($pipes[1])) {\r\n\r\n$now = microtime(true);\r\n\r\nif (($now - $starttime) &gt; $timeout) {\r\n$procarray = proc_get_status($casprocess);\r\nif ($procarray['running']) {\r\nproc_terminate($casprocess);\r\n}\r\n$continue = false;\r\n} else {\r\n$out = fread($pipes[1], 1024);\r\nif ('' == $out) {\r\n\/\/ Pause.\r\nusleep(1000);\r\n}\r\n$ret .= $out;\r\n}\r\n\r\n}\r\n\r\nif ($continue) {\r\nfclose($pipes[0]);\r\nfclose($pipes[1]);\r\n$debug-&gt;log('Timings', \"Start: {$starttime}, End: {$now}, Taken = \" .($now - $starttime));\r\n\r\n} else {\r\n\/\/ Add sufficient closing ]'s to allow something to be un-parsed from the CAS.\r\n\/\/ WARNING: the string 'The CAS timed out' is used by the cache to search for a timeout occurrence.\r\n$ret .= ' The CAS timed out. ] ] ] ]';\r\n}\r\n\r\nreturn $ret;\r\n\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u5f15\u6570\u306e $initcommand \u306e\u4e2d\u8eab\u306f, &#8216;load(&#8220;\/var\/www\/html\/for_stack333\/moodledata\/stack\/maximalocal.mac&#8221;);&#8217; \u3067\u3059\u3002\u6b21\u306e $command \u306f\u5148\u306b\u7d44\u307f\u4e0a\u3052\u305f Maxima \u30b3\u30de\u30f3\u30c9\uff08cab:block([],\u00a0 . . .\u3000\u3067\u59cb\u307e\u308b\u3082\u306e\uff09\u3067\u3059\u3002\u6b21\u306e\u00a0 $debug \u306f stack_debug_log_base \u30af\u30e9\u30b9\u3067\u3001\u3042\u3068\u3067\u66f8\u304d\u307e\u3059\u3002 $timeout \u306f\u30b3\u30fc\u30c9\u4e2d\u306e\u30eb\u30fc\u30d7\u306e\u6700\u5927\u6642\u9593\u3092\u6c7a\u3081\u308b\u3082\u306e\u306e\u3088\u3046\u3067\u3001\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u9069\u5f53\u306b 30 \u3068\u5165\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3055\u3066\u3001$debug \u3067\u3059\u304c\u3001\u30ed\u30b0\u3092\u8caf\u3081\u3066\u3044\u304f\u5909\u6570\u3067\u3001\u5148\u307b\u3069\u66f8\u3044\u305f\u3088\u3046\u306b stack_debug_log_base \u30af\u30e9\u30b9\u3067\u3001utils.class.php \u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u30b3\u30fc\u30c9\u3067\u306f log() \u30e1\u30bd\u30c3\u30c9\u304c\u4f7f\u308f\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u307e\u307e\u3067\u306f\u5229\u7528\u3067\u304d\u306a\u304b\u3063\u305f\u306e\u3067\uff08html_writer \u304c\u5fc5\u8981\uff09\u3001\u591a\u5c11\u66f8\u304d\u63db\u3048\u307e\u3057\u305f\u3002\u305d\u308c\u3067\u3082 moodle \u306e s( ) \u304c\u5fc5\u8981\u3067\u3001\u3053\u308c\u306f weblib.php \u306b\u3042\u308a\u307e\u3059\u3002weblib.php \u304b\u3089\u306f s( )\u3001p( ) \u3092\u6b8b\u3057\u3066\u4ed6\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b9f\u884c\u6642\u306e\u753b\u9762\u3067\u3059\u3002\u6700\u5f8c\u306e\u51fa\u529b\u3001\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3067\u8a00\u3048\u3070\u3001 $ret \u5909\u6570\u306e\u5185\u5bb9\u3092\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002\u3059\u3079\u3066\u306e\u30b3\u30fc\u30c9\u306e zip \u30d5\u30a1\u30a4\u30eb\u3092<span style=\"color: #0000ff;\"><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/maxima_run.zip\"><span style=\"color: #0000ff;\">\u3053\u3053<\/span><\/a><\/span>\u306b\u304a\u304d\u307e\u3059\u3002\u305f\u3060\u3001maximalocal.mac \u306b\u30d5\u30a9\u30eb\u30c0\u30fc\u540d\u7b49\u304c\u76f4\u63a5\u8a18\u5165\u3057\u3066\u3042\u308b\u306e\u3067\u3001\u9069\u5f53\u306a\u5909\u66f4\u304c\u5fc5\u8981\u3067\u3059\u3002\u4ed6\u306b\u3082 maxima \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5834\u6240\u306b\u4f9d\u5b58\u3059\u308b\u7b87\u6240\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3905\" title=\"term4\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term4-217x300.png\" alt=\"\" width=\"217\" height=\"300\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u7d9a\u3044\u3066\u3001Maxima \u306e\u8a08\u7b97\u7d50\u679c\u306e\u5f8c\u51e6\u7406\u306e\u3068\u3053\u308d\u3067\u3059\u3002 stack_cas_session ( cassession.class.php \u3067\u5b9a\u7fa9)\u306b\u623b\u308a\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u306e instantiate() \u306f\uff0c<\/p>\n<pre><code style=\"color:midnightblue;\">\/* This is the function which actually sends the commands off to Maxima. *\/\r\npublic function instantiate() {\r\nif (null === $this-&gt;valid) {\r\n$this-&gt;validate();\r\n}\r\nif (!$this-&gt;valid) {\r\nreturn false;\r\n}\r\n\/\/ Lazy instantiation - only do this once...\r\n\/\/ Empty session.\u00a0 Nothing to do.\r\nif ($this-&gt;instantiated || null === $this-&gt;session) {\r\nreturn true;\r\n}\r\n\r\n$connection = stack_connection_helper::make();\r\n$results = $connection-&gt;compute($this-&gt;construct_maxima_command());\r\n$this-&gt;debuginfo = $connection-&gt;get_debuginfo();\r\n\r\n\/\/ Now put the information back into the correct slots.\r\n$session\u00a0\u00a0\u00a0 = $this-&gt;session;\r\n$newsession = array();\r\n$newerrors\u00a0 = '';\r\n$allfail\u00a0\u00a0\u00a0 = true;\r\n$i\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n\r\n\/\/ We loop over each entry in the session, not over the result.\r\n\/\/ This way we can add an error for missing values.\r\nforeach ($session as $cs) {\r\n$gotvalue = false;\r\n\r\nif ('' == $cs-&gt;get_key()) {\r\n$key = 'dumvar'.$i;\r\n} else {\r\n$key = $cs-&gt;get_key();\r\n}\r\n\r\nif (array_key_exists($i, $results)) {\r\n$allfail = false; \/\/ We at least got one result back from the CAS!\r\n\r\n$result = $results[\"$i\"]; \/\/ GOCHA!\u00a0 results have string represenations of numbers, not int....\r\n\r\nif (array_key_exists('value', $result)) {\r\n$val = str_replace('QMCHAR', '?', $result['value']);\r\n$cs-&gt;set_value($val);\r\n$gotvalue = true;\r\n}\r\n\r\nif (array_key_exists('display', $result)) {\r\n\/\/ Need to add this in here also because strings may contain question mark characters.\r\n$disp = str_replace('QMCHAR', '?', $result['display']);\r\n$cs-&gt;set_display($disp);\r\n}\r\n\r\nif (array_key_exists('valid', $result)) {\r\n$cs-&gt;set_valid($result['valid']);\r\n}\r\n\r\nif (array_key_exists('answernote', $result)) {\r\n$cs-&gt;set_answernote($result['answernote']);\r\n}\r\n\r\nif (array_key_exists('feedback', $result)) {\r\n$cs-&gt;set_feedback($result['feedback']);\r\n}\r\n\r\nif ('' != $result['error'] and false === strstr($result['error'], 'clipped')) {\r\n$cs-&gt;add_errors($result['error']);\r\n$cs-&gt;decode_maxima_errors($result['error']);\r\n$newerrors .= stack_maxima_format_casstring($cs-&gt;get_raw_casstring());\r\n$newerrors .= ' '.stack_string(\"stackCas_CASErrorCaused\") .\r\n' ' . $result['error'] . ' ';\r\n}\r\n} else if (!$gotvalue) {\r\n$errstr = stack_string(\"stackCas_failedReturn\").' '.stack_maxima_format_casstring($cs-&gt;get_raw_casstring());\r\n$cs-&gt;add_errors($errstr);\r\n$cs-&gt;set_answernote('CASFailedReturn');\r\n$newerrors .= $errstr;\r\n}\r\n\r\n$newsession[] = $cs;\r\n$i++;\r\n}\r\n$this-&gt;session = $newsession;\r\n\r\nif ('' != $newerrors) {\r\n$this-&gt;errors .= '&lt;span&gt;'.stack_string('stackCas_CASError').'&lt;\/span&gt;'.$newerrors;\r\n}\r\nif ($allfail) {\r\n$this-&gt;errors = '&lt;span&gt;'.stack_string('stackCas_allFailed').'&lt;\/span&gt;';\r\n}\r\n\r\n$this-&gt;instantiated = true;\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>16\u884c\u76ee\u3042\u305f\u308a\u306e\u00a0compute($this-&gt;construct_maxima_command() \u304c\u3001Maxima \u3067\u8a08\u7b97\u3092\u3059\u308b\u3068\u3053\u308d\u3067\u3059\u3002 stack_connection_helper \u306f\u3001\u5b9a\u7fa9\u304c\u00a0connectorhelper.class.php \u306b\u3042\u308a\u307e\u3059\u3002compute( ) \u306f\u00a0connector.class.php \u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u4e0b\u8a18\u306b\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/* @see stack_cas_connection::compute() *\/\r\npublic function compute($command) {\r\n\r\n$context = \"Platform: \". stack_connection_helper::get_platform() . \"\\n\";\r\n$context .= \"Maxima shell command: \". $this-&gt;command . \"\\n\";;\r\n$context .= \"Maxima initial command: \". $this-&gt;initcommand . \"\\n\";\r\n$context .= \"Maxima timeout: \". $this-&gt;timeout;\r\n$this-&gt;debug-&gt;log('Context used', $context);\r\n\r\n$this-&gt;debug-&gt;log('Maxima command', $command);\r\n\r\n$rawresult = $this-&gt;call_maxima($command);\r\n$this-&gt;debug-&gt;log('CAS result', $rawresult);\r\n\r\n$unpackedresult = $this-&gt;unpack_raw_result($rawresult);\r\n$this-&gt;debug-&gt;log('Unpacked result as', print_r($unpackedresult, true));\r\n\r\nif (!stack_connection_helper::check_stackmaxima_version($unpackedresult)) {\r\nstack_connection_helper::warn_about_version_mismatch($this-&gt;debug);\r\n}\r\n\r\nreturn $unpackedresult;\r\n}\r\n<\/code><\/pre>\n<p>call_maxima($command) \u304b\u3089\u306e\u8fd4\u4e8b\u00a0$rawresult \u3092\u3001unpack_raw_result \u306b\u6e21\u3057\u3066\u3044\u307e\u3059\u3002unpack_raw_result\u3092\u4e0b\u8a18\u306b\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">protected function unpack_raw_result($rawresult) {\r\n$result = '';\r\n$errors = false;\r\n\r\nif ('' == trim($rawresult)) {\r\n$this-&gt;debug-&gt;log('Warning, empty result!', 'unpack_raw_result: completely empty result was returned by the CAS.');\r\nreturn array();\r\n}\r\n\r\n\/\/ Check we have a timestamp &amp; remove everything before it.\r\n$ts = substr_count($rawresult, '[TimeStamp');\r\nif ($ts != 1) {\r\n$this-&gt;debug-&gt;log('', 'unpack_raw_result: no timestamp returned. Data returned was: '.$rawresult);\r\nreturn array();\r\n} else {\r\n$result = strstr($rawresult, '[TimeStamp'); \/\/ Remove everything before the timestamp.\r\n}\r\n\r\n$result = trim(str_replace('#', '', $result));\r\n$result = trim(str_replace(\"\\n\", '', $result));\r\n\r\n$unp = $this-&gt;unpack_helper($result);\r\n\r\nif (array_key_exists('Locals', $unp)) {\r\n$uplocs = $unp['Locals']; \/\/ Grab the local variables.\r\nunset($unp['Locals']);\r\n} else {\r\n$uplocs = '';\r\n}\r\n\r\n\/\/ Now we need to turn the (error,key,value,display) tuple into an array.\r\n$locals = array();\r\n\r\nforeach ($this-&gt;unpack_helper($uplocs) as $var =&gt; $valdval) {\r\nif (is_array($valdval)) {\r\n$errors[\"CAS\"] = \"unpack_raw_result: CAS failed to generate any useful output.\";\r\n} else {\r\nif (preg_match('\/.*\\[.*\\].*\/', $valdval)) {\r\n\/\/ There are some []'s in the string.\r\n$loc = $this-&gt;unpack_helper($valdval);\r\nif ('' == trim($loc['error'])) {\r\nunset($loc['error']);\r\n}\r\n$locals[$var] = $loc;\r\n\r\n} else {\r\n$errors[\"LocalVarGet$var\"] = \"Couldn't unpack the local variable $var from the string $valdval.\";\r\n}\r\n}\r\n}\r\n\r\n\/\/ Next process and tidy up these values.\r\nforeach ($locals as $i =&gt; &amp;$local) {\r\n\r\nif (isset($local['error'])) {\r\n$local['error'] = $this-&gt;tidy_error($local['error']);\r\n} else {\r\n$local['error'] = '';\r\n}\r\n\/\/ If there are plots in the output.\r\n$plot = isset($local['display']) ? substr_count($local['display'], '&lt;img') : 0;\r\nif ($plot &gt; 0) {\r\n\/\/ Plots always contain errors, so remove.\r\n$local['error'] = '';\r\n\/\/ For mathml display, remove the mathml that is inserted wrongly round the plot.\r\n$local['display'] = str_replace('&lt;math xmlns=\\'http:\/\/www.w3.org\/1998\/Math\/MathML\\'&gt;',\r\n'', $local['display']);\r\n$local['display'] = str_replace('&lt;\/math&gt;', '', $local['display']);\r\n\r\n\/\/ For latex mode, remove the mbox.\r\n\/\/ This handles forms: \\mbox{image} and (earlier?) \\mbox{{} {image} {}}.\r\n$local['display'] = preg_replace(\"|\\\\\\mbox{({})? (&lt;html&gt;.+&lt;\/html&gt;) ({})?}|\", \"$2\", $local['display']);\r\n\r\nif ($this-&gt;wwwroothasunderscores) {\r\n$local['display'] = str_replace($this-&gt;wwwrootfixupfind,\r\n$this-&gt;wwwrootfixupreplace, $local['display']);\r\n}\r\n}\r\n}\r\nreturn $locals;\r\n}\r\n<\/code><\/pre>\n<p>\u3053\u3053\u3067\u3001call_maxima( ) \u304b\u3089\u306e\u8fd4\u4e8b\u3092\u914d\u5217\u306b\u4f5c\u308a\u306a\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002unpack_raw_result \u4ee5\u5916\u306b\u3082\u3001\u540c\u3058\u30af\u30e9\u30b9\u5185\u306e unpack_helper \u3068 tidy_error \u3082\u5fc5\u8981\u3067\u3059\u3002\u3053\u308c\u3089\u3092\u591a\u5c11\u66f8\u304d\u63db\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001unpack_raw_result \u304b\u3089\u5f97\u3089\u308c\u308b\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3092\u66f8\u3044\u3066\u898b\u307e\u3057\u305f\u3002\u4e0b\u8a18\u306b\u5b9f\u884c\u6642\u306e\u753b\u9762\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3092\u3042\u3052\u307e\u3059\u3002\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3067\u8a00\u3048\u3070 $locals \u3092 var_dump( ) \u3067\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002\u3059\u3079\u3066\u306e\u30b3\u30fc\u30c9\u306f<span style=\"color: #0000ff;\"><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/get_raw_result.zip\"><span style=\"color: #0000ff;\">\u3053\u3053<\/span><\/a><\/span>\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/raw_result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3924\" title=\"raw_result\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/raw_result-216x300.png\" alt=\"\" width=\"216\" height=\"300\" \/><\/a><\/p>\n<p>\u7d9a\u3044\u3066\u3053\u306e\u5f8c\u306e\u90e8\u5206\u3067\u3059\u3002Maxima \u304b\u3089\u8fd4\u3063\u3066\u304d\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5bfe\u5fdc\u3059\u308b\u8a00\u8449\u306b\u5909\u63db\u3059\u308b\u6a5f\u80fd\u306a\u3069\u304c\u542b\u307e\u308c\u308b\u3068\u601d\u308f\u308c\u307e\u3059\uff08&#8217;ATList_wrongentries&#8217; \u306a\u3069\u3092\u5bfe\u5fdc\u3059\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u5909\u63db\u3059\u308b\u6a5f\u80fd\uff09\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u518d\u3073\u5f15\u7528\u3057\u307e\u3059\u304c\u3001cassession.class.php \u306e instantiate() \u3092\u4e0b\u8a18\u306b\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/* This is the function which actually sends the commands off to Maxima. *\/\r\npublic function instantiate() {\r\nif (null === $this-&gt;valid) {\r\n$this-&gt;validate();\r\n}\r\nif (!$this-&gt;valid) {\r\nreturn false;\r\n}\r\n\/\/ Lazy instantiation - only do this once...\r\n\/\/ Empty session.\u00a0 Nothing to do.\r\nif ($this-&gt;instantiated || null === $this-&gt;session) {\r\nreturn true;\r\n}\r\n\r\n$connection = stack_connection_helper::make();\r\n$results = $connection-&gt;compute($this-&gt;construct_maxima_command());\r\n$this-&gt;debuginfo = $connection-&gt;get_debuginfo();\r\n\r\n\/\/ Now put the information back into the correct slots.\r\n$session\u00a0\u00a0\u00a0 = $this-&gt;session;\r\n$newsession = array();\r\n$newerrors\u00a0 = '';\r\n$allfail\u00a0\u00a0\u00a0 = true;\r\n$i\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n\r\n\/\/ We loop over each entry in the session, not over the result.\r\n\/\/ This way we can add an error for missing values.\r\nforeach ($session as $cs) {\r\n$gotvalue = false;\r\n\r\nif ('' == $cs-&gt;get_key()) {\r\n$key = 'dumvar'.$i;\r\n} else {\r\n$key = $cs-&gt;get_key();\r\n}\r\n\r\nif (array_key_exists($i, $results)) {\r\n$allfail = false; \/\/ We at least got one result back from the CAS!\r\n\r\n$result = $results[\"$i\"]; \/\/ GOCHA!\u00a0 results have string represenations of numbers, not int....\r\n\r\nif (array_key_exists('value', $result)) {\r\n$val = str_replace('QMCHAR', '?', $result['value']);\r\n$cs-&gt;set_value($val);\r\n$gotvalue = true;\r\n}\r\n\r\nif (array_key_exists('display', $result)) {\r\n\/\/ Need to add this in here also because strings may contain question mark characters.\r\n$disp = str_replace('QMCHAR', '?', $result['display']);\r\n$cs-&gt;set_display($disp);\r\n}\r\n\r\nif (array_key_exists('valid', $result)) {\r\n$cs-&gt;set_valid($result['valid']);\r\n}\r\n\r\nif (array_key_exists('answernote', $result)) {\r\n$cs-&gt;set_answernote($result['answernote']);\r\n}\r\n\r\nif (array_key_exists('feedback', $result)) {\r\n$cs-&gt;set_feedback($result['feedback']);\r\n}\r\n\r\nif ('' != $result['error'] and false === strstr($result['error'], 'clipped')) {\r\n$cs-&gt;add_errors($result['error']);\r\n$cs-&gt;decode_maxima_errors($result['error']);\r\n$newerrors .= stack_maxima_format_casstring($cs-&gt;get_raw_casstring());\r\n$newerrors .= ' '.stack_string(\"stackCas_CASErrorCaused\") .\r\n' ' . $result['error'] . ' ';\r\n}\r\n} else if (!$gotvalue) {\r\n$errstr = stack_string(\"stackCas_failedReturn\").' '.stack_maxima_format_casstring($cs-&gt;get_raw_casstring());\r\n$cs-&gt;add_errors($errstr);\r\n$cs-&gt;set_answernote('CASFailedReturn');\r\n$newerrors .= $errstr;\r\n}\r\n\r\n$newsession[] = $cs;\r\n$i++;\r\n}\r\n$this-&gt;session = $newsession;\r\n\r\nif ('' != $newerrors) {\r\n$this-&gt;errors .= '&lt;span&gt;'.stack_string('stackCas_CASError').'&lt;\/span&gt;'.$newerrors;\r\n}\r\nif ($allfail) {\r\n$this-&gt;errors = '&lt;span&gt;'.stack_string('stackCas_allFailed').'&lt;\/span&gt;';\r\n}\r\n\r\n$this-&gt;instantiated = true;\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u307e\u305a16\u884c\u76ee\u306e compute() \u306e\u7d50\u679c\u3092 $results \u306b\u5165\u308c\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u4e2d\u8eab\u306f unpack_raw_result() \u306e\u8fd4\u4e8b\u3067\u3059\u300228\u884c\u76ee\u3067\u306f\u3001$session \u306e\u305d\u308c\u305e\u308c\u306e\u8981\u7d20\u306b\u95a2\u3057\u3066\u30eb\u30fc\u30d7\u3057\u307e\u3059\u3002\u8981\u7d20\u3092 $cs \u3068\u3057\u3066\u3044\u307e\u3059\u304c\u3001$cs \u306f stack_cas_casstring \u30af\u30e9\u30b9 \u3067\u3059\u3002\u3053\u306e $cs \u306b $results \u306e\u7d50\u679c\u3092\u683c\u7d0d\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u5909\u66f4\u5f8c\u306e\u5185\u5bb9\u3092\u753b\u9762\u51fa\u529b\u3055\u305b\u305f\u3082\u306e\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3092\u4e0b\u8a18\u306b\u3042\u3052\u307e\u3059\u3002$session \u306f3\u500b\u306e\u8981\u7d20\u306a\u306e\u3067\u3059\u304c\u3001\u753b\u9762\u306b\u5165\u308a\u304d\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u5f8c\u308d\u306e\u65b9\u306e2\u9805\u306e\u5185\u5bb9\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u5148\u306e $locals \u306f\u914d\u5217\u3067\u3001\u3053\u308c\u306fstack_cas_casstring \u30af\u30e9\u30b9\u3068\u3044\u3046\u9055\u3044\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3938\" title=\"term5\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term5-237x300.png\" alt=\"\" width=\"237\" height=\"300\" \/><\/a><\/p>\n<p>\u4e0a\u8a18\u306f\u3001stack_cas_session \u30af\u30e9\u30b9\u306e instantiate() \u3092\u5b9f\u884c\u3057\u305f\u3068\u3053\u308d\u306a\u308f\u3051\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u9061\u3063\u3066\u5143\u306b\u623b\u308a\u307e\u3059\u3002\u3053\u308c\u306e\u547c\u3073\u51fa\u3057\u5143\u306f\u3001\u4f8b\u3048\u3070 stack_answertest_general_cas \u30af\u30e9\u30b9\uff08at_general_cas.class.php\uff09\u306e do_test() \u3067\u3059\u3002\u4e0b\u8a18\u306b\u5f15\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/**\r\n*\r\n*\r\n* @return bool\r\n* @access public\r\n*\/\r\npublic function do_test() {\r\n\r\nif ('' == trim($this-&gt;sanskey)) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptySA\")));\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptySA\")));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'TEST_FAILED:Empty SA.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\nif ('' == trim($this-&gt;tanskey)) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptyTA\")));\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_EmptyTA\")));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'TEST_FAILED:Empty TA.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\nif ($this-&gt;processcasoptions) {\r\nif (null == $this-&gt;atoption or '' == $this-&gt;atoption) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; stack_string(\"AT_MissingOptions\")));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = 'STACKERROR_OPTION.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n} else {\r\n\/\/ Validate with teacher privileges, strict syntax &amp; no automatically adding stars.\r\n$ct\u00a0 = new stack_cas_casstring($this-&gt;atoption);\r\n\r\nif (!$ct-&gt;get_valid('t', true, 1)) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; ''));\r\n$this-&gt;atfeedback\u00a0 .= stack_string('AT_InvalidOptions', array('errors' =&gt; $ct-&gt;get_errors()));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = 'STACKERROR_OPTION.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n}\r\n$atopt = $this-&gt;atoption;\r\n$ta\u00a0\u00a0 = \"[$this-&gt;tanskey,$atopt]\";\r\n} else {\r\n$ta = $this-&gt;tanskey;\r\n}\r\n\r\n\/\/ Sort out options.\r\nif (null === $this-&gt;options) {\r\n$this-&gt;options = new stack_options();\r\n}\r\nif (!(null === $this-&gt;simp)) {\r\n$this-&gt;options-&gt;set_option('simplify', $this-&gt;simp);\r\n}\r\n\r\n$cascommands = array();\r\n$cascommands[] = \"STACKSA:$this-&gt;sanskey\";\r\n$cascommands[] = \"STACKTA:$ta\";\r\n$cascommands[] = \"result:StackReturn({$this-&gt;casfunction}(STACKSA,STACKTA))\";\r\n\r\n$cts = array();\r\nforeach ($cascommands as $com) {\r\n$cs\u00a0\u00a0\u00a0 = new stack_cas_casstring($com);\r\n$cs-&gt;get_valid('t', true, 0);\r\n$cts[] = $cs;\r\n}\r\n\r\n$session = new stack_cas_session($cts, $this-&gt;options, 0);\r\n$session-&gt;instantiate();\r\n$this-&gt;debuginfo = $session-&gt;get_debuginfo();\r\n\r\nif ('' != $session-&gt;get_errors_key('STACKSA')) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; $session-&gt;get_errors_key('STACKSA')));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'_STACKERROR_SAns.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\nif ('' != $session-&gt;get_errors_key('STACKTA')) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n$this-&gt;atfeedback\u00a0\u00a0 = stack_string('TEST_FAILED', array('errors' =&gt; $session-&gt;get_errors_key('STACKTA')));\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = $this-&gt;casfunction.'_STACKERROR_TAns.';\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\n$sessionvars = $session-&gt;get_session();\r\n$result = $sessionvars[2];\r\n\r\nif ('' != $result-&gt;get_errors()) {\r\n$this-&gt;aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\nif ('' != trim($result-&gt;get_feedback())) {\r\n$this-&gt;atfeedback = $result-&gt;get_feedback();\r\n} else {\r\n$this-&gt;atfeedback = stack_string('TEST_FAILED', array('errors' =&gt; $result-&gt;get_errors()));\r\n}\r\n$this-&gt;atansnote\u00a0\u00a0\u00a0 = trim($result-&gt;get_answernote());\r\n$this-&gt;atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\nreturn null;\r\n}\r\n\r\n$this-&gt;atansnote\u00a0 = trim($result-&gt;get_answernote());\r\n\r\n\/\/ Convert the Maxima string 'true' to PHP true.\r\nif ('true' == $result-&gt;get_value()) {\r\n$this-&gt;atmark = 1;\r\n} else {\r\n$this-&gt;atmark = 0;\r\n}\r\n$this-&gt;atfeedback = $result-&gt;get_feedback();\r\n$this-&gt;atvalid\u00a0\u00a0\u00a0 = $result-&gt;get_valid();\r\n\r\nif ($this-&gt;atmark) {\r\nreturn true;\r\n} else {\r\nreturn false;\r\n}\r\n}\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>do_test() \u306f\u300176\u884c\u76ee\u3067\u3059\u3002\u4ee5\u964d\u306e\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066\u3044\u304d\u307e\u3059\u304c\uff08\u5229\u7528\u3057\u306a\u3044\u3082\u306e\u3082\u3042\u308a\u307e\u3059\uff09\u3001\u304a\u304a\u3088\u305d\u306f\u30a8\u30e9\u30fc\u306e\u691c\u51fa\u3068\u5909\u6570\u3078\u306e\u5024\u306e\u683c\u7d0d\u3067\u3057\u3087\u3046\u304b\u300298\u884c\u76ee\u306e $result \u306f\u8a55\u4fa1\u7d50\u679c\u304c\u5165\u3063\u305f stack_answertest_general_cas \u30af\u30e9\u30b9 \u3067\u3059\u3002103\u884c\u76ee\u306a\u3069\u3067\u3001get_feedback() \u30e1\u30bd\u30c3\u30c9\u304c\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u3068\u304d\u5f97\u3089\u308c\u308b\u5024\uff08$this-&gt;atfeedback \u306e\u5024\uff09\u306f\u3001\u4f8b\u3048\u3070 &#8220;stack_trans(&#8216;ATList_wrongentries&#8217; , !quot!\\[\\left[ 1 , 2 , {\\color{red}{\\underline{4}}} \\right] \\]!quot! );&#8221; \u306a\u3069\u3067\u3001\u307e\u3060\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u6210\u3063\u3066\u3044\u307e\u305b\u3093\u3002\u4f9d\u3063\u3066\u66f4\u306b\u9061\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>stack_answertest_general_cas \u30af\u30e9\u30b9\u306e\u547c\u3073\u51fa\u3057\u3082\u3068\u306f\u3001\u4f8b\u3048\u3070 stack_ans_test_controller \u30af\u30e9\u30b9\uff08controller.class.php \u3067\u5b9a\u7fa9\uff09\u3067\u3059\u3002\u3053\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30fc\u3067\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002\u3055\u3089\u306b\u3001stack_ans_test_controller \u30af\u30e9\u30b9\u306e\u547c\u3073\u51fa\u3057\u3082\u3068\u3092\u63a2\u308b\u3068\u3001stack_answertest_test_data \u30af\u30e9\u30b9\uff08answertestfixtures.class.php \u3067\u5b9a\u7fa9\uff09\u3067\u3001\u305d\u306e run_test() \u3092\u5f15\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre><code style=\"color:midnightblue;\">public static function run_test($test) {\r\n$anst = new stack_ans_test_controller($test-&gt;name, $test-&gt;studentanswer,\r\n$test-&gt;teacheranswer, new stack_options(), $test-&gt;options);\r\n\r\n\/\/ The false clause is useful for developers to track down which test case is breaking Maxima.\r\nif (true) {\r\n$result\u00a0\u00a0 = $anst-&gt;do_test(); \/\/ This actually executes the answer test in the CAS.\r\n$errors\u00a0\u00a0 = $anst-&gt;get_at_errors();\r\n$rawmark\u00a0 = $anst-&gt;get_at_mark();\r\n$feedback = $anst-&gt;get_at_feedback();\r\n$ansnote\u00a0 = $anst-&gt;get_at_answernote();\r\n} else {\r\n$feedback = 'AT'.$test-&gt;name.'('.$test-&gt;studentanswer.','.$test-&gt;teacheranswer.');';\r\n$result\u00a0\u00a0 = true; \/\/ This actually executes the answer test in the CAS.\r\n$errors\u00a0\u00a0 = '';\r\n$rawmark\u00a0 = 0;\r\n$ansnote\u00a0 = '';\r\n}\r\n\r\n$passed = false;\r\nif ($rawmark === $test-&gt;expectedscore) {\r\n$passed = true;\r\n}\r\n\r\n\/\/ The test failed, and we expected it to fail.\r\nif ($errors === 'TEST_FAILED') {\r\nif (-1 === $test-&gt;expectedscore) {\r\n$passed = true;\r\n} else {\r\n$passed = false;\r\n}\r\n}\r\n\/\/ These tests are all expected to fail, so we make them all pass.\r\nif (-2 === $test-&gt;expectedscore) {\r\n$passed = true;\r\n}\r\n\r\nreturn array($passed, $errors, $rawmark, $feedback, $ansnote);\r\n}\r\n\r\n<\/code><\/pre>\n<p>10\u884c\u76ee\u306e $feedback \u306f\u3001\u4f8b\u3048\u3070<\/p>\n<p>&#8220;\u8d64\u5b57\u3067\u793a\u3055\u308c\u305f\u90e8\u5206\u304c\u4e0d\u6b63\u89e3\u3067\u3059\u3002\\[\\left[ 1 , 2 , {\\color{red}{\\underline{4}}} \\right] \\]&#8221;<\/p>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u5909\u63db\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u4f9d\u3063\u3066\u3001\u3053\u306e run_test() \u306e\u5185\u5bb9\u3092\u5229\u7528\u3057\u3066\u3044\u3051\u3070\u826f\u3055\u305d\u3046\u3067\u3059\u3002stack_ans_test_controller \u30af\u30e9\u30b9\u306e get_at_feedback() \u3092\u898b\u3066\u307f\u308b\u3068\u3001<\/p>\n<p>&nbsp;<\/p>\n<pre><code style=\"color:midnightblue;\">\/**\r\n*\r\n*\r\n* @return string\r\n* @access public\r\n*\/\r\npublic function get_at_feedback() {\r\nreturn stack_maxima_translate($this-&gt;at-&gt;get_at_feedback());\r\n}\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u3053\u306b\u3042\u308b\u3001stack_maxima_translate() \u306f\u3001locallib.php \u306b\u3042\u308a\u307e\u3059\u3002\u4e00\u7dd2\u306bstack_trans() \u3082\u5fc5\u8981 \u3067\u3001\u305d\u306e\u5185\u5bb9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">\/**\r\n* Translates a string taken as output from Maxima.\r\n*\r\n* This function takes a variable number of arguments, the first of which is assumed to be the identifier\r\n* of the string to be translated.\r\n*\/\r\nfunction stack_trans() {\r\n$nargs = func_num_args();\r\n\r\nif ($nargs &gt; 0) {\r\n$arglist = func_get_args();\r\n$identifier = func_get_arg(0);\r\n$a = array();\r\nif ($nargs &gt; 1) {\r\nfor ($i = 1; $i &lt; $nargs; $i++) {\r\n$index = $i - 1;\r\n$a[\"m{$index}\"] = func_get_arg($i);\r\n}\r\n}\r\n$return = stack_string($identifier, $a);\r\necho $return;\r\n}\r\n}\r\n\r\nfunction stack_maxima_translate($rawfeedback) {\r\n\r\nif (strpos($rawfeedback, 'stack_trans') === false) {\r\nreturn trim($rawfeedback);\r\n} else {\r\n$rawfeedback = str_replace('[[', '', $rawfeedback);\r\n$rawfeedback = str_replace(']]', '', $rawfeedback);\r\n$rawfeedback = str_replace('\\n', '', $rawfeedback);\r\n$rawfeedback = str_replace('\\\\', '\\\\\\\\', $rawfeedback);\r\n$rawfeedback = str_replace('!quot!', '\"', $rawfeedback);\r\n\r\nob_start();\r\neval($rawfeedback);\r\n$translated = ob_get_contents();\r\nob_end_clean();\r\n\r\nreturn trim($translated);\r\n}\r\n}\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3068\u304f\u306b\u554f\u984c\u306a\u304f\u5229\u7528\u3067\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u5909\u63db\u3059\u308b\u969b\u306e\u5143\u30c7\u30fc\u30bf\u304c\u3001 qtype_stack.php \u306b\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u65e5\u672c\u8a9e\u7248\u3067\u306f\u3001$a \u3068\u306a\u308b\u3079\u304d\u3068\u3053\u308d\u304c a \u3068\u306a\u3063\u3066\u3044\u308b\u7b87\u6240\u304c\u3042\u308b\u306a\u3069\u3001$\u304c\u629c\u3051\u3066\u3044\u308b\u3068\u3053\u308d\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002\u3044\u304f\u3089\u304b\u4fee\u6b63\u3057\u305f\u306e\u3067\u3059\u304c\u3001\u5168\u90e8\u306f\u8a02\u6b63\u3067\u304d\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u4e0b\u8a18\u304c\u6700\u7d42\u30b3\u30fc\u30c9\u306e\u5b9f\u884c\u753b\u9762\u3067\u3059\u3002\u51fa\u529b\u306e\u6700\u5f8c\u306e\u65b9\u3060\u3051\u898b\u3048\u3066\u3044\u307e\u3059\u3002$atmark \u304c\u6b63\u89e3\u4e0d\u6b63\u89e3\u3092\u793a\u3057\u3001$atvalid \u306f\u8a55\u4fa1\u304c\u6210\u529f\u3057\u305f\u3053\u3068\u3092\u8868\u3059\u5909\u6570\u3067\u3059\u3002<\/p>\n<p>\u8aad\u307f\u8fbc\u3080\u30d5\u30a1\u30a4\u30eb\u3082\u542b\u3081\u305f\u5168\u90e8\u306e\u30b3\u30fc\u30c9\u306f<span style=\"color: #0000ff;\"><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/all.zip\"><span style=\"color: #0000ff;\">\u3053\u3053<\/span><\/a><\/span>\u3067\u3059\u3002\u7e70\u308a\u8fd4\u3057\u3067\u3059\u304c\u3001maximalocal.mac \u306b moodledata \u30d5\u30a9\u30eb\u30c0\u30fc\u3084 maxima \u30d5\u30a1\u30a4\u30eb\u306e\u5834\u6240\u304c\u66f8\u304d\u8fbc\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u4ed6\u306b\u3082\u95a2\u6570call_maxima \u306b maxima \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5834\u6240\u306b\u4f9d\u5b58\u3059\u308b\u7b87\u6240\u304c\u3042\u308a\u307e\u3059\u3002\u5229\u7528\u3059\u308b\u969b\u306b\u306f\u9069\u5f53\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"term6\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term6-237x300.png\" alt=\"\" width=\"237\" height=\"300\" \/><\/a><\/p>\n<p>\u9577\u304f\u306a\u308a\u307e\u3059\u304c\u3001 \u4e0a\u8a18\u306e\u753b\u9762\u3067\u5b9f\u884c\u3057\u305f\u30d5\u30a1\u30a4\u30eb\uff08test.php\uff09\u3092\u3042\u3052\u307e\u3059\u3002 \u5b66\u751f\u306e\u89e3\u7b54\u3084\u5148\u751f\u306e\u6b63\u89e3\u304c Maxima \u306e\u5f0f\u3068\u3057\u3066\u6b63\u3057\u304f\u306a\u3044\u3068\u304d\u306b\u306f\u3001\u30a8\u30e9\u30fc\u304c\u751f\u3058\u3066\u52d5\u4f5c\u3057\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\uff08\u3053\u308c\u307e\u3067\u3082\u3084\u3063\u3066\u3044\u305f\u3053\u3068\u3067\u3059\u304c\uff09\u4f55\u304b\u524d\u51e6\u7406\u3092\u3057\u3066\u3001\u5f0f\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3057\u3066\u304a\u304f\u5fc5\u8981\u306f\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre><code style=\"color:midnightblue;\">&lt;?php\r\n\r\nrequire_once('locallib.php');\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ stack_maxima_format_casstring \u3068 stack_string \u30af\u30e9\u30b9\u306e\u5b9a\u7fa9\r\nrequire_once('outputcomponents.php');\u00a0\u00a0 \u00a0\/\/ html_writer \u30af\u30e9\u30b9\u306e\u5b9a\u7fa9\r\nrequire_once('get_config.php');\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ get_config() \u306e\u5b9a\u7fa9\r\nrequire_once('my_get_string.php');\u00a0\u00a0 \u00a0\/\/ get_string() \u306e\u5b9a\u7fa9\r\nrequire_once('weblib.php');\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ s() \u306e\u5b9a\u7fa9\r\nrequire_once('utils.class.php');\u00a0\u00a0 \u00a0\/\/ stack_debug_log \u306e\u5b9a\u7fa9\r\nrequire_once('casstring.class.php');\r\nrequire_once('options.class.php');\r\n\r\n\/\/ \u4e0b\u8a18\u306e\u30c7\u30fc\u30bf\u306f answertestfixtures.class.php \u304b\u3089\r\n\r\n\/\/$rawdata = array('AlgEquiv', 'a^b*a^c', 'a^(b+c)', 1, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'integerp(3.1)', 'true', 0, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'abs(x)', 'sqrt(x^2)', 1, '', '');\r\n\/\/$rawdata = array('EqualComAss', '2\/4', '1\/2', 0, '', 'Numbers');\r\n\/\/$rawdata = array('FacForm', '24*(x-1\/4)', '24*x-6', 1, 'x', 'Factors over other fields');\r\n\/\/$rawdata = array('AlgEquiv', '[1,2,4]', '[1,2,3]', 0, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'x^(1\/2)', 'sqrt(x)', 1, '', 'Powers and roots');\r\n\/\/$rawdata = array('AlgEquiv', '1\/0', '1', -1, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'x-1)^2', '(x-1)^2', -1, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'a^b*a^c', 'a^(b+c)', 1, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'x', '{1,2,3}', 0, '', 'Sets');\r\n\/\/$rawdata = array('AlgEquiv', '[1,2]', '[1,2,3]', 0, '', '');\r\n$rawdata = array('AlgEquiv', '[1,2,4]', '[1,2,3]', 0, '', '');\r\n\/\/$rawdata = array('AlgEquiv', '{1,2}', '{1,2,3}', 0, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'matrix([epsilon[2],2],[2,x^2])', 'matrix([epsilon[0],2],[2,x^3])', 0, '', '');\r\n\/\/$rawdata = array('AlgEquiv', '1', 'x=1', 0, '', 'Equations');\r\n\/\/$rawdata = array('AlgEquiv', 'f(x)=x^2', 'f(x):=x^2', 0, '', '');\r\n\/\/$rawdata = array('AlgEquiv', 'sqrt(12)', '2*sqrt(3)', 1, '', 'Surds');\r\n\/\/$rawdata = array('SubstEquiv', 'X^2+1', 'x^2+1', 1, '', '');\r\n\/\/$rawdata = array('SubstEquiv', 'x^2+y', 'a^2+b', 1, '', '');\r\n\/\/$rawdata = array('EqualComAss', '2\/4', '1\/2', 0, '', 'Numbers');\r\n\/\/$rawdata = array('EqualComAss', 'x+1', 'y=2*x+1', 0, '', 'Equations');\r\n\/\/$rawdata = array('EqualComAss', '[2*x+1,2]', '[1+x*2,2]', 1, '', 'Lists');\r\n\/\/$rawdata = array('CasEqual', '0.5', '1\/2', 0, '', 'Mix of floats and rational numbers');\r\n\/\/$rawdata = array('SameType', 'x&gt;2', 'x&gt;1', 1, '', '');\r\n\/\/$rawdata = array('SysEquiv', '[90=v*t,90=(v+5)*(t*x-1\/4)]', '[90=v*t,90=(v+5)*(t-1\/4)]', 0, '', '');\r\n\/\/$rawdata = array('SysEquiv', '[90=v*t,90=(v+5)*(t-1\/4),90=(v+6)*(t-1\/5)]', '[90=v*t,90=(v+5)*(t-1\/4)]', 0, '', '');\r\n\/\/$rawdata = array('Expanded', '(x-1)*(x+1)', '0', 0, '', '');\r\n\/\/$rawdata = array('Expanded', 'x^2-a*x-b*x+a*b', '0', 1, '', '');\r\n\/\/$rawdata = array('FacForm', '2*(x^2-3*x)', '2*x*(x-3)', 0, 'x', '');\r\n\/\/$rawdata = array('FacForm', '(y-4)*y*(3*y+6)', '3*(y-4)*y*(y+2)', 0, 'y', '');\r\n\/\/$rawdata = array('CompSquare', 'x^2-2*x+2', '(x-1)^2+1', 0, 'x', '');\r\n\/\/$rawdata = array('SingleFrac', 'a+1\/2', '(2*a+1)\/2', 0, '', '');\r\n\/\/$rawdata = array('SingleFrac', '(1\/2)\/(3\/4)', '2\/3', 0, '', 'Fractions within fractions');\r\n\/\/$rawdata = array('PartFrac', '1\/(x-1)-(x+1)\/(x^2+1)', '2\/((x-1)*(x^2+1))', 1, 'x', 'Irreducible quadratic in denominator');\r\n\/\/$rawdata = array('PartFrac', '1\/(2*(x-1))+x\/(2*(x^2+1))', '1\/((x-1)*(x^2+1))', 0, 'x', '');\r\n\/\/$rawdata = array('PartFrac', '1\/(n-1)-1\/n^2', '1\/((n+1)*n)', 0, 'n', '');\r\n\/\/$rawdata = array('Diff', 'x^4\/4', '3*x^2', 0, 'x', '');\r\n\/\/$rawdata = array('Diff', '6000*(x-a)^5999', '6000*(x-a)^5999', 1, 'x', '');\r\n\/\/$rawdata = array('Int', 'x^3\/3+c+1', 'x^3\/3', 1, 'x', '');\r\n\/\/$rawdata = array('Int', 'x^3\/3+c+k', 'x^3\/3', 0, 'x', '');\r\n\/\/$rawdata = array('Int', 'x^3\/3*c', 'x^3\/3', 0, 'x', '');\r\n\/\/$rawdata = array('Int', 'ln(x)+c', 'ln(k*abs(x))', 0, 'x', '');\r\n\/\/$rawdata = array('Int', '((5*%e^7*x-%e^7)*%e^(5*x))', '((5*%e^7*x-%e^7)*%e^(5*x))\/25+c', 0, '[x,x*%e^(5*x+7)]', '');\r\n\/\/$rawdata = array('GT', 'pi', '3', 1, '', '');\r\n\/\/$rawdata = array('NumRelative', '1.05', '1', 1, '', '');\r\n\/\/$rawdata = array('NumRelative', '1.05', '1', 1, '0.1', 'Options passed');\r\n\/\/$rawdata = array('NumRelative', '[3,1.414]', '[pi,sqrt(2)]', 0, '0.01', '');\r\n\/\/$rawdata = array('NumSigFigs', '3.142', 'pi', 1, '4', '');\r\n\/\/$rawdata = array('NumSigFigs', '3141', '3.1415927', 0, '4', '');\r\n\/\/$rawdata = array('LowestTerms', '2\/4', '0', 0, '', '');\r\n\r\n$test = new stdClass();\r\n$test-&gt;name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $rawdata[0];\r\n$test-&gt;studentanswer = $rawdata[1];\r\n$test-&gt;teacheranswer = $rawdata[2];\r\n$test-&gt;expectedscore = $rawdata[3];\r\n$test-&gt;options\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $rawdata[4];\r\n$test-&gt;notes\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $rawdata[5];\r\n\r\n$options = null;\r\n$expectedscore = $test-&gt;expectedscore;\r\n$seed = 0;\r\n$notes = $test-&gt;notes;\r\n\r\n$param = ATconstruct($test-&gt;name, $test-&gt;studentanswer, $test-&gt;teacheranswer, $test-&gt;options, $options);\r\n\r\n$sanskey = $param-&gt;sans;\r\n$tanskey = $param-&gt;tans;\r\n$casfunction = $param-&gt;casfunction;\r\n$processcasoptions = $param-&gt;processcasoptions;\r\n$options = $param-&gt;options;\r\n$casoption = $param-&gt;casoption;\r\n$simp = $param-&gt;simp;\r\n$requiredoptions = $param-&gt;requiredoptions;\r\n\r\nif ($processcasoptions) {\r\n$ta\u00a0\u00a0 = \"[$tanskey,$casoption]\";\r\n} else {\r\n$ta = $tanskey;\r\n}\r\n\r\n\/\/ Sort out options.\r\n\r\nif (null === $options) {\r\n$options = new stack_options();\r\n}\r\n\r\nif (!(null === $simp)) {\r\n$options-&gt;set_option('simplify', $simp);\r\n}\r\n\r\n$cascommands = array();\r\n$cascommands[] = \"STACKSA:$sanskey\";\r\n$cascommands[] = \"STACKTA:$ta\";\r\n$cascommands[] = \"result:StackReturn({$casfunction}(STACKSA,STACKTA))\";\r\n\r\n$keys = array();\r\n$keys[] = \"STACKSA\";\r\n$keys[] = \"STACKTA\";\r\n$keys[] = \"result\";\r\n\r\n$casstring = array();\r\n$casstring[] = $sanskey;\r\n$casstring[] = $ta;\r\n$casstring[] = \"StackReturn({$casfunction}(STACKSA,STACKTA))\";\r\n\r\n$cts = array();\r\n$i = 0;\r\n\r\nforeach ($cascommands as $com) {\r\n\r\n$cs\u00a0\u00a0\u00a0 = new stack_cas_casstring($com);\r\n\r\n\/\/$cs-&gt;get_valid('t', true, 0); \/\/ \u3053\u306e\u6a5f\u80fd\u306f\u524a\u9664\u3057\u305f\r\n\r\n$cs-&gt;set_key($keys[$i]);\r\n\r\n$cs-&gt;set_casstring($casstring[$i]);\r\n\r\n$cts[] = $cs;\r\n\r\n$i++;\r\n}\r\n\r\n$secondcommand = construct_maxima_command($cts, $options, $seed);\r\n\r\necho $secondcommand.\"\\n\\n\";\r\n\r\n$a_debug_log = new stack_debug_log_base();\r\n\r\n$initcommand = 'load(\"\/var\/www\/html\/for_stack333\/moodledata\/stack\/maximalocal.mac\");';\r\n\r\n$after_string = call_maxima($initcommand, $secondcommand, $a_debug_log, 30);\r\n\r\necho $after_string.\"\\n\";\r\n\r\n$results = unpack_raw_result($after_string, $a_debug_log);\r\n\r\nvar_dump($results);\r\n\r\n\/\/ cassession.class.php \u306e instantiate() \u304b\u3089\r\n\r\n\/\/ Now put the information back into the correct slots.\r\n$session\u00a0\u00a0\u00a0 = $cts;\r\n$newsession = array();\r\n$newerrors\u00a0 = '';\r\n$allfail\u00a0\u00a0\u00a0 = true;\r\n$i\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n\r\n$errors = \"\"; \/\/ \u3069\u3046\u5229\u7528\u3059\u308b\u306e\u304b\u4e0d\u660e\u3002\r\n\r\n\/\/ We loop over each entry in the session, not over the result.\r\n\/\/ This way we can add an error for missing values.\r\n\r\nforeach ($session as $cs) {\r\n\r\n$gotvalue = false;\r\n\r\nif ('' == $cs-&gt;get_key()) {\r\n$key = 'dumvar'.$i;\r\n} else {\r\n$key = $cs-&gt;get_key();\r\n}\r\n\r\nif (array_key_exists($i, $results)) {\r\n$allfail = false; \/\/ We at least got one result back from the CAS!\r\n\r\n$result = $results[\"$i\"]; \/\/ GOCHA!\u00a0 results have string represenations of numbers, not int....\r\n\r\nif (array_key_exists('value', $result)) {\r\n$val = str_replace('QMCHAR', '?', $result['value']);\r\n$cs-&gt;set_value($val);\r\n$gotvalue = true;\r\n}\r\n\r\nif (array_key_exists('display', $result)) {\r\n\/\/ Need to add this in here also because strings may contain question mark characters.\r\n$disp = str_replace('QMCHAR', '?', $result['display']);\r\n$cs-&gt;set_display($disp);\r\n}\r\n\r\nif (array_key_exists('valid', $result)) {\r\n$cs-&gt;set_valid($result['valid']);\r\n}\r\n\r\nif (array_key_exists('answernote', $result)) {\r\n$cs-&gt;set_answernote($result['answernote']);\r\n}\r\n\r\nif (array_key_exists('feedback', $result)) {\r\n$cs-&gt;set_feedback($result['feedback']);\r\n}\r\n\r\nif ('' != $result['error'] and false === strstr($result['error'], 'clipped')) {\r\n$cs-&gt;add_errors($result['error']);\r\n$cs-&gt;decode_maxima_errors($result['error']);\r\n$newerrors .= stack_maxima_format_casstring($cs-&gt;get_raw_casstring());\r\n$newerrors .= ' '.stack_string(\"stackCas_CASErrorCaused\") . ' ' . $result['error'] . ' ';\r\n}\r\n} else if (!$gotvalue) {\r\n$errstr = stack_string(\"stackCas_failedReturn\").' '.stack_maxima_format_casstring($cs-&gt;get_raw_casstring());\r\n$cs-&gt;add_errors($errstr);\r\n$cs-&gt;set_answernote('CASFailedReturn');\r\n$newerrors .= $errstr;\r\n}\r\n\r\n$newsession[] = $cs;\r\n$i++;\r\n}\r\n\r\n$session = $newsession;\r\n\r\nif ('' != $newerrors) {\r\n$errors .= '&lt;span&gt;'.stack_string('stackCas_CASError').'&lt;\/span&gt;'.$newerrors;\r\n}\r\n\r\nif ($allfail) {\r\n$errors = '&lt;span&gt;'.stack_string('stackCas_allFailed').'&lt;\/span&gt;';\r\n}\r\n\r\necho \"\\n\\n\".'$errors : '.$errors.\"\\n\\n\";\r\n\r\nvar_dump($session);\r\n\r\n\/\/at_general_cas.class.php \u306e do_test() \u304b\u3089\r\n\r\n$aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = null;\r\n$atfeedback\u00a0\u00a0 = null;\r\n$atansnote\u00a0\u00a0\u00a0 = null;\r\n$atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = null;\r\n\r\nif ('' != $session[2]-&gt;get_errors()) {\r\n\r\n$aterror\u00a0\u00a0\u00a0\u00a0\u00a0 = 'TEST_FAILED';\r\n\r\nif ('' != trim($session[2]-&gt;get_feedback())) {\r\n$atfeedback = $session[2]-&gt;get_feedback();\r\n} else {\r\n$atfeedback = stack_string('TEST_FAILED', array('errors' =&gt; $session[2]-&gt;get_errors()));\r\n}\r\n\r\n$atansnote\u00a0\u00a0\u00a0 = trim($session[2]-&gt;get_answernote());\r\n$atmark\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;\r\n$atvalid\u00a0\u00a0\u00a0\u00a0\u00a0 = false;\r\n\/\/return null;\r\n\r\n} else {\r\n\r\n$atansnote\u00a0 = trim($session[2]-&gt;get_answernote());\r\n\r\n\/\/ Convert the Maxima string 'true' to PHP true.\r\nif ('true' == $session[2]-&gt;get_value()) {\r\n$atmark = 1;\r\n} else {\r\n$atmark = 0;\r\n}\r\n\r\n$atfeedback = $session[2]-&gt;get_feedback();\r\n$atfeedback = stack_maxima_translate($atfeedback);\r\n\r\n$atvalid\u00a0\u00a0\u00a0 = $session[2]-&gt;get_valid();\r\n}\r\n\r\n\/\/if ($atmark) {\r\n\/\/return true;\r\n\/\/} else {\r\n\/\/return false;\r\n\/\/}\r\n\r\necho \"\\n\\n\";\r\necho '$aterror\u00a0\u00a0\u00a0 = '.$aterror.\"\\n\";\r\necho '$atfeedback = '.$atfeedback.\"\\n\";\r\necho '$atansnote\u00a0 = '.$atansnote.\"\\n\";\r\necho '$atmark\u00a0\u00a0\u00a0\u00a0 = '.$atmark.\"\\n\";\r\necho '$atvalid\u00a0\u00a0\u00a0 = '.$atvalid.\"\\n\";\r\n\r\nfunction ATconstruct($anstest = null, $sans = null, $tans = null, $casoption = null, $options = null) {\r\n\r\n\/\/ ($anstest = null, $sans = null, $tans = null, $options = null, $casoption = null)\r\n\r\nswitch($anstest) {\r\ncase 'AlgEquiv':\r\nreturn new parameter_constract($sans, $tans, 'ATAlgEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\n\/\/ \u4fee\u6b63\u3057\u305f\u3068\u3053\u308d Dimension \u7528\u306e\u90e8\u5206\r\n\r\ncase 'Dimension':\r\nreturn new parameter_constract($sans, $tans, 'ATAlgEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'EqualComAss':\r\nreturn new parameter_constract($sans, $tans, 'ATEqualComAss', false, $casoption, $options, false);\r\nbreak;\r\n\r\ncase 'CasEqual':\r\nreturn new parameter_constract($sans, $tans, 'ATCASEqual', false, $casoption, $options, false);\r\nbreak;\r\n\r\ncase 'SameType':\r\nreturn new parameter_constract($sans, $tans, 'ATSameType', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'SubstEquiv':\r\nreturn new parameter_constract($sans, $tans, 'ATSubstEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'Expanded':\r\nreturn new parameter_constract($sans, $tans, 'ATExpanded', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'FacForm':\r\nreturn new parameter_constract($sans, $tans, 'ATFacForm', true, $casoption, $options, false, true);\r\nbreak;\r\n\r\ncase 'SingleFrac':\r\nreturn new parameter_constract($sans, $tans, 'ATSingleFrac', false, $casoption, $options, false);\r\nbreak;\r\n\r\ncase 'PartFrac':\r\nreturn new parameter_constract($sans, $tans, 'ATPartFrac',\r\ntrue, $casoption, $options, true, false, true);\r\nbreak;\r\n\r\ncase 'CompSquare':\r\nreturn new parameter_constract($sans, $tans, 'ATCompSquare',\r\ntrue, $casoption, $options, true, false, true);\r\nbreak;\r\n\r\ncase 'String':\r\n\/\/require_once(__DIR__ . '\/atstring.class.php');\r\n\/\/return new stack_anstest_atstring($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'StringSloppy':\r\n\/\/require_once(__DIR__ . '\/stringsloppy.class.php');\r\n\/\/return new stack_anstest_stringsloppy($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'RegExp':\r\n\/\/require_once(__DIR__ . '\/atregexp.class.php');\r\n\/\/return new stack_anstest_atregexp($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'Diff':\r\nreturn new parameter_constract($sans, $tans, 'ATDiff', true, $casoption, $options, false, true);\r\nbreak;\r\n\r\ncase 'Int':\r\nreturn new parameter_constract($sans, $tans, 'ATInt', true, $casoption, $options, false, true);\r\nbreak;\r\n\r\ncase 'GT':\r\nreturn new parameter_constract($sans, $tans, 'ATGT', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'GTE':\r\nreturn new parameter_constract($sans, $tans, 'ATGTE', false, $casoption, $options);\r\nbreak;\r\n\r\ncase 'NumAbsolute':\r\nif (trim($casoption) == '') {\r\n$casoption = '0.05';\r\n}\r\nreturn new parameter_constract($sans, $tans, 'ATNumAbsolute', true, $casoption, $options, true, true);\r\nbreak;\r\n\r\ncase 'NumRelative':\r\nif (trim($casoption) == '') {\r\n$casoption = '0.05';\r\n}\r\nreturn new parameter_constract($sans, $tans, 'ATNumRelative', true, $casoption, $options, true, true);\r\nbreak;\r\n\r\ncase 'NumSigFigs':\r\nreturn new parameter_constract($sans, $tans, 'ATNumSigFigs', true, $casoption, $options, true, true);\r\nbreak;\r\n\r\ncase 'NumDecPlaces':\r\n\/\/require_once(__DIR__ . '\/atdecplaces.class.php');\r\n\/\/$this-&gt;at = new stack_anstest_atdecplaces($sans, $tans, $options, $casoption);\r\nreturn null;\r\nbreak;\r\n\r\ncase 'LowestTerms':\r\nreturn new parameter_constract($sans, $tans, 'ATLowestTerms', false, $casoption, $options, 0);\r\nbreak;\r\n\r\ncase 'SysEquiv':\r\nreturn new parameter_constract($sans, $tans, 'ATSysEquiv', false, $casoption, $options);\r\nbreak;\r\n\r\ndefault:\r\nreturn 'stack_ans_test_controller: called with invalid answer test name: '.$anstest;\r\nbreak;\r\n}\r\n}\r\n\r\n\/\/ \u5143\u306f\u3001class stack_answertest_general_cas\r\n\r\nclass parameter_constract {\r\n\r\npublic $sans;\r\npublic $tans;\r\n\r\n\/**\r\n* @var string The name of the cas function this answer test uses.\r\n*\/\r\npublic $casfunction;\r\n\r\n\/**\r\n* $var bool Are options processed by the CAS.\r\n*\/\r\npublic $processcasoptions;\r\n\r\npublic $casoption;\r\npublic $options;\r\n\r\n\/**\r\n* $var bool If this variable is set to true or false we override the\r\n*\u00a0\u00a0\u00a0\u00a0\u00a0 simplification options in the CAS variables.\r\n*\/\r\npublic $simp;\r\n\r\n\/**\r\n* $var bool Are options required for this test.\r\n*\/\r\npublic $requiredoptions;\r\n\r\n\/**\r\n* @param\u00a0 string $sans\r\n* @param\u00a0 string $tans\r\n* @param\u00a0 string $casoption\r\n*\/\r\npublic function __construct($sans, $tans, $casfunction, $processcasoptions = false, $casoption = null, $options = null, $simp = false, $requiredoptions = false) {\r\n\r\n$this-&gt;sans\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $sans;\r\n$this-&gt;tans\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $tans;\r\n\r\n$this-&gt;casfunction\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $casfunction;\r\n$this-&gt;processcasoptions = $processcasoptions;\r\n\r\n$this-&gt;casoption\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $casoption;\r\n$this-&gt;options\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = $options;\r\n\r\n$this-&gt;simp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = (bool) $simp;\r\n\r\n$this-&gt;requiredoptions\u00a0\u00a0 = $requiredoptions;\r\n}\r\n}\r\n\r\n\/**\r\n* Creates the string which Maxima will execute\r\n*\r\n* @return string\r\n*\/\r\nfunction construct_maxima_command($cts, $options, $seed) {\r\n\/\/ Ensure that every command has a valid key.\r\n\r\n$casoptions = $options-&gt;get_cas_commands();\r\n\r\n$csnames = $casoptions['names'];\r\n$csvars\u00a0 = $casoptions['commands'];\r\n$cascommands = '';\r\n$caspreamble = '';\r\n\r\n$cascommands .= ', print(\"-1=[ error= [\"), cte(\"__stackmaximaversion\",errcatch(__stackmaximaversion:stackmaximaversion)) ';\r\n\r\n$i = 0;\r\nforeach ($cts as $cs) {\r\nif ('' == $cs-&gt;get_key()) {\r\n$label = 'dumvar'.$i;\r\n} else {\r\n$label = $cs-&gt;get_key();\r\n}\r\n\r\n\/\/ Replace any ?'s with a safe value.\r\n$cmd = str_replace('?', 'QMCHAR', $cs-&gt;get_casstring());\r\n\/\/ Strip off any []s at the end of a variable name.\r\n\/\/ These are used to assign elements of lists and matrices, but this breaks Maxima's block command.\r\nif (false === strpos($label, '[')) {\r\n$cleanlabel = $label;\r\n} else {\r\n$cleanlabel = substr($label, 0, strpos($label, '['));\r\n}\r\n\r\n\/\/ Now we do special things if we have a command to re-order expressions.\r\nif (false !== strpos($cmd, 'ordergreat') || false !== strpos($cmd, 'orderless')) {\r\n\/\/ These commands must be in a separate block, and must only appear once.\r\n$caspreamble = $cmd.\"$\\n\";\r\n$cmd = '0';\r\n}\r\n\r\n$csnames\u00a0\u00a0 .= \", $cleanlabel\";\r\n$cascommands .= \", print(\\\"$i=[ error= [\\\"), cte(\\\"$label\\\",errcatch($label:$cmd)) \";\r\n$i++;\r\n\r\n}\r\n\r\n$cass\u00a0 = $caspreamble;\r\n$cass .= 'cab:block([ RANDOM_SEED';\r\n$cass .= $csnames;\r\n$cass .= '], stack_randseed(';\r\n$cass .= $seed.')'.$csvars;\r\n$cass .= \", print(\\\"[TimeStamp= [ $seed ], Locals= [ \\\") \";\r\n$cass .= $cascommands;\r\n$cass .= \", print(\\\"] ]\\\") , return(true) ); \\n \";\r\n\r\nreturn $cass;\r\n}\r\n\r\n\/\/ connector.unix.class.php \u304b\u3089\u4f5c\u6210\r\n\r\nfunction call_maxima($initcommand, $command, $debug, $timeout) {\r\n\r\n$ret = false;\r\n$err = '';\r\n$cwd = null;\r\n$env = array('why' =&gt; 'itworks');\r\n\r\n$descriptors = array(\r\n0 =&gt; array('pipe', 'r'),\r\n1 =&gt; array('pipe', 'w'),\r\n2 =&gt; array('pipe', 'w'));\r\n\r\n$casprocess = proc_open('\/usr\/local\/bin\/maxima', $descriptors, $pipes, $cwd, $env);\r\n\r\nfwrite($pipes[0], $initcommand);\r\nfwrite($pipes[0], $command);\r\nfwrite($pipes[0], 'quit();'.\"\\n\\n\");\r\n\r\n$ret = '';\r\n\/\/ Read output from stdout.\r\n$starttime = microtime(true);\r\n$continue\u00a0\u00a0 = true;\r\n\r\nif (!stream_set_blocking($pipes[1], false)) {\r\n$debug-&gt;log('', 'Warning: could not stream_set_blocking to be FALSE on the CAS process.');\r\n}\r\n\r\nwhile ($continue and !feof($pipes[1])) {\r\n\r\n$now = microtime(true);\r\n\r\nif (($now - $starttime) &gt; $timeout) {\r\n$procarray = proc_get_status($casprocess);\r\nif ($procarray['running']) {\r\nproc_terminate($casprocess);\r\n}\r\n$continue = false;\r\n} else {\r\n$out = fread($pipes[1], 1024);\r\nif ('' == $out) {\r\n\/\/ Pause.\r\nusleep(1000);\r\n}\r\n$ret .= $out;\r\n}\r\n\r\n}\r\n\r\nif ($continue) {\r\nfclose($pipes[0]);\r\nfclose($pipes[1]);\r\n$debug-&gt;log('Timings', \"Start: {$starttime}, End: {$now}, Taken = \" .($now - $starttime));\r\n\r\n} else {\r\n\/\/ Add sufficient closing ]'s to allow something to be un-parsed from the CAS.\r\n\/\/ WARNING: the string 'The CAS timed out' is used by the cache to search for a timeout occurrence.\r\n$ret .= ' The CAS timed out. ] ] ] ]';\r\n}\r\n\r\nreturn $ret;\r\n\r\n}\r\n\r\n\/\/ connector.class.php\u3000\u304b\u3089\u6301\u3063\u3066\u304d\u305f\r\n\/**\r\n* Top level Maxima-specific function used to parse CAS output into an array.\r\n*\r\n* @param array $rawresult Raw CAS output\r\n* @return array\r\n*\/\r\nfunction unpack_raw_result($rawresult, $debug) {\r\n\r\n$result = '';\r\n$errors = false;\r\n\r\nif ('' == trim($rawresult)) {\r\n$debug-&gt;log('Warning, empty result!', 'unpack_raw_result: completely empty result was returned by the CAS.');\r\nreturn array();\r\n}\r\n\r\n\/\/ Check we have a timestamp &amp; remove everything before it.\r\n$ts = substr_count($rawresult, '[TimeStamp');\r\nif ($ts != 1) {\r\n$debug-&gt;log('', 'unpack_raw_result: no timestamp returned. Data returned was: '.$rawresult);\r\nreturn array();\r\n} else {\r\n$result = strstr($rawresult, '[TimeStamp'); \/\/ Remove everything before the timestamp.\r\n}\r\n\r\n$result = trim(str_replace('#', '', $result));\r\n$result = trim(str_replace(\"\\n\", '', $result));\r\n\r\n$unp = unpack_helper($result);\r\n\r\nif (array_key_exists('Locals', $unp)) {\r\n$uplocs = $unp['Locals']; \/\/ Grab the local variables.\r\nunset($unp['Locals']);\r\n} else {\r\n$uplocs = '';\r\n}\r\n\r\n\/\/ Now we need to turn the (error,key,value,display) tuple into an array.\r\n$locals = array();\r\n\r\nforeach (unpack_helper($uplocs) as $var =&gt; $valdval) {\r\nif (is_array($valdval)) {\r\n$errors[\"CAS\"] = \"unpack_raw_result: CAS failed to generate any useful output.\";\r\n} else {\r\nif (preg_match('\/.*\\[.*\\].*\/', $valdval)) {\r\n\/\/ There are some []'s in the string.\r\n$loc = unpack_helper($valdval);\r\nif ('' == trim($loc['error'])) {\r\nunset($loc['error']);\r\n}\r\n$locals[$var] = $loc;\r\n\r\n} else {\r\n$errors[\"LocalVarGet$var\"] = \"Couldn't unpack the local variable $var from the string $valdval.\";\r\n}\r\n}\r\n}\r\n\r\n\/\/ Next process and tidy up these values.\r\nforeach ($locals as $i =&gt; &amp;$local) {\r\n\r\nif (isset($local['error'])) {\r\n$local['error'] = tidy_error($local['error']);\r\n} else {\r\n$local['error'] = '';\r\n}\r\n\/\/ If there are plots in the output.\r\n$plot = isset($local['display']) ? substr_count($local['display'], '&lt;img') : 0;\r\nif ($plot &gt; 0) {\r\n\/\/ Plots always contain errors, so remove.\r\n$local['error'] = '';\r\n\/\/ For mathml display, remove the mathml that is inserted wrongly round the plot.\r\n$local['display'] = str_replace('&lt;math xmlns=\\'http:\/\/www.w3.org\/1998\/Math\/MathML\\'&gt;',\r\n'', $local['display']);\r\n$local['display'] = str_replace('&lt;\/math&gt;', '', $local['display']);\r\n\r\n\/\/ For latex mode, remove the mbox.\r\n\/\/ This handles forms: \\mbox{image} and (earlier?) \\mbox{{} {image} {}}.\r\n$local['display'] = preg_replace(\"|\\\\\\mbox{({})? (&lt;html&gt;.+&lt;\/html&gt;) ({})?}|\", \"$2\", $local['display']);\r\n\r\n\/\/if ($this-&gt;wwwroothasunderscores) {\r\n\/\/\u00a0\u00a0\u00a0 $local['display'] = str_replace($this-&gt;wwwrootfixupfind,\r\n\/\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $this-&gt;wwwrootfixupreplace, $local['display']);\r\n\/\/}\r\n}\r\n}\r\nreturn $locals;\r\n}\r\n\r\nfunction unpack_helper($rawresultfragment) {\r\n\/\/ Take the raw string from the CAS, and unpack this into an array.\r\n$offset = 0;\r\n$rawresultfragmentlen = strlen($rawresultfragment);\r\n$unparsed = '';\r\n$errors = '';\r\n\r\nif ($eqpos = strpos($rawresultfragment, '=', $offset)) {\r\n\/\/ Check there are ='s.\r\ndo {\r\n$gb = stack_utils::substring_between($rawresultfragment, '[', ']', $eqpos);\r\n$val = substr($gb[0], 1, strlen($gb[0]) - 2);\r\n$val = trim($val);\r\n\r\nif (preg_match('\/[-A-Za-z0-9].*\/', substr($rawresultfragment, $offset, $eqpos - $offset), $regs)) {\r\n$var = trim($regs[0]);\r\n} else {\r\n$var = 'errors';\r\n$errors['LOCVARNAME'] = \"Couldn't get the name of the local variable.\";\r\n}\r\n\r\n$unparsed[$var] = $val;\r\n$offset = $gb[2];\r\n} while (($eqpos = strpos($rawresultfragment, '=', $offset)) &amp;&amp; ($offset &lt; $rawresultfragmentlen));\r\n\r\n} else {\r\n$errors['PREPARSE'] = \"There are no ='s in the raw output from the CAS!\";\r\n}\r\n\r\nif ('' != $errors) {\r\n$unparsed['errors'] = $errors;\r\n}\r\n\r\nreturn $unparsed;\r\n}\r\n\r\n\/**\r\n* Deals with Maxima errors. Enables some translation.\r\n*\r\n* @param string $errstr a Maxima error string\r\n* @return string\r\n*\/\r\nfunction tidy_error($errstr) {\r\n\r\n\/\/ This case arises when we use a numerical text for algebraic equivalence.\r\nif (strpos($errstr, 'STACK: ignore previous error.') !== false) {\r\nreturn '';\r\n}\r\n\r\nif (strpos($errstr, '0 to a negative exponent') !== false) {\r\n$errstr = stack_string('Maxima_DivisionZero');\r\n}\r\nreturn $errstr;\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u308c\u3067\u7d42\u4e86\u3060\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001ubuntu1510 \u3067\u52d5\u304b\u3057\u3066\u307f\u305f\u3089\u3046\u307e\u304f\u3044\u304b\u305a\u3001\u3082\u3046\u5c11\u3057\u66f8\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u3001\u4e0a\u624b\u304f\u52d5\u3044\u3066\u3044\u308b\u6642\u306e\u3001\u52d5\u304d\u51fa\u3057\u306e\u3068\u3053\u308d\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3067\u3059\u3002maxima \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f 5.360\u3001Lisp \u306f SBCL 1.1.14.debian \u3067\u3059\u3002\u5834\u6240\u306f\/usr\/local\/bin\/maxima\u3067\u3001\u30bd\u30fc\u30b9\u304b\u3089\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5c0e\u5165\u3057\u305fmaxima \u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3964\" title=\"term7\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2015\/09\/term7-241x300.png\" alt=\"\" width=\"241\" height=\"300\" \/><\/a><\/p>\n<p>ubuntu1510 \u3067\u306f\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u30bb\u30f3\u30bf\u30fc\u304b\u3089\u5165\u308b maxima \u306f 5.361 \u3067\u3001LISP \u306fGCL2.6.12 \u3067\u3059\u3002\u5834\u6240\u306f \/usr\/bin\/maxima \u3067\u3059\u3002\u3053\u306e\u5834\u6240\u3082\u554f\u984c\u3067\u3059\u304c\u3001LISP\u306e\u9055\u3044\u3082\u554f\u984c\u306b\u306a\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>sbcl \u3092\u5229\u7528\u3059\u308b maxima \u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u3068\u304d\u306f\u4e0b\u8a18\u3002\u30bd\u30fc\u30b9\u3092\u5c55\u958b\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u30fc\u306b\u79fb\u52d5\u3057\u3066\u30012,3\u30b3\u30de\u30f3\u30c9\u3092\u6253\u3061\u307e\u3059\u3002<\/p>\n<p>cd .\/maxima-5.36.0<\/p>\n<p>.\/configure &#8211;enable-sbcl<\/p>\n<p>make<\/p>\n<p>sudo make install<\/p>\n<p>GCL\u3067\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u304c\u4e0a\u624b\u304f\u3044\u304d\u307e\u305b\u3093\u3002GCL\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u304c\u3067\u304d\u305f\u3089\u3001\u6bd4\u8f03\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c,\u73fe\u6cc1\u306f\u539f\u56e0\u304c maxima \u306a\u306e\u304b LISP \u306a\u306e\u304b\u306f\u3063\u304d\u308a\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u3044\u307e\u306e\u3068\u3053\u308d maxima \u306f\u3001ubuntu \u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u30bb\u30f3\u30bf\u30fc\u304b\u3089\u5c0e\u5165\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3066\u3001\u30bd\u30fc\u30b9\u304b\u3089 sbcl \u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u4f7f\u3046\u306e\u304c\u826f\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; ubuntu14.04 \u3067 STACK 3.3.3 \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb &#8230; <a class=\"more-link\" href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=3651\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3651","post","type-post","status-publish","format-standard","hentry","category-column"],"_links":{"self":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3651"}],"version-history":[{"count":3,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3651\/revisions"}],"predecessor-version":[{"id":5420,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3651\/revisions\/5420"}],"wp:attachment":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3651"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}