Average Error: 5.0 → 1.8
Time: 54.9s
Precision: 64
\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\]
\[\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) = -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t \cdot z}{y} + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), 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) \le 7.3734911360919146 \cdot 10^{307}:\\ \;\;\;\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\mathsf{fma}\left(y, z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), x\right)\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}
\mathbf{if}\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) = -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{t \cdot z}{y} + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), 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) \le 7.3734911360919146 \cdot 10^{307}:\\
\;\;\;\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;e^{\log \left(\mathsf{fma}\left(y, z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), x\right)\right)}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r418019 = x;
        double r418020 = y;
        double r418021 = z;
        double r418022 = r418020 * r418021;
        double r418023 = t;
        double r418024 = r418023 / r418020;
        double r418025 = tanh(r418024);
        double r418026 = r418019 / r418020;
        double r418027 = tanh(r418026);
        double r418028 = r418025 - r418027;
        double r418029 = r418022 * r418028;
        double r418030 = r418019 + r418029;
        return r418030;
}

double f(double x, double y, double z, double t) {
        double r418031 = x;
        double r418032 = y;
        double r418033 = z;
        double r418034 = r418032 * r418033;
        double r418035 = t;
        double r418036 = r418035 / r418032;
        double r418037 = tanh(r418036);
        double r418038 = r418031 / r418032;
        double r418039 = tanh(r418038);
        double r418040 = r418037 - r418039;
        double r418041 = r418034 * r418040;
        double r418042 = r418031 + r418041;
        double r418043 = -inf.0;
        bool r418044 = r418042 <= r418043;
        double r418045 = r418035 * r418033;
        double r418046 = r418045 / r418032;
        double r418047 = -r418039;
        double r418048 = r418033 * r418047;
        double r418049 = r418046 + r418048;
        double r418050 = fma(r418032, r418049, r418031);
        double r418051 = 7.373491136091915e+307;
        bool r418052 = r418042 <= r418051;
        double r418053 = r418033 * r418037;
        double r418054 = r418053 + r418048;
        double r418055 = fma(r418032, r418054, r418031);
        double r418056 = log(r418055);
        double r418057 = exp(r418056);
        double r418058 = r418052 ? r418042 : r418057;
        double r418059 = r418044 ? r418050 : r418058;
        return r418059;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.0
Target2.1
Herbie1.8
\[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 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ 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. Simplified1.8

      \[\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. Using strategy rm
    4. Applied sub-neg1.8

      \[\leadsto \mathsf{fma}\left(y, z \cdot \color{blue}{\left(\tanh \left(\frac{t}{y}\right) + \left(-\tanh \left(\frac{x}{y}\right)\right)\right)}, x\right)\]
    5. Applied distribute-lft-in1.8

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right)}, x\right)\]
    6. Taylor expanded around inf 0.8

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

    if -inf.0 < (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))) < 7.373491136091915e+307

    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)\]

    if 7.373491136091915e+307 < (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y)))))

    1. Initial program 63.1

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

      \[\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. Using strategy rm
    4. Applied sub-neg20.5

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

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right)}, x\right)\]
    6. Using strategy rm
    7. Applied add-exp-log26.5

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

    \[\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) = -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t \cdot z}{y} + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), 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) \le 7.3734911360919146 \cdot 10^{307}:\\ \;\;\;\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\mathsf{fma}\left(y, z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), x\right)\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020083 +o rules:numerics
(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))))))