6
6
7
7
use Sanitize ;
8
8
9
- class CalculatedNTupleAnswerBox implements AnswerBox
9
+ class AlgebraicNTupleAnswerBox implements AnswerBox
10
10
{
11
11
private $ answerBoxParams ;
12
12
@@ -40,8 +40,8 @@ public function generate(): void
40
40
$ preview = '' ;
41
41
$ params = [];
42
42
43
- $ optionkeys = ['ansprompt ' , 'answerboxsize ' , 'hidepreview ' , 'answerformat ' ,
44
- 'answer ' , 'reqdecimals ' , 'displayformat ' , 'readerlabel ' ];
43
+ $ optionkeys = ['answerboxsize ' , 'answerformat ' , 'answer ' , 'displayformat ' ,
44
+ 'ansprompt ' , 'readerlabel ' , 'hidepreview ' , 'variables ' , ' domain ' ];
45
45
foreach ($ optionkeys as $ optionkey ) {
46
46
$ {$ optionkey } = getOptionVal ($ options , $ optionkey , $ multi , $ partnum );
47
47
}
@@ -52,34 +52,44 @@ public function generate(): void
52
52
if ($ multi ) {$ qn = ($ qn + 1 ) * 1000 + $ partnum ;}
53
53
54
54
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 ' );
57
57
} 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 ' );
60
60
} 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: <x,x^2> ' ) . "<br/> " ;
62
+ $ shorttip = _ ('Enter an algebraic vector ' );
63
63
} 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: <x,x^2>, <3,x> ' ) . "<br/> " ;
65
+ $ shorttip = _ ('Enter a list of algebraic vectors ' );
66
66
} 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 ' );
69
69
} 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 ' );
72
72
} 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 ' );
75
75
} 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 ' );
78
78
}
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/> ' ;
81
81
}
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
+
83
93
84
94
$ classes = ['text ' ];
85
95
if ($ colorbox != '' ) {
@@ -97,13 +107,17 @@ public function generate(): void
97
107
];
98
108
$ params ['tip ' ] = $ shorttip ;
99
109
$ params ['longtip ' ] = $ tip ;
110
+
100
111
$ params ['calcformat ' ] = $ answerformat . (($ answerformat == '' ) ? '' : ', ' ) . $ displayformat ;
101
112
if ($ useeqnhelper ) {
102
113
$ params ['helper ' ] = 1 ;
103
114
}
104
115
if (empty ($ hidepreview )) {
105
116
$ params ['preview ' ] = !empty ($ _SESSION ['userprefs ' ]['livepreview ' ]) ? 1 : 2 ;
106
117
}
118
+ $ params ['vars ' ] = $ variables ;
119
+ $ params ['fvars ' ] = $ ofunc ;
120
+ $ params ['domain ' ] = $ newdomain ;
107
121
108
122
$ out .= '<input ' .
109
123
Sanitize::generateAttributeString ($ attributes ) .
@@ -115,7 +129,7 @@ public function generate(): void
115
129
$ preview .= _ ('Preview ' ) . ' <span class="sr-only"> ' . $ this ->answerBoxParams ->getQuestionIdentifierString () . '</span> ' ;
116
130
$ preview .= '</button> ' ;
117
131
}
118
- $ preview .= "<span id=p $ qn></span> " ;
132
+ $ preview .= "<span id=p $ qn></span> " ;
119
133
120
134
$ nosolntype = 0 ;
121
135
if (in_array ('nosoln ' , $ ansformats ) || in_array ('nosolninf ' , $ ansformats )) {
@@ -125,10 +139,15 @@ public function generate(): void
125
139
if ($ nosolntype > 0 ) {
126
140
$ sa = $ answer ;
127
141
} 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 ' ) {
130
147
$ sa = str_replace (array ('< ' , '> ' ), array ('(: ' , ':) ' ), $ sa );
131
148
}
149
+ $ sa = numfuncPrepShowanswer ($ sa , $ variables );
150
+ $ sa = '` ' . $ sa . '` ' ;
132
151
}
133
152
}
134
153
0 commit comments