_Softplus

it.grypho.scala.leonardo.scalar._Softplus
case class _Softplus(x: _Expression, k: _Expression) extends NamedFunction

The smooth max(0, x): softplus(x, k) = ln(1 + e^(k·x))/k, tending to max(0, x) as k grows. k must be positive.

Never evaluated as written: ln(1 + e^(k·x)) overflows once k·x passes ~709, so the value is (max(k·x, 0) + log1p(e^(−|k·x|)))/k — the numerical conditioning rule. An exact argument re-enters the exact tier through fromApproximation, the transcendental precedent.

Value parameters

k

the sharpness, positive

x

the argument(s), element-wise

Attributes

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
override 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

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

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product
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
NamedFunction -> Any
Inherited from:
NamedFunction

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