MathE Documentation

TablE

TablE is a command that extends the functionality of the built-in Table command. If EOn is in effect, Table will be converted to TablE. If syntax for the builtin Table command is used, the same output will result. Several enhancements have been added, described in the following sections.

List Iterators

In addition to standard iterators, TablE will accept "list iterators" which contain lists of values for an index. The syntax for a list iterator is {index,{values}}.
    For example, in

TablE[k+m,{k,{2,5,a,b}},{m,2,4}]

the first iterator is a list iterator. The list of values may contain arbitrary expressions to be substituted for the index.

Show

TablE can print a TableForm version of the result as well as the usual structured list output. TablE never outputs a TableForm object. To print a TableForm version, either include the keyword Show or set the option Show to True. (The default for this option is False.) If the option Show is set to True, the keyword Hide will negate it.

TablE[n,Sin[n],{n,1,5},Show]

Note that formulas to be used in composing the table do not have to be in a list, you can just include them separated them by commas. To suppress the standard output, just put a semicolon at the end of the TablE command.

It is not necessary to have iterators; TablE may be used simply as a convenient means to place data into a formatted table. If there are no iterators, it is not necessary to include the keyword Show; it is assumed you want a formatted table.

data = {{3.41,8.03,7.65},{4.24,9.91,0.25},{1.78,2.64,5.53}};
TablE[data,"A","B","C"];

Headings

The following two paragraphs describe what is done if the Headings option is Automatic (default).
    Default column headings are the given functions in InputForm format. Customized column headings can simply be included as string items in the command, either in a list or separately. If you give any strings or a list of strings, the default headings will not be used. If you don't give enough strings for all the columns, some columns will not have headings.

TablE[n,Sin[Cos[Tan[n]]],Sqrt[n],{n,1,5},Show,
"garbage in","garbage out"];

If more than one list of headings is given, they are applied in order to the levels of the list structure. Example:

TablE[i*j*k*l,{i,1,3},{j,1,3},{k,1,2},{l,1,2},Show,
{"a","b","c"},{"d","e","f"}];

The Headings option can also be given any value which would be legitimate for the TableHeadings option of TableForm. In particular it can be a list, each entry of which is None, Automatic, or a list of strings.

TablE[i*j*k*l,{i,1,3},{j,1,3},{k,1,2},{l,1,2},Show,
Headings->{None,Automatic,{"a","b"},{"c","d"}}];

The keyword Number applies standard Automatic headings to all dimensions which do not otherwise have headings. The effect of this is to number rows and columns, except that function expressions are kept as headings where appropriate. Warning:  such numbering may become confused with the actual table entries.

TablE[Sin[n],{n,1,5},Show,Number];

TablE[1/(i+j),{i,1,5},{j,1,5},Show,Number];

Precision

By default, numerical values to six significant digits are used. This default can be altered in two ways.

Exact

The keyword Exact means that expression are not to be numerically approximated.

TablE[t,Sin[t],Cos[t],Tan[t],{t,{0,Pi/6,Pi/4,Pi/3,Pi/2}},
	Show,Exact];

Digits & Places

An item of the form n Digits or n Places (lower case can also be used) indicates that table entries are to by rounded to n significant digits or to n decimal places respectively.

TablE[t,Sin[t],Cos[t],Tan[t],{t,{0,Pi/6,Pi/4,Pi/3,Pi/2}},
	Show,3 Places];

Note that this can result in minor deceptions when the input values are part of the table; for example, tan(1.571) is not  undefined.

Tan[1.571]

Structure

Switch

The keyword Switch will transpose a two-dimensional table, with rows becoming columns and columns becoming rows. There is no effect on a one-dimensional table. Switch is equivalent to the option Level->1 as explained below.

TablE[t,Sin[t],Cos[t],Tan[t],{t,{0,Pi/6,Pi/4,Pi/3,Pi/2}},
	Show,Exact,Switch];

The difference between Switch and the Transpose command is that Switch alters the display of the list but not the list structure itself.

Level

In a multi-dimensional table, the list structure of the resulting data can vary in ways analogous to the switching of rows and columns in a two-dimensional table. If only one function is being evaluated, changing the order of the iterators can account for all possible structures. But if a list of functions is being evaluated, that list can be treated as another iterator, and its possible positions in the list of iterators offers additional possible structures for the table. This position is called "level", and the possibilities for it range from 1 (meaning first in the list of iterators) to the number of iterators plus 1 (meaning last). If all this seems abstract, it is! Here are some examples that show the practical effect.

