?

Average Error: 6.7 → 2.0
Time: 12.5s
Precision: binary64
Cost: 7112

?

\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{-156}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-230}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, 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 -4.5e-156)
   (+ x (/ (- y x) (/ t z)))
   (if (<= x 5.8e-230) (+ x (/ z (/ t (- y x)))) (fma (- y x) (/ z t) 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 <= -4.5e-156) {
		tmp = x + ((y - x) / (t / z));
	} else if (x <= 5.8e-230) {
		tmp = x + (z / (t / (y - x)));
	} else {
		tmp = fma((y - x), (z / t), x);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -4.5e-156)
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	elseif (x <= 5.8e-230)
		tmp = Float64(x + Float64(z / Float64(t / Float64(y - x))));
	else
		tmp = fma(Float64(y - x), Float64(z / t), x);
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[x, -4.5e-156], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5.8e-230], N[(x + N[(z / N[(t / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-156}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

\mathbf{elif}\;x \leq 5.8 \cdot 10^{-230}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\

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


\end{array}

Error?

Target

Original6.7
Target2.0
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation?

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

    1. Initial program 7.2

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

      \[\leadsto \color{blue}{x + \frac{y - x}{\frac{t}{z}}} \]
      Proof

      [Start]7.2

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

      associate-/l* [=>]0.9

      \[ x + \color{blue}{\frac{y - x}{\frac{t}{z}}} \]

    if -4.49999999999999986e-156 < x < 5.80000000000000011e-230

    1. Initial program 4.8

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

      \[\leadsto \color{blue}{x + \frac{y - x}{t} \cdot z} \]
      Proof

      [Start]4.8

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

      associate-*l/ [<=]5.5

      \[ x + \color{blue}{\frac{y - x}{t} \cdot z} \]
    3. Applied egg-rr5.4

      \[\leadsto x + \color{blue}{\frac{z}{\frac{t}{y - x}}} \]

    if 5.80000000000000011e-230 < x

    1. Initial program 7.1

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

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

      [Start]7.1

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

      +-commutative [=>]7.1

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

      associate-*r/ [<=]1.3

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

      fma-def [=>]1.3

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

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

Alternatives

Alternative 1
Error0.8
Cost1865
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+307}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error10.7
Cost1240
\[\begin{array}{l} t_1 := x - x \cdot \frac{z}{t}\\ t_2 := x + \frac{y \cdot z}{t}\\ \mathbf{if}\;y \leq -1.7 \cdot 10^{+278}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;y \leq -1.95 \cdot 10^{-37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{-174}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -4.2 \cdot 10^{-255}:\\ \;\;\;\;x - z \cdot \frac{x}{t}\\ \mathbf{elif}\;y \leq 1.62 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error27.7
Cost1112
\[\begin{array}{l} t_1 := y \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{-95}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-114}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.26 \cdot 10^{-88}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.32 \cdot 10^{+64}:\\ \;\;\;\;z \cdot \frac{-x}{t}\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error24.2
Cost1112
\[\begin{array}{l} \mathbf{if}\;t \leq -6.5 \cdot 10^{+47}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 2.7 \cdot 10^{-13}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;t \leq 9 \cdot 10^{+115}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 3.5 \cdot 10^{+149}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;t \leq 3.5 \cdot 10^{+210}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{+243}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error12.8
Cost1108
\[\begin{array}{l} t_1 := x - z \cdot \frac{x}{t}\\ t_2 := x + \frac{y \cdot z}{t}\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{+279}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-164}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{-222}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error2.0
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -9.4 \cdot 10^{-157}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-216}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{t}{z}}{y - x}}\\ \end{array} \]
Alternative 7
Error26.2
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-30}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-110} \lor \neg \left(x \leq 1.26 \cdot 10^{-88}\right) \land x \leq 3.2 \cdot 10^{-13}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error26.5
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{-90}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.4 \cdot 10^{-110}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-88}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-14}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error4.6
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+169} \lor \neg \left(x \leq 2.9 \cdot 10^{+72}\right):\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \end{array} \]
Alternative 10
Error4.4
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+170} \lor \neg \left(x \leq 8.2 \cdot 10^{+72}\right):\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \end{array} \]
Alternative 11
Error2.0
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{-160} \lor \neg \left(x \leq 1.75 \cdot 10^{-240}\right):\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \end{array} \]
Alternative 12
Error26.4
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-262}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-13}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error13.3
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -2.2 \cdot 10^{-147} \lor \neg \left(t \leq 2.45 \cdot 10^{-191}\right):\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \end{array} \]
Alternative 14
Error31.7
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023039 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

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