Q  (v8.5 – June 17, 2010)

© 2005-2010 Mark Furtney.  All rights reserved.

ComputeSoup – Web Computational Engine

(Equation/Expression Evaluation)


 
                       
 

              Enter expression in this box
Expr  




ComputeSoup – Advanced Features

ComputeSoup is an expression evaluator.  It evaluates the user's input expression and tabulates the result and variable values for up to eight variables (each with one or more values).  194 Constants (e.g., PI, SQRT2) and 226 Functions (e.g., Sqrt, Refinance, Cubic, Payoff, Complexdiv, Ira, Integrate) are available for use.  Click the Constants button for a list/description of the available constants, or the Functions button for a list/description of the available functions.

There are several features which can make using the basic functionality of expression (and equation) evaluation easier.  Among these features:

1)     Equations 8)     Statistics
2)     Pre-setting variables 9)     User-defined functions
3)     Options 10)     Nested arguments
4)     History 11)     Integration
5)     The Store 12)     Error messages
6)     Using previous values       13)     FYI messages
7)     Input shortcuts 14)     Specialty functions




      Equations

An equation is a simple variable followed by "=" followed by an expression.  The expression may contain variables, constants, and functions.  The result of each expression evaluation (one for each set of variable values) is saved in the Store under the left hand side variable name.  When that variable is next referenced in an expression, those saved values are automatically loaded (although they are subject to user override).  Here is a simple sample of an equation:

omega = (rho-a)*sin((pi-rho)*(1-a));

For this sample, the user would be prompted for one or more values for the variables rho and a.  If the user entered two values for one variable and three for the other, six values for omega would be calculated and saved in the Store.  When omega is later used in the same session, these six values would be automatically loaded.



      Pre-setting variables

It is straightforward to load variable values directly into the Store for use later in the session.  The format is  $var  =  value[s]  --  later you can use var in an expression without needing to enter values.  Here are some examples:
$e  =  enatural
$i  =  1,  2,  3,  4
$index  =  loop  1  17  2
$beta  =  5.103,  4.1219,  pi,  2.171,  sqrt3
$xyz  =  interp  3  7  4
In these examples, values for e, i, index, beta and xyz are placed in the Store.  Enatural, pi and sqrt3 are constants (click the Constants button for a list/description of the available constants), and loop and interp are special input shortcuts.  The values for index are 1, 3, 5, ..., 17.  The values for xyz are 3, 3.125, 3.25, ..., 3.875, 4.  That is, seven equally-spaced values are placed between 3 and 4, making nine values total.  Details about loop and interp can be found below, or by clicking the Input Shortcuts button, which can also be found via the button.





      Options

Several user-settable options control various aspects of displaying results and saving information in the Store.  Clicking the [Options] button above yields the following matrix of options:

Alternate Bases     Save LHS        
Append  Save RHS  
Extra Precision  Show FYIs 
Hide History  Show Stats  
Ignore Store  Warnings 
Save History  Zoctal
 
Any of these options can be turned on or off.  By default, all left-hand-side (LHS) variables are saved in the Store.  Click the save right-hand-side [Save RHS] box, then the [Apply] button to save the values of your input variables for later reuse.

Click to get details about the options.



      History

Equations and expressions entered in the [Expr] box are saved in a history file (the History dropdown menu) for the duration of the session.  Any of them can be recalled for resubmission or editing and reuse.  Note that the History dropdown menu only appears after an expression has been entered.  Here is a simple sample of the History dropdown menu (note – the menu is most-recent-first):

              (3 previous entries)
(History)




      The Store

The Store holds variables and user-defined functions.  It persists for the lifetime of the session.  Various usage statistics are maintained for the data stored in the Store.  The most useful information maintained in the Store is the data saved for user-defined functions and the values of variables.  Variables and their values are sent to the store as the result of Equation Evaluations (when the SaveLHS option is On), when direct Store requests are made (e.g., "$iter = 2 4 6 8 12 16 22"), and when variables are used in an expression while the SaveRHS option is On.  By default, SaveLHS = On  and  SaveRHS = Off.  These values can be changed by clicking the [Options] button.

When there is data in the Store, a Store button will appear in the matrix above the [Expr] box, as below:

                       
                       
 

