Average Error: 4.7 → 1.1
Time: 5.0s
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:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{elif}\;t_2 \leq 2.809893081464871 \cdot 10^{+293}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, t_1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t - x, 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)\\
t_2 := x + \left(y \cdot z\right) \cdot t_1\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;z \cdot \left(t - x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, 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)))) (t_2 (+ x (* (* y z) t_1))))
   (if (<= t_2 (- INFINITY))
     (* z (- t x))
     (if (<= t_2 2.809893081464871e+293)
       (fma (* y z) t_1 x)
       (fma z (- t x) 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)) {
		tmp = z * (t - x);
	} else if (t_2 <= 2.809893081464871e+293) {
		tmp = fma((y * z), t_1, x);
	} else {
		tmp = fma(z, (t - x), 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
Herbie1.1
\[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 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. Taylor expanded around -inf 0.0

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

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

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

    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 2.8098930814648709e293 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 50.2

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

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

      \[\leadsto \color{blue}{x + z \cdot \left(t - x\right)} \]
    5. Taylor expanded around 0 11.0

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

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

    \[\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:\\ \;\;\;\;z \cdot \left(t - 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 2.809893081464871 \cdot 10^{+293}:\\ \;\;\;\;\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 2021211 
(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))))))