Average Error: 4.4 → 2.5
Time: 21.7s
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)\\ t_2 := \tanh \left(\frac{x}{y}\right)\\ \mathbf{if}\;x + \left(y \cdot z\right) \cdot \left(t_1 - t_2\right) \leq 5.7506994441799065 \cdot 10^{+290}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, t_1 - \mathsf{log1p}\left(\mathsf{expm1}\left(t_2\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t, x\right) - x \cdot z\\ \end{array} \]
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)\\
t_2 := \tanh \left(\frac{x}{y}\right)\\
\mathbf{if}\;x + \left(y \cdot z\right) \cdot \left(t_1 - t_2\right) \leq 5.7506994441799065 \cdot 10^{+290}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, t_1 - \mathsf{log1p}\left(\mathsf{expm1}\left(t_2\right)\right), x\right)\\

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


\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))) (t_2 (tanh (/ x y))))
   (if (<= (+ x (* (* y z) (- t_1 t_2))) 5.7506994441799065e+290)
     (fma (* y z) (- t_1 (log1p (expm1 t_2))) x)
     (- (fma z t x) (* 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);
	double t_2 = tanh(x / y);
	double tmp;
	if ((x + ((y * z) * (t_1 - t_2))) <= 5.7506994441799065e+290) {
		tmp = fma((y * z), (t_1 - log1p(expm1(t_2))), x);
	} else {
		tmp = fma(z, t, x) - (x * z);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.4
Target1.8
Herbie2.5
\[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))))) < 5.75069944417990655e290

    1. Initial program 1.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)} \]
    3. Applied log1p-expm1-u_binary641.9

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

    if 5.75069944417990655e290 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 47.4

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

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

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

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

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

Reproduce

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