?

Average Error: 7.55% → 2.44%
Time: 16.3s
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

Original7.55%
Target3.12%
Herbie2.44%
\[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 7.55

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

    \[\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]7.55

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

    +-commutative [=>]7.55

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

    *-commutative [=>]7.55

    \[ \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* [=>]2.45

    \[ \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 [=>]2.44

    \[ \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 simplification2.44

    \[\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
Error3.69%
Cost41033
\[\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 \lor \neg \left(t_1 \leq \infty\right):\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error12.24%
Cost13513
\[\begin{array}{l} \mathbf{if}\;t \leq -1.62 \cdot 10^{-31} \lor \neg \left(t \leq 5.8 \cdot 10^{-63}\right):\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \tanh \left(\frac{t}{y}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right)\right)\\ \end{array} \]
Alternative 3
Error27.94%
Cost7769
\[\begin{array}{l} t_1 := x + z \cdot \left(t - x\right)\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-269}:\\ \;\;\;\;y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-182}:\\ \;\;\;\;x + \frac{\frac{z \cdot y}{y}}{\frac{1}{t - x}}\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-72} \lor \neg \left(x \leq 4 \cdot 10^{-31}\right):\\ \;\;\;\;x - z \cdot \left(y \cdot \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error18.09%
Cost7496
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-82}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-31}:\\ \;\;\;\;x + \left(z \cdot y\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \left(y \cdot \tanh \left(\frac{x}{y}\right)\right)\\ \end{array} \]
Alternative 5
Error30.69%
Cost7244
\[\begin{array}{l} t_1 := x + z \cdot \left(t - x\right)\\ \mathbf{if}\;x \leq -6.5 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-269}:\\ \;\;\;\;y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-185}:\\ \;\;\;\;x + \frac{\frac{z \cdot y}{y}}{\frac{1}{t - x}}\\ \mathbf{elif}\;x \leq 10^{-74}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error30.79%
Cost977
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.3 \cdot 10^{-183} \lor \neg \left(x \leq 8 \cdot 10^{-72}\right) \land x \leq 9.8 \cdot 10^{-29}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error27.54%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+48} \lor \neg \left(y \leq 1.18 \cdot 10^{+48}\right):\\ \;\;\;\;x + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error35.18%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{-153}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.48 \cdot 10^{-269}:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error35.8%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{-154}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-269}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error34.96%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023088 
(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))))))