Average Error: 2.0 → 2.1
Time: 3.8s
Precision: binary64
\[x + \left(y - x\right) \cdot \frac{z}{t} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-26}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \mathbf{elif}\;x \leq 10^{-130}:\\ \;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{t} \cdot \left(y - x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= x -1e-26)
   (fma (/ z t) (- y x) x)
   (if (<= x 1e-130) (+ x (/ (* z (- y x)) t)) (+ x (* (/ z t) (- y x))))))
double code(double x, double y, double z, double t) {
	return x + ((y - x) * (z / t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1e-26) {
		tmp = fma((z / t), (y - x), x);
	} else if (x <= 1e-130) {
		tmp = x + ((z * (y - x)) / t);
	} else {
		tmp = x + ((z / t) * (y - x));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - x) * Float64(z / t)))
end
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -1e-26)
		tmp = fma(Float64(z / t), Float64(y - x), x);
	elseif (x <= 1e-130)
		tmp = Float64(x + Float64(Float64(z * Float64(y - x)) / t));
	else
		tmp = Float64(x + Float64(Float64(z / t) * Float64(y - x)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[x, -1e-26], N[(N[(z / t), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 1e-130], N[(x + N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z / t), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \left(y - x\right) \cdot \frac{z}{t}
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\

\mathbf{elif}\;x \leq 10^{-130}:\\
\;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original2.0
Target2.2
Herbie2.1
\[\begin{array}{l} \mathbf{if}\;\left(y - x\right) \cdot \frac{z}{t} < -1013646692435.8867:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;\left(y - x\right) \cdot \frac{z}{t} < 0:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if x < -1e-26

    1. Initial program 0.1

      \[x + \left(y - x\right) \cdot \frac{z}{t} \]
    2. Applied egg-rr0.1

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

    if -1e-26 < x < 1.0000000000000001e-130

    1. Initial program 4.4

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

      \[\leadsto x + \color{blue}{{\left(\sqrt[3]{\left(y - x\right) \cdot \frac{z}{t}}\right)}^{3}} \]
    3. Applied egg-rr4.5

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

    if 1.0000000000000001e-130 < x

    1. Initial program 0.6

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

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

Reproduce

herbie shell --seed 2022166 
(FPCore (x y z t)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:tickPosition from plot-0.2.3.4"
  :precision binary64

  :herbie-target
  (if (< (* (- y x) (/ z t)) -1013646692435.8867) (+ x (/ (- y x) (/ t z))) (if (< (* (- y x) (/ z t)) 0.0) (+ x (/ (* (- y x) z) t)) (+ x (/ (- y x) (/ t z)))))

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