Average Error: 4.0 → 3.1
Time: 22.1s
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{x}{y}\right)\\ t_2 := \tanh \left(\frac{t}{y}\right) - t_1\\ \mathbf{if}\;t \leq -2.2211093071045775 \cdot 10^{-30}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, t_2, x\right)\\ \mathbf{elif}\;t \leq 1.2596353575889675 \cdot 10^{-263}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, -t_1, t\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot t_2, 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{x}{y}\right)\\
t_2 := \tanh \left(\frac{t}{y}\right) - t_1\\
\mathbf{if}\;t \leq -2.2211093071045775 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot z, t_2, x\right)\\

\mathbf{elif}\;t \leq 1.2596353575889675 \cdot 10^{-263}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, -t_1, t\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot t_2, 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 (/ x y))) (t_2 (- (tanh (/ t y)) t_1)))
   (if (<= t -2.2211093071045775e-30)
     (fma (* y z) t_2 x)
     (if (<= t 1.2596353575889675e-263)
       (fma z (fma y (- t_1) t) x)
       (fma y (* z 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(x / y);
	double t_2 = tanh(t / y) - t_1;
	double tmp;
	if (t <= -2.2211093071045775e-30) {
		tmp = fma((y * z), t_2, x);
	} else if (t <= 1.2596353575889675e-263) {
		tmp = fma(z, fma(y, -t_1, t), x);
	} else {
		tmp = fma(y, (z * t_2), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.0
Target2.0
Herbie3.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 t < -2.2211093071045775e-30

    1. Initial program 2.6

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

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

    if -2.2211093071045775e-30 < t < 1.2596353575889675e-263

    1. Initial program 6.1

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

      \[\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 add-log-exp_binary6412.2

      \[\leadsto \mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \color{blue}{\log \left(e^{\tanh \left(\frac{x}{y}\right)}\right)}, x\right) \]
    4. Applied add-log-exp_binary6415.6

      \[\leadsto \mathsf{fma}\left(y \cdot z, \color{blue}{\log \left(e^{\tanh \left(\frac{t}{y}\right)}\right)} - \log \left(e^{\tanh \left(\frac{x}{y}\right)}\right), x\right) \]
    5. Applied diff-log_binary6415.6

      \[\leadsto \mathsf{fma}\left(y \cdot z, \color{blue}{\log \left(\frac{e^{\tanh \left(\frac{t}{y}\right)}}{e^{\tanh \left(\frac{x}{y}\right)}}\right)}, x\right) \]
    6. Taylor expanded in t around 0 42.6

      \[\leadsto \color{blue}{y \cdot \left(\log \left(\frac{1}{e^{\frac{e^{\frac{x}{y}} - \frac{1}{e^{\frac{x}{y}}}}{\frac{1}{e^{\frac{x}{y}}} + e^{\frac{x}{y}}}}}\right) \cdot z\right) + \left(t \cdot z + x\right)} \]
    7. Simplified5.9

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

    if 1.2596353575889675e-263 < t

    1. Initial program 3.7

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Simplified3.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 add-log-exp_binary646.4

      \[\leadsto \mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \color{blue}{\log \left(e^{\tanh \left(\frac{x}{y}\right)}\right)}, x\right) \]
    4. Applied add-log-exp_binary6412.5

      \[\leadsto \mathsf{fma}\left(y \cdot z, \color{blue}{\log \left(e^{\tanh \left(\frac{t}{y}\right)}\right)} - \log \left(e^{\tanh \left(\frac{x}{y}\right)}\right), x\right) \]
    5. Applied diff-log_binary6412.5

      \[\leadsto \mathsf{fma}\left(y \cdot z, \color{blue}{\log \left(\frac{e^{\tanh \left(\frac{t}{y}\right)}}{e^{\tanh \left(\frac{x}{y}\right)}}\right)}, x\right) \]
    6. Taylor expanded in y around 0 54.9

      \[\leadsto \color{blue}{y \cdot \left(z \cdot \log \left(\frac{e^{\frac{e^{\frac{t}{y}} - \frac{1}{e^{\frac{t}{y}}}}{\frac{1}{e^{\frac{t}{y}}} + e^{\frac{t}{y}}}}}{e^{\frac{e^{\frac{x}{y}} - \frac{1}{e^{\frac{x}{y}}}}{\frac{1}{e^{\frac{x}{y}}} + e^{\frac{x}{y}}}}}\right)\right) + x} \]
    7. Simplified1.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -2.2211093071045775 \cdot 10^{-30}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right), x\right)\\ \mathbf{elif}\;t \leq 1.2596353575889675 \cdot 10^{-263}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, -\tanh \left(\frac{x}{y}\right), t\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)\\ \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))))))