Average Error: 24.5 → 7.8
Time: 6.1s
Precision: binary64
\[x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(z, \frac{y - x}{a - t}, x\right) + \frac{t}{a - t} \cdot \left(x - y\right)\\ t_2 := x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+284}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{-279}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;y - \frac{\left(y - x\right) \cdot \left(z - a\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y x) (- z t)) (- a t))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (+ (fma z (/ (- y x) (- a t)) x) (* (/ t (- a t)) (- x y))))
        (t_2 (+ x (/ (* (- y x) (- z t)) (- a t)))))
   (if (<= t_2 -2e+284)
     t_1
     (if (<= t_2 -1e-279)
       t_2
       (if (<= t_2 0.0) (- y (/ (* (- y x) (- z a)) t)) t_1)))))
double code(double x, double y, double z, double t, double a) {
	return x + (((y - x) * (z - t)) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = fma(z, ((y - x) / (a - t)), x) + ((t / (a - t)) * (x - y));
	double t_2 = x + (((y - x) * (z - t)) / (a - t));
	double tmp;
	if (t_2 <= -2e+284) {
		tmp = t_1;
	} else if (t_2 <= -1e-279) {
		tmp = t_2;
	} else if (t_2 <= 0.0) {
		tmp = y - (((y - x) * (z - a)) / t);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t)))
end
function code(x, y, z, t, a)
	t_1 = Float64(fma(z, Float64(Float64(y - x) / Float64(a - t)), x) + Float64(Float64(t / Float64(a - t)) * Float64(x - y)))
	t_2 = Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t)))
	tmp = 0.0
	if (t_2 <= -2e+284)
		tmp = t_1;
	elseif (t_2 <= -1e-279)
		tmp = t_2;
	elseif (t_2 <= 0.0)
		tmp = Float64(y - Float64(Float64(Float64(y - x) * Float64(z - a)) / t));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z * N[(N[(y - x), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + N[(N[(t / N[(a - t), $MachinePrecision]), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2e+284], t$95$1, If[LessEqual[t$95$2, -1e-279], t$95$2, If[LessEqual[t$95$2, 0.0], N[(y - N[(N[(N[(y - x), $MachinePrecision] * N[(z - a), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, \frac{y - x}{a - t}, x\right) + \frac{t}{a - t} \cdot \left(x - y\right)\\
t_2 := x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{+284}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-279}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;y - \frac{\left(y - x\right) \cdot \left(z - a\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original24.5
Target9.5
Herbie7.8
\[\begin{array}{l} \mathbf{if}\;a < -1.6153062845442575 \cdot 10^{-142}:\\ \;\;\;\;x + \frac{y - x}{1} \cdot \frac{z - t}{a - t}\\ \mathbf{elif}\;a < 3.774403170083174 \cdot 10^{-182}:\\ \;\;\;\;y - \frac{z}{t} \cdot \left(y - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{1} \cdot \frac{z - t}{a - t}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -2.00000000000000016e284 or 0.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t)))

    1. Initial program 30.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z - t, \frac{y - x}{a - t}, x\right)} \]
    3. Taylor expanded in z around 0 26.3

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot \left(y - x\right)}{a - t} + \left(z \cdot \left(\frac{y}{a - t} - \frac{x}{a - t}\right) + x\right)} \]
    4. Simplified11.1

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

    if -2.00000000000000016e284 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -1.00000000000000006e-279

    1. Initial program 2.6

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

    if -1.00000000000000006e-279 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < 0.0

    1. Initial program 59.5

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

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

      \[\leadsto \color{blue}{y + -1 \cdot \frac{\left(y - x\right) \cdot z + -1 \cdot \left(a \cdot \left(y - x\right)\right)}{t}} \]
    4. Simplified2.0

      \[\leadsto \color{blue}{y - \frac{\left(y - x\right) \cdot \left(z - a\right)}{t}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} \leq -2 \cdot 10^{+284}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{y - x}{a - t}, x\right) + \frac{t}{a - t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} \leq -1 \cdot 10^{-279}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} \leq 0:\\ \;\;\;\;y - \frac{\left(y - x\right) \cdot \left(z - a\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{y - x}{a - t}, x\right) + \frac{t}{a - t} \cdot \left(x - y\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022170 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Chart.Axis.Types:linMap from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< a -1.6153062845442575e-142) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t)))) (if (< a 3.774403170083174e-182) (- y (* (/ z t) (- y x))) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t))))))

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