Skip to content

Commit b091a94

Browse files
committed
Add complex, calccomplex, and algebraic ntuple and matrix qtypes
Squashed commit of the following: commit 44045bc7c4297cff7120cea732e40547d13e1f5a Author: drlippman <[email protected]> Date: Mon Nov 4 11:33:08 2024 -0800 Rebuild min JS commit 8a08abe5134d3235516ef0c8cc68867f796d0148 Merge: 792194714 6d9168f Author: drlippman <[email protected]> Date: Mon Nov 4 11:31:30 2024 -0800 Merge branch 'master' into feature.new_matrixntuple_qtypes commit 792194714e6290728afc3241ba659d5461a405cf Author: drlippman <[email protected]> Date: Mon Nov 4 11:29:18 2024 -0800 Bug fixes, add sameform to algmatrix commit b6015818811c54470cd65904da458c6410896652 Author: drlippman <[email protected]> Date: Sun Nov 3 16:53:07 2024 -0800 New question type selector commit e91177559f675c283a611e86b5e77e87129ab572 Author: drlippman <[email protected]> Date: Sat Nov 2 12:41:50 2024 -0700 More help for new types commit 7c4e9b643a500b410928b26ea2cc04e4833266c5 Author: drlippman <[email protected]> Date: Thu Oct 31 20:01:23 2024 -0700 Add new types to help commit b505be27209c06146607008f8e445a28f10165b7 Merge: 7f6136002 85e5106 Author: drlippman <[email protected]> Date: Thu Oct 31 15:29:04 2024 -0700 Merge branch 'master' into feature.new_matrixntuple_qtypes commit 7f6136002bd7ffe8fddc264e85cd47394440161b Author: drlippman <[email protected]> Date: Wed Oct 30 23:11:55 2024 -0700 Add amhelpers2 for complex,alg ntuple commit 443d686bc2f287336550cfd2f5ca4074da9a6680 Author: drlippman <[email protected]> Date: Wed Oct 30 19:58:24 2024 -0700 Add algntuple scoring commit 1e8e4626a41ff31ac166bb6e735da67cc46e4f4f Author: drlippman <[email protected]> Date: Wed Oct 30 13:33:10 2024 -0700 Add complexntuple scoring to ntuplescorepart, complex parsing to parseNtuple commit 4e283e69f8a830f64e66bb0e4b3c8ad1b037ba82 Author: drlippman <[email protected]> Date: Wed Oct 30 12:10:59 2024 -0700 Move complex, ntuple parsing out of scoreparts andinto answerboxhelpers/macros commit cf487b13fd33cbf3973e4dc4b667b307ca29537b Author: drlippman <[email protected]> Date: Wed Oct 30 10:47:06 2024 -0700 Add algebraic ntuple answerbox commit 767713c28582a78a9863cebccdc1726edc99d0ce Author: drlippman <[email protected]> Date: Tue Oct 29 21:29:38 2024 -0700 Add complexntuple answerbox generator commit f5cb7627fae1776062a24c42e0e07985945e4106 Author: drlippman <[email protected]> Date: Tue Oct 29 21:13:30 2024 -0700 Consolidate ntupleanswerbox and calculatentupleanswerbox commit 834d6dd8ebafe168ee413ad2ab0323c7b61664de Author: drlippman <[email protected]> Date: Tue Oct 29 20:56:09 2024 -0700 Tweak entry tips commit d51ce7027afc7661f3c1343a93c1f41a2f0bd820 Author: drlippman <[email protected]> Date: Tue Oct 29 20:49:51 2024 -0700 Add frontend processing for algmatrix commit faa4461891159483be44b4b6685b504437be84f5 Author: drlippman <[email protected]> Date: Tue Oct 29 20:47:11 2024 -0700 Add complexmatrix and calccomplexmatrix. Start on algmatrix.
1 parent 6d9168f commit b091a94

26 files changed

+2118
-603
lines changed

assess2/questions/answerboxes/CalculatedNTupleAnswerBox.php renamed to assess2/questions/answerboxes/AlgebraicNTupleAnswerBox.php

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Sanitize;
88

