Average Error: 4.9 → 1.0
Time: 14.4s
Precision: binary64
\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(z, t - x, x\right)\\ t_2 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\ t_3 := x + \left(y \cdot z\right) \cdot t_2\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_3 \leq 1.2426167098962203 \cdot 10^{+303}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, t_2, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (fma z (- t x) x))
        (t_2 (- (tanh (/ t y)) (tanh (/ x y))))
        (t_3 (+ x (* (* y z) t_2))))
   (if (<= t_3 (- INFINITY))
     t_1
     (if (<= t_3 1.2426167098962203e+303) (fma (* y z) t_2 x) t_1))))
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) {
	double t_1 = fma(z, (t - x), x);
	double t_2 = tanh((t / y)) - tanh((x / y));
	double t_3 = x + ((y * z) * t_2);
	double tmp;
	if (t_3 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_3 <= 1.2426167098962203e+303) {
		tmp = fma((y * z), t_2, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
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)
	t_1 = fma(z, Float64(t - x), x)
	t_2 = Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))
	t_3 = Float64(x + Float64(Float64(y * z) * t_2))
	tmp = 0.0
	if (t_3 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_3 <= 1.2426167098962203e+303)
		tmp = fma(Float64(y * z), t_2, x);
	else
		tmp = t_1;
	end
	return tmp
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_] := Block[{t$95$1 = N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x + N[(N[(y * z), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], t$95$1, If[LessEqual[t$95$3, 1.2426167098962203e+303], N[(N[(y * z), $MachinePrecision] * t$95$2 + x), $MachinePrecision], t$95$1]]]]]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t - x, x\right)\\
t_2 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\
t_3 := x + \left(y \cdot z\right) \cdot t_2\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_3 \leq 1.2426167098962203 \cdot 10^{+303}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, t_2, x\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0 or 1.24261670989622029e303 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 60.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)} \]
    3. Taylor expanded in y around inf 5.3

      \[\leadsto \color{blue}{\left(t \cdot z + x\right) - z \cdot x} \]
    4. Simplified5.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, t, x\right) - x \cdot z} \]
    5. Applied add-cube-cbrt_binary646.0

      \[\leadsto \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(z, t, x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, t, x\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(z, t, x\right)}} - x \cdot z \]
    6. Applied prod-diff_binary646.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\mathsf{fma}\left(z, t, x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, t, x\right)}, \sqrt[3]{\mathsf{fma}\left(z, t, x\right)}, -z \cdot x\right) + \mathsf{fma}\left(-z, x, z \cdot x\right)} \]
    7. Simplified5.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, t - x, x\right)} + \mathsf{fma}\left(-z, x, z \cdot x\right) \]
    8. Simplified5.3

      \[\leadsto \mathsf{fma}\left(z, t - x, x\right) + \color{blue}{0} \]

    if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 1.24261670989622029e303

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\ \mathbf{elif}\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \leq 1.2426167098962203 \cdot 10^{+303}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\ \end{array} \]

Reproduce

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