When data is saved in the Store, clicking the [Store] button displays a panel (as below) which allows the user to manipulate and report on the contents of the Store.  Note that deleting a variable or a user-defined function is final – that is, no recovery is possible.  However, variables can be deactivated and later activated.  While a variable is deactivated, ComputeSoup behaves as if it does not exist.  At creation, all variables are activated.

When an expression contains a variable which is in the Store, ComputeSoup automatically loads its values.  Thus the results of previous computations can be easily used in subsequent expressions.  The user is able to override these values.

( 1 User-defined function )
( 5 variables,  29 values )


(Sorting silently drops duplicates)

Ascending   Descending

All         Selected

List    Nolist


All   Selected


All   Selected


Click to find descriptions of these buttons.  For example, clicking on   would lead to a report which looks like this:

the Store (with values)

( 1 User-defined function )
( 5 variables,  29 values )

  ActvSrcSort#NameValues
1YesLHS No   5   a   -96,   -97,   -92,   -154,   -95
2Yes$= --   1   e   2.71828182845905
3Yes$= No   9   index   1,   3,   5,   7,   9,   11,   13,   15,   17
4YesLHS No   5   czero   94.4244235616971,   36.8219506856696,   -71.710878404654,   -9.53573193743283,   64.9098628999315
5YesLHS No   9   rstar   .841470984807897,   .141120008059867,   -.958924274663138,   .656986598718789,   .412118485241757,   -.999990206550703,   .420167036826641,   .650287840157117,   -.961397491879557


Further, values in the Store may be sorted (ascending or descending), but note that duplicate values are silently deleted.  Click  



      Using previous values

Data in the Store is automatically used (although the user may override some or all of the previous values).  Here is a sample: Assume that index is in the Store with values 1,3,5,...,17 (as above).  Then entering dist = index*(pi-theta) in the [Expr] box and clicking [Go] would lead to:

dist = index*(PI-theta);


              Enter value(s) for each variable

index
theta
 

 
 
 


Note that the yellow box indicates that the values have been withdrawn from the Store.  These values may be accepted, deleted, or overridden for this evaluation.



      Input shortcuts

Input values may be integers, floating point values, or ComputeSoup-recognized constants (like pi or sqrt2).  Input values are separated by one or more commas, blanks, or newlines.  Further, there are three special strings that can be used with input values:  Loop,  Interp, and Last






      Statistics

ComputeSoup provides three mechanisms to review some simple statistics about computed (and input) values.  First, when an equation is used, statistics about the computed variable are saved in the Store.   These simple stats (count,max,min,avg,stdev) are available by clicking .  Second, maximum, minimum and median values are highlighted in the standard output when more than two values are computed.  (When there are an even number of results, the median value is computed.)  And finally, if the Show Stats option is enabled, a small table of statistics is displayed below the computed results.  Here is a sample (after clicking and checking the Show Stats box).  Note that the (Min,Max,Mdn) values are displayed independent of the status of the Show Stats option.

alpha = b*((x2+sqrt(x2))/(sin(pi*angle/exp(b))-.137))

For this equation with three values for b, three values for x2, and one value for angle, typical results could look like:

alpha = b*((x2+Sqrt(x2))/(Sin(PI*angle/Exp(b))−.137));

    alpha    b    x2    angle  
    -------    ---    ----    -------  
  1)      8.1176609   1.401   1    0.6501 
  2)      9.139128    1.401   1.17   0.6501 
Max    3)      9.5526721   1.401   1.24   0.6501 
Min    4)      3.892497    1.03   1    0.6501 
  5)      4.3823003   1.03   1.17   0.6501 
  6)      4.5805987   1.03   1.24   0.6501 
  7)      5.5954168   1.213   1    0.6501 
Mdn    8)      6.2995031   1.213   1.17   0.6501 
  9)      6.5845546   1.213   1.24   0.6501 

 Avg   StdDev   Min   Max  Median 
 6.460481   2.083267   3.892497   9.552672  6.299503 


After completing the computation, clicking   yields:


the Store – Statistics

( 1 variable,  9 values )

  ActvSrcSort#NameMinMaxAvgStdDev
1YesLHS No   9   alpha3.89259.552676.460482.08327




      User-defined functions

