0
Vote

Handle built-in functions (e.g., cos) properly

description

When converting the formula for cos α + cos β, MML# outputs the following:
 
double cos, α, β;
cos⁡cosα+cos⁡cosβ=2cos⁡cos((1) / (2))(α+β)cos⁡cos((1) / (2))(α-β);
 
There are many problems here - cos appears more than once (extra data), there's a weird '⁡' symbol. Most annoying is that 'cos' is formed as mrow(cos) followed by mo(⁡)mi(cos)mi(α), which is difficult to interpret.

comments

wrote Jul 1, 2008 at 2:41 AM

The strange symbol appears to be "f()" enclosed in dashed lines. This is the Unicode Function Application character (U+2061). It is used in Presentation MathML to specify that a function applies to a quantity and is used to remove ambiguity. For example, does f(x+y) mean f of (x+y) or f*(x+y). The former would use U+2061, and the latter would use U+2062 (the Invisible Times operator). I am unclear as to the scope of this operator. Content MathML defines the scope explicitly with the <apply> and </apply> tags. However, with Presentation MathML, the scope seems to be determined by the parser. The operator could be applied to the next <mi> element, the next <mrow> element, or the next set of brackets.
 
As for the topic of this issue, the MathML produced is not correct for the intended meaning of the expression. Word seems to be the culprit. If you copy the MathML from Word and paste it back into Word, it is displayed correctly. However, if the MathML is copied, pasted in plaintext in another document, then copied back into Word, the behavior mentioned in this issue is exhibited. So, Word cannot even handle its own output when copied from another document. Does this same problem exist with MathType?

wrote Jul 1, 2008 at 6:28 AM

MathType does it properly - sin(t) is output as <mi>sin</mi><mo>f()</mo><mi>t</mi>. We know when to stop because, in actual fact, the whole thing is inside an <mrow>, so that tells us what to apply it to. MathType doesn't use the 'invisible times' either. And MS Word does it wrongly by introducing a spurious <mrow> that repeats what is said later - and of course its f() operator is out of place. But it's nothing that can't be handled. We do have another problem however: take the arcsin (sin^-1) - this is defined in an <msup>, and what's annying is that f() is inside this <msup> element.

wrote Jul 2, 2008 at 5:17 AM

Associated with changeset 13317.

wrote Jul 2, 2008 at 5:46 AM

Associated with changeset 13320.

wrote Jul 2, 2008 at 8:23 AM

Okay, so you got rid of the extra row. What we should do next, I think, is actually implement the functionality. We have an <mrow> that has: name of function followed by f() or f() followed by name of function; these are followed by the function arguments. So sin(x) is is <mi><mo><mi> in MathType and <mo><mi><mi> in Word. So this can be replaced by Math.Sin(parse arguments). It will also word recursively, i.e., sin(sin(x)) will work just fine. Now, onto the second problem - doing arcsin (sin^-1) and such. We now have a logic that should say: if <msup>'s first content includes the name of the function, check its second content. If the second content is -1 (<mo>-</mo><mn>1</mn>) and the function is sin, cos, etc., substitute Math.ArcCos and whatnot. Otherwise, do a Math.Pow.

wrote Jul 2, 2008 at 5:41 PM

One important addition: we'll need to add the 'exp' function, since many people use it instead of e^, and we'll probably need a separate option in BuildOptions specifically for this.

wrote Jul 3, 2008 at 4:26 AM

Associated with changeset 13517.

wrote Jul 3, 2008 at 11:30 AM

The expression sin sin x works fine from Word, but when using MathType, it forgets the final (

wrote Jul 3, 2008 at 11:30 AM

Sorry, meant the final )

wrote Jul 13, 2008 at 7:26 PM

Associated with changeset 14607.

wrote Jul 15, 2008 at 7:02 AM

It seems that the braces still do not work as expected, especially on inverse trig functions.

wrote Jul 15, 2008 at 7:41 AM

Associated with changeset 14738.

wrote Jul 16, 2008 at 4:14 AM

Associated with changeset 14798.

wrote Jul 26, 2008 at 12:51 AM

Associated with changeset 15376.

wrote Oct 18, 2008 at 7:40 PM

wrote Feb 13, 2013 at 8:30 PM