Introduction

What is MathWeb

MathWeb is a flexible, powerful math assistant for people who understand or want to learn computational math. Each MathWeb file is a collection of cells, each of which has a name , a value, and a script. The script may be empty, contain comments, and/or specify a computation involving other cells. When a script contains one or more other cell names, those cells may be browsed to by touching their names in the current cell script.

MathWeb Screen

The MathWeb screen has a navigation bar at the top and a tool bar at the bottom. Between the nav bar and the toolbar, one of four main views may be selected from the nav bar.The four views are Editor, Console, Plot. and Settings.

Editor View

At the top of the Editor view is a light grey field for entry and/or display of the numeric value of the currently selected cell.

Below the numeric value field is the cell’s script, which may contain arithmetic expressions involving other cells, as well as statements in a simple script language.

At the bottom of the Editor view is a light grey browser toolbar that provides for linking to and returning from highlighted cells, creating new cells, as well as editing or deleting the current cell.

A picker view may be deployed from the ^Cells^ button in the bottom toolbar. When deployed, it contains the names of all the cells in the current MathWeb file. The cell in the center of the picker view is the currently selected cell, whose value and formula fields are shown in the Editor view.

The picker view may be retracted by the “v Cells v” button which appears in the bottom toolbar when the picker view is deployed.

The run button |> in the bottom toolbar causes the script of the current cell to be invoked, along with all the cell scripts it my invoke directly or indirectly. If in doubt about the current cell, check the picker view deployed from the ^ Cells ^ button in the bottom toolbar.

Console View

The Console view displays the output of scripts and allows input to scripts.

The run button |> at the bottom causes the selected cell script to be run, along with all the cell scripts it my invoke directly or indirectly. If in doubt about the selected cell, deploy the picker view from the ^ Cells ^ button in the bottom toolbar.

The big X at the left end of the bottom toolbar clears the console.

It is a good idea to clear the console when you no longer need it. The more text is placed into the scrollable console view, the longer it takes for output to be placed into the console.

Plot View

The plot view automatically plots values resulting from the execution of scripts. The plot limits, grid intervals, and X and Y cells are user specified in the Settings view.

The user can choose manual plotting, in which case the X and Y cell names are not used, and the script must contain startat() and drawto() builtin function calls.

The run button |> in the bottom tool bar causes the selected cell script to be executed, along with all the cell scripts it may invoke directly or indirectly. If in doubt about the the selected cell, deploy the picker view from the ^ Cells ^ button in the bottom toolbar.

The big X at the left end of the bottom toolbar clears the plot view.

Settings View

The Settings view scrolls vertically, and contains three panels:

The Files panel allows the user to create, save, and delete MathWeb files, and to enable and disable the inclusion of eXample files in the file selector wheel.

The Number panel contains settings for number format: fixed, float, or exponential, number of decimal or significant digits, and interpretation of angles in degrees or radians.

MathWeb can accept plotting commands from a cell script, or can automatically plot a selected Y cell value against a selected X cell value. The Plot Panel of the Settings View allows the user to choose an X and a Y cell, select the number of Xgrid lines and Y grid lines, and select the numeric X and Y minimum and maximum limits of the plot window. It also allows the user to set the line width, and choose manual (scripted) or automatic plot mode.

The loop limit panel lets the user prevent infinite repeat, while, or for loops by setting a maximum number of loops to allow before aborting the script execution.

Getting Started

Installing MathWeb

  1. Open Safari in your iPhone and go to www.canyoncode.com
  2. Click on the AppStore badge adjacent to the MathWeb icon.
  3. The MathWeb App page should appear.
  4. If you have purchased the app already, you may install the current version. Otherwise, purchase and install.

Computing With Cell Scripts

A MathWeb cell script appears in the cell’s Editor view, between the value field above and the browser toolbar below. It may contain comments and zero or more statements in the C-ish script language. Statements in a cell script may refer to other cells by name.

Cell References Within Cell Scripts

Since each cell may contain a value as well as a script, there are two kinds of cell references in a cell script. A cell name which is preceded by a $ sign refers to the current value of the named cell. A cell name, not preceded by a $ sign, causes the named cell’s script to be executed, and returns the value of the cell after the execution of the script.

User defined functions

A bare cell name followed by an argument list in parentheses is called a user defined function. Within that cells script, the value references $1, $2, and $3 refer to the first second and third of the comma separated argument expressions supplied when the function is called.

