Skip to content

Commit

Permalink
Issue #1199: add in texput rules to display root(x,n) as surd.
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwinc committed Jun 6, 2024
1 parent 77550a0 commit 81cabf6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/en/Authoring/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Do you really want to continue using \(\sqrt{}\) in your teaching? In his *Elem
A lot of elementary mathematics involves converting from one form to another and back again. Sometimes these forms have important differences of use, e.g. factored form or completed square form for a quadratic. However, sometimes these equivalent forms are more customary than because it *"manifestly corresponds with the nature of the thing"* in question. I digress...

STACK defines an \(n\)th root function `root(x,n)` which is a noun form for \(\sqrt[n](x)\). This can be used by students, but if teachers wish to use this in question variables etc. then they must prefix this with the apostophie to create the nounform `'root(x,n)` to prevent immediate evaluation to `x^(1/n)`.

### sqrt(-1) {#sqrt_minus_one} ###

In Maxima `%i` is the complex unit satisfying `%i^2=-1`. However, students would
Expand Down
7 changes: 6 additions & 1 deletion stack/cas/security-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -6708,7 +6708,12 @@
"globalyforbiddenfunction": true
},
"root": {
"function": "s"
"function": "s",
"nounfunction": "'root"
},
"'root": {
"function": "t",
"nounfunctionfor": "root"
},
"rootsconmode": {
"variable": "s"
Expand Down
4 changes: 4 additions & 0 deletions stack/maxima/assessment.mac
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ root([ex]) := block(
if length(ex) = 1 then return(sqrt(first(ex))),
if length(ex) = 2 then return(first(ex)^(1/second(ex)))
)$
texroot(ex) := if is(length(args(ex))=1) then concat("\\sqrt{", tex1(first(args(ex))), "}") else concat("\\sqrt[", tex1(second(args(ex))), "]{", tex1(first(args(ex))), "}")$
texput(nounify(root), texroot)$
texput(verbify(root), texroot)$


/* Denominators of fractions should not contain sqrt, root, %i or fractional powers. */
rational_fail(ex) := block(
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/answertestfixtures.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class stack_answertest_test_data {

['AlgEquiv', '', 'x^(1/2)', 'sqrt(x)', 1, '', 'Powers and roots'],
['AlgEquiv', '', 'x', 'sqrt(x^2)', 0, '', ''],
['AlgEquiv', '', '\'root(x)', 'x^(1/2)', 1, '', ''],
['AlgEquiv', '', '\'root(x,m)', 'x^(1/m)', 1, '', ''],
['AlgEquiv', '', 'x', '\'root(x^2)', 0, '', ''],
['AlgEquiv', '', 'abs(x)', 'sqrt(x^2)', 1, '', ''],
['AlgEquiv', '', '1/abs(x)^(1/3)', '(abs(x)^(1/3)/abs(x))^(1/2)', 1, '', ''],
['AlgEquiv', '', 'sqrt((x-3)*(x-5))', 'sqrt(x-3)*sqrt(x-5)', 0, '', ''],
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/inputfixtures.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ function at a point \(f(x)\). Maybe a 'gocha' for the question author....",
"There is an option to display this as \(x^{1/2}|\).",
],
['root(x)', 'php_true', 'root(x)', 'cas_true', '\sqrt{x}', '', ''],
['root(x,3)', 'php_true', 'root(x,3)', 'cas_true', 'x^{\frac{1}{3}}', '', ''],
['root(2,-3)', 'php_true', 'root(2,-3)', 'cas_true', '2^{\frac{1}{-3}}', '', ''],
['root(x,3)', 'php_true', 'root(x,3)', 'cas_true', '\sqrt[3]{x}', '', ''],
['root(2,-3)', 'php_true', 'root(2,-3)', 'cas_true', '\sqrt[-3]{2}', '', ''],
// Parser rules in 4.3, identify cases where known functions (cf) are prefixed with single letter variables.
['bsin(t)', 'php_true', 'b*sin(t)', 'cas_true', 'b\cdot \sin \left( t \right)', 'missing_stars', ""],
// So we have added gcf as a function so it is not g*cf...
Expand Down
16 changes: 16 additions & 0 deletions tests/input_algebraic_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,22 @@ public function test_validate_student_response_realsets_sametype_ok() {
'\[ \left( a,\, b\right] \]');
}

public function test_validate_student_response_root() {
$options = new stack_options();
$el = stack_input_factory::make('algebraic', 'sans1', 'x^(1/n)');
$el->set_parameter('sameType', true);

// We don't require intervals to have real numbers in them.
$state = $el->validate_student_response(['sans1' => 'root(x,n)'], $options, 'x^(1/n)',
new stack_cas_security(false, '', '', ['ta']));
$this->assertEquals($state->status, stack_input::VALID);
$this->assertEquals('', $state->note);
$this->assertEquals('', $state->errors);
$this->assertEquals($state->contentsmodified, '\'root(x,n)');
$this->assertEquals($state->contentsdisplayed,
'\[ \sqrt[n]{x} \]');
}

public function test_validate_student_response_tex() {
$options = new stack_options();
$el = stack_input_factory::make('algebraic', 'sans1', '{}');
Expand Down

0 comments on commit 81cabf6

Please sign in to comment.