| Alternative 1 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 3280 |
(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ t (- 1.0 z)))
(t_2 (- (/ y z) t_1))
(t_3 (- (* (/ y z) x) (* t_1 x))))
(if (<= t_2 (- INFINITY))
(/ y (/ z x))
(if (<= t_2 -5e-128)
t_3
(if (<= t_2 0.0)
(/ (* x (+ y t)) z)
(if (<= t_2 1e+289) t_3 (* 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 = t / (1.0 - z);
double t_2 = (y / z) - t_1;
double t_3 = ((y / z) * x) - (t_1 * x);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = y / (z / x);
} else if (t_2 <= -5e-128) {
tmp = t_3;
} else if (t_2 <= 0.0) {
tmp = (x * (y + t)) / z;
} else if (t_2 <= 1e+289) {
tmp = t_3;
} 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 = t / (1.0 - z);
double t_2 = (y / z) - t_1;
double t_3 = ((y / z) * x) - (t_1 * x);
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = y / (z / x);
} else if (t_2 <= -5e-128) {
tmp = t_3;
} else if (t_2 <= 0.0) {
tmp = (x * (y + t)) / z;
} else if (t_2 <= 1e+289) {
tmp = t_3;
} 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 = t / (1.0 - z) t_2 = (y / z) - t_1 t_3 = ((y / z) * x) - (t_1 * x) tmp = 0 if t_2 <= -math.inf: tmp = y / (z / x) elif t_2 <= -5e-128: tmp = t_3 elif t_2 <= 0.0: tmp = (x * (y + t)) / z elif t_2 <= 1e+289: tmp = t_3 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(t / Float64(1.0 - z)) t_2 = Float64(Float64(y / z) - t_1) t_3 = Float64(Float64(Float64(y / z) * x) - Float64(t_1 * x)) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(y / Float64(z / x)); elseif (t_2 <= -5e-128) tmp = t_3; elseif (t_2 <= 0.0) tmp = Float64(Float64(x * Float64(y + t)) / z); elseif (t_2 <= 1e+289) tmp = t_3; else tmp = Float64(y * Float64(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 = t / (1.0 - z); t_2 = (y / z) - t_1; t_3 = ((y / z) * x) - (t_1 * x); tmp = 0.0; if (t_2 <= -Inf) tmp = y / (z / x); elseif (t_2 <= -5e-128) tmp = t_3; elseif (t_2 <= 0.0) tmp = (x * (y + t)) / z; elseif (t_2 <= 1e+289) tmp = t_3; 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[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y / z), $MachinePrecision] - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision] - N[(t$95$1 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -5e-128], t$95$3, If[LessEqual[t$95$2, 0.0], N[(N[(x * N[(y + t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$2, 1e+289], t$95$3, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]]]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{t}{1 - z}\\
t_2 := \frac{y}{z} - t_1\\
t_3 := \frac{y}{z} \cdot x - t_1 \cdot x\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;t_2 \leq -5 \cdot 10^{-128}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{x \cdot \left(y + t\right)}{z}\\
\mathbf{elif}\;t_2 \leq 10^{+289}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
Results
| Original | 92.4% |
|---|---|
| Target | 92.9% |
| Herbie | 98.5% |
if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -inf.0Initial program 0.0%
Taylor expanded in y around inf 99.6%
Simplified99.6%
[Start]99.6 | \[ \frac{y \cdot x}{z}
\] |
|---|---|
associate-/l* [=>]99.6 | \[ \color{blue}{\frac{y}{\frac{z}{x}}}
\] |
if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -5.0000000000000001e-128 or 0.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.0000000000000001e289Initial program 99.6%
Applied egg-rr99.6%
[Start]99.6 | \[ x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\] |
|---|---|
sub-neg [=>]99.6 | \[ x \cdot \color{blue}{\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)}
\] |
distribute-rgt-in [=>]99.6 | \[ \color{blue}{\frac{y}{z} \cdot x + \left(-\frac{t}{1 - z}\right) \cdot x}
\] |
+-commutative [=>]99.6 | \[ \color{blue}{\left(-\frac{t}{1 - z}\right) \cdot x + \frac{y}{z} \cdot x}
\] |
distribute-neg-frac [=>]99.6 | \[ \color{blue}{\frac{-t}{1 - z}} \cdot x + \frac{y}{z} \cdot x
\] |
Taylor expanded in t around 0 86.1%
Simplified99.6%
[Start]86.1 | \[ \frac{y \cdot x}{z} + -1 \cdot \frac{t \cdot x}{1 - z}
\] |
|---|---|
associate-*l/ [<=]93.5 | \[ \color{blue}{\frac{y}{z} \cdot x} + -1 \cdot \frac{t \cdot x}{1 - z}
\] |
associate-*l/ [<=]99.6 | \[ \frac{y}{z} \cdot x + -1 \cdot \color{blue}{\left(\frac{t}{1 - z} \cdot x\right)}
\] |
*-commutative [<=]99.6 | \[ \frac{y}{z} \cdot x + -1 \cdot \color{blue}{\left(x \cdot \frac{t}{1 - z}\right)}
\] |
mul-1-neg [=>]99.6 | \[ \frac{y}{z} \cdot x + \color{blue}{\left(-x \cdot \frac{t}{1 - z}\right)}
\] |
sub-neg [<=]99.6 | \[ \color{blue}{\frac{y}{z} \cdot x - x \cdot \frac{t}{1 - z}}
\] |
*-commutative [=>]99.6 | \[ \color{blue}{x \cdot \frac{y}{z}} - x \cdot \frac{t}{1 - z}
\] |
if -5.0000000000000001e-128 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 0.0Initial program 87.9%
Applied egg-rr87.9%
[Start]87.9 | \[ x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\] |
|---|---|
sub-neg [=>]87.9 | \[ x \cdot \color{blue}{\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)}
\] |
distribute-rgt-in [=>]87.9 | \[ \color{blue}{\frac{y}{z} \cdot x + \left(-\frac{t}{1 - z}\right) \cdot x}
\] |
+-commutative [=>]87.9 | \[ \color{blue}{\left(-\frac{t}{1 - z}\right) \cdot x + \frac{y}{z} \cdot x}
\] |
distribute-neg-frac [=>]87.9 | \[ \color{blue}{\frac{-t}{1 - z}} \cdot x + \frac{y}{z} \cdot x
\] |
Taylor expanded in z around inf 94.1%
Simplified94.1%
[Start]94.1 | \[ \frac{t \cdot x + y \cdot x}{z}
\] |
|---|---|
distribute-rgt-out [=>]94.1 | \[ \frac{\color{blue}{x \cdot \left(t + y\right)}}{z}
\] |
if 1.0000000000000001e289 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) Initial program 24.9%
Taylor expanded in z around 0 24.7%
Applied egg-rr24.6%
[Start]24.7 | \[ x \cdot \left(\frac{y}{z} - t\right)
\] |
|---|---|
flip3-- [=>]0.0 | \[ x \cdot \color{blue}{\frac{{\left(\frac{y}{z}\right)}^{3} - {t}^{3}}{\frac{y}{z} \cdot \frac{y}{z} + \left(t \cdot t + \frac{y}{z} \cdot t\right)}}
\] |
associate-*r/ [=>]0.0 | \[ \color{blue}{\frac{x \cdot \left({\left(\frac{y}{z}\right)}^{3} - {t}^{3}\right)}{\frac{y}{z} \cdot \frac{y}{z} + \left(t \cdot t + \frac{y}{z} \cdot t\right)}}
\] |
associate-/l* [=>]0.0 | \[ \color{blue}{\frac{x}{\frac{\frac{y}{z} \cdot \frac{y}{z} + \left(t \cdot t + \frac{y}{z} \cdot t\right)}{{\left(\frac{y}{z}\right)}^{3} - {t}^{3}}}}
\] |
*-un-lft-identity [=>]0.0 | \[ \frac{x}{\frac{\color{blue}{1 \cdot \left(\frac{y}{z} \cdot \frac{y}{z} + \left(t \cdot t + \frac{y}{z} \cdot t\right)\right)}}{{\left(\frac{y}{z}\right)}^{3} - {t}^{3}}}
\] |
associate-/l* [=>]0.0 | \[ \frac{x}{\color{blue}{\frac{1}{\frac{{\left(\frac{y}{z}\right)}^{3} - {t}^{3}}{\frac{y}{z} \cdot \frac{y}{z} + \left(t \cdot t + \frac{y}{z} \cdot t\right)}}}}
\] |
flip3-- [<=]24.6 | \[ \frac{x}{\frac{1}{\color{blue}{\frac{y}{z} - t}}}
\] |
Taylor expanded in y around inf 90.2%
Simplified90.2%
[Start]90.2 | \[ \frac{y \cdot x}{z}
\] |
|---|---|
*-commutative [=>]90.2 | \[ \frac{\color{blue}{x \cdot y}}{z}
\] |
associate-/l* [=>]23.5 | \[ \color{blue}{\frac{x}{\frac{z}{y}}}
\] |
associate-/r/ [=>]90.2 | \[ \color{blue}{\frac{x}{z} \cdot y}
\] |
Final simplification98.5%
| Alternative 1 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 3280 |
| Alternative 2 | |
|---|---|
| Accuracy | 58.4% |
| Cost | 1509 |
| Alternative 3 | |
|---|---|
| Accuracy | 58.5% |
| Cost | 1509 |
| Alternative 4 | |
|---|---|
| Accuracy | 57.8% |
| Cost | 1244 |
| Alternative 5 | |
|---|---|
| Accuracy | 68.7% |
| Cost | 981 |
| Alternative 6 | |
|---|---|
| Accuracy | 68.7% |
| Cost | 980 |
| Alternative 7 | |
|---|---|
| Accuracy | 91.2% |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Accuracy | 84.3% |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 713 |
| Alternative 10 | |
|---|---|
| Accuracy | 91.4% |
| Cost | 713 |
| Alternative 11 | |
|---|---|
| Accuracy | 91.2% |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Accuracy | 48.0% |
| Cost | 585 |
| Alternative 13 | |
|---|---|
| Accuracy | 20.7% |
| Cost | 256 |
herbie shell --seed 2023133
(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)))))