| Alternative 1 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 1992 |

(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (/ y z) (/ t (- 1.0 z)))))
(if (<= t_1 (- INFINITY))
(* y (/ x z))
(if (<= t_1 1e+300) (* t_1 x) (/ (* y x) z)))))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 t_1 = (y / z) - (t / (1.0 - z));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = y * (x / z);
} else if (t_1 <= 1e+300) {
tmp = t_1 * x;
} else {
tmp = (y * x) / z;
}
return tmp;
}
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 t_1 = (y / z) - (t / (1.0 - z));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = y * (x / z);
} else if (t_1 <= 1e+300) {
tmp = t_1 * x;
} else {
tmp = (y * x) / z;
}
return tmp;
}
def code(x, y, z, t): return x * ((y / z) - (t / (1.0 - z)))
def code(x, y, z, t): t_1 = (y / z) - (t / (1.0 - z)) tmp = 0 if t_1 <= -math.inf: tmp = y * (x / z) elif t_1 <= 1e+300: tmp = t_1 * x else: tmp = (y * x) / z 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) t_1 = Float64(Float64(y / z) - Float64(t / Float64(1.0 - z))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(y * Float64(x / z)); elseif (t_1 <= 1e+300) tmp = Float64(t_1 * x); else tmp = Float64(Float64(y * x) / z); 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) t_1 = (y / z) - (t / (1.0 - z)); tmp = 0.0; if (t_1 <= -Inf) tmp = y * (x / z); elseif (t_1 <= 1e+300) tmp = t_1 * x; else tmp = (y * x) / z; 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_] := Block[{t$95$1 = N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+300], N[(t$95$1 * x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]]]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{y}{z} - \frac{t}{1 - z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;t_1 \leq 10^{+300}:\\
\;\;\;\;t_1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 94.4% |
|---|---|
| Target | 95.0% |
| Herbie | 98.1% |
if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -inf.0Initial program 53.0%
Applied egg-rr53.0%
[Start]53.0% | \[ x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\] |
|---|---|
frac-2neg [=>]53.0% | \[ x \cdot \left(\color{blue}{\frac{-y}{-z}} - \frac{t}{1 - z}\right)
\] |
div-inv [=>]53.0% | \[ x \cdot \left(\color{blue}{\left(-y\right) \cdot \frac{1}{-z}} - \frac{t}{1 - z}\right)
\] |
fma-neg [=>]53.0% | \[ x \cdot \color{blue}{\mathsf{fma}\left(-y, \frac{1}{-z}, -\frac{t}{1 - z}\right)}
\] |
distribute-neg-frac [=>]53.0% | \[ x \cdot \mathsf{fma}\left(-y, \frac{1}{-z}, \color{blue}{\frac{-t}{1 - z}}\right)
\] |
Simplified53.0%
[Start]53.0% | \[ x \cdot \mathsf{fma}\left(-y, \frac{1}{-z}, \frac{-t}{1 - z}\right)
\] |
|---|---|
fma-udef [=>]53.0% | \[ x \cdot \color{blue}{\left(\left(-y\right) \cdot \frac{1}{-z} + \frac{-t}{1 - z}\right)}
\] |
+-commutative [=>]53.0% | \[ x \cdot \color{blue}{\left(\frac{-t}{1 - z} + \left(-y\right) \cdot \frac{1}{-z}\right)}
\] |
distribute-lft-neg-out [=>]53.0% | \[ x \cdot \left(\frac{-t}{1 - z} + \color{blue}{\left(-y \cdot \frac{1}{-z}\right)}\right)
\] |
unsub-neg [=>]53.0% | \[ x \cdot \color{blue}{\left(\frac{-t}{1 - z} - y \cdot \frac{1}{-z}\right)}
\] |
neg-mul-1 [=>]53.0% | \[ x \cdot \left(\frac{\color{blue}{-1 \cdot t}}{1 - z} - y \cdot \frac{1}{-z}\right)
\] |
*-commutative [=>]53.0% | \[ x \cdot \left(\frac{\color{blue}{t \cdot -1}}{1 - z} - y \cdot \frac{1}{-z}\right)
\] |
associate-*r/ [<=]53.0% | \[ x \cdot \left(\color{blue}{t \cdot \frac{-1}{1 - z}} - y \cdot \frac{1}{-z}\right)
\] |
metadata-eval [<=]53.0% | \[ x \cdot \left(t \cdot \frac{\color{blue}{\frac{1}{-1}}}{1 - z} - y \cdot \frac{1}{-z}\right)
\] |
associate-/r* [<=]53.0% | \[ x \cdot \left(t \cdot \color{blue}{\frac{1}{-1 \cdot \left(1 - z\right)}} - y \cdot \frac{1}{-z}\right)
\] |
neg-mul-1 [<=]53.0% | \[ x \cdot \left(t \cdot \frac{1}{\color{blue}{-\left(1 - z\right)}} - y \cdot \frac{1}{-z}\right)
\] |
associate-*r/ [=>]53.0% | \[ x \cdot \left(\color{blue}{\frac{t \cdot 1}{-\left(1 - z\right)}} - y \cdot \frac{1}{-z}\right)
\] |
*-rgt-identity [=>]53.0% | \[ x \cdot \left(\frac{\color{blue}{t}}{-\left(1 - z\right)} - y \cdot \frac{1}{-z}\right)
\] |
neg-sub0 [=>]53.0% | \[ x \cdot \left(\frac{t}{\color{blue}{0 - \left(1 - z\right)}} - y \cdot \frac{1}{-z}\right)
\] |
associate--r- [=>]53.0% | \[ x \cdot \left(\frac{t}{\color{blue}{\left(0 - 1\right) + z}} - y \cdot \frac{1}{-z}\right)
\] |
metadata-eval [=>]53.0% | \[ x \cdot \left(\frac{t}{\color{blue}{-1} + z} - y \cdot \frac{1}{-z}\right)
\] |
neg-mul-1 [=>]53.0% | \[ x \cdot \left(\frac{t}{-1 + z} - y \cdot \frac{1}{\color{blue}{-1 \cdot z}}\right)
\] |
associate-/r* [=>]53.0% | \[ x \cdot \left(\frac{t}{-1 + z} - y \cdot \color{blue}{\frac{\frac{1}{-1}}{z}}\right)
\] |
metadata-eval [=>]53.0% | \[ x \cdot \left(\frac{t}{-1 + z} - y \cdot \frac{\color{blue}{-1}}{z}\right)
\] |
Taylor expanded in t around 0 99.8%
Simplified99.8%
[Start]99.8% | \[ \frac{y \cdot x}{z}
\] |
|---|---|
associate-*r/ [<=]99.8% | \[ \color{blue}{y \cdot \frac{x}{z}}
\] |
if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.0000000000000001e300Initial program 98.6%
if 1.0000000000000001e300 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) Initial program 81.2%
Taylor expanded in y around inf 100.0%
Final simplification98.8%
| Alternative 1 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 1992 |
| Alternative 2 | |
|---|---|
| Accuracy | 40.3% |
| Cost | 850 |
| Alternative 3 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 848 |
| Alternative 4 | |
|---|---|
| Accuracy | 71.2% |
| Cost | 844 |
| Alternative 5 | |
|---|---|
| Accuracy | 64.7% |
| Cost | 716 |
| Alternative 6 | |
|---|---|
| Accuracy | 89.0% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Accuracy | 93.3% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 62.6% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Accuracy | 22.8% |
| Cost | 256 |
herbie shell --seed 2023272
(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)))))