Average Error: 4.8 → 2.4
Time: 4.1s
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 -2.72912351136822846 \cdot 10^{171} \lor \neg \left(y \le 1.7957852336618656 \cdot 10^{200}\right):\\ \;\;\;\;\mathsf{fma}\left(z, t, x - x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + \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)\\ \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 -2.72912351136822846 \cdot 10^{171} \lor \neg \left(y \le 1.7957852336618656 \cdot 10^{200}\right):\\
\;\;\;\;\mathsf{fma}\left(z, t, x - x \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;x + \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)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r248382 = x;
        double r248383 = y;
        double r248384 = z;
        double r248385 = r248383 * r248384;
        double r248386 = t;
        double r248387 = r248386 / r248383;
        double r248388 = tanh(r248387);
        double r248389 = r248382 / r248383;
        double r248390 = tanh(r248389);
        double r248391 = r248388 - r248390;
        double r248392 = r248385 * r248391;
        double r248393 = r248382 + r248392;
        return r248393;
}

double f(double x, double y, double z, double t) {
        double r248394 = y;
        double r248395 = -2.7291235113682285e+171;
        bool r248396 = r248394 <= r248395;
        double r248397 = 1.7957852336618656e+200;
        bool r248398 = r248394 <= r248397;
        double r248399 = !r248398;
        bool r248400 = r248396 || r248399;
        double r248401 = z;
        double r248402 = t;
        double r248403 = x;
        double r248404 = r248403 * r248401;
        double r248405 = r248403 - r248404;
        double r248406 = fma(r248401, r248402, r248405);
        double r248407 = r248394 * r248401;
        double r248408 = r248402 / r248394;
        double r248409 = tanh(r248408);
        double r248410 = r248407 * r248409;
        double r248411 = r248403 / r248394;
        double r248412 = tanh(r248411);
        double r248413 = -r248412;
        double r248414 = r248407 * r248413;
        double r248415 = r248410 + r248414;
        double r248416 = r248403 + r248415;
        double r248417 = r248400 ? r248406 : r248416;
        return r248417;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.8
Target2.1
Herbie2.4
\[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 < -2.7291235113682285e+171 or 1.7957852336618656e+200 < y

    1. Initial program 18.5

      \[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-neg18.5

      \[\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-in18.5

      \[\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. Taylor expanded around 0 20.5

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

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

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

    if -2.7291235113682285e+171 < y < 1.7957852336618656e+200

    1. Initial program 1.9

      \[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-neg1.9

      \[\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-in1.9

      \[\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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.72912351136822846 \cdot 10^{171} \lor \neg \left(y \le 1.7957852336618656 \cdot 10^{200}\right):\\ \;\;\;\;\mathsf{fma}\left(z, t, x - x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + \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)\\ \end{array}\]

Reproduce

herbie shell --seed 2020046 +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))))))