_Reduction

it.grypho.scala.leonardo.scalar._Reduction
case class _Reduction(kind: ReduceKind, e: _Expression, v: _Variable, lo: _Expression, hi: _Expression) extends _Functional

sum(e, k, lo, hi) / product(e, k, lo, hi) -- a finite reduction over an integer range.

The counterpart of _Tabulate, which yields the terms rather than their total, and the reason a summation could not be converted from the editor before: tabulate is not an answer to a Σ, so the AsciiMath reader had nothing to translate one into and refused it by name. Same shape as tabulate -- k is a binder (excluded from children, carried through rebuild, so substitute cannot rewrite it) while lo/hi are ordinary children, the _DefIntegral convention -- and the same MaxTabulateTerms cap, shared through indexRange.

The terms are folded with reduce, never a seeded fold. Seeding with a literal _Number(0) would be an inexact-tier constant, so an exact sum would be demoted through float contagion before anything could use it -- the numeric-tier rule, and the single most repeated bug of issues 4.L and 4.N. The identity is therefore used for the empty range only, where there is nothing to combine with and nothing to demote.

An empty range is the identity rather than a refusal, unlike tabulate's empty grid: the empty sum is 0 and the empty product 1 by universal convention, which is exactly what makes sum(f, k, 1, n) read correctly at n = 0 instead of declining a base case.

Symbolic terms EXPAND. sum(k*x, k, 1, 3) becomes x + 2x + 3x rather than staying folded, so normalize/simplify can collect it -- and since this is a _Functional, F_0034's pass reduces it under the simplify command with no further wiring.

Value parameters

e

the term, in which v is bound

hi

the last index, inclusive

kind

which reduction this is

lo

the first index, inclusive

v

the index variable (a binder)

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class _Functional
trait _Expression
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def children: List[_Expression]

Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.

Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.

Attributes

Definition Classes
override def eval(env: Environment): Either[_Expression, _Value]

Reduces this expression in the given environment.

Reduces this expression in the given environment.

Value parameters

env

variable bindings and display precision

Attributes

Returns

Right(v) when all free variables resolved to concrete values; Left(e) when reduction is partial or impossible

Definition Classes
override def rebuild(c: List[_Expression]): _Expression

Reconstructs the same node shape with replacement sub-expressions.

Reconstructs the same node shape with replacement sub-expressions.

Value parameters

newChildren

replacements in the same order and count as children

Attributes

Definition Classes
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Inherited fields

lazy val freeVars: Set[String]

Cached set of free variable names; O(1) after the first access.

Cached set of free variable names; O(1) after the first access.

Attributes

Inherited from:
_Expression