_Constant

it.grypho.scala.leonardo.core._Constant
See the_Constant companion object
final case class _Constant(kind: ConstantKind, exact: Boolean = ...) extends _Expression

A named constant kept as a symbol (F_0289), so a formula, a definition and :save say pi rather than 3.14159.

Outside exact mode it evaluates to its Double, so every value computed outside exact mode is what it was when the parser folded the constant. In exact mode it stays symbolic — pi/2 is pi/2, and the functions answer exactly where a rule knows the value (sin(pi/6) is 1/2) — except goldenratio, which is algebraic and so evaluates to the exact surd 1/2 + √5/2. Where a number is needed and no rule applies, evalNumeric reads every constant at the working precision, as the parser's rational reading did.

An _Expression, not a _Value: nothing widens it to a Double by accident, and an exact computation can keep it. It has no free variables, so it is a constant to every pass.

Value parameters

exact

whether it was read in exact mode, which makes it symbolic even where the environment does not say exact mode (a library caller's exact parse)

kind

which constant

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
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

The constant as a number in env's tier: its Double outside exact mode, its reading at the working precision inside it.

The constant as a number in env's tier: its Double outside exact mode, its reading at the working precision inside it.

Value parameters

env

the environment

Attributes

Returns

the reading

override def rebuild(newChildren: 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