| Alternative 1 | |
|---|---|
| Accuracy | 8.5% |
| Cost | 26432 |
\[\frac{\pi}{2} + 2 \cdot \left(\cos^{-1} \left(\sqrt{0.5 - 0.5 \cdot x}\right) - \pi \cdot 0.5\right)
\]
(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
(FPCore (x)
:precision binary64
(if (<= x -1.7e-162)
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0)))))
(if (<= x 3.6e-156)
(+ (/ PI 2.0) (* 2.0 (+ 1.0 (- -1.0 (asin (sqrt 0.5))))))
(- (/ PI 2.0) (* 2.0 (asin (/ (sqrt (- 1.0 x)) (sqrt 2.0))))))))double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
double code(double x) {
double tmp;
if (x <= -1.7e-162) {
tmp = (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
} else if (x <= 3.6e-156) {
tmp = (((double) M_PI) / 2.0) + (2.0 * (1.0 + (-1.0 - asin(sqrt(0.5)))));
} else {
tmp = (((double) M_PI) / 2.0) - (2.0 * asin((sqrt((1.0 - x)) / sqrt(2.0))));
}
return tmp;
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
}
public static double code(double x) {
double tmp;
if (x <= -1.7e-162) {
tmp = (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
} else if (x <= 3.6e-156) {
tmp = (Math.PI / 2.0) + (2.0 * (1.0 + (-1.0 - Math.asin(Math.sqrt(0.5)))));
} else {
tmp = (Math.PI / 2.0) - (2.0 * Math.asin((Math.sqrt((1.0 - x)) / Math.sqrt(2.0))));
}
return tmp;
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
def code(x): tmp = 0 if x <= -1.7e-162: tmp = (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0)))) elif x <= 3.6e-156: tmp = (math.pi / 2.0) + (2.0 * (1.0 + (-1.0 - math.asin(math.sqrt(0.5))))) else: tmp = (math.pi / 2.0) - (2.0 * math.asin((math.sqrt((1.0 - x)) / math.sqrt(2.0)))) return tmp
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))) end
function code(x) tmp = 0.0 if (x <= -1.7e-162) tmp = Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))); elseif (x <= 3.6e-156) tmp = Float64(Float64(pi / 2.0) + Float64(2.0 * Float64(1.0 + Float64(-1.0 - asin(sqrt(0.5)))))); else tmp = Float64(Float64(pi / 2.0) - Float64(2.0 * asin(Float64(sqrt(Float64(1.0 - x)) / sqrt(2.0))))); end return tmp end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.7e-162) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); elseif (x <= 3.6e-156) tmp = (pi / 2.0) + (2.0 * (1.0 + (-1.0 - asin(sqrt(0.5))))); else tmp = (pi / 2.0) - (2.0 * asin((sqrt((1.0 - x)) / sqrt(2.0)))); end tmp_2 = tmp; end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -1.7e-162], N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.6e-156], N[(N[(Pi / 2.0), $MachinePrecision] + N[(2.0 * N[(1.0 + N[(-1.0 - N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[(N[Sqrt[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-162}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{-156}:\\
\;\;\;\;\frac{\pi}{2} + 2 \cdot \left(1 + \left(-1 - \sin^{-1} \left(\sqrt{0.5}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)\\
\end{array}
Results
| Original | 7.0% |
|---|---|
| Target | 100.0% |
| Herbie | 9.9% |
if x < -1.7e-162Initial program 12.6%
if -1.7e-162 < x < 3.59999999999999999e-156Initial program 3.3%
Taylor expanded in x around 0 3.3%
Applied egg-rr7.0%
[Start]3.3 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{0.5}\right)
\] |
|---|---|
expm1-log1p-u [=>]3.3 | \[ \frac{\pi}{2} - 2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{0.5}\right)\right)\right)}
\] |
expm1-udef [=>]3.3 | \[ \frac{\pi}{2} - 2 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sin^{-1} \left(\sqrt{0.5}\right)\right)} - 1\right)}
\] |
log1p-udef [=>]7.0 | \[ \frac{\pi}{2} - 2 \cdot \left(e^{\color{blue}{\log \left(1 + \sin^{-1} \left(\sqrt{0.5}\right)\right)}} - 1\right)
\] |
add-exp-log [<=]7.0 | \[ \frac{\pi}{2} - 2 \cdot \left(\color{blue}{\left(1 + \sin^{-1} \left(\sqrt{0.5}\right)\right)} - 1\right)
\] |
if 3.59999999999999999e-156 < x Initial program 8.1%
Applied egg-rr12.6%
[Start]8.1 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\] |
|---|---|
sqrt-div [=>]12.6 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x}}{\sqrt{2}}\right)}
\] |
div-inv [=>]12.6 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\sqrt{1 - x} \cdot \frac{1}{\sqrt{2}}\right)}
\] |
Simplified12.6%
[Start]12.6 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{1 - x} \cdot \frac{1}{\sqrt{2}}\right)
\] |
|---|---|
associate-*r/ [=>]12.6 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \color{blue}{\left(\frac{\sqrt{1 - x} \cdot 1}{\sqrt{2}}\right)}
\] |
*-rgt-identity [=>]12.6 | \[ \frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{\color{blue}{\sqrt{1 - x}}}{\sqrt{2}}\right)
\] |
Final simplification9.9%
| Alternative 1 | |
|---|---|
| Accuracy | 8.5% |
| Cost | 26432 |
| Alternative 2 | |
|---|---|
| Accuracy | 9.9% |
| Cost | 20616 |
| Alternative 3 | |
|---|---|
| Accuracy | 9.9% |
| Cost | 20232 |
| Alternative 4 | |
|---|---|
| Accuracy | 9.2% |
| Cost | 20105 |
| Alternative 5 | |
|---|---|
| Accuracy | 5.8% |
| Cost | 19844 |
| Alternative 6 | |
|---|---|
| Accuracy | 7.0% |
| Cost | 19840 |
| Alternative 7 | |
|---|---|
| Accuracy | 4.1% |
| Cost | 19584 |
herbie shell --seed 2023147
(FPCore (x)
:name "Ian Simplification"
:precision binary64
:herbie-target
(asin x)
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))