?

Average Error: 4.5 → 1.6
Time: 14.2s
Precision: binary64
Cost: 19904

?

\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
\[\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right) \]
(FPCore (x y z t)
 :precision binary64
 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
 :precision binary64
 (fma z (* y (- (tanh (/ t y)) (tanh (/ x y)))) x))
double code(double x, double y, double z, double t) {
	return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
double code(double x, double y, double z, double t) {
	return fma(z, (y * (tanh((t / y)) - tanh((x / y)))), x);
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))
end
function code(x, y, z, t)
	return fma(z, Float64(y * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), x)
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(z * N[(y * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)

Error?

Target

Original4.5
Target2.1
Herbie1.6
\[x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right) \]

Derivation?

  1. Initial program 4.5

    \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
  2. Simplified1.6

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)} \]
    Proof

    [Start]4.5

    \[ x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]

    +-commutative [=>]4.5

    \[ \color{blue}{\left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x} \]

    *-commutative [=>]4.5

    \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x \]

    associate-*l* [=>]1.6

    \[ \color{blue}{z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)} + x \]

    fma-def [=>]1.6

    \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)} \]
  3. Final simplification1.6

    \[\leadsto \mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right) \]

Alternatives

Alternative 1
Error0.9
Cost41032
\[\begin{array}{l} t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+302}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot t - z \cdot x\\ \end{array} \]
Alternative 2
Error8.2
Cost13769
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{-23} \lor \neg \left(x \leq 1.5 \cdot 10^{-43}\right):\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot \tanh \left(\frac{t}{y}\right), x \cdot \left(1 - z\right)\right)\\ \end{array} \]
Alternative 3
Error9.9
Cost13576
\[\begin{array}{l} t_1 := \tanh \left(\frac{x}{y}\right)\\ t_2 := \tanh \left(\frac{t}{y}\right)\\ t_3 := x + y \cdot \left(z \cdot t_2\right)\\ \mathbf{if}\;t \leq -0.031:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -2.2 \cdot 10^{-109}:\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \left(-t_1\right), x\right)\\ \mathbf{elif}\;t \leq -5.4 \cdot 10^{-117}:\\ \;\;\;\;x + \left(z \cdot y\right) \cdot \left(t_2 - \frac{x}{y}\right)\\ \mathbf{elif}\;t \leq 2.05 \cdot 10^{-69}:\\ \;\;\;\;x + \left(z \cdot y\right) \cdot \left(\frac{t}{y} - t_1\right)\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error9.1
Cost7497
\[\begin{array}{l} \mathbf{if}\;t \leq -1.42 \cdot 10^{-92} \lor \neg \left(t \leq 7.2 \cdot 10^{-66}\right):\\ \;\;\;\;x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(z \cdot y\right) \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right)\\ \end{array} \]
Alternative 5
Error11.1
Cost7241
\[\begin{array}{l} \mathbf{if}\;t \leq -3.1 \cdot 10^{-235} \lor \neg \left(t \leq 1.75 \cdot 10^{-223}\right):\\ \;\;\;\;x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 6
Error20.2
Cost848
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;t \leq -8600:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.4 \cdot 10^{-235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{-232}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{-40}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error22.9
Cost717
\[\begin{array}{l} \mathbf{if}\;z \leq -7.6 \cdot 10^{+199} \lor \neg \left(z \leq 7.2 \cdot 10^{+130}\right) \land z \leq 8.6 \cdot 10^{+193}:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error15.7
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -8.8 \cdot 10^{-7} \lor \neg \left(y \leq 7.5 \cdot 10^{+137}\right):\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error15.7
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -8.8 \cdot 10^{-7}:\\ \;\;\;\;x + \left(z \cdot t - z \cdot x\right)\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+136}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 10
Error20.5
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -1900:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.2 \cdot 10^{-37}:\\ \;\;\;\;x + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error22.1
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{-262}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-190}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error22.2
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023060 
(FPCore (x y z t)
  :name "SynthBasics:moogVCF from YampaSynth-0.2"
  :precision binary64

  :herbie-target
  (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))

  (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))