9-
class CalculatedNTupleAnswerBox implements AnswerBox
9+
class AlgebraicNTupleAnswerBox implements AnswerBox
1010
{
1111
private $answerBoxParams;
1212

@@ -40,8 +40,8 @@ public function generate(): void
4040
$preview = '';
4141
$params = [];
4242

43-
$optionkeys = ['ansprompt', 'answerboxsize', 'hidepreview', 'answerformat',
44-
'answer', 'reqdecimals', 'displayformat', 'readerlabel'];
43+
$optionkeys = ['answerboxsize', 'answerformat', 'answer', 'displayformat',
44+
'ansprompt', 'readerlabel', 'hidepreview', 'variables', 'domain'];
4545
foreach ($optionkeys as $optionkey) {
4646
${$optionkey} = getOptionVal($options, $optionkey, $multi, $partnum);
4747
}
@@ -52,34 +52,44 @@ public function generate(): void
5252
if ($multi) {$qn = ($qn + 1) * 1000 + $partnum;}
5353

5454
if ($displayformat == 'point') {
55-
$tip = _('Enter your answer as a point. Example: (2,5.5172)') . "<br/>";
56-
$shorttip = _('Enter a point');
55+
$tip = _('Enter your answer as an algebraic point. Example: (x,x^2)') . "<br/>";
56+
$shorttip = _('Enter an algebraic point');
5757
} else if ($displayformat == 'pointlist') {
58-
$tip = _('Enter your answer a list of points separated with commas. Example: (1,2), (3.5172,5)') . "<br/>";
59-
$shorttip = _('Enter a list of points');
58+
$tip = _('Enter your answer a list of algebraic points separated with commas. Example: (x,x^2), (3,4x)') . "<br/>";
59+
$shorttip = _('Enter a list of algebraic points');
6060
} else if ($displayformat == 'vector') {
61-
$tip = _('Enter your answer as a vector. Example: <2,5.5172>') . "<br/>";
62-
$shorttip = _('Enter a vector');
61+
$tip = _('Enter your answer as an algebraic vector. Example: &lt;x,x^2&gt;') . "<br/>";
62+
$shorttip = _('Enter an algebraic vector');
6363
} else if ($displayformat == 'vectorlist') {
64-
$tip = _('Enter your answer a list of vectors separated with commas. Example: <1,2>, <3.5172,5>') . "<br/>";
65-
$shorttip = _('Enter a list of vectors');
64+
$tip = _('Enter your answer a list of algebraic vectors separated with commas. Example: &lt;x,x^2&gt;, &lt;3,x&gt;') . "<br/>";
65+
$shorttip = _('Enter a list of algebraic vectors');
6666
} else if ($displayformat == 'set') {
67-
$tip = _('Enter your answer as a set of numbers. Example: {1,2,3}') . "<br/>";
68-
$shorttip = _('Enter a set');
67+
$tip = _('Enter your answer as a set of algebraic expressions. Example: {x,x^2,3x}') . "<br/>";
68+
$shorttip = _('Enter an algebraic set');
6969
} else if ($displayformat == 'setlist') {
70-
$tip = _('Enter your answer as a list of sets separated with commas. Example: {1,2,3},{4,5}') . "<br/>";
71-
$shorttip = _('Enter a list of sets');
70+
$tip = _('Enter your answer as a list of sets separated with commas. Example: {x,3,x^2},{2x,5}') . "<br/>";
71+
$shorttip = _('Enter a list of algebraic sets');
7272
} else if ($displayformat == 'list') {
73-
$tip = _('Enter your answer as a list of n-tuples of numbers separated with commas: Example: (1,2),(3.5172,4)') . "<br/>";
74-
$shorttip = _('Enter a list of n-tuples');
73+
$tip = _('Enter your answer as a list of n-tuples of algebraic expressions separated with commas: Example: (x,x^2),(3,4x)') . "<br/>";
74+
$shorttip = _('Enter a list of algebraic n-tuples');
7575
} else {
76-
$tip = _('Enter your answer as an n-tuple of numbers. Example: (2,5.5172)') . "<br/>";
77-
$shorttip = _('Enter an n-tuple');
76+
$tip = _('Enter your answer as an n-tuple of algebraic expressions. Example: (x,x^2)') . "<br/>";
77+
$shorttip = _('Enter an algebraic n-tuple');
7878
}
79-
if ($reqdecimals !== '') {
80-
list($reqdecimals, $exactreqdec, $reqdecoffset, $reqdecscoretype) = parsereqsigfigs($reqdecimals);
79+
if (in_array('generalcomplex', $ansformats)) {
80+
$tip .= _('Your answer can contain complex numbers.') . '<br/>';
8181
}
82-
$tip .= formathint('each value', $ansformats, ($reqdecimals !== '') ? $reqdecimals : null, 'calcntuple');
82+
if (!in_array('nosoln', $ansformats) && !in_array('nosolninf', $ansformats)) {
83+
$tip .= _('Enter DNE for Does Not Exist');
84+
}
85+
86+
if (empty($variables)) {$variables = "x";}
87+
$addvars = [];
88+
if (in_array('generalcomplex', $ansformats)) {
89+
$addvars[] = 'i';
90+
}
91+
list($variables, $ofunc, $newdomain, $restrictvartoint) = numfuncParseVarsDomain($variables, $domain, $addvars);
92+
8393

8494
$classes = ['text'];
8595
if ($colorbox != '') {
@@ -97,13 +107,17 @@ public function generate(): void
97107
];
98108
$params['tip'] = $shorttip;
99109
$params['longtip'] = $tip;
110+
100111
$params['calcformat'] = $answerformat . (($answerformat == '') ? '' : ',') . $displayformat;
101112
if ($useeqnhelper) {
102113
$params['helper'] = 1;
103114
}
104115
if (empty($hidepreview)) {
105116
$params['preview'] = !empty($_SESSION['userprefs']['livepreview']) ? 1 : 2;
106117
}
118+
$params['vars'] = $variables;
119+
$params['fvars'] = $ofunc;
120+
$params['domain'] = $newdomain;
107121

108122
$out .= '<input ' .
109123
Sanitize::generateAttributeString($attributes) .
@@ -115,7 +129,7 @@ public function generate(): void
115129
$preview .= _('Preview') . ' <span class="sr-only">' . $this->answerBoxParams->getQuestionIdentifierString() . '</span>';
116130
$preview .= '</button> &nbsp;';
117131
}
118-
$preview .= "<span id=p$qn></span> ";
132+
$preview .= "<span id=p$qn></span>";
119133

120134
$nosolntype = 0;
121135
if (in_array('nosoln', $ansformats) || in_array('nosolninf', $ansformats)) {
@@ -125,10 +139,15 @@ public function generate(): void
125139
if ($nosolntype > 0) {
126140
$sa = $answer;
127141
} else {
128-
$sa = makeprettydisp($answer);
129-
if ($displayformat == 'vector') {
142+
if ($GLOBALS['myrights'] > 10 && strpos($answer, '|') !== false) {
143+
echo 'Warning: use abs(x) not |x| in $answer';
144+
}
145+
$sa = $answer;
146+
if ($displayformat == 'vectorlist' || $displayformat == 'vector') {
130147
$sa = str_replace(array('<', '>'), array('(:', ':)'), $sa);
131148
}
149+
$sa = numfuncPrepShowanswer($sa, $variables);
150+
$sa = '`' . $sa . '`';
132151
}
133152
}
134153

assess2/questions/answerboxes/AnswerBoxFactory.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require_once __DIR__ . '/CalculatedComplexAnswerBox.php';
77
require_once __DIR__ . '/CalculatedIntervalAnswerBox.php';
88
require_once __DIR__ . '/CalculatedMatrixAnswerBox.php';
9-
require_once __DIR__ . '/CalculatedNTupleAnswerBox.php';
109
require_once __DIR__ . '/ChoicesAnswerBox.php';
1110
require_once __DIR__ . '/ComplexAnswerBox.php';
1211
require_once __DIR__ . '/DrawingAnswerBox.php';
@@ -18,6 +17,8 @@
1817
require_once __DIR__ . '/MatrixAnswerBox.php';
1918
require_once __DIR__ . '/MultipleAnswerAnswerBox.php';
2019
require_once __DIR__ . '/NTupleAnswerBox.php';
20+
require_once __DIR__ . '/ComplexNTupleAnswerBox.php';
21+
require_once __DIR__ . '/AlgebraicNTupleAnswerBox.php';
2122
require_once __DIR__ . '/NumberAnswerBox.php';
2223
require_once __DIR__ . '/StringAnswerBox.php';
2324
require_once __DIR__ . '/ChemEquationAnswerBox.php';
@@ -43,6 +44,9 @@
4344
* - Drawing: "draw"
4445
* - N-tuple: "ntuple"
4546
* - Calculated N-tuple: "calcntuple"
47+
* - Complex N-tuple: "complexntuple"
48+
* - Calculated Complex N-tuple: "calccomplexntuple"
49+
* - Algebraic N-tuple: "algntuple"
4650
* - Matrix: "matrix"
4751
* - Calculated Matrix: "calcmatrix"
4852
* - Complex: "complex"
@@ -81,11 +85,10 @@ public static function getAnswerBoxGenerator(AnswerBoxParams $answerBoxParams):
8185
return new CalculatedIntervalAnswerBox($answerBoxParams);
8286
break;
8387
case 'calcmatrix':
88+
case 'calccomplexmatrix':
89+
case 'algmatrix':
8490
return new CalculatedMatrixAnswerBox($answerBoxParams);
8591
break;
86-
case 'calcntuple':
87-
return new CalculatedNTupleAnswerBox($answerBoxParams);
88-
break;
8992
case 'choices':
9093
return new ChoicesAnswerBox($answerBoxParams);
9194
break;
@@ -110,15 +113,24 @@ public static function getAnswerBoxGenerator(AnswerBoxParams $answerBoxParams):
110113
case 'matching':
111114
return new MatchingAnswerBox($answerBoxParams);
112115
break;
116+
case 'complexmatrix':
113117
case 'matrix':
114118
return new MatrixAnswerBox($answerBoxParams);
115119
break;
116120
case 'multans':
117121
return new MultipleAnswerAnswerBox($answerBoxParams);
118122
break;
119123
case 'ntuple':
124+
case 'calcntuple':
120125
return new NTupleAnswerBox($answerBoxParams);
121126
break;
127+
case 'complexntuple':
128+
case 'calccomplexntuple':
129+
return new ComplexNTupleAnswerBox($answerBoxParams);
130+
break;
131+
case 'algntuple':
132+
return new AlgebraicNTupleAnswerBox($answerBoxParams);
133+
break;
122134
case 'number':
123135
return new NumberAnswerBox($answerBoxParams);
124136
break;

assess2/questions/answerboxes/CalculatedComplexAnswerBox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function generate(): void
8181
$tip = _('Enter your answer as a complex number in a+bi form. Example: 2+5i') . "<br/>";
8282
$shorttip = _('Enter a complex number');
8383
}
84-
$tip .= formathint('each value',$ansformats,($reqdecimals!=='')?$reqdecimals:null,'calccomplex');
84+
$tip .= formathint(_('each value'),$ansformats,($reqdecimals!=='')?$reqdecimals:null,'calccomplex');
8585
}
8686

