Average Error: 4.8 → 1.4
Time: 19.5s
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) \le -9.787277693119323462190151087140993540522 \cdot 10^{113} \lor \neg \left(x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \le 1.538272331212940556859696907235950781054 \cdot 10^{214}\right):\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\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}\;x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \le -9.787277693119323462190151087140993540522 \cdot 10^{113} \lor \neg \left(x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \le 1.538272331212940556859696907235950781054 \cdot 10^{214}\right):\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot \tanh \left(\frac{t}{y}\right) + z \cdot \left(-\tanh \left(\frac{x}{y}\right)\right), x\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r202928 = x;
        double r202929 = y;
        double r202930 = z;
        double r202931 = r202929 * r202930;
        double r202932 = t;
        double r202933 = r202932 / r202929;
        double r202934 = tanh(r202933);
        double r202935 = r202928 / r202929;
        double r202936 = tanh(r202935);
        double r202937 = r202934 - r202936;
        double r202938 = r202931 * r202937;
        double r202939 = r202928 + r202938;
        return r202939;
}

double f(double x, double y, double z, double t) {
        double r202940 = x;
        double r202941 = y;
        double r202942 = z;
        double r202943 = r202941 * r202942;
        double r202944 = t;
        double r202945 = r202944 / r202941;
        double r202946 = tanh(r202945);
        double r202947 = r202940 / r202941;
        double r202948 = tanh(r202947);
        double r202949 = r202946 - r202948;
        double r202950 = r202943 * r202949;
        double r202951 = r202940 + r202950;
        double r202952 = -9.787277693119323e+113;
        bool r202953 = r202951 <= r202952;
        double r202954 = 1.5382723312129406e+214;
        bool r202955 = r202951 <= r202954;
        double r202956 = !r202955;
        bool r202957 = r202953 || r202956;
        double r202958 = r202942 * r202946;
        double r202959 = -r202948;
        double r202960 = r202942 * r202959;
        double r202961 = r202958 + r202960;
        double r202962 = fma(r202941, r202961, r202940);
        double r202963 = r202957 ? r202962 : r202951;
        return r202963;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.8
Target1.9
Herbie1.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 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))) < -9.787277693119323e+113 or 1.5382723312129406e+214 < (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y)))))

    1. Initial program 12.4

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

      \[\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 sub-neg2.7

      \[\leadsto \mathsf{fma}\left(y, z \cdot \color{blue}{\left(\tanh \left(\frac{t}{y}\right) + \left(-\tanh \left(\frac{x}{y}\right)\right)\right)}, x\right)\]
    5. Applied distribute-lft-in2.7

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

    if -9.787277693119323e+113 < (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))) < 1.5382723312129406e+214

    1. Initial program 0.8

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.4

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

Reproduce

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