?

Average Error: 6.5 → 0.9
Time: 9.2s
Precision: binary64
Cost: 7492

?

\[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 -\infty:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+284}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \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 (- INFINITY))
     (fma (- y x) (/ z t) x)
     (if (<= t_1 5e+284) t_1 (+ x (/ (- y x) (/ t z)))))))
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 <= -((double) INFINITY)) {
		tmp = fma((y - x), (z / t), x);
	} else if (t_1 <= 5e+284) {
		tmp = t_1;
	} else {
		tmp = x + ((y - x) / (t / z));
	}
	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 <= Float64(-Inf))
		tmp = fma(Float64(y - x), Float64(z / t), x);
	elseif (t_1 <= 5e+284)
		tmp = t_1;
	else
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	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, (-Infinity)], N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 5e+284], t$95$1, N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $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 -\infty:\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+284}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\


\end{array}

Error?

Target

Original6.5
Target2.0
Herbie0.9
\[\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)) < -inf.0

    1. Initial program 64.0

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

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

      [Start]64.0

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

      +-commutative [=>]64.0

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

      associate-*r/ [<=]0.2

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

      fma-def [=>]0.2

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

    if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 4.9999999999999999e284

    1. Initial program 0.9

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

    if 4.9999999999999999e284 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 42.8

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

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

      [Start]42.8

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

      associate-/l* [=>]1.3

      \[ x + \color{blue}{\frac{y - x}{\frac{t}{z}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

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

Alternatives

Alternative 1
Error1.1
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 2 \cdot 10^{+291}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.9
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 5 \cdot 10^{+284}\right):\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error29.2
Cost1176
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ t_2 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{+36}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.3 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-86}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+144}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.95 \cdot 10^{+289}:\\ \;\;\;\;\frac{-z}{\frac{t}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error29.4
Cost850
\[\begin{array}{l} \mathbf{if}\;z \leq -2.7 \cdot 10^{+141} \lor \neg \left(z \leq -8.5 \cdot 10^{-14}\right) \land \left(z \leq -6.2 \cdot 10^{-88} \lor \neg \left(z \leq 1.65 \cdot 10^{+70}\right)\right):\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error28.6
Cost848
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-86}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error28.7
Cost848
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{-88}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;z \leq 1.66 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error21.6
Cost844
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;y \leq -1.4 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-12}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;y \leq 1.22 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 8
Error4.2
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -8 \cdot 10^{-83} \lor \neg \left(z \leq 4 \cdot 10^{-111}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 9
Error9.0
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.7 \cdot 10^{-40} \lor \neg \left(y \leq 4.1 \cdot 10^{-40}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 10
Error8.9
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -7 \cdot 10^{-40} \lor \neg \left(y \leq 5.2 \cdot 10^{-40}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{t}{z}}\\ \end{array} \]
Alternative 11
Error32.5
Cost64
\[x \]

Error

Reproduce?

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