?

Average Accuracy: 89.8% → 96.8%
Time: 13.2s
Precision: binary64
Cost: 7112

?

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

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

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


\end{array}

Error?

Target

Original89.8%
Target96.8%
Herbie96.8%
\[\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 < -3.49999999999999993e-276

    1. Initial program 89.5%

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

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

      [Start]89.5

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

      associate-/l* [=>]97.3

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

    if -3.49999999999999993e-276 < x < 1.99999999999999985e-76

    1. Initial program 92.3%

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

    if 1.99999999999999985e-76 < x

    1. Initial program 88.1%

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

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

      [Start]88.1

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

      +-commutative [=>]88.1

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

      *-commutative [=>]88.1

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

      associate-*l/ [<=]99.5

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

      fma-def [=>]99.5

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

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

Alternatives

Alternative 1
Accuracy96.1%
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+299}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \end{array} \]
Alternative 2
Accuracy51.6%
Cost1376
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;y \leq -3.1 \cdot 10^{+223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.55 \cdot 10^{+134}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{-137}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.25 \cdot 10^{-175}:\\ \;\;\;\;\frac{-z}{\frac{t}{x}}\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+32}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+200}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 3
Accuracy51.4%
Cost1376
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;y \leq -7 \cdot 10^{+223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.1 \cdot 10^{+132}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{-137}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -5.4 \cdot 10^{-176}:\\ \;\;\;\;z \cdot \frac{-x}{t}\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+30}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+207}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 4
Accuracy66.6%
Cost1240
\[\begin{array}{l} t_1 := z \cdot \frac{y - x}{t}\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;y \leq -5.2 \cdot 10^{+223}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{+114}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{+29}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{+67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.14 \cdot 10^{+204}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 5
Accuracy67.7%
Cost1240
\[\begin{array}{l} t_1 := \left(y - x\right) \cdot \frac{z}{t}\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;y \leq -3.1 \cdot 10^{+223}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+139}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{+32}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+64}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{+200}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy52.5%
Cost1115
\[\begin{array}{l} \mathbf{if}\;y \leq -3.1 \cdot 10^{+223} \lor \neg \left(y \leq -2.35 \cdot 10^{+120} \lor \neg \left(y \leq -3.9 \cdot 10^{+49}\right) \land \left(y \leq 4.5 \cdot 10^{+32} \lor \neg \left(y \leq 4.8 \cdot 10^{+64}\right) \land y \leq 2.4 \cdot 10^{+200}\right)\right):\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy52.3%
Cost1113
\[\begin{array}{l} t_1 := y \cdot \frac{z}{t}\\ \mathbf{if}\;y \leq -3.5 \cdot 10^{+223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.5 \cdot 10^{+131}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{+49}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+32}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+65} \lor \neg \left(y \leq 2.5 \cdot 10^{+200}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Accuracy52.7%
Cost1112
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;y \leq -3.1 \cdot 10^{+223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.3 \cdot 10^{+132}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+30}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+203}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 9
Accuracy67.8%
Cost976
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;y \leq -3.2 \cdot 10^{+223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+32}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+203}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 10
Accuracy96.8%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{-276} \lor \neg \left(x \leq 2.4 \cdot 10^{-77}\right):\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \end{array} \]
Alternative 11
Accuracy84.0%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -9 \cdot 10^{-68} \lor \neg \left(y \leq 1.8 \cdot 10^{-83}\right):\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 12
Accuracy83.6%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-67} \lor \neg \left(y \leq 3.3 \cdot 10^{-83}\right):\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 13
Accuracy82.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{-68} \lor \neg \left(y \leq 6.2 \cdot 10^{-84}\right):\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{\frac{t}{x}}\\ \end{array} \]
Alternative 14
Accuracy50.2%
Cost64
\[x \]

Error

Reproduce?

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