The default is that the function list occupies the highest level, which would be 3 in the case of two iterators. The other two possibilities for the level follow below. Three other structures can be obtained by reversing the order of the iterators.

TablE[f[x*y],g[x*y],{x,1,4},{y,{a,b,c,d}},Show,Number];

TablE[f[x*y],g[x*y],{x,1,4},{y,{a,b,c,d}},Show,Number,
Level->1];

TablE[f[x*y],g[x*y],{x,1,4},{y,{a,b,c,d}},Show,Number,
Level->2];

TablE Options

Digits->Automatic

Determines the number of significant digits or decimal places used in table entries. Automatic indicates that N is applied to all entries. Other allowed values are integers (positive indicating significant digits and negative indicating decimal places) or expressions of the form n Digits or n Places, and result in RoundE being applied to all entries.

Headings->Automatic

Gives headings for rows and columns, and for groupings in higher dimensional tables. The use of this option is explained above.

Level->Automatic

Controls the list structure when a list of functions is evaluated in a table. Allowed values are integers from 1 to the number of interators + 1. See examples above for the effect of this option.

Show->False

The default action concerning the printing of the table in TableForm format. When this option is False, the keyword Show is needed to print in TableForm format. When this option is True, printing in TableForm format will occur unless the keyword Hide is present. The output is never affected; it is always in List format.

In addition, any option for TableForm may be included in a Table command, and will be applied to printing in TableForm format should it occur.

TableAlignments->Automatic

TableDepth->Infinity

TableDirections->Automatic

TableHeadings->None

TableSpacing->Automatic

Other Improvements

DefinE

DefinE is a command for defining functions that uses more natural syntax and avoids a couple of common problems. If EOn is in effect, Define will be converted to DefinE.

DefinE is intended for everyday use; in rare situations it may not be appropriate. For those situations, use standard Mathematica  syntax.

Examples

DefinE[f[x] = Sin[x^2]]

Standard Equivalent:  Clear[f,x]; f[x_]:= Sin[x^2]

The syntax requires a function name with one or more variables inside square brackets, followed by an equals sign and an expression. You may define functions of several variables, and you may define more than one function in a single command.

DefinE[g[x,y] = a Cos[x^2 + y^2],h[t] = 2t/(1-t)]

Benefits

The DefinE command relieves the user of the responsibility for remembering the underscore and the colon in the standard syntax, a common difficulty for novice users. It also clears any previous assignments to any of the variables or function names on the left side of the equation. This avoids a common problem with novice and intermediate users: they may define f[x_] at one point and f[r_] later. With both definitions attached to the symbol f, the definition actually used by Mathematica may not be the one the user is expecting.
     The clearing of symbols is technically a "side effect" and may be undesirable in some cases, but for everyday use it will prevent far more problems than it causes. One situation where DefinE is clearly not useful is when multiple function definitions to the same symbol are desired.

Delayed and Immediate Assignment

DefinE also avoids a problem with the usual method of function definition: deciding whether to use delayed assignment or immediate assignment. Consider the following possibilities:

g[x_]:= Integrate[Cos[x]^7,x]
g[x_] = Integrate[Cos[x]^7,x]

The first line, a delayed assignment, uses the typical format for a function definition. However if you were now to plot g(x), the integral would be recalculated for every point that was plotted! Therefore the second line is superior, as it will calculate the integral once and assign the result to be the function g(x). In more complex situations, neither of these alternatives may be entirely satisfactory.

This point is a subtle one for novices and an annoyance even for experienced users. DefinE sidesteps this problem by first evaluating the right side and then making a delayed assignment, which works well regardless of whether the right side is subject to evaluation. Observe:

DefinE[g[x] = Integrate[Cos[x]^7,x]];
??g

Here is one type of situation where one must be careful:

g[x_]:= Integrate[f[x],x]

This standard definition sets up a link between the symbolic functions f(x) and g(x). If f(x) is now defined several times, g(x) will always represent its integral. 
    Let's compare this to

DefinE[g[x] = Integrate[f[x],x]]

If f(x) has already been defined, then the right side will be evaluated and g(x) defined to be the result; future changes to the definition of f(x) will have no effect on g(x). Of course this may be the behavior you want! But if you want the symbolic link between f(x) and g(x), you can achieve it simply executing this definition before f(x) is defined, or by clearing the symbol f first, in which case this definition is identical to the standard definition above

