Numeric.Histogram:binBounds from Chart-1.5.3

?

Percentage Accurate: 92.7% → 93.1%
Time: 10.6s
Precision: binary64
Cost: 708

?

\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+166}:\\ \;\;\;\;x + \frac{z}{t} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= y -4e+166) (+ x (* (/ z t) y)) (+ x (/ (* z (- y x)) t))))
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 (y <= -4e+166) {
		tmp = x + ((z / t) * y);
	} else {
		tmp = x + ((z * (y - x)) / t);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + (((y - x) * z) / t)
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (y <= (-4d+166)) then
        tmp = x + ((z / t) * y)
    else
        tmp = x + ((z * (y - x)) / t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -4e+166) {
		tmp = x + ((z / t) * y);
	} else {
		tmp = x + ((z * (y - x)) / t);
	}
	return tmp;
}
def code(x, y, z, t):
	return x + (((y - x) * z) / t)
def code(x, y, z, t):
	tmp = 0
	if y <= -4e+166:
		tmp = x + ((z / t) * y)
	else:
		tmp = x + ((z * (y - x)) / t)
	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 (y <= -4e+166)
		tmp = Float64(x + Float64(Float64(z / t) * y));
	else
		tmp = Float64(x + Float64(Float64(z * Float64(y - x)) / t));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x + (((y - x) * z) / t);
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (y <= -4e+166)
		tmp = x + ((z / t) * y);
	else
		tmp = x + ((z * (y - x)) / t);
	end
	tmp_2 = 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[y, -4e+166], N[(x + N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+166}:\\
\;\;\;\;x + \frac{z}{t} \cdot y\\

\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original92.7%
Target97.5%
Herbie93.1%
\[\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 2 regimes
  2. if y < -3.99999999999999976e166

    1. Initial program 83.9%

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Taylor expanded in y around inf 83.9%

      \[\leadsto x + \color{blue}{\frac{y \cdot z}{t}} \]
    3. Simplified99.8%

      \[\leadsto x + \color{blue}{y \cdot \frac{z}{t}} \]
      Step-by-step derivation

      [Start]83.9%

      \[ x + \frac{y \cdot z}{t} \]

      associate-*r/ [<=]99.8%

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

    if -3.99999999999999976e166 < y

    1. Initial program 97.5%

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+166}:\\ \;\;\;\;x + \frac{z}{t} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy93.1%
Cost708
\[\begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+166}:\\ \;\;\;\;x + \frac{z}{t} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\ \end{array} \]
Alternative 2
Accuracy97.5%
Cost6848
\[\mathsf{fma}\left(\frac{z}{t}, y - x, x\right) \]
Alternative 3
Accuracy53.0%
Cost980
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot y\\ \mathbf{if}\;t \leq -4.8 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.9 \cdot 10^{-261}:\\ \;\;\;\;\frac{z}{t} \cdot \left(-x\right)\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-298}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{-250}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{t}\\ \mathbf{elif}\;t \leq 620000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Accuracy53.3%
Cost716
\[\begin{array}{l} \mathbf{if}\;t \leq -8.2 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -8 \cdot 10^{-262}:\\ \;\;\;\;\frac{z}{t} \cdot \left(-x\right)\\ \mathbf{elif}\;t \leq 255000000:\\ \;\;\;\;\frac{z}{t} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Accuracy84.2%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+47} \lor \neg \left(z \leq 5.8 \cdot 10^{+33}\right):\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{t} \cdot y\\ \end{array} \]
Alternative 6
Accuracy85.0%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -7.6 \cdot 10^{-17} \lor \neg \left(y \leq 4.2 \cdot 10^{-170}\right):\\ \;\;\;\;x + \frac{z}{t} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{t} \cdot x\\ \end{array} \]
Alternative 7
Accuracy84.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -2.6 \cdot 10^{-66} \lor \neg \left(t \leq 185000000\right):\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{z \cdot \left(y - x\right)}{t}\\ \end{array} \]
Alternative 8
Accuracy68.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -3.8 \cdot 10^{+160}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+33}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Accuracy55.2%
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -2.2 \cdot 10^{-56}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 390000000:\\ \;\;\;\;\frac{z}{t} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy97.5%
Cost576
\[x + \frac{y - x}{\frac{t}{z}} \]
Alternative 11
Accuracy38.8%
Cost64
\[x \]

Reproduce?

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