Average Error: 4.4 → 3.0
Time: 20.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}\;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 r293791 = x;
        double r293792 = y;
        double r293793 = z;
        double r293794 = r293792 * r293793;
        double r293795 = t;
        double r293796 = r293795 / r293792;
        double r293797 = tanh(r293796);
        double r293798 = r293791 / r293792;
        double r293799 = tanh(r293798);
        double r293800 = r293797 - r293799;
        double r293801 = r293794 * r293800;
        double r293802 = r293791 + r293801;
        return r293802;
}

double f(double x, double y, double z, double t) {
        double r293803 = x;
        double r293804 = y;
        double r293805 = z;
        double r293806 = r293804 * r293805;
        double r293807 = t;
        double r293808 = r293807 / r293804;
        double r293809 = tanh(r293808);
        double r293810 = r293803 / r293804;
        double r293811 = tanh(r293810);
        double r293812 = r293809 - r293811;
        double r293813 = r293806 * r293812;
        double r293814 = r293803 + r293813;
        double r293815 = -inf.0;
        bool r293816 = r293814 <= r293815;
        double r293817 = r293807 * r293805;
        double r293818 = r293817 / r293804;
        double r293819 = fma(r293804, r293818, r293803);
        double r293820 = 1.2338270197053233e+303;
        bool r293821 = r293814 <= r293820;
        double r293822 = r293809 * r293809;
        double r293823 = r293811 * r293811;
        double r293824 = r293822 - r293823;
        double r293825 = r293805 * r293824;
        double r293826 = r293809 + r293811;
        double r293827 = r293825 / r293826;
        double r293828 = fma(r293804, r293827, r293803);
        double r293829 = r293821 ? r293814 : r293828;
        double r293830 = r293816 ? r293819 : r293829;
        return r293830;
}

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