NamedFunction

it.grypho.scala.leonardo.scalar.NamedFunction
trait NamedFunction extends _Expression

The token a function node prints and parses as, plus the one rendering built from it.

A separate trait rather than members on _Function, and the reason is binary compatibility (issue F_0016 step 0). Putting an abstract name on the published _Function would oblige every external subclass to supply it, which MiMa correctly reports as a break — an abstract val is no better, since a Scala val compiles to an accessor method and the JVM has no abstract fields. A new trait is additive, and mixing it into an existing class adds an interface rather than an obligation on anyone else's code, so nothing outside the library can be broken by it.

Mix it into a node whose printed form is exactly name(child, child, …).

Attributes

Graph
Supertypes
trait _Expression
class Object
trait Matchable
class Any
Known subtypes
class Acos
class Acosh
class Asin
class Asinh
class Atan
class Atanh
class Beta
class BetaI
class Binom
class Catalan
class Ci
class Cos
class Cosh
class Cot
class Coth
class Csc
class Csch
class Digamma
class Ei
class Erf
class Erfc
class Exp
class Factorial
class FresnelC
class FresnelS
class Gamma
class GammaP
class GammaQ
class Harmonic
class Li
class Ln
class LogBase
class LogGamma
class Sec
class Sech
class Si
class Sin
class Sinh
class Tanh
class Tg
Show all

Members list

Value members

Abstract methods

def name: String

The token this function prints and parses as — "exp", "tan", "Gamma".

The token this function prints and parses as — "exp", "tan", "Gamma".

Stated per node rather than derived, and that is deliberate. A case class knows its own name through productPrefix, so this could have defaulted to it — but Exp prints exp while Gamma prints Gamma (capitalised by 4.K so the lower-case name stays free as a variable), and Tg prints tan. Neither productPrefix nor its lower-cased form is right for all three, and a default that is right for most nodes and silently wrong for a few is the confidently-wrong failure this codebase declines everywhere — here it would mean a session saving under one spelling and reloading under another.

Attributes

Concrete methods

override def toString: String

Renders as name(arg, arg, …) — the grammar's own call syntax, so it re-parses.

Renders as name(arg, arg, …) — the grammar's own call syntax, so it re-parses.

One definition replacing 41 identical hand-written overrides.

_Functional is a separate hierarchy and deliberately does not mix this in. Its nine nodes — _Derivative, the integrals, _Limit and the transforms — print a binder that children excludes on purpose, so rendering from children alone would emit derive(e) for what is derive(e, v) and silently lose the variable. They keep their own toString, and would gain nothing from a name either: their LaTeX is \int, \frac{d}{dx} and \lim, bespoke however the token is spelled.

Attributes

Definition Classes
Any

Inherited and Abstract methods

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

Inherited from:
_Expression
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

Inherited from:
_Expression
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

Inherited from:
_Expression

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