?

Average Accuracy: 89.5% → 97.8%
Time: 13.8s
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 -1 \cdot 10^{+303}:\\ \;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+171}:\\ \;\;\;\;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 -1e+303)
     (+ x (* (- y x) (/ z t)))
     (if (<= t_1 5e+171) 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 <= -1e+303) {
		tmp = x + ((y - x) * (z / t));
	} else if (t_1 <= 5e+171) {
		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 <= -1e+303)
		tmp = Float64(x + Float64(Float64(y - x) * Float64(z / t)));
	elseif (t_1 <= 5e+171)
		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, -1e+303], N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+171], 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 -1 \cdot 10^{+303}:\\
\;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\

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

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


\end{array}

Error?

Target

Original89.5%
Target96.6%
Herbie97.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 (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -1e303

    1. Initial program 8.9%

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

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

      [Start]8.9

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

      +-commutative [=>]8.9

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

      associate-*r/ [<=]99.0

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

      fma-def [=>]99.0

      \[ \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    3. Applied egg-rr99.0%

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

      [Start]99.0

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

      fma-udef [=>]99.0

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

    if -1e303 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 5.0000000000000004e171

    1. Initial program 98.6%

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

    if 5.0000000000000004e171 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 72.5%

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

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

      [Start]72.5

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

      +-commutative [=>]72.5

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

      associate-*r/ [<=]94.4

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

      fma-def [=>]94.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq -1 \cdot 10^{+303}:\\ \;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq 5 \cdot 10^{+171}:\\ \;\;\;\;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
Accuracy98.5%
Cost1865
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+303} \lor \neg \left(t_1 \leq 5 \cdot 10^{+277}\right):\\ \;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy98.8%
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+304}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \end{array} \]
Alternative 3
Accuracy72.9%
Cost976
\[\begin{array}{l} t_1 := z \cdot \frac{y - x}{t}\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -7.4 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-279}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-110}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy89.7%
Cost972
\[\begin{array}{l} t_1 := x + z \cdot \frac{y - x}{t}\\ \mathbf{if}\;x \leq 5.2 \cdot 10^{-279}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-110}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+156}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 5
Accuracy54.7%
Cost848
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -1.2 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1100000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 6
Accuracy54.7%
Cost848
\[\begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -1.32 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 80000000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 7
Accuracy54.9%
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -1.12 \cdot 10^{-12}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;z \leq 16500000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 8
Accuracy58.5%
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+19}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -0.000108:\\ \;\;\;\;\frac{-x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq -7.1 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-23}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Accuracy58.6%
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+19}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -0.000108:\\ \;\;\;\;\frac{x}{t} \cdot \left(-z\right)\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-24}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy58.5%
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+19}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -0.000108:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{t}\\ \mathbf{elif}\;x \leq -1.62 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-22}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy71.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{-67} \lor \neg \left(x \leq 2.1 \cdot 10^{-84}\right):\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 12
Accuracy87.2%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.1 \cdot 10^{-76} \lor \neg \left(y \leq 9 \cdot 10^{-144}\right):\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 13
Accuracy87.2%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -4.7 \cdot 10^{-76} \lor \neg \left(y \leq 8.2 \cdot 10^{-137}\right):\\ \;\;\;\;x + \frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 14
Accuracy85.5%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{-80}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-142}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 15
Accuracy91.1%
Cost708
\[\begin{array}{l} \mathbf{if}\;y \leq 8 \cdot 10^{-48}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 16
Accuracy59.2%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.15 \cdot 10^{-67}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-22}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 17
Accuracy50.0%
Cost64
\[x \]

Error

Reproduce?

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