Average Error: 4.6 → 1.5
Time: 4.8s
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}\;y \le -8.2577738980353727 \cdot 10^{235}:\\ \;\;\;\;\mathsf{fma}\left(z, t - x, 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}\]
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}\;y \le -8.2577738980353727 \cdot 10^{235}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, 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}
double f(double x, double y, double z, double t) {
        double r303389 = x;
        double r303390 = y;
        double r303391 = z;
        double r303392 = r303390 * r303391;
        double r303393 = t;
        double r303394 = r303393 / r303390;
        double r303395 = tanh(r303394);
        double r303396 = r303389 / r303390;
        double r303397 = tanh(r303396);
        double r303398 = r303395 - r303397;
        double r303399 = r303392 * r303398;
        double r303400 = r303389 + r303399;
        return r303400;
}

double f(double x, double y, double z, double t) {
        double r303401 = y;
        double r303402 = -8.257773898035373e+235;
        bool r303403 = r303401 <= r303402;
        double r303404 = z;
        double r303405 = t;
        double r303406 = x;
        double r303407 = r303405 - r303406;
        double r303408 = fma(r303404, r303407, r303406);
        double r303409 = r303405 / r303401;
        double r303410 = tanh(r303409);
        double r303411 = r303406 / r303401;
        double r303412 = tanh(r303411);
        double r303413 = r303410 - r303412;
        double r303414 = r303404 * r303413;
        double r303415 = fma(r303401, r303414, r303406);
        double r303416 = r303403 ? r303408 : r303415;
        return r303416;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target1.9
Herbie1.5
\[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 y < -8.257773898035373e+235

    1. Initial program 20.7

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\]
    2. Using strategy rm
    3. Applied sub-neg20.7

      \[\leadsto x + \left(y \cdot z\right) \cdot \color{blue}{\left(\tanh \left(\frac{t}{y}\right) + \left(-\tanh \left(\frac{x}{y}\right)\right)\right)}\]
    4. Applied distribute-rgt-in20.7

      \[\leadsto x + \color{blue}{\left(\tanh \left(\frac{t}{y}\right) \cdot \left(y \cdot z\right) + \left(-\tanh \left(\frac{x}{y}\right)\right) \cdot \left(y \cdot z\right)\right)}\]
    5. Applied associate-+r+20.7

      \[\leadsto \color{blue}{\left(x + \tanh \left(\frac{t}{y}\right) \cdot \left(y \cdot z\right)\right) + \left(-\tanh \left(\frac{x}{y}\right)\right) \cdot \left(y \cdot z\right)}\]
    6. Simplified20.6

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, t, x - x \cdot z\right)}\]
    9. Taylor expanded around 0 1.6

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

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

    if -8.257773898035373e+235 < y

    1. Initial program 3.8

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\]
    2. Simplified1.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. Recombined 2 regimes into one program.
  4. Final simplification1.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -8.2577738980353727 \cdot 10^{235}:\\ \;\;\;\;\mathsf{fma}\left(z, t - x, 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 2020062 +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))))))