maths / moodle-qtype_stack

Stack question type for Moodle
GNU General Public License v3.0
142 stars 149 forks source link

Can't type in an n-th root #292

Closed C0untC0unt closed 7 years ago

C0untC0unt commented 7 years ago

We created some questions concerning roots. These work out fine, as long as the students have to work on sqare roots. But when it comes to other types, we can't find a way to type in an n-th root as a student. Is there an option for this? Otherwise, this would be a nice feature to add.

sangwinc commented 7 years ago

Good question. This is all about syntax really. Currently students need to type in 2^(1/3) for the principal cube root of two. The square root function in Maxima (sqrt) is actually converted internally to x^(1/2). We can see this using the "?print" command to reveal the internal representation.

(%i1) sqrt(x);
(%o1)                               sqrt(x)
(%i2) ?print(%);
((MEXPT SIMP) $X ((RAT SIMP) 1 2))
(%o2)                               sqrt(x)

I'm nervous about adding "syntactic sugar" for this beyond the sqrt function. Do you have a specific request?

C0untC0unt commented 7 years ago

Hello and sorry for the delay.

Here is an example of our tasks: forum - n-th root

These tasks are meant to be solved by students from school, not by students at university. So, not all of these students know that they should type in "^(1/3)" or "^(1/2)" for a cube/square root. Furthermore, we have a demonstration of an n-th root within the text of the task. That is why we thought it would be nice if there was an option or a chance to type in an n-th root in the traditional way.

Maybe, there is an solution similar to the one of the logarithm-input problem.(#243)

sangwinc commented 7 years ago

Thanks for the update.

What is the "traditional way" to type in an nth root using a typed keyboard?! Without a 2D input mechanism, I'm not sure I know what you mean.

christianp commented 7 years ago

In Numbas, the nth root of x is root(x,n). I think we inherited the order of the arguments from i-assess. I think root(n,x) would be better - it reads more easily as "nth root of x".

sangwinc commented 7 years ago

Argh the (x,n) vs (n,x) dilemma! .....

christianp commented 7 years ago

I've been convinced by the Haskell people: if it's root n x, you can create a curried function like cuberoot = root 3, which you would then be able to use as cuberoot 8 == 2. The idea is that you'd put first the bit you might want to reuse. I think that convention's sufficiently general that you can apply it pretty much everywhere, and you can avoid a mess like PHP's function ordering (for example, it's array_filter(input,callback), but array_map(callback,input). Following my rule, (callback,input) is preferred because mapping the same function over a general array is a thing you might want a shorthand for, while you're much less likely to want to have a routine which maps an arbitrary function over a particular array)

C0untC0unt commented 7 years ago

Ah Sorry! I see that this could be confusing. By the "traditional way", I mean, like it's mentioned by Christian, that there is the option to type in a "root(x,n)" (or "root(n,x)") command and STACK interpretes it as the n-th root of x. So that the validation field shows a (for the students) "traditional way" of an n-th root and no "^(1/n)" version.

aharjula commented 7 years ago

A bit more declarative viewpoint to counter that Haskell viewpoint (perfectly valid point, nothing against it) in most declarative languages functions may have optional parameters that have default values and in cases where we do not target the function arguments to specific parameters we tend to keep those optional and more configuration related parameters last. Basically, I am thinking like this root(x[,n=2]) => x^(1/n). Which gives the default behaviour of root(x) = sqrt(x) when the second parameter is omitted. Naturally, similar single argument behaviour would work with the parameters in different order, but then the implementation needs to handle the switching and potential default values itself.

In any case, I have a feeling that having the ability to call root(...) with just one argument and getting the behaviour of sqrt would be useful. I.e. students would not need to fill in the second argument in the most common case and they would not need to use a differently named function to avoid writing that argument. That feeling might be based on some student having problems understanding what the "squirt" function is. On the other hand, root feels a bit of a loaded word for equating it directly to square root.

sangwinc commented 7 years ago

Having some general rule in mind (Haskell or a declarative viewpoint) is certainly much more sensible that a random guess. The validation display of \sqrt[n]{x} should help students avoid confusion, or worrying they might get it the wrong way round.

timhunt commented 7 years ago

@aharjula's suggestion makes sense to me.