Average Error: 6.6 → 1.6
Time: 10.7s
Precision: binary64
Cost: 7112
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -9.5 \cdot 10^{+46}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{elif}\;t \leq 6 \cdot 10^{-208}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \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 (<= t -9.5e+46)
   (+ x (* (/ (- y x) t) z))
   (if (<= t 6e-208) (+ x (/ (* (- y x) z) t)) (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 (t <= -9.5e+46) {
		tmp = x + (((y - x) / t) * z);
	} else if (t <= 6e-208) {
		tmp = x + (((y - x) * z) / t);
	} 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 (t <= -9.5e+46)
		tmp = Float64(x + Float64(Float64(Float64(y - x) / t) * z));
	elseif (t <= 6e-208)
		tmp = Float64(x + Float64(Float64(Float64(y - x) * z) / t));
	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[t, -9.5e+46], N[(x + N[(N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 6e-208], N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $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}\;t \leq -9.5 \cdot 10^{+46}:\\
\;\;\;\;x + \frac{y - x}{t} \cdot z\\

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

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


\end{array}

Error

Target

Original6.6
Target1.8
Herbie1.6
\[\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 t < -9.5000000000000008e46

    1. Initial program 10.9

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

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

      [Start]10.9

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

      associate-*l/ [<=]1.3

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

    if -9.5000000000000008e46 < t < 5.99999999999999972e-208

    1. Initial program 2.2

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

    if 5.99999999999999972e-208 < t

    1. Initial program 6.8

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

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

      [Start]6.8

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

      +-commutative [=>]6.8

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

      associate-*r/ [<=]1.5

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

      fma-def [=>]1.5

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

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

Alternatives

Alternative 1
Error0.9
Cost1865
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+302} \lor \neg \left(t_1 \leq 5 \cdot 10^{+305}\right):\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error24.7
Cost1108
\[\begin{array}{l} t_1 := \frac{y - x}{t} \cdot z\\ \mathbf{if}\;z \leq -3.4 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-209}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;z \leq 5000000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error24.7
Cost1108
\[\begin{array}{l} t_1 := \frac{y - x}{t} \cdot z\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-209}:\\ \;\;\;\;\frac{1}{t} \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+15}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error27.1
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -1350000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-108}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-142}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-180}:\\ \;\;\;\;\frac{-x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 9.4 \cdot 10^{-135}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error26.9
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -28:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-108}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-151}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-180}:\\ \;\;\;\;\frac{x \cdot z}{-t}\\ \mathbf{elif}\;x \leq 9.4 \cdot 10^{-135}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error11.9
Cost845
\[\begin{array}{l} \mathbf{if}\;z \leq -1.75 \cdot 10^{+16} \lor \neg \left(z \leq 3.4 \cdot 10^{+144}\right) \land z \leq 4.2 \cdot 10^{+215}:\\ \;\;\;\;\frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 7
Error4.1
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1.9 \cdot 10^{-92} \lor \neg \left(z \leq 1.4 \cdot 10^{-193}\right):\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \end{array} \]
Alternative 8
Error4.0
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-92} \lor \neg \left(z \leq 2.8 \cdot 10^{-216}\right):\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \end{array} \]
Alternative 9
Error1.6
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -1 \cdot 10^{+52}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{elif}\;t \leq 1.85 \cdot 10^{-211}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]
Alternative 10
Error8.4
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.3 \cdot 10^{-189} \lor \neg \left(y \leq 8.5 \cdot 10^{-95}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \end{array} \]
Alternative 11
Error8.4
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{-187} \lor \neg \left(y \leq 6.6 \cdot 10^{-95}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{t}{z}}\\ \end{array} \]
Alternative 12
Error26.2
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -26:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{-135}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error26.2
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -125:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-135}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error31.9
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2023016 
(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)))