Empty scripts

When the name of a cell with an empty script appears in a formula, it returns the current value of the cell, regardless of the presence or absence of a dollar sign prefix.

Comments

Two kinds of comments may be entered in cell scripts: Block Comments start with /* and end with */. Line comments start with // or # and end at the end of the line on which they appear.

Expressions

An expression is a syntax-ruled configuration
of cell references, numbers, and builtin function 
calls related by arithmetic, assignment, logical, and
relational operators and parentheses.

Script Language Statements

The script language supports the following statement types: expressionStmt, blockStmt, ifStmt, repeatStmt, whileStmt, forStmt, breakStmt, continueStmt, inStmt, outStmt, and bpStmt.

Expression Statement

An expression that appears where a statement is expected is called an expression statement. An expression statement may either be an assignment expression, or a bare expression. An assignment expression consists of a cell value reference followed by an assignment operator followed by an expression. For example:

 $goober = 14*snafu/salamander +3

$goober is a cell value reference. On the right side of the equal sign is an expression. When an assignment expression is executed, the righthand side is evaluated, and the resulting value is assigned to the cell named on the left side of the equal sign.

If the left side and equals sign are omitted, as in:

 14*snafu/salamander + 3

the bare expression evaluates to the same value as the previous formula, but the resulting value is assigned to the cell in which the expression appears.

Some examples of expression statements are shown below:

1
1+3
1+sin(14)
$grouch = $Groucho - humor
$someval*another / 4
pow(sin(pi/4),2) + pow(cos(pi/4),2)
$hokey *= pokey
1/(1/$cellname1 + 1/$cellname2))
$touchdown = omaha+hut+$hut
cellname 
( $x += x - 1  )

Block Statement

A block statement consists of a left brace “{” followed by zero or more script statements, followed by a right brace “}” The block statement is sometimes useful for structuring nested combinations of repeat, while, for, and if statements.

{
    statement
    statement
    ......
    statement
}

if Statement

 if (expression) statement
     or
 if (expression) statement
 else statement

if the value of the expression is non-zero the immediately following statement is executed.

if the value of the expression is zero and there is no else statement, nothing further is done by the if statement. If the value of the expression is zero and there is an else statement, the else statement is executed.

if Statement Examples

if ($x)  
    if(y)  25
    else  30
else 35

if(goober == x - $y) {
   $goofy++
   $x+=4
} else {
   pow(1.5,21)
}

repeat Statement

repeat <number> statement

The statement is repeated a number of times equal to the greatest positive integer less than or equal to the supplied.

repeat Statement Example

 repeat 25 {
     if( $j++ < 25 ) {
         $y = gyrate($j)
     }
}

