?

Average Error: 10.04% → 3.31%
Time: 10.1s
Precision: binary64
Cost: 7112

?

\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-125}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-280}:\\ \;\;\;\;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 (<= x -5e-125)
   (+ x (/ (- y x) (/ t z)))
   (if (<= x 5e-280) (+ 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 (x <= -5e-125) {
		tmp = x + ((y - x) / (t / z));
	} else if (x <= 5e-280) {
		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 (x <= -5e-125)
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	elseif (x <= 5e-280)
		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[x, -5e-125], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5e-280], 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}\;x \leq -5 \cdot 10^{-125}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

\mathbf{elif}\;x \leq 5 \cdot 10^{-280}:\\
\;\;\;\;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

Original10.04%
Target3.22%
Herbie3.31%
\[\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.99999999999999967e-125

    1. Initial program 10.88

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

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

      [Start]10.88

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

      associate-/l* [=>]1

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

    if -4.99999999999999967e-125 < x < 5.00000000000000028e-280

    1. Initial program 8.81

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

    if 5.00000000000000028e-280 < x

    1. Initial program 9.96

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

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

      [Start]9.96

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

      +-commutative [=>]9.96

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

      associate-*r/ [<=]2.72

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

      fma-def [=>]2.71

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-125}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-280}:\\ \;\;\;\;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
Error44.76%
Cost1508
\[\begin{array}{l} t_1 := \frac{-z}{\frac{t}{x}}\\ \mathbf{if}\;x \leq -1.05 \cdot 10^{+59}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-58}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-71}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.95 \cdot 10^{-190}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -5.7 \cdot 10^{-218}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.3 \cdot 10^{-62}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error44.81%
Cost1508
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+59}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-37}:\\ \;\;\;\;\frac{-z}{\frac{t}{x}}\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.9 \cdot 10^{-72}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-106}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{t}\\ \mathbf{elif}\;x \leq -2.05 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-191}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-217}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.3 \cdot 10^{-62}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error6.02%
Cost1220
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq 10^{+302}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \end{array} \]
Alternative 4
Error42.5%
Cost1114
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+20}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-71} \lor \neg \left(x \leq -1.26 \cdot 10^{-129}\right) \land \left(x \leq -1.22 \cdot 10^{-189} \lor \neg \left(x \leq -2.85 \cdot 10^{-217}\right) \land x \leq 1.95 \cdot 10^{-54}\right):\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error42.53%
Cost1112
\[\begin{array}{l} t_1 := y \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -1.6 \cdot 10^{+21}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-191}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-217}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.15 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error42.65%
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+20}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-108}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-189}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-217}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-55}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error43.12%
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{+20}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-108}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.7 \cdot 10^{-191}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -6.7 \cdot 10^{-218}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.16 \cdot 10^{-61}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error9.83%
Cost1108
\[\begin{array}{l} t_1 := x + z \cdot \frac{y - x}{t}\\ t_2 := x - x \cdot \frac{z}{t}\\ t_3 := x + y \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -4 \cdot 10^{+206}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-218}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+206}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error29.23%
Cost977
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -7.5 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.56 \cdot 10^{-189}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq -6.4 \cdot 10^{-218} \lor \neg \left(x \leq 6.3 \cdot 10^{-62}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \end{array} \]
Alternative 10
Error28.59%
Cost977
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -1.06 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-190}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-217} \lor \neg \left(x \leq 6.3 \cdot 10^{-62}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \end{array} \]
Alternative 11
Error14.77%
Cost976
\[\begin{array}{l} t_1 := x + y \cdot \frac{z}{t}\\ \mathbf{if}\;y \leq -3.45 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{-229}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{-165}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-125}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error14.75%
Cost976
\[\begin{array}{l} t_1 := x + y \cdot \frac{z}{t}\\ \mathbf{if}\;y \leq -5.2 \cdot 10^{-150}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-230}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{-165}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-125}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error3.28%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -1.52 \cdot 10^{-125} \lor \neg \left(x \leq 3 \cdot 10^{-280}\right):\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \end{array} \]
Alternative 14
Error17.3%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+112} \lor \neg \left(z \leq 6.8 \cdot 10^{+24}\right):\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 15
Error49.88%
Cost64
\[x \]

Error

Reproduce?

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