?

Average Error: 10.38% → 1.91%
Time: 10.2s
Precision: binary64
Cost: 8136

?

\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+251}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;t_1 \leq 10^{+255}:\\ \;\;\;\;t_1\\ \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
 (let* ((t_1 (+ x (/ (* (- y x) z) t))))
   (if (<= t_1 -2e+251)
     (+ x (/ (- y x) (/ t z)))
     (if (<= t_1 1e+255) t_1 (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 t_1 = x + (((y - x) * z) / t);
	double tmp;
	if (t_1 <= -2e+251) {
		tmp = x + ((y - x) / (t / z));
	} else if (t_1 <= 1e+255) {
		tmp = t_1;
	} 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)
	t_1 = Float64(x + Float64(Float64(Float64(y - x) * z) / t))
	tmp = 0.0
	if (t_1 <= -2e+251)
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	elseif (t_1 <= 1e+255)
		tmp = t_1;
	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_] := Block[{t$95$1 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+251], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+255], t$95$1, N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+251}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

\mathbf{elif}\;t_1 \leq 10^{+255}:\\
\;\;\;\;t_1\\

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


\end{array}

Error?

Target

Original10.38%
Target3.3%
Herbie1.91%
\[\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 (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -2.0000000000000001e251

    1. Initial program 45.67

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

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

      [Start]45.67

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

      associate-/l* [=>]4.85

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

    if -2.0000000000000001e251 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 9.99999999999999988e254

    1. Initial program 1.22

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

    if 9.99999999999999988e254 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 48.64

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

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

      [Start]48.64

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

      +-commutative [=>]48.64

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

      associate-*r/ [<=]4.56

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

      fma-def [=>]4.56

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq -2 \cdot 10^{+251}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq 10^{+255}:\\ \;\;\;\;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
Error2.32%
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^{+267}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error1.77%
Cost1865
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+251} \lor \neg \left(t_1 \leq 2 \cdot 10^{+277}\right):\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error41.02%
Cost980
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;x \leq -1.2 \cdot 10^{-48}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.25 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-187}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-278}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 2.65 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error36.7%
Cost977
\[\begin{array}{l} \mathbf{if}\;t \leq -2250000:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 6 \cdot 10^{-99} \lor \neg \left(t \leq 3.65 \cdot 10^{-66}\right) \land t \leq 3.5 \cdot 10^{+101}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error6.54%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -7.4 \cdot 10^{-51} \lor \neg \left(z \leq 4.2 \cdot 10^{-119}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 6
Error19.08%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -52000 \lor \neg \left(t \leq 4.6 \cdot 10^{-219}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \end{array} \]
Alternative 7
Error14.73%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{-137} \lor \neg \left(y \leq 1.86 \cdot 10^{-211}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{t}\\ \end{array} \]
Alternative 8
Error14.14%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{-129} \lor \neg \left(y \leq 3.3 \cdot 10^{-208}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \end{array} \]
Alternative 9
Error18.69%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -130000:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;t \leq 4.4 \cdot 10^{-206}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 10
Error18.78%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -52000:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;t \leq 4.6 \cdot 10^{-212}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 11
Error40.91%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{-41}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-105}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error40.41%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.7 \cdot 10^{-38}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-107}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error50.19%
Cost64
\[x \]

Error

Reproduce?

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