ComputeSoup provides a mechanism to create user-defined functions, and use them in subsequent computations during the same session.  Each must have 1-8 arguments and return a single value.  Each argument must be used at least once.  User-defined function names follow the same rules as variable names, and may not take on the name of an existing ComputeSoup function or constant.  A user-defined function can be used just like any other function (e.g., it may have constants, variables, and other single-valued functions as arguments; it may be used in expressions and equations and as the arguments to other functions), except that user-defined functions may not nest.  That is, a user-defined function may not be used as an argument to a user-defined function.  The special format for creating a user-defined function is illustrated below:

cos2(a,b)  ::=  pi*(a*cos(2*a+b) - b*cos(a-2*b));

The cos2(a,b) is the user function prototype, with two dummy arguments (a and b), followed by ::= (two colons and an equal sign), followed by the function definition pi*(a*cos(2*a+b) - b*cos(a-2*b)) and an optional semicolon (;).  The function definition must use each of the dummy arguments at least once (no other variables are allowed), and may also use numbers, ComputeSoup constants, functions, and any of the ComputeSoup mathematical operations (e.g., +, –, *, etc).  As with any other entry in the [Expr] box, whitespace is ignored and entries are case-insensitive.

Note that user functions are stored as complete parse-trees (not symbolically).  This means that it is not necessary to encase the definition in parentheses.  That is, given a user function abc:

abc(x,y)  ::=  x - y

the expression  r * abc(x,y)  will always be evaluated as  r*(x-y),  not as  (r*x) - y.

A review of the current user functions and some information about each is available in the Store: click .  User functions can not be overwritten, but may be deleted: click .

Here is some sample output from an equation which uses both user functions mentioned above.  Note that in this sample, three of the four user function dummy arguments are populated by constants and one is a variable (p).  In fact, any dummy argument in a user function may be replaced with a constant, a simple variable, or an expression.

zippo = abc(6.733, pi)*cos2(p, 1.53)

One variable p with values of "Loop 1.103, 1.83, 0.084" was used.  Note that when user-defined functions are employed in an expression, they are always listed in green.

Abc(x,y)  ::=  x-y;

Cos2(a,b)  ::=  pi*(a*cos(2*a+b)-b*cos(a-2*b));

zippo = Abc(6.733, PI)*Cos2(p, 1.53);

zippo p
    -------    ---  
Mdn   1)   -3.8079488   1.103 
2)   -4.5474335   1.187 
Min   3)   -4.8315311   1.271 
4)   -4.6465638   1.355 
5)   -3.9997734   1.439 
6)   -2.919697   1.523 
7)   -1.4557149   1.607 
8)     0.3232277   1.691 
Max   9)     2.330699   1.775 






      Nested arguments

Arguments to functions may include functions – that is, functions can nest.  Here is a sample.

a2 = sqrt(abs(1+sin(x)*cos(y)/sqrt(x^2+y^2)))

Setting x to 3, 4, 5 and y to 7.5, 4.3, 2.2 yields:

a2 = Sqrt(Abs(1+Sin(x)*Cos(y)/Sqrt(x^2+y^2)));

a2 x y
    ----    ---    ---  
Mdn   1)     1.0030233   3    7.5 
2)     0.9945915   3    4.3 
3)     0.9887751   3    2.2 
4)     0.9844476   4    7.5 
5)     1.0254994   4    4.3 
6)     1.047646   4    2.2 
Min   7)     0.9813887   5    7.5 
8)     1.0287272   5    4.3 
Max   9)     1.0503845   5    2.2 




      Integration

ComputeSoup provides two functions to perform approximate integrations {Integrate() and Quadrature()}.  They use the same numerical approximations to integrations, and produce the same results.  The only difference is that Quadrature() always shows the convergence to the approximate solution, while Integrate only displays convergence data when convergence has not been achieved.  Quadrature() is recommended.
Here is the definition:  Integrate( a, b, expr ):  a b{expr(x)} dx.  Approximate result of integrating the expression (expr) from a to bA and b are the lower and upper bounds of the (dummy) variable in expr, and must be constants with (ab).  The expression expr must have exactly one variable, must be single-valued, and may be a single user-defined function or an expression with no user-defined functions.  The expression expr must be continuous over the specified range, and may include any single-valued function except Rand() and IRand().  Unpredictable results may occur when expr is not continuous or is otherwise ill-behaved.
Here are a sample of each:

Integrate(1.33, 1.57, x*Sin(x)^2);

~  .3416035



Quadrature(1.33, 1.57, x*Sin(x)^2);

~  .3416035

