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

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

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.0
Target2.0
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 7.8626015401926985e302 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 59.4

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Simplified59.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 5.4

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

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

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

    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. Applied expm1-log1p-u_binary640.6

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

Reproduce

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