| Alternative 1 | |
|---|---|
| Accuracy | 94.2% |
| Cost | 836 |
\[\begin{array}{l}
\mathbf{if}\;y \leq 3.9 \cdot 10^{+149}:\\
\;\;\;\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + t\right)\\
\end{array}
\]

(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t) :precision binary64 (if (<= y 3.9e+149) (* x (- (/ y z) (/ t (- 1.0 z)))) (* (/ x z) (+ y t))))
double code(double x, double y, double z, double t) {
return x * ((y / z) - (t / (1.0 - z)));
}
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3.9e+149) {
tmp = x * ((y / z) - (t / (1.0 - z)));
} else {
tmp = (x / z) * (y + 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 / z) - (t / (1.0d0 - z)))
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 <= 3.9d+149) then
tmp = x * ((y / z) - (t / (1.0d0 - z)))
else
tmp = (x / z) * (y + t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return x * ((y / z) - (t / (1.0 - z)));
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3.9e+149) {
tmp = x * ((y / z) - (t / (1.0 - z)));
} else {
tmp = (x / z) * (y + t);
}
return tmp;
}
def code(x, y, z, t): return x * ((y / z) - (t / (1.0 - z)))
def code(x, y, z, t): tmp = 0 if y <= 3.9e+149: tmp = x * ((y / z) - (t / (1.0 - z))) else: tmp = (x / z) * (y + t) return tmp
function code(x, y, z, t) return Float64(x * Float64(Float64(y / z) - Float64(t / Float64(1.0 - z)))) end
function code(x, y, z, t) tmp = 0.0 if (y <= 3.9e+149) tmp = Float64(x * Float64(Float64(y / z) - Float64(t / Float64(1.0 - z)))); else tmp = Float64(Float64(x / z) * Float64(y + t)); end return tmp end
function tmp = code(x, y, z, t) tmp = x * ((y / z) - (t / (1.0 - z))); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 3.9e+149) tmp = x * ((y / z) - (t / (1.0 - z))); else tmp = (x / z) * (y + t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x * N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[y, 3.9e+149], N[(x * N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * N[(y + t), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
\mathbf{if}\;y \leq 3.9 \cdot 10^{+149}:\\
\;\;\;\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + t\right)\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 94.5% |
|---|---|
| Target | 95.0% |
| Herbie | 94.2% |
if y < 3.8999999999999999e149Initial program 96.8%
if 3.8999999999999999e149 < y Initial program 84.4%
Taylor expanded in z around inf 76.8%
Simplified97.3%
[Start]76.8% | \[ \frac{\left(y - -1 \cdot t\right) \cdot x}{z}
\] |
|---|---|
*-commutative [<=]76.8% | \[ \frac{\color{blue}{x \cdot \left(y - -1 \cdot t\right)}}{z}
\] |
associate-/l* [=>]85.2% | \[ \color{blue}{\frac{x}{\frac{z}{y - -1 \cdot t}}}
\] |
associate-/r/ [=>]97.3% | \[ \color{blue}{\frac{x}{z} \cdot \left(y - -1 \cdot t\right)}
\] |
cancel-sign-sub-inv [=>]97.3% | \[ \frac{x}{z} \cdot \color{blue}{\left(y + \left(--1\right) \cdot t\right)}
\] |
metadata-eval [=>]97.3% | \[ \frac{x}{z} \cdot \left(y + \color{blue}{1} \cdot t\right)
\] |
*-lft-identity [=>]97.3% | \[ \frac{x}{z} \cdot \left(y + \color{blue}{t}\right)
\] |
Final simplification96.8%
| Alternative 1 | |
|---|---|
| Accuracy | 94.2% |
| Cost | 836 |
| Alternative 2 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 716 |
| Alternative 3 | |
|---|---|
| Accuracy | 93.7% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Accuracy | 93.6% |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Accuracy | 73.1% |
| Cost | 712 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.6% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Accuracy | 42.5% |
| Cost | 585 |
| Alternative 8 | |
|---|---|
| Accuracy | 44.6% |
| Cost | 585 |
| Alternative 9 | |
|---|---|
| Accuracy | 66.4% |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 584 |
| Alternative 11 | |
|---|---|
| Accuracy | 67.4% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 22.9% |
| Cost | 256 |
herbie shell --seed 2023165
(FPCore (x y z t)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C"
:precision binary64
:herbie-target
(if (< (* x (- (/ y z) (/ t (- 1.0 z)))) -7.623226303312042e-196) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z))))) (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) 1.4133944927702302e-211) (+ (/ (* y x) z) (- (/ (* t x) (- 1.0 z)))) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z)))))))
(* x (- (/ y z) (/ t (- 1.0 z)))))