Math Minion

May 01

Version 2.2.2


	The iOS version 2.2.2 has been available in the app store for about a week and now the OS/X has been reviewed and approved as well.  No major changes here, but rather just minor cosmetics and fixes:

The input and outlet connection lines for the selected object are now highlighted in different colours on the diagram.  This makes them easier to follow on complex diagrams.
	There is also now an option on an object’s context menu to hide its diagram connections.  However the connections of a selected object are always shown.
	Added mg as a standard mass unit and mass volume (inverse of mass density) as a standard unit type.
	Upgraded the embedded JQuery to version 2.0
In the diagram shown, the connections for r have been hidden, but its connection to x is still shown as x is selected.  The red highlights indicate connection points of hidden connections.

Version 2.2.2

The iOS version 2.2.2 has been available in the app store for about a week and now the OS/X has been reviewed and approved as well. No major changes here, but rather just minor cosmetics and fixes:

In the diagram shown, the connections for r have been hidden, but its connection to x is still shown as x is selected. The red highlights indicate connection points of hidden connections.

Feb 22

Version 2.2.1 submitted to App Store

Yesterday I submitted a minor release for both the Mac and iOS versions to the app store. This addresses a few fairly minor issues and adds a couple of new functions as well as relaxing restrictions on the if function:

These updates will automatically be released when approved by Apple.

Feb 07

Version 2.2 for Mac Approved

My comments yesterday about the long wait for Mac app reviews was apparently outdated, for late in the day Math Minion 2.2 for the Mac was also approved and has now been released to the store. :-)

Feb 06

Version 2.2 for iOS Approved

I have just released the newly approved version 2.2 of Math Minion to the App Store and it should show up in all regions over the next 24 hours or so.

In the past I have alway delayed releasing the iOS version until the Mac version was approved, but as this can, for some reason, take an additional two or more weeks, I have decided to release the iOS version right away.

For those of you using both, there should be no problem for sessions that don’t use the new version 2.2 features. The only thing to be careful of is that if you accidentally open a 2.2 session containing a new HTML form object on the 2.1 Mac version, close the session without making any changes to avoid losing the object.

Feb 01

Version 2.2 of Math Minion has been submitted to both the IOS and Mac App stores. The waiting begins. :-)

Jan 31

Quotes in Strings
Math Minion does not have an escape mechanism for including special characters in strings.  For the most part the special character is just entered as normal.  For instance to create a two line string, you might enter the following formula into an expression’s expanded formula editor:


"first line
second line"


The same is true of tabs and the iOS version of Math Minion includes a tab key on the keyboard when editing formulas.


But what about entering quote marks into strings?


Entering a single quote is easy as it can just be included in the string:


"A single 'quoted' word"


Normally a single quote is used to begin a comment at the end of a formula, but if the quote is inside a double quoted string, then it is simply included in the string.


Another special case for a single quote is when it appears as the first character of a formula, in which case it designates that everything following it, including quote marks, are part of a single string.  This makes it easy to paste a long string into an expression, without having to worry about a closing quote or entrained quotes.  For example the formula:


'A "double" and 'single' quoted
string.


would result in the string:


A "double" and 'single' quoted
string.


This suggests a nice trick for including double quotes in more complex formulas.  Suppose you want to construct a drop down menu for a HTML form object (being introduced in version 2.2) using a select tag and a list of contact names.  If we create an expression qq, whose formula is just:


'"


Then we can create the option tags in an expression named options, with this formula:


{join
	"<option name=" + qq + contacts + qq +
	">" + contacts + "</option>",
	"
"}


Which results in a string like:


<option name="Tom">Tom</option>
<option name="Dick">Dick</option>
<option name="Harry">Harry</option>


A HTML form object with the formula:


'<select><mm>options</mm></select>


would then create a drop down menu like the one shown in the picture.

Quotes in Strings

Math Minion does not have an escape mechanism for including special characters in strings. For the most part the special character is just entered as normal. For instance to create a two line string, you might enter the following formula into an expression’s expanded formula editor:

"first line
second line"

The same is true of tabs and the iOS version of Math Minion includes a tab key on the keyboard when editing formulas.

But what about entering quote marks into strings?

Entering a single quote is easy as it can just be included in the string:

"A single 'quoted' word"

Normally a single quote is used to begin a comment at the end of a formula, but if the quote is inside a double quoted string, then it is simply included in the string.

Another special case for a single quote is when it appears as the first character of a formula, in which case it designates that everything following it, including quote marks, are part of a single string. This makes it easy to paste a long string into an expression, without having to worry about a closing quote or entrained quotes. For example the formula:

'A "double" and 'single' quoted
string.

would result in the string:

A "double" and 'single' quoted
string.

This suggests a nice trick for including double quotes in more complex formulas. Suppose you want to construct a drop down menu for a HTML form object (being introduced in version 2.2) using a select tag and a list of contact names. If we create an expression qq, whose formula is just:

'"

Then we can create the option tags in an expression named options, with this formula:

{join
	"<option name=" + qq + contacts + qq +
	">" + contacts + "</option>",
	"
"}

Which results in a string like:

<option name="Tom">Tom</option>
<option name="Dick">Dick</option>
<option name="Harry">Harry</option>

A HTML form object with the formula:

'<select><mm>options</mm></select>

would then create a drop down menu like the one shown in the picture.

Jan 30

Using Commas to Separate Thousands
A very special user, my wife, recently asked if the Math Minion fmt function could insert commas to separate each group of three digits in numbers.  Alas, the answer was no, as the C style formatting used by Math Minion does not include that capability.


Fortunately there is an easy work around using the regular expressions of the replace function.  In the example pictured above, the commas expression uses the following formula to format the random numbers in n


{replace
	"(\d)(\d\d\d,)",
	"$1,$2",
	{replace
		"(\d)(\d\d\d\.)",
		"$1,$2"
		{fmt "%12.2f", n}
	}
}


This will work for numbers of less than one billion, but could be extended if need be.  The only caution is that regular expressions are fairly time consuming, so this might not be appropriate for huge arrays, but should be fine for anything that you would normally want to display.

Using Commas to Separate Thousands

A very special user, my wife, recently asked if the Math Minion fmt function could insert commas to separate each group of three digits in numbers. Alas, the answer was no, as the C style formatting used by Math Minion does not include that capability.

Fortunately there is an easy work around using the regular expressions of the replace function. In the example pictured above, the commas expression uses the following formula to format the random numbers in n

{replace
	"(\d)(\d\d\d,)",
	"$1,$2",
	{replace
		"(\d)(\d\d\d\.)",
		"$1,$2"
		{fmt "%12.2f", n}
	}
}

This will work for numbers of less than one billion, but could be extended if need be. The only caution is that regular expressions are fairly time consuming, so this might not be appropriate for huge arrays, but should be fine for anything that you would normally want to display.

Jan 28

[video]

Jan 22

[video]

Dec 13

Math Minion and the Web Part 2
Yesterday I

posted an article about using the wget command to retrieve Yahoo! stock quotes.  In that case a single URL was constructed that returned a page consisting of comma separated values.  Unfortunately not everything will be that tidy and  in fact Yahoo! does not return Canadian mutual fund information that way.  You can request a quote for a single mutual fund and have the result returned as part of a fully formatted web page though.


In this example, a single wget function call is used to return an array of web pages, which are then searched for the nugget of information, the price, that we are looking for.


The process again starts with a table, Funds, which in this case contains columns for the fund name, symbol and number of units held.  The YahooFunds object uses the Funds.Symbol column to create an array of addresses using the following formula:


{wget "http://finance.yahoo.com/quotes/" +
		Funds.Symbol
}


The address array would be:


    1 http://finance.yahoo.com/quotes/AGFCANADIANR.TO
    2 http://finance.yahoo.com/quotes/F0CAN05NJO.TO
    3 http://finance.yahoo.com/quotes/F0CAN05O0V.TO


The result of the wget function call will be an array of three strings, where each string is the full web page for the corresponding address.  This will contain all the html boilerplate, javascript, styles etc. that constitutes a web page.  Hidden in there will be the number we want and snooping around in the page source reveals that it immediately follows a class attribute col-price cell-raw:.  The fundPrices expression uses the formula:



{table {cc "Name", "Price"}
	Funds.Name, 
	{numeric
		{substr yahooFunds,
			{strfind yahooFunds,
				"col-price cell-raw:"
			}[0,1]+19,
			14
		}
	}
}


to find the location of that string with the strfind function and then uses that in the substr function to grab a bunch (14) of characters following it.  The numeric function is used to change these into numbers.  It will only consider valid number characters at the beginning of the string, which is what allows us to grab an arbitrarily longer string to ensure we get the whole number.


All of this is done on the entire array of pages, so the table function is able to use it along with the Funds.Name column to create a new table with the name and value:


    1 AGF Cdn Resources             46.43000
    2 TD Cdn Index                  20.12000
    3 Trimark Global Endeavor       14.35000


Finally the FundMktValue expression multiplies the fundPrices table by the Funds.Units column with the formula:


Funds.units * fundPrices


To produce a table value:


    1 AGF Cdn Resources            4643.00000
    2 TD Cdn Index                10060.00050
    3 Trimark Global Endeavor     14350.00000


Note that multiplying a table by a numeric ignores, but preserves, the string columns.


One final note is that this kind of page scraping is rather fragile as it will probably need to be modified whenever the source page is modified with new formatting or whatever.  However sometimes it is the only viable way to automatically retrieve the information you need.

Downloading the session:


On a Mac, use this link:
	Mac download	

Unfortunately Tumblr does not allow the tricky links that open directly in Math Minion on iOS, so you will have to copy the link below and paste it into the Safari address bar to make that happen:


minion://redtree.com/mmmanual/wget_funds.minion

Math Minion and the Web Part 2

Yesterday I posted an article about using the wget command to retrieve Yahoo! stock quotes. In that case a single URL was constructed that returned a page consisting of comma separated values. Unfortunately not everything will be that tidy and in fact Yahoo! does not return Canadian mutual fund information that way. You can request a quote for a single mutual fund and have the result returned as part of a fully formatted web page though.

In this example, a single wget function call is used to return an array of web pages, which are then searched for the nugget of information, the price, that we are looking for.

The process again starts with a table, Funds, which in this case contains columns for the fund name, symbol and number of units held. The YahooFunds object uses the Funds.Symbol column to create an array of addresses using the following formula:

{wget "http://finance.yahoo.com/quotes/" +
		Funds.Symbol
}

The address array would be:

    1 http://finance.yahoo.com/quotes/AGFCANADIANR.TO
    2 http://finance.yahoo.com/quotes/F0CAN05NJO.TO
    3 http://finance.yahoo.com/quotes/F0CAN05O0V.TO

The result of the wget function call will be an array of three strings, where each string is the full web page for the corresponding address. This will contain all the html boilerplate, javascript, styles etc. that constitutes a web page. Hidden in there will be the number we want and snooping around in the page source reveals that it immediately follows a class attribute col-price cell-raw:. The fundPrices expression uses the formula:


{table {cc "Name", "Price"}
	Funds.Name, 
	{numeric
		{substr yahooFunds,
			{strfind yahooFunds,
				"col-price cell-raw:"
			}[0,1]+19,
			14
		}
	}
}

to find the location of that string with the strfind function and then uses that in the substr function to grab a bunch (14) of characters following it. The numeric function is used to change these into numbers. It will only consider valid number characters at the beginning of the string, which is what allows us to grab an arbitrarily longer string to ensure we get the whole number.

All of this is done on the entire array of pages, so the table function is able to use it along with the Funds.Name column to create a new table with the name and value:

    1 AGF Cdn Resources             46.43000
    2 TD Cdn Index                  20.12000
    3 Trimark Global Endeavor       14.35000

Finally the FundMktValue expression multiplies the fundPrices table by the Funds.Units column with the formula:

Funds.units * fundPrices

To produce a table value:

    1 AGF Cdn Resources            4643.00000
    2 TD Cdn Index                10060.00050
    3 Trimark Global Endeavor     14350.00000

Note that multiplying a table by a numeric ignores, but preserves, the string columns.

One final note is that this kind of page scraping is rather fragile as it will probably need to be modified whenever the source page is modified with new formatting or whatever. However sometimes it is the only viable way to automatically retrieve the information you need.

Downloading the session: On a Mac, use this link: Mac download

Unfortunately Tumblr does not allow the tricky links that open directly in Math Minion on iOS, so you will have to copy the link below and paste it into the Safari address bar to make that happen:

minion://redtree.com/mmmanual/wget_funds.minion