Known Problems

An example of a situation where DefinE does not work well is given by

DefinE[g[x] = D[f,x]]

where f is a soon-to-be-defined expression involving the variable x. As DefinE evaluates the right side before making the delayed assignment, the result is that g(x) is set equal to 0. If f were defined in advance there would be no problem. Likewise if the right side were D[f[x],x] there would be no problem as this expression evaluates to f'[x], not 0.

SolvE & NSolvE

SolvE and NSolvE are relatively minor improvements of the respective builtin commands Solve and NSolve. If EOn is in effect, Solve and NSolve will be converted to SolvE and NSolvE.

SolvE and NSolvE will accept equations with a single equals sign and treat them as if they had a double equals sign.

SolvE and NSolvE both can give solutions either in Rules format or in "normal" format (default), which is just a list of solutions. The choice can be made via the Rules option or by including the keywords Rules or Normal in the command.

Examples

SolvE[x^2 - 3x + 2 = 0]

SolvE[x^2 - 3x + 2 = 0,Rules]

SolvE[{2a + 3b - 2c = 7,
				a -  b + 4c = -1,
			-3a + 2b +  c = 3}]

SolvE[{2a + 3b - 2c = 7,
				a -  b + 4c = -1,
			-3a + 2b +  c = 3},Rules]

SolvE[{x^2 - y^2 = 4,x^2 + y^2 = 9}]

NSolvE[{x^3 - 3x*y + y^3 = 7,2x^2*y + x*y^2 + y = 1}]

Did you really want to see that in Rule format?

SolvE Options

Rules->False

This controls whether solutions are given in Rules format or in "normal" format. A value of True gives output identical to the standard output (Rules) whereas a value of False gives output as a list of solutions. The setting of this option can be overridden by including the keywords Rules or Normal.
    Although officially an option for SolvE, the setting of this option applies to both SolvE and NSolvE.

RoundE

RoundE is an extension of Round. If EOn is in effect, Round will be converted to RoundE. When called with a second argument, RoundE will round to a certain number of significant digits or a certain number of decimal places. You can give the number of digits or places as a positive or negative integer (respectively) in the second slot. An alternative is to place n Digits or n Places in the second slot, where n is a nonnegative integer.

RoundE[Pi^E,8]

RoundE[E^Pi,-6]

TablE[RoundE[E^5,k Digits],{k,1,10},Show,Exact];

TablE[RoundE[E^5,k Places],{k,0,10},Show,Exact]

Unfortunately, the TablE command rounds off to six significant figures by default. So we need the keyword Exact to see the full results.

Known Problems

