For(x) declares the given symbol as locally bound variable in the
scope of the parent call. For example, f(a, For(x), b) declares x
as a locally bound variable that may be used within the expressions a
and b. The interpretation of the variable is left to the
parent operator f.
Called with a tuple of symbols, For(Tuple(x, y, z)), each symbol
becomes a locally bound variable.
Called with several arguments, for example For(x, a, b, c), the additional parameters a
b
c
specify information about the range of x. The interpretation of the parameters is up to the parent operator f. Most operators recognize For() with two additional parameters as
specifying an iteration range: for example, Sum(Factorial(n), For(n, 2, 10)) gives ∑n=210n!. (When For(n, a, b) is used in this sense, the endpoints a
and b
must be integers or possibly a=−∞
and/or b=∞
where an infinite sequence makes sense. The iteration sequence is empty if b<a.)
There are various exceptions. For example, Integral understands two
parameters as representing the endpoints (not necessarily integers)
of a directed line segment to integrate over: Integral(Cos(x), For(x, Neg(Pi), Pi)) becomes ∫−ππcos(x)dx. Derivative takes one or two parameters denoting the evaluation point and optionally the order of differentiation: Derivative(Sin(x), For(x, y)) becomes sin′(y)
and Derivative(Sin(x), For(x, y, 2)) becomes sin′′(y).
Definitions:
Fungrim symbol | Notation | Short description |
---|---|---|
Sum | ∑nf(n) | Sum |
Factorial | n! | Factorial |
Infinity | ∞ | Positive infinity |
Integral | ∫abf(x)dx | Integral |
Cos | cos(z) | Cosine |
Pi | π | The constant pi (3.14...) |
Derivative | dzdf(z) | Derivative |
Sin | sin(z) | Sine |
Source code for this entry:
Entry(ID("43cc72"), SymbolDefinition(For, Ellipsis, "General-purpose generator"), Description(SourceForm(For(x)), "declares the given symbol as locally bound variable in the scope of the parent call. For example,", SourceForm(f(a, For(x), b)), "declares", x, "as a locally bound variable that may be used within the expressions ", a, "and", b, ". The interpretation of the variable is left to the parent operator", f, "."), Description("Called with a tuple of symbols,", SourceForm(For(Tuple(x, y, z))), ", each symbol becomes a locally bound variable."), Description(" Called with several arguments, for example ", SourceForm(For(x, a, b, c)), ", the additional parameters", a, b, c, "specify information about the range of", x, ".", "The interpretation of the parameters is up to the parent operator", f, ". Most operators recognize ", SourceForm(For()), "with two additional parameters as specifying an iteration range: for example, ", SourceForm(Sum(Factorial(n), For(n, 2, 10))), "gives", Sum(Factorial(n), For(n, 2, 10)), ".", "(When", SourceForm(For(n, a, b)), " is used in this sense, the endpoints", a, "and", b, "must be integers or possibly", Equal(a, Neg(Infinity)), "and/or", Equal(b, Infinity), "where an infinite sequence makes sense. ", "The iteration sequence is empty if", Less(b, a), ".)"), Description(" There are various exceptions. For example,", SourceForm(Integral), "understands two parameters as representing the endpoints (not necessarily integers) of a directed line segment to integrate over: ", SourceForm(Integral(Cos(x), For(x, Neg(Pi), Pi))), "becomes", Integral(Cos(x), For(x, Neg(Pi), Pi)), ". ", SourceForm(Derivative), "takes one or two parameters", "denoting the evaluation point and optionally the order of differentiation:", SourceForm(Derivative(Sin(x), For(x, y))), "becomes", Derivative(Sin(x), For(x, y)), "and", SourceForm(Derivative(Sin(x), For(x, y, 2))), "becomes", Derivative(Sin(x), For(x, y, 2)), "."))