Indeed, that is the functionality that the new Parser has (or had until
I changed the default for function-apply to mimic the current WeBWorK
The new parser's approach is to consider function application to have a
precedence, just like addition, multiplcation and all the other
operations. Since "cos x " looks like multiplication, I had originally
made function apply have the same precedence as multiplication, so "cos
x^2" would parse as cos(x^2) since ^ has higher precedence.
Making function apply have precedence slightly lower than
multiplication makes "cos 2x" parse as cos(2x). Unforunately, it also
makes things like "cos 2xy (x+1)" parse as cos(2xy(x+1)), and also "cos
x / (x+1)" parse as "cos(x/(x+1))". I'm not sure these are the most
appropriate choices. The first might be better as "(cos 2xy) (x+1)" and
the second as (cos x)/(x+1).
My solution was to make the spacing count (by making two kinds of
implied multiplication, direct juxtaposition and juxtaposition with a
space, each with a separate precedence). By making the precedence of
justaposition higher than function apply which is higher than
space-justaposition, we can make "cos 2xy (x+1)" be "(cos(2xy))(x+1)".
Similarly, we can make a difference between / and /-with-spaces to make
"cos x/2" become cos(x/2) but "cos x / 2" be "(cos x)/2".
Of course, this makes the statement of the "rules of precedence"
considerably more complicated, so students may find it harder to
understand. On the other hand, they don't understand the current rules,
so how much is lost? Especially if it gets more of the situations to
correspond to what they think they mean. And since the parser allows
you to set the precedences, you can always pick the style that you want
for your class (though this may confuse students when they use WeBWorK
in another class).
Note, however, that this doesn't help one other situation that students
find hard, namely e^2x meaning (e^2)x rather than e^(2x). Here the
standard precedences should make this clear, but apparently doesn't.
Note that the real problem with cos 2x is not knowing what the
precedence of function apply is.
Anyway, I'm not sure that the non-standard precedences is really a good
idea, but they are in the Parser so you can try them out if you like.
<| Post or View Comments |>