Convergence Information

Criterion:   | Δ/Value |  <  10-6

TrapezoidsValueΔ/Value
16      0.341593     
32      0.341601    2.29166*10-5 
64      0.341603    5.72906*10-6 
128      0.341603    1.43226*10-6 
256      0.341603    3.58064*10-7 




      Error messages



ComputeSoup checks input expressions for validity, and puts out a message when it detects an anomaly (e.g., a non-standard character, a parsing problem, mismatched parentheses, unrecognized function names, et cetera).  Here are some samples:

val=(0.5/a)*(-b+-sqrt(b^2-4*a*c))


input error -- can't understand "+-" (character 18)
                                  ^


1 Diagnostic: see input equation below

     val = (0.5/a)*(-b+-Sqrt(b^2-4*a*c));
     .................^

abc = sin(gg,omega)*cos(gg*omega))


input error -- expression has an unmatched ")" at character 35

input error -- equation has mismatched "()"s, 2 "("s but 3 ")"s

input error -- Sin() should have 1 argument (2 arguments at character 7)

3 Diagnostics (2 pointers): see input equation below

     abc = Sin(gg, omega)*Cos(gg*omega));
     ......^...........................^

Function Args Results Prototype/Description Expr Use?
 Sin  1 1   Sin( radians ):  Sine of the angle radians (radians).  Same as Sinr()  Yes


bb = sqrtt(time+0.2*penalty)


input error -- "sqrtt" at character 6 is not a recognized Function

1 Diagnostic: see input equation below

     bb = sqrtt(time+0.2*penalty);
     .....^



When a computational error is encountered, ComputeSoup highlights the error and attempts to complete the other data sets.  No statistics are compiled when an error is encountered, and data is not transferred into the Store.  Here is a sample.

seabiscuit = sqrt(x-y)/(y-x)

Setting x = 3, 5, 9 and y = 1, 2, 5, 8 generates these results:

seabiscuit x y
   ------------   ---    ---  
1)   -0.7071068   3    1  
2)   -1   3    2  
NSqr 3)     ???   3    5  
NSqr 4)     ???   3    8  
5)   -0.5   5    1  
6)   -0.5773503   5    2  
ZDiv 7)     ???   5    5  
NSqr 8)     ???   5    8  
9)   -0.3535534   9    1  
10)   -0.3779645   9    2  
11)   -0.5   9    5  
12)   -1   9    8  

4 runtime errors:

     1 * ZDiv - Division by zero
     3 * NSqr - Square Root of a negative number



      FYI messages

Under certain circumstances, ComputeSoup generates informational messages (usually preceded by FYI – ).  Here are some samples:

FYI – 9 Store values for a2 will be replaced by new value(s).

FYI – 4 new values for a2 replaced 9 previous values

FYI – The Store is full:  no new entries allowed until some data removed.

FYI – 6 new values appended to alpha.

FYI – gstar changed to Active.

FYI – Sort: 2 duplicate values dropped for qzero





      Specialty functions