8787
$classes = ['text'];

assess2/questions/answerboxes/CalculatedMatrixAnswerBox.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function generate(): void
4242

4343
$optionkeys = ['ansprompt', 'answersize', 'answerboxsize', 'hidepreview', 'answerformat',
4444
'answer', 'reqdecimals', 'displayformat', 'readerlabel'];
45+
if ($anstype === 'algmatrix') {
46+
array_push($optionkeys, 'domain', 'variables');
47+
}
4548
foreach ($optionkeys as $optionkey) {
4649
${$optionkey} = getOptionVal($options, $optionkey, $multi, $partnum);
4750
}
@@ -55,7 +58,12 @@ public function generate(): void
5558
$out .= $ansprompt;
5659
}
5760
if (!empty($answersize)) {
58-
list($tip, $shorttip) = formathint(_('each element of the matrix'), $ansformats, ($reqdecimals !== '') ? $reqdecimals : null, 'calcmatrix', false, true);
61+
if ($anstype === 'algmatrix') {
62+
$shorttip = _('Enter an algebraic expression');
63+
$tip = _('Enter each element of the matrix as an algebraic expression. Example: 3x^2, x/5, (a+b)/c');
64+
} else {
65+
list($tip, $shorttip) = formathint(_('each element of the matrix'), $ansformats, ($reqdecimals !== '') ? $reqdecimals : null, $anstype, false, true);
66+
}
5967
//$tip = "Enter each element of the matrix as number (like 5, -3, 2.2) or as a calculation (like 5/3, 2^3, 5+4)";
6068

6169
if (empty($answerboxsize)) {$answerboxsize = 3;}
@@ -125,8 +133,16 @@ public function generate(): void
125133
} else {
126134
$qnref = ($multi - 1) . '-' . ($qn % 1000);
127135
}
128-
$shorttip = _('Enter your answer as a matrix');
129-
$tip = $shorttip . _(', like [(2,3,4),(1,4,5)]') . '<br/>' . formathint(_('each element of the matrix'), $ansformats, ($reqdecimals !== '') ? $reqdecimals : null, 'calcmatrix');
136+
if ($anstype === 'calccomplexmatrix') {
137+
$shorttip = _('Enter a matrix of complex numbers');
138+
$tip = $shorttip . _(', like [(2+i,3,i),(2-i,4,5)]') . '<br/>' . formathint(_('each element of the matrix'), $ansformats, ($reqdecimals !== '') ? $reqdecimals : null, $anstype);
139+
} else if ($anstype === 'algmatrix') {
140+
$shorttip = _('Enter a matrix of algebraic expressions');
141+
$tip = $shorttip . _(', like [(x,2,x^2),(1,3x,5)]');
142+
} else {
143+
$shorttip = _('Enter your answer as a matrix');
144+
$tip = $shorttip . _(', like [(2,3,4),(1,4,5)]') . '<br/>' . formathint(_('each element of the matrix'), $ansformats, ($reqdecimals !== '') ? $reqdecimals : null, $anstype);
145+
}
130146
if (empty($answerboxsize)) {$answerboxsize = 20;}
131147

