See English definition for "compute".
Also see NoopNamedErrors.
Compute[expr]
evaluates in an
intentionally restricted lexical environment for
numeric operations called RARE.
When either of the following constructs is
invoked...
(1) Reckon[Compute[expr]]
or
(2) Function[...Compute[expr]...]
...expr is evaluated such that
every
encountered elicitation assigned to a Compute[...]-expression
is
also Reckoned.
(1) or (2) precipitates the
Reckoning of every subExpression assigned to another Compute[...]-expression.
See, for
example, the RecursiveComputeExample.
Within expr, when either (1) or (2) is
invoked, processing comports with the Restricted
Arithmetic Rule Environment
(RARE).
Compute can only evaluate expressions that conform to a Restricted Arithmetic Rule Environment.
When Compute[eval]
is invoked,
eval is evaluated if it is an Expression, or ElicitationForm assigned
to an Expression,
with Head
matching one of the
following:
{Noop, True, Not, Or, And, Xor, Cardinal, Real,
List,
Set,
Tally,
Function,
Slot,
Loop,
If, Name}
- an arithmetic
operator defined and named in `Number`Compute`.
All Names
in `Number`Compute`
are assigned to
RARE Expressions.
In Grok32`,
numeric
processing, (everything in Compute[...]'s
brackets), always occurs only in
the RARE.
It is believed that expressions constructed in The
Restricted Arithmetic Rule Environment
(RARE), with Cardinal & Real
atoms, are sufficient to model any numeric type or
function. See RARE
in depth.
Any attempt to call an elicitation
which does not conform with the RARE
returns the error...
Noop[Compute][elicitation]
When one of the 16 disallowed keywords
is encountered in Compute, the error
message:
Noop[Compute][disallowedKeyword, elicitation]
...is returned.
Compute's RAREincludes arithmetic Functions and operators, defined in the `Number`Compute` Context.
In order of precedence, these operators are:
(*, /, %), (+, -), (<, >, <=, >=), (==, !=)
[Operators with equal precedence are grouped together with parenthesis in the above sequence.]
In addition to the above operators, there are the following functions:
{=+, =-, =*, =/, =%, Power, Mod, Abs, Floor, Ceiling, Sqrt, Sin, Cos, Tan, ArcSin, ArcCos, ArcTan, ArcTan, Cosh, Sinh, Tanh, Exp, Ln, Random}
Compute[...] constructions employ an intentionally restricted Grok32` lexicon and standard arithmetic operators. This increases speed and lucidity by forcing numeric computations into a well-defined, lexically simple numerical computational environment.
Compute[...] does not tolerate procedures which leave the RARE within its brackets.
Any attempt to call an ElicitationForm
Name
leading into a non-RARE, returns...
(3)
Noop[Compute][elicitation]
...where "elicitation" is the egregious ElicitationForm that invoked the non-RARE.
Named
Compute[...] ElicitationForms
may be recursive. Here is
an illustrative recursion:
Name[logSeries[Type[v, Cardinal],
Compute[If[v != 0, 1/v + logSeries[v-1]]
]
If Reckon[logSeries[n]],
is invoked with a Cardinal value for n, it
will effectively evaluate the following:
Compute[1 + 1/2 + 1/3 +1/4 + 1/5 +... + 1/n]
As noted above, within Compute[...]
's brackets, expressions must conform to
RARE.
Most notably restricted from the Compute[...] environment is the Expression.
This would be a burdensome restriction if it
were not for the fact that values from other procedures may be
brought into Compute[...]'s
brackets
with:
Use of SubstitutionNames, With
constants, Cast
variables, or Names
to
import keywords specifically restricted from Compute[...]'s brackets will
produce error (2).
The restricted (16 element), Grok32`
lexicon includes the following keywords:
These keywords have reduced scope in Compute[...]
because they can only operate on
objects formed from the above List. For example, within Compute[...],
there are no Tally[func,
StreamObject]
constructions because StreamObjects are not allowed in Compute's brackets.
Not in the above list are the following
keywords:
{Compute, Sequence, String, Branch, Expression,
Pattern, Type, With, Cast, Context, Time, Stream, Trap, Return,
Reckon, Compile}
Compute may invoke Names
that execute Compute[...]
environments which are embedded
in lexical scopes defined outside the Compute[...]
environment. When Compute is executing,
and one of the 16
disallowed keywords is encountered, it elicits an error message
with the following form:
(4) Noop[Compute][disallowedKeyword, elicitation]
In the last section, the restricted Grok32`
keyword lexicon recognized
within Compute[...]'s
brackets was
discussed. That restricted lexical environment is
supplemented by, and is designed to
facilitate the special arithmetic Functions,
operators and procedures defined in the subContext,
Grok32`Number`Compute`.
The "Grok32`Number`Compute`"
Context
include the following math functions
in order of decreasing precedence:
Operator |
Description |
Attribute/Comment |
|
*, /, % |
Times, Divide, Mod |
All Equal Precedence |
|
+, - |
Plus |
[The "-" (minus) operator is constructed from Plus and negative numbers.] |
|
<, >, <=, >= |
Tests for (in)equality. Less, Greater, Less[Equal], Greater[Equal] |
All Equal Precedence |
|
==, != |
Equal, Not[Equal] |
All Equal Precedence |
|
|
All of the following are of equal precedence! |
|
|
= |
A.k.a. Name[lhs, rhs] |
|
|
+=, -= |
Name[Plus], Name[Subtract] |
|
|
*=, /=, %= |
Name[Times], Name[Divide], Name[Mod] |
|
In addition to these operators, there are the
following numeric
functions.
These, like the preceding operators, all take Real or Integer arguments to elicit an evaluation.
|
Power[x, y] |
x to the y power.(Also written as: x^y) |
|
Mod[x, y] |
The remainder when x is divided by y. |
|
Abs[x] |
Absolute value of x. |
|
Floor[x] |
x rounded down to the nearest Integer. |
|
Ceiling[x] |
x rounded up to the nearest Integer. |
|
Sqrt[x] |
Square root of x. |
|
Sin[x] |
Sine of x. |
|
Cos[x] |
Cosine of x. |
|
Tan[x] |
Tangent of x. |
|
ArcSin[x] |
Arc Sine of x in radians. |
|
ArcCos[x] |
Arc Cosine of x in radians. |
|
ArcTan[x] |
Arc Tangent of x in radians. |
|
ArcTan[y, x] |
Arc tangent of x/y in radians. |
|
Cosh[x] |
Hyperbolic cosine of x. |
|
Sinh[x] |
Hyperbolic sine of x. |
|
Tanh[x] |
Hyperbolic tangent of x. |
|
Exp[x] |
e to the x power. |
|
Ln[x] |
The natural log of x. |
|
Random[min, max] |
Returns a random Integer between min and max if both min and max are Integers. If either min or max are real numbers, then a random Real number between min and max is returned. |
The operations available to Compute
normally include the numeric operations
described above. These Named
operations
are all stored in the subcontext,
Grok32`Number`Compute`. This subcontext is a
compiled
Context, and is treated
differently then other Contexts. Within Compute[...]'s
brackets, the ContextSequence begins
with
Grok32`Number`Compute`, but the environment
is otherwise the same as it
would be outside the brackets.
Different Grok32`
implementations may include
more or less numeric operations. Some floating point processors,
for example, include machine instructions specifically tailored to
implement Fourier series. If that is the case, that
instruction should be part of the `Number`Compute`
subcontext. In general, the `Compute` subcontext is
home to fundamental numeric operations.
{Times, Divide, Mod, Plus,
Less, Greater, Less[Equal],
Greater[Equal], Equal,
Not[Equal], Name[Plus],
Name[Subtract], Name[Times],
Name[Divide], Name[Mod], Power,
Mod, Abs, Floor, Ceiling, Sqrt,
Sin, Cos, Tan, ArcSin, ArcCos,
ArcTan, ArcTan, Cosh, Sinh,
Tanh, Exp, Ln, Random}
compute n.
1. To determine by calculation; to reckon, or count; to take account of; as, to compute areas, profits, duration.
2. To make up or count;
compute of numbers. Milton
intransitive: To make calculation; to
reckon.
computer n.
One who or that which computes; calculator; specif.,
a calculating machine.
[From Websters1949Unabridged.]
(c) 2004-2007 by
John Van Wie Bergamini.
All rights reserved.