diff --git a/doc/en/Authoring/Options.md b/doc/en/Authoring/Options.md index e7a89777946..d2354de241a 100644 --- a/doc/en/Authoring/Options.md +++ b/doc/en/Authoring/Options.md @@ -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 diff --git a/stack/cas/security-map.json b/stack/cas/security-map.json index bac110da349..f87a44cfdad 100644 --- a/stack/cas/security-map.json +++ b/stack/cas/security-map.json @@ -6708,7 +6708,12 @@ "globalyforbiddenfunction": true }, "root": { - "function": "s" + "function": "s", + "nounfunction": "'root" + }, + "'root": { + "function": "t", + "nounfunctionfor": "root" }, "rootsconmode": { "variable": "s" diff --git a/stack/maxima/assessment.mac b/stack/maxima/assessment.mac index e102cdf5189..6a1907a0887 100644 --- a/stack/maxima/assessment.mac +++ b/stack/maxima/assessment.mac @@ -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( diff --git a/tests/fixtures/answertestfixtures.class.php b/tests/fixtures/answertestfixtures.class.php index b5d09729208..e48551c3290 100644 --- a/tests/fixtures/answertestfixtures.class.php +++ b/tests/fixtures/answertestfixtures.class.php @@ -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, '', ''], diff --git a/tests/fixtures/inputfixtures.class.php b/tests/fixtures/inputfixtures.class.php index ce0a6f69610..56e1c41b9c9 100644 --- a/tests/fixtures/inputfixtures.class.php +++ b/tests/fixtures/inputfixtures.class.php @@ -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... diff --git a/tests/input_algebraic_test.php b/tests/input_algebraic_test.php index 7e99025a966..6e64e13e8ef 100644 --- a/tests/input_algebraic_test.php +++ b/tests/input_algebraic_test.php @@ -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', '{}');