?

Average Error: 6.5 → 1.3
Time: 11.5s
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^{+227}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;t_1 \leq 10^{+279}:\\ \;\;\;\;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+227)
     (+ x (/ (- y x) (/ t z)))
     (if (<= t_1 1e+279) 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+227) {
		tmp = x + ((y - x) / (t / z));
	} else if (t_1 <= 1e+279) {
		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+227)
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	elseif (t_1 <= 1e+279)
		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+227], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+279], 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^{+227}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

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

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


\end{array}

Error?

Target

Original6.5
Target2.2
Herbie1.3
\[\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.0000000000000002e227

    1. Initial program 22.6

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

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

      [Start]22.6

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

      associate-/l* [=>]3.3

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

    if -2.0000000000000002e227 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 1.00000000000000006e279

    1. Initial program 0.9

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

    if 1.00000000000000006e279 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 40.3

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

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

      [Start]40.3

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

      +-commutative [=>]40.3

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

      associate-*r/ [<=]2.6

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

      fma-def [=>]2.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq -2 \cdot 10^{+227}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq 10^{+279}:\\ \;\;\;\;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
Error1.6
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 2
Error2.0
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+227}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 3
Error6.5
Cost1104
\[\begin{array}{l} t_1 := x + z \cdot \frac{y - x}{t}\\ \mathbf{if}\;t \leq -1.35 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{-210}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{elif}\;t \leq 1.6 \cdot 10^{-138}:\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \mathbf{elif}\;t \leq 1.85 \cdot 10^{-16}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error18.2
Cost977
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -2 \cdot 10^{-79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-147}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-154} \lor \neg \left(x \leq 1.4 \cdot 10^{-101}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \end{array} \]
Alternative 5
Error26.2
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -2500000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-25}:\\ \;\;\;\;\frac{-x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq -4.7 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-98}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error16.2
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-79} \lor \neg \left(x \leq 2.1 \cdot 10^{-98}\right):\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \end{array} \]
Alternative 7
Error9.3
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{+44} \lor \neg \left(y \leq 1.85 \cdot 10^{-134}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 8
Error25.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{-78}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-102}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error25.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{-76}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-96}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error31.9
Cost64
\[x \]

Error

Reproduce?

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