ComputeSoup provides a variety of special purpose functions which perform very specific computations (e.g., exploring Mortgage payoff strategies, computing calories burned during a workout, computing Body Mass Index (BMI), finding the day of the week of any date, finding your target workout heartrate, integrating, exercising Ohm's Law, counting the number of 1-bits in a word, solving quadratic, cubic, and quartic equations, ...).  Here is a summary of a few of these functions:

ComputeSoup – A few of the Special Purpose Functions

Function Args Results Prototype/Description Expr Use?
 Base  1 3   Base( int ):  Display the integer argument int in octal, hex and binary  No
 BitCount  1 1   BitCount( int ):  Return the number of 1 bits in the 32-bit integer argument int.  Same as PopCount()  Yes
 Bmi  2 1   Bmi( weight, height ):  Body Mass Index – a measure of weight for height in adults.  As BMI increases, risk for many weight-related diseases increases.  Weight is weight (lbs), height is height (ins).  Approx results:  (<18.5 Underweight), (18.5–25 Normal), (25–30 Overweight), (>30 Obese)  Yes
 Calories  5 text   Calories( activity, weight, dist, min, sec ):  Approximate calories consumed by various activities.  Arguments as in the table below.  For example: "Calories( running, 165, 3.25, 25, 20 )" yields "408 calories -- Running (165lbs, 3.25mi in 25:20 =>  7:48/mi = 7.70 mph)".  See also Fitness(), HeartRate(), Karvonen(), Points(), Bmi()
activity   weight     dist    min    sec    |   Others
Walking lbs miles min sec | Aerobicdance, Aerobicshi, Aerobicslo, Basketball,
Running lbs miles min sec | Handball, Hockey, Iceskating, Judo, Karate, Lacrosse,
Cycling lbs miles min sec | Pingpong, Racketball, Rollerblading, Rollerskating,
Swimmingmylbs yards min sec | Rowing, Skiingcc, Skiingdh, Skiingwater,
Swimmingfy lbs yards min sec | Snowshoeing, Snowshoveling, Soccer, Squash,
Swimmingmm lbs meters min sec | Taichi, Tennisd, Tenniss, Volleyball,
Swimmingfmlbs meters min sec | Wateraerobics
Skiprope lbs rpm min sec | Swimming__; my=(male,yards), fy=(female,yards);
Golfcarry lbs # holes min sec |       mm=(male,meters), fm=(female,meters);
Golfwalk lbs # holes min sec | Aerobics__;  lo=low-impact,  hi=high-impact
Others lbs 0 min sec | Skiing__;  cc=cross-country,  dh=downhill
Stepcount lbs # steps 0 0 | Tennis_;  d=doubles,  s=singles
 
No
 Cubic  4 3 (r,i)s   Cubic( a, b, c, d ):  The roots to the 3rd order equation:
    ax³ + bx² + cx + d  =  0,   where  (a ≠ 0) 
No
 DayOfWeek  3 text   DayOfWeek( year, month, day ):  Print day-of-week for input date: year > 1752, month (1-12) for (Jan-Dec), and day (1-x), (28 ≤ x=f(month,year) ≤ 31)  No
 Factor  1 mult   Factor( int ):  List all the prime values which divide evenly (with no remainder) into integer int.  Max value for int is (231–1)  =  2,147,483,647  No
Function Args Results Prototype/Description Expr Use?
 HeartRate  2 text   HeartRate( age, restingPulse ):  Display maximum and various other workout-related target heart rates: age is age (integer, (10–100)), and restingPulse is resting heart rate (integer, (35–90)).  Same as Karvonen().  No
 Integrate  3 text   Integrate( a, b, expr ):  a b{expr(x)} dx.  Approximate result of integrating the expression (expr) from a to bA and b are the lower and upper bounds of the (dummy) variable in expr, and must be constants with (ab).  The expression expr must have exactly one variable, must be single-valued, and may be a single user-defined function or an expression with no user-defined functions.  The expression expr must be continuous over the specified range, and may include any single-valued function except Rand() and IRand().  Unpredictable results may occur when expr is not continuous or is otherwise ill-behaved.  Same as Quadrature(), except Quadrature() always shows convergence of the approximate solution.  Quadrature() is recommended.  No
 PayoffExtra2  4 table   PayoffExtra2( payment, rate, balance, extra ):  Show impact of extra amount submitted with each future mortgage payment when the loan is partly paid off:
    payment  =  Monthly payment (principal + interest only: no escrow)
    rate  =  Annual interest rate (percent - e.g., 6.75)
    balance  =  Current balance (principal)
    extra  =  Extra amount with each payment
Same as Payoff2().  See also Refinance(), Mortgage(), and the other Payoff*() functions. 
No
 RacePace  4 text   RacePace( distance, hours, minutes, seconds ):  Pace (mm:ss/mi) for race of distance distance miles run in hours hours, minutes minutes, and seconds seconds.  Note that distance may be a constant or an expression, e.g., MARATHON, TENK, FIVEK, 100/1760, 0.8*KM, METRICMILE, HALFMARATHON, etc  No
 Solver  many mult   Solver( nEqns, x1, x2, ... ):  Solve nEqns equations in nEqns unknowns (1 ≤  nEqns ≤ 8).  There are (nEqns*(nEqns+1)) more arguments, representing the equations.  Solver() is the same as Unknowns().  For example:
   x + 2y + 3z  =   4
  2x +  y + 4z  =   5
  3x + 3y + 6z  =  12

For these equations, using
  Solver(3, 1,2,3,4, 2,1,4,5, 3,3,6,12)

yields:   x = 7,   y = 3,   z = –3 
No
Function Args Results Prototype/Description Expr Use?