Average Error: 24.9 → 8.9
Time: 24.7s
Precision: 64
\[x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}\]
\[\begin{array}{l} \mathbf{if}\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} \le -3.956280165893758193874340988906388103674 \cdot 10^{-277}:\\ \;\;\;\;\mathsf{fma}\left(\left(y - z\right) \cdot \frac{1}{a - z}, t - x, x\right)\\ \mathbf{elif}\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} \le 0.0:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z} - \frac{t}{z}, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(y - z\right) \cdot \frac{1}{a - z}, t - x, x\right)\\ \end{array}\]
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\begin{array}{l}
\mathbf{if}\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} \le -3.956280165893758193874340988906388103674 \cdot 10^{-277}:\\
\;\;\;\;\mathsf{fma}\left(\left(y - z\right) \cdot \frac{1}{a - z}, t - x, x\right)\\

\mathbf{elif}\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} \le 0.0:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z} - \frac{t}{z}, t\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r38423267 = x;
        double r38423268 = y;
        double r38423269 = z;
        double r38423270 = r38423268 - r38423269;
        double r38423271 = t;
        double r38423272 = r38423271 - r38423267;
        double r38423273 = r38423270 * r38423272;
        double r38423274 = a;
        double r38423275 = r38423274 - r38423269;
        double r38423276 = r38423273 / r38423275;
        double r38423277 = r38423267 + r38423276;
        return r38423277;
}

double f(double x, double y, double z, double t, double a) {
        double r38423278 = x;
        double r38423279 = y;
        double r38423280 = z;
        double r38423281 = r38423279 - r38423280;
        double r38423282 = t;
        double r38423283 = r38423282 - r38423278;
        double r38423284 = r38423281 * r38423283;
        double r38423285 = a;
        double r38423286 = r38423285 - r38423280;
        double r38423287 = r38423284 / r38423286;
        double r38423288 = r38423278 + r38423287;
        double r38423289 = -3.956280165893758e-277;
        bool r38423290 = r38423288 <= r38423289;
        double r38423291 = 1.0;
        double r38423292 = r38423291 / r38423286;
        double r38423293 = r38423281 * r38423292;
        double r38423294 = fma(r38423293, r38423283, r38423278);
        double r38423295 = 0.0;
        bool r38423296 = r38423288 <= r38423295;
        double r38423297 = r38423278 / r38423280;
        double r38423298 = r38423282 / r38423280;
        double r38423299 = r38423297 - r38423298;
        double r38423300 = fma(r38423279, r38423299, r38423282);
        double r38423301 = r38423296 ? r38423300 : r38423294;
        double r38423302 = r38423290 ? r38423294 : r38423301;
        return r38423302;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original24.9
Target11.8
Herbie8.9
\[\begin{array}{l} \mathbf{if}\;z \lt -1.253613105609503593846459977496550767343 \cdot 10^{188}:\\ \;\;\;\;t - \frac{y}{z} \cdot \left(t - x\right)\\ \mathbf{elif}\;z \lt 4.446702369113811028051510715777703865332 \cdot 10^{64}:\\ \;\;\;\;x + \frac{y - z}{\frac{a - z}{t - x}}\\ \mathbf{else}:\\ \;\;\;\;t - \frac{y}{z} \cdot \left(t - x\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (+ x (/ (* (- y z) (- t x)) (- a z))) < -3.956280165893758e-277 or 0.0 < (+ x (/ (* (- y z) (- t x)) (- a z)))

    1. Initial program 22.0

      \[x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}\]
    2. Simplified7.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y - z}{a - z}, t - x, x\right)}\]
    3. Using strategy rm
    4. Applied div-inv7.7

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

    if -3.956280165893758e-277 < (+ x (/ (* (- y z) (- t x)) (- a z))) < 0.0

    1. Initial program 58.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y - z}{a - z}, t - x, x\right)}\]
    3. Using strategy rm
    4. Applied div-inv58.7

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - z\right) \cdot \frac{1}{a - z}}, t - x, x\right)\]
    5. Using strategy rm
    6. Applied add-cube-cbrt58.7

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{\left(y - z\right) \cdot \frac{1}{a - z}} \cdot \sqrt[3]{\left(y - z\right) \cdot \frac{1}{a - z}}\right) \cdot \sqrt[3]{\left(y - z\right) \cdot \frac{1}{a - z}}}, t - x, x\right)\]
    7. Taylor expanded around inf 20.7

      \[\leadsto \color{blue}{\left(t + \frac{x \cdot y}{z}\right) - \frac{t \cdot y}{z}}\]
    8. Simplified23.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{x}{z} - \frac{t}{z}, t\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} \le -3.956280165893758193874340988906388103674 \cdot 10^{-277}:\\ \;\;\;\;\mathsf{fma}\left(\left(y - z\right) \cdot \frac{1}{a - z}, t - x, x\right)\\ \mathbf{elif}\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} \le 0.0:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z} - \frac{t}{z}, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(y - z\right) \cdot \frac{1}{a - z}, t - x, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x y z t a)
  :name "Graphics.Rendering.Chart.Axis.Types:invLinMap from Chart-1.5.3"

  :herbie-target
  (if (< z -1.2536131056095036e+188) (- t (* (/ y z) (- t x))) (if (< z 4.446702369113811e+64) (+ x (/ (- y z) (/ (- a z) (- t x)))) (- t (* (/ y z) (- t x)))))

  (+ x (/ (* (- y z) (- t x)) (- a z))))