Average Error: 4.4 → 3.0
Time: 20.6s
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}, 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 1.2338270197053233 \cdot 10^{303}:\\ \;\;\;\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z \cdot \left(\tanh \left(\frac{t}{y}\right) \cdot \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right) \cdot \tanh \left(\frac{x}{y}\right)\right)}{\tanh \left(\frac{t}{y}\right) + \tanh \left(\frac{x}{y}\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}\;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}, 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 1.2338270197053233 \cdot 10^{303}:\\
\;\;\;\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r350733 = x;
        double r350734 = y;
        double r350735 = z;
        double r350736 = r350734 * r350735;
        double r350737 = t;
        double r350738 = r350737 / r350734;
        double r350739 = tanh(r350738);
        double r350740 = r350733 / r350734;
        double r350741 = tanh(r350740);
        double r350742 = r350739 - r350741;
        double r350743 = r350736 * r350742;
        double r350744 = r350733 + r350743;
        return r350744;
}

double f(double x, double y, double z, double t) {
        double r350745 = x;
        double r350746 = y;
        double r350747 = z;
        double r350748 = r350746 * r350747;
        double r350749 = t;
        double r350750 = r350749 / r350746;
        double r350751 = tanh(r350750);
        double r350752 = r350745 / r350746;
        double r350753 = tanh(r350752);
        double r350754 = r350751 - r350753;
        double r350755 = r350748 * r350754;
        double r350756 = r350745 + r350755;
        double r350757 = -inf.0;
        bool r350758 = r350756 <= r350757;
        double r350759 = r350749 * r350747;
        double r350760 = r350759 / r350746;
        double r350761 = fma(r350746, r350760, r350745);
        double r350762 = 1.2338270197053233e+303;
        bool r350763 = r350756 <= r350762;
        double r350764 = r350751 * r350751;
        double r350765 = r350753 * r350753;
        double r350766 = r350764 - r350765;
        double r350767 = r350747 * r350766;
        double r350768 = r350751 + r350753;
        double r350769 = r350767 / r350768;
        double r350770 = fma(r350746, r350769, r350745);
        double r350771 = r350763 ? r350756 : r350770;
        double r350772 = r350758 ? r350761 : r350771;
        return r350772;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.4
Target1.9
Herbie3.0
\[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.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. Taylor expanded around inf 32.7

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

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

    1. Initial program 0.5

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

    if 1.2338270197053233e+303 < (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y)))))

    1. Initial program 58.5

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

      \[\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 flip--42.7

      \[\leadsto \mathsf{fma}\left(y, z \cdot \color{blue}{\frac{\tanh \left(\frac{t}{y}\right) \cdot \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right) \cdot \tanh \left(\frac{x}{y}\right)}{\tanh \left(\frac{t}{y}\right) + \tanh \left(\frac{x}{y}\right)}}, x\right)\]
    5. Applied associate-*r/42.8

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

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

Reproduce

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