Monday 15 September 2008

User Interfaces and MathML

An article on linguistic user interfaces caught my attention the other day. I like Jono DiCarlo's theory about what makes for a good user interface: easy to learn; efficient; expressive.

It struck me later that DiCarlo's theory helps to explain what I see as the main difficulty in working with MathML. If you are someone who wants to construct equations in MathML to display on your website, in all likelihood you have been using some tool, probably a WYSIWYG one with a drag-and-drop or palette-based interface, to construct the equations which then generates the MathML for you. You then need to transplant this into your website.

So what's wrong with this? While these tools and their interfaces meet the criteria of easy to learn (usually) and expressive (usually), they are definitely not efficient. GUI-based interfaces are easy to learn and use, but they are also comparatively slow next to keyboard-based input methods. And having to move the generated MathML to your webpage is another bottleneck.

But thankfully there appears to be some light on the horizon. Peter Jipsen of Chapman University has created a javascript script (called ASCIIMathML) that converts structured text to presentation MathML. So you can type `x=(-b +- sqrt(b^2-4ac))/(2a)` into your webpage and what appears is the quadratic formula. If the ASCIIMathML script is missing, the expression is still reasonably comprehensible. Compare that to the following MathML for the same formula:
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>x</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo>−</mo>
<mi>b</mi>
<mo>±</mo>
<msqrt>
<msup>
<mi>b</mi>
<mn>2</mn>
</msup>
<mo>−</mo>
<mn>4</mn>
<mi>ac</mi>
</msqrt>
</mrow>
<mrow>
<mn>2</mn>
<mi>a</mi>
</mrow>
</mfrac>
</math>

ASCIIMathML in my opinion represents a huge step forward. It begins to address the efficiency problem by allowing the user to enter equations without needing another tool, or having to open up and click on palettes, or having to copy the MathML from one place to another.

I've added ASCIIMathML to my school's Moodle server - my students can now enter equations simply by typing. They can mouse over equations that I've placed in pages on Moodle and copy the ASCIIMath expression and then change it as they need to. And all this without sacrificing ease of learning or expressiveness. The basic syntax is very easy to learn, but extends in a logical manner to cover even extremely complicated expressions.

Now all that's needed is for the makers of all browsers to include support for MathML, including the requisite fonts, by default.

Saturday 19 January 2008

The Pluses Problem

On his blog, Rational Mathematics Education, Michael Goldenberg mentions this problem by way of one Maria Miller (her blog here.)
How many addition signs should be put between digits of the number 987654321 and where should we put them to get a total of 99?
Michael finished his blog entry with "It would also be great if anyone has other extension ideas for this ... The one I'd suggest right away is: What happens if we change 99 to other values?"

This got me thinking along a slightly different line - what other totals have multiple solutions and could I write a program to find them?

It turns out that there are 209 possible totals (including 987654321), of which 31 can be formed in more than one way. Four totals (153, 171, 180, 189) can be formed in four different ways, seven totals can be formed in three different ways, and the rest in two different ways.

The program to find this is conceptually quite simple... if you can get your head around recursion.

The logic: for a given number, take the first n digits (where n is progressively a number from 1 to the total number of digits), convert to a single value, then with the remainder, do the same thing again.

Programming this in Python ended up being simple, but not before I went down a few blind alleys:

def Chunkit(x,p=[]):
for i in range(len(x)):
p.append(int(x[:i+1]))
if i == len(x)-1:
print p, sum(p)
print
else:
Chunkit(x[i+1:])
p.pop()
return p

num = raw_input("Enter a number: ")
Chunkit(str(num))

The sticking point was line 9:
p.pop()
At first, it's not obvious why this is necessary, but if you leave it out (as I initially did), you soon see the consequences.

With the program written and working correctly (with a few additions to produce the list of totals and how often they occur), exploring the original problem led to the results given above. It also allowed me to examine different number sequences, such as 123456789, which can be made to total 99 three different ways rather than two. (And totals of 153 and 162 can be made five different ways.) Or 123454321, which can be made to total 97 in eight different ways.

Of course, having posted here what I think is a fairly neat solution (only 13 lines of code), no doubt some script-kiddy will pop up with a four line solution in Ruby or OCaml or whatever is the trendy language this week. But at least I now have another interesting problem to discuss with my students.