repeat 25 if($j++ < 25) $y = gyrate($j

while Statement

while ( expression ) statement

if the expression is non-zero the block statement is executed repeatedly as long as the expression remains non-zero.

while Statement Example

$flag=2.4
while ($flag) {
     $flag= $flag - 0.1
     $gandalf += sin(velociRaptor/4.0)
}

for Statement

for ( $cellname = expr to expr) statement
    or
for ($cellname=expr to expr step expr) statement

The value of the cell name is increased by the step expression, and the blockStatement is executed repeatedly until the value of the cell name reaches the until the second expression. For the first option, the value of the step expression is assumed to be +1.0.

For Statement Example

for($angle = 0 to pi step 0.1)
    $y = $x*sin($angle)/4.0

break Statement

break

The break statement immediately exits the most interior, enclosing for, while, or repeat statement, and begins executing after that statement.

break Statement Example

while(1==1) {
    computeSomething
    if($done==1) break
}

continue Statement

continue

The continue statement immediately executes the iteration logic of the innermost enclosing repeat, for, or while statement, and either begins it’s executable statement again, or exits it, depending upon the outcome of the iteration logic.

continue Statement Example

 while($done++) {
    if($done < 7) continue;
    computeSomething;
}

in Statement

in "prompt string",$cellname
        or
in $cellname

The in statement shows the console view, issues a prompt if one is supplied (otherwise prompts with cell name?), and waits for input in the input bar at the bottom of the console view. The input bar also contains a cancel button. If the user presses the cancel button, the current run is over. If the user enters a number, the value of that number is assigned to the cell named. If the user enters anything else, the console issues a NOT A NUMBER complaint, and re-prompts for the requested numeric input.

in Statement Example

in "How many fingers am I holding up?",$fingers
    or
in $fingers

out Statement

out "output string"

The out statement copies the quoted output string to the console. If the quoted string contains a cell value reference, the value of the cell is substituted for the value reference in the output. The word out by itself, causes a blank line to be output to the console. The word out followed by a string followed by a semi-colon, outputs the string but does not issue a newline.

bp Statement

bp "string"

The breakpoint statement outputs the string supplied, and temporarily halts execution of the script which contains the statement. This allows the user to examine the stack of active cells, or any other cells, and their values. The user can continue execution by touching the run button, |>, or abort execution by touching the STOP button, which appear when the breakpoint is taken.

Builtin Functions

min

returns the minimum value in a variable length list of arguments.

max

returns the maximum value in a variable length list of arguments.

mean

returns the mean value of a variable length list of arguments.

abs

returns the absolute value of its argument.

sign

returns +1.0 if the single argument is non-negative, and minus 1 if the single argument is negative.

step

same as sign.

logistic

returns 1/(1+e^(-arg).

lookup

return the value obtained by interpolating between successive endpoints in a piecewise linear approximation to a function. First argument is the entry value, the value for which the function approximation is sought. The remaining values are x-y pairs and that define the piecewise linear function.

sin

returns the sine of its argument, which must be in radians or degrees, as specified in the Number panel of the settings view.

cos

returns the cosine of its argument, which must be in radians or degrees, as specified in the Number panel of the settings view.

tan

returns the tangent of its argument, which must be in radians or degrees, as specified in the Number panel of the settings view.

asin

returns the principal angle in radians or degrees, as specified by the Number panel of the settings view, which corresponds to the sine value supplied.

acos

returns the principal angle in radians or degrees, as specified by the Number panel of the settings view, which corresponds to the cosine value supplied.

atan

returns the principal angle in radians or degrees, as specified by the Number panel of the settings view, which corresponds to the tangent value supplied.

sqrt

Returns the square root of its argument if the argument is positive. Otherwise returns a NaN (Not a Number) value.

ln

returns the natural logarithm of its argument.

exp

returns Euler’s number (e) to the power of its argument.

log10

returns the log base 10 of its argument.

pow

returns its first argument raised to the power of its second.

rand

if no argument is supplied, returns a random number between 0 and 1000. If there is an argument, returns a random number between 0 and it’s argument.

startat

positions the plot routine to the x, y position given by its first and second arguments respectively.

drawto

draws a line from the current plot position to the x, y position given by its first and second arguments respectively.

MathWeb File eXamples

MathWeb comes with several example files which demonstrate various features of the program and script language. The examples may be included or excluded from the File list in the Settings View by touching the Examples button in the upper right corner of the Files panel.

Babbage

Babbage illustrates multi-cellular evaluation of execution references (cell names without $ sign prefixes), which works like spreadsheet evaluation. When the run button, |>, is pressed, the current cell is executed, which includes the execution of any cell it references, directly or indirectly.

Bisect

Bisect demonstrates the method of bisection for finding the roots of a polynomial within a specified interval. It also shows the use of a recursive algorithm using cell execution references.

Hamurabi

Hamurabi is a port of the classic basic game by the same name. It lets the user try his hand at governing a kingdom at the dawn of agricultural civilization.

The Logo file uses the simple script above to draw the MathWeb logo shown below:

Other eXamples

Euler employs a recursive algorithm to compute Euler’s number, e, from the factorials of non-negative integers.

Cocomo which uses the COCOMO II method to estimate time and staffing needed to develop software.

PresentValue estimates the present value of a bond, given face value, current period market rate, compounding periods, and interest payments.

RungeKutta computes a numerical solution to the differential equation for simple harmonic motion.

Piggy computes the total cash in your piggy bank given the count of pennies, nickels, dimes, quarters, half-dollars, and dollars.

Fpoint calculates an estimate of time and resources needed to develop software, given the number of function points required or the number of lines of source code.

Newton uses the slope of the graph of a polynomial to rapidly zero in on its roots.

Fourier plots the sum of five harmonics of a sine wave.

Cramer solves three linear equations in three unknowns.

Conway shows the result of repeatedly applying a collection of binary relations to randomly chosen arrays of 16 binary bits.