132148
$classes = ['text'];
@@ -156,13 +172,29 @@ public function generate(): void
156172
$preview .= '</button> &nbsp;';
157173
}
158174
$preview .= "<span id=p$qn></span> ";
175+
if ($anstype === 'algmatrix' && in_array('generalcomplex', $ansformats)) {
176+
$tip .= '<br>'._('Your answer can contain complex numbers.');
177+
}
159178
$params['tip'] = $shorttip;
160179
$params['longtip'] = $tip;
161180
$params['calcformat'] = $answerformat;
162181
if ($useeqnhelper) {
163182
$params['helper'] = 1;
164183
}
165184

185+
if ($anstype === 'algmatrix') {
186+
if (empty($variables)) {$variables = "x";}
187+
$addvars = [];
188+
if (in_array('generalcomplex', $ansformats)) {
189+
$addvars[] = 'i';
190+
}
191+
list($variables, $ofunc, $newdomain, $restrictvartoint) = numfuncParseVarsDomain($variables, $domain, $addvars);
192+
193+
$params['vars'] = $variables;
194+
$params['fvars'] = $ofunc;
195+
$params['domain'] = $newdomain;
196+
}
197+
166198
$nosolntype = 0;
167199
if (in_array('nosoln', $ansformats) || in_array('nosolninf', $ansformats)) {
168200
list($out, $answer,$nosolntype) = setupnosolninf($qn, $out, $answer, $ansformats, $la, $ansprompt, $colorbox);

0 commit comments

Comments
 (0)