:

Maple

 The following interaction with Maple's Excel link came to my attention today.  I thought it had many interesting points that lead to insights about Excel and Maple that are worth sharing.  After installing the Excell Add-in, set up a sample spreadsheet as follows:   In cell A1, type:  =maple("x+x")   in cell A2, type:  =maple("&1^3", A1)   in cell B1, type:  =maple("M:=Matrix(&1);", A1:A2)   in cell B2, type:  =maple("M[1,1]+M[2,1]")   in cell A2, change "&1^3" to "(&1)^3", and press enter. The complaint was that after changing A2, B2 doesn't automatically updated too.  This boils down to the way Excel knows which fields to update when one cell changes.  Because B2 references the Maple name `M`, and not cell B1, there is no dependency tracing back from B2 to B1 to A2.  Excel doesn't know that B2 needs to be updated after changing A2. One way around this is to fake a dependency.  The formula in cell B2 can be changed to:    =maple("&1: M[1,1]+M[2,1]",B1) Now the cell reference, B1 is part of the formula, making the dependency explicit.  Note that not only does the reference need to be there, but it also needs to be used, so the &1 must be included in the formula.  Multiple Maple statements are allowed in a single Excel formula.  The trick here is to put &1 on its own as the first statement.  Then, terminate it with a colon so the output is not visible.  The extra statement in the above trick works because the result of the Excel formula is its display value.  This leads to another best-practice. It is a good idea to assign the matrix to a variable `M` as was done in cell B1.  The variable `M` can then be used everywhere rather than refering back to cell B1.  This optimizes the data flow.  References to `M` are directly done within the Maple engine, rather than having to pass the string shown as the result in cell B1 back to the Maple engine to be parsed and reevaluated.  Making assignments to Maple variables also allows you to work with mutable matrices and other objects like modules which may not display in an easily re-parsible representation. If the Matrix in cell B1 happened to be very large, you might also want to suppress the visible output to something more managable.  The multiple statement trick can be used to do that too.  Cell B1 could be changed to:    =maple("M:=Matrix(&1): sprintf(`Matrix M: [%a …] `,M[1,1])",A1:A2)  This will create the matrix and assign it to M as desired, and then show only the first element prefixed with the caption "Matrix M:".   You'd definitely want to do something like this for a million element matrix. One more note.  In the sprintf command above I used back-ticks around the format string.  This is really an abuse of Maple's NAME quotes.  I really should have used double-quotes, but I forgot how to escape them in Excel.  The way to do this in Maple is via \".  In Excel, to specify a double-quote within a string you use two double quotes, "".  The previous command could be restated as:    =maple("M:=Matrix(&1): sprintf(""Matrix M: [%a …] "",M[1,1])",A1:A2)    In summary, the new sheet should be created as:   In cell A1, type:  =maple("x+x")   in cell A2, type:  =maple("&1^3", A1)   in cell B1, type:   =maple("M:=Matrix(&1): sprintf(""Matrix M: [%a …] "",M[1,1])",A1:A2)    in cell B2, type:   =maple("&1: M[1,1]+M[2,1]",B1) Now, updating cell A2 will cascade throughout the spreadsheet and cause B2 to be updated.  Additionally, the change to cell B1 looks nicer and results in better performance. -PD

﻿