Unlike the N[#,k] command, RoundE actually destroys information. The results really are rounded off!

N[RoundE[Pi,6],10]
N[Pi,10]

MinE & MaxE

The built-in Min and Max functions do not deal with exact constants or non-numbers. The extended versions MinE and MaxE do. If EOn is in effect, Min and Max will be converted to MinE and MaxE.

MaxE[{20,E^Pi,Sqrt[167],fred}]
MinE[{20,E^Pi,Sqrt[167],fred}]

Known Problems

The fact that MinE and MaxE ignore nonnumeric entries has a disadvantage: it may conceal the fact that a variable has not been assigned a value when it should have been.

ExpandE & FactorE

ExpandE and FactorE are a very small beginning at making algebraic manipulation easier. In addition to the usual activities of Expand and Factor, these commands operate with logarithm rules. ExpandE converts logarithms of products into sums of logarithms, logarithms of quotients into differences of logarithms, and logarithms of powers into powers times logarithms. FactorE applies these same rules in reverse. These conversions take place only the keyword Log appears in the command, or if the expression is a simple one of logarithmic type.
    ExpandE supports the keywords Top and Num, expanding only the numerator, Bottom and Den, expanding only the denominator, and All, expanding everything. The keyword Both expands both numerator and denominator. These keywords can be used in combination, with many different effects, as shown in the examples below.

Logarithms

ExpandE[Log[a*b/c]]

ExpandE[Sin[Log[a^x]],Log]

FactorE[Log[a] + 3 Log[b] - 1/2 Log[c]]

FactorE[Sum[(-1)^n Log[n],{n,1,10}]]

Fractions

ExpandE[(x-1)^3/(x-2)^2,Top]

ExpandE[(x-1)^3/(x-2)^2,Bottom]

ExpandE[(x-1)^3/(x-2)^2,All]

ExpandE[(x-1)^3/(x-2)^2,Top,Bottom]

ExpandE[(x-1)^3/(x-2)^2 + Sin[(x+1)^2/(x+2)^3],
Top]

ExpandE[(x-1)^3/(x-2)^2 + Sin[(x+1)^2/(x+2)^3],
Top,All]

ExpandE[(x-1)^3/(x-2)^2 + Sin[(x+1)^2/(x+2)^3],
Bottom,All]

ExpandE[(x-1)^3/(x-2)^2 + Sin[(x+1)^2/(x+2)^3],
Both,All]

NestE & NestListE

NestE and NestListE differ only from Nest and NestList in that they will accept single-variable expressions as well as function names.

Examples

NestE[4x-4x^2,0.6,10]

NestListE[4x-4x^2,0.6,10]

Miscellanea

Piece Functions

"Piece functions" are functions that are defined by different formulas on different intervals. Such functions can be defined in Mathematica  by using the Which structure. calcE contains a Piece command, an extension of Which specifically designed to help define and use such functions.

Defining

Define[f[x] = 
	Piece[0 <= x <= 1,x^2,1 <= x <= 2,2 - x,2 <= x <= 4,Exp[2-x]]
];
f[x]

In this case, Piece was just a synonym for Which. However Piece has several advantages. One is that you donàt have to remember what comes first, the functions or the intervals; Piece will straighten you out.

Define[g[x] = 
	Piece[x^2,0 <= x <= 1,2 - x,1 <= x <= 2,Exp[2-x],2 <= x <= 4]
];
g[x]

You can give the intervals as ordered pairs instead of inequalities:

Define[g1[x] = Piece[x^2,{0,1},2 - x,{1,2},Exp[2-x],{2,4}]];
g1[x]

Also you can specify a default condition by else or otherwise, which are converted to True. (Of course, you can also use True directly.)

Define[h[x] = 
	Piece[1,-2 <= x <= -1,-1,1 <= x <= 2,0,otherwise]
];
h[x]
PlotE[h[x],{-3,3},Same];

Graphing Piece Functions

PlotE[f[x],{0,4},{0,2}];

Graphing Piece functions is just like graphing any other function. But when there are jumps in the graph, as above, you get unsightly vertical lines that are not really part of the graph. These vertical lines can be removed using Split.

PlotE[f[x],{0,4},{0,2},Split[2]];

Algebra with Piece Functions

Piece functions defined with the Piece command behave as expected in the following examples. Note that composition of piece functions is not supported.

g[x]
2 g[x]
g[x] + a
g[x]^2
Sin[x] g[x]

MakeString

Often you want to print a string composed of both numerical and text information. The MakeString command does the job. It converts items that are not already strings into strings, and combines all into one result.

a = 9; b = 6;
MakeString["The product of ",a," and ",b," equals ",a*b]
InputForm[%]

Sub

For those who have trouble with rules and replacement, a Sub command is provided that may feel more natural. Note that x is not altered by this syntax.

Sub[x^3 - 4x^2 + 12,x = 2]
x

You can also use an equation or in the second slot, or a list of any of these..

Sub[x^3 - 4x^2 + 12,{x->2,x=3,x==4}]

Mean & StDev

Mean[data] calculates the mean, or average of the items in data.
StDev[data] calculates the standard deviation of the items in data, using n-1 in the denominator.
StDev[data,Pop] calculates the standard deviation of the items in data, using n in the denominator.

Both Mean and StDev can be applied to multidimensional data, calculations being done coordinate-wise.

data = {3.5, 7.6, 2.9, 8.0, 4.1};
Mean[data]
StDev[data]
StDev[data,Pop]

data = {{3.5,8.4},{7.6,1.5},{2.9,6.3},{8.0,2.7}, {4.1,9.0}};
Mean[data]
StDev[data]
StDev[data,Pop]

Sum, NSum, Product & NProduct

Sum, NSum, Product and NProduct can now be applied directly to a list of items. NSum and NProduct can also accept an extra integer indicating the number of significant figures desired in the answer.

Examples

Sum[Range[1,100]]

Actually, it doesn't even have to be a list; any other head will work as well.

Sum[AddMe[33,45,78]]

NSum[Range[1,100,Pi],12]

Product[Table[Prime[k],{k,10}]]

NProduct[Table[Zeta[Prime[k]],{k,10}],10]