Average Error: 4.6 → 1.5
Time: 4.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}\;y \le -8.2577738980353727 \cdot 10^{235}:\\ \;\;\;\;\mathsf{fma}\left(z, t, x - x \cdot z\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 \cdot z\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 r230398 = x;
        double r230399 = y;
        double r230400 = z;
        double r230401 = r230399 * r230400;
        double r230402 = t;
        double r230403 = r230402 / r230399;
        double r230404 = tanh(r230403);
        double r230405 = r230398 / r230399;
        double r230406 = tanh(r230405);
        double r230407 = r230404 - r230406;
        double r230408 = r230401 * r230407;
        double r230409 = r230398 + r230408;
        return r230409;
}

double f(double x, double y, double z, double t) {
        double r230410 = y;
        double r230411 = -8.257773898035373e+235;
        bool r230412 = r230410 <= r230411;
        double r230413 = z;
        double r230414 = t;
        double r230415 = x;
        double r230416 = r230415 * r230413;
        double r230417 = r230415 - r230416;
        double r230418 = fma(r230413, r230414, r230417);
        double r230419 = r230414 / r230410;
        double r230420 = tanh(r230419);
        double r230421 = r230415 / r230410;
        double r230422 = tanh(r230421);
        double r230423 = r230420 - r230422;
        double r230424 = r230413 * r230423;
        double r230425 = fma(r230410, r230424, r230415);
        double r230426 = r230412 ? r230418 : r230425;
        return r230426;
}

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-lft-in20.7

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tanh \left(\frac{t}{y}\right) \cdot y, z, x\right)} + \left(y \cdot z\right) \cdot \left(-\tanh \left(\frac{x}{y}\right)\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)}\]

    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 \cdot z\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))))))