Average Error: 4.7 → 0.9
Time: 7.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)\\ \mathbf{if}\;\begin{array}{l} t_2 := x + \left(y \cdot z\right) \cdot t_1\\ t_2 \leq -\infty \lor \neg \left(t_2 \leq 5.073647105141176 \cdot 10^{+304}\right) \end{array}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, t_1, x\right)\\ \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) - \tanh \left(\frac{x}{y}\right)\\
\mathbf{if}\;\begin{array}{l}
t_2 := x + \left(y \cdot z\right) \cdot t_1\\
t_2 \leq -\infty \lor \neg \left(t_2 \leq 5.073647105141176 \cdot 10^{+304}\right)
\end{array}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, t_1, x\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)))))
   (if (let* ((t_2 (+ x (* (* y z) t_1))))
         (or (<= t_2 (- INFINITY)) (not (<= t_2 5.073647105141176e+304))))
     (+ x (* z (- t x)))
     (fma (* y z) t_1 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) {
	double t_1 = tanh(t / y) - tanh(x / y);
	double t_2 = x + ((y * z) * t_1);
	double tmp;
	if ((t_2 <= -((double) INFINITY)) || !(t_2 <= 5.073647105141176e+304)) {
		tmp = x + (z * (t - x));
	} else {
		tmp = fma((y * z), t_1, x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.7
Target2.1
Herbie0.9
\[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 5.073647105141176e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 60.9

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Simplified60.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 expm1-log1p-u_binary6461.3

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

      \[\leadsto \color{blue}{\left(t \cdot z + x\right) - z \cdot x} \]
    5. Simplified3.6

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

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

    1. Initial program 0.7

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

      \[\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 pow1_binary640.7

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

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

Reproduce

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