Average Error: 4.8 → 0.8
Time: 14.3s
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 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\ t_2 := x + \left(y \cdot z\right) \cdot t_1\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;t_2 \leq 1.827654576281754 \cdot 10^{+305}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, t_1, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(z \cdot t - x \cdot z\right)\\ \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 (- (tanh (/ t y)) (tanh (/ x y)))) (t_2 (+ x (* (* y z) t_1))))
   (if (<= t_2 (- INFINITY))
     (fma (- t x) z x)
     (if (<= t_2 1.827654576281754e+305)
       (fma (* y z) t_1 x)
       (+ x (- (* z t) (* x z)))))))
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 = tanh((t / y)) - tanh((x / y));
	double t_2 = x + ((y * z) * t_1);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma((t - x), z, x);
	} else if (t_2 <= 1.827654576281754e+305) {
		tmp = fma((y * z), t_1, x);
	} else {
		tmp = x + ((z * t) - (x * z));
	}
	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 = Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))
	t_2 = Float64(x + Float64(Float64(y * z) * t_1))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = fma(Float64(t - x), z, x);
	elseif (t_2 <= 1.827654576281754e+305)
		tmp = fma(Float64(y * z), t_1, x);
	else
		tmp = Float64(x + Float64(Float64(z * t) - Float64(x * z)));
	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[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y * z), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[t$95$2, 1.827654576281754e+305], N[(N[(y * z), $MachinePrecision] * t$95$1 + x), $MachinePrecision], N[(x + N[(N[(z * t), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
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 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\
t_2 := x + \left(y \cdot z\right) \cdot t_1\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\

\mathbf{elif}\;t_2 \leq 1.827654576281754 \cdot 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, t_1, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(z \cdot t - x \cdot z\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.8
Target2.0
Herbie0.8
\[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 3 regimes
  2. if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0

    1. Initial program 64.0

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

      \[\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 0.0

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

      \[\leadsto \color{blue}{x + z \cdot \left(t - x\right)} \]
    5. Applied egg-rr0.0

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

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

    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)} \]

    if 1.827654576281754e305 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 60.5

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

      \[\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 6.1

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

      \[\leadsto \color{blue}{x + z \cdot \left(t - x\right)} \]
    5. Applied egg-rr6.1

      \[\leadsto x + \color{blue}{\left(z \cdot t + z \cdot \left(-x\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.8

    \[\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(t - x, z, 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.827654576281754 \cdot 10^{+305}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(z \cdot t - x \cdot z\right)\\ \end{array} \]

Reproduce

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