
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos((1.0d0 - x))
end function
public static double code(double x) {
return Math.acos((1.0 - x));
}
def code(x): return math.acos((1.0 - x))
function code(x) return acos(Float64(1.0 - x)) end
function tmp = code(x) tmp = acos((1.0 - x)); end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(1 - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos((1.0d0 - x))
end function
public static double code(double x) {
return Math.acos((1.0 - x));
}
def code(x): return math.acos((1.0 - x))
function code(x) return acos(Float64(1.0 - x)) end
function tmp = code(x) tmp = acos((1.0 - x)); end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(1 - x\right)
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))) (t_1 (pow t_0 2.0)))
(/
(+ (- (* 0.25 (pow PI 2.0)) t_1) (fma (- t_0) t_0 t_1))
(+ t_0 (* PI 0.5)))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = pow(t_0, 2.0);
return (((0.25 * pow(((double) M_PI), 2.0)) - t_1) + fma(-t_0, t_0, t_1)) / (t_0 + (((double) M_PI) * 0.5));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = t_0 ^ 2.0 return Float64(Float64(Float64(Float64(0.25 * (pi ^ 2.0)) - t_1) + fma(Float64(-t_0), t_0, t_1)) / Float64(t_0 + Float64(pi * 0.5))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, N[(N[(N[(N[(0.25 * N[Power[Pi, 2.0], $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision] + N[((-t$95$0) * t$95$0 + t$95$1), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := {t_0}^{2}\\
\frac{\left(0.25 \cdot {\pi}^{2} - t_1\right) + \mathsf{fma}\left(-t_0, t_0, t_1\right)}{t_0 + \pi \cdot 0.5}
\end{array}
\end{array}
Initial program 8.6%
acos-asin8.6%
flip--8.6%
div-inv8.6%
metadata-eval8.6%
div-inv8.6%
metadata-eval8.6%
div-inv8.6%
metadata-eval8.6%
Applied egg-rr8.6%
expm1-log1p-u8.6%
expm1-udef12.2%
pow212.2%
Applied egg-rr12.2%
expm1-def8.6%
expm1-log1p-u8.6%
unpow28.6%
prod-diff8.6%
unpow28.6%
fma-neg12.3%
pow212.3%
*-commutative12.3%
unpow-prod-down12.3%
metadata-eval12.3%
unpow212.3%
Applied egg-rr12.3%
Final simplification12.3%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (asin (- 1.0 x))))) (+ (acos (- 1.0 x)) (fma (- t_0) t_0 (pow t_0 2.0)))))
double code(double x) {
double t_0 = sqrt(asin((1.0 - x)));
return acos((1.0 - x)) + fma(-t_0, t_0, pow(t_0, 2.0));
}
function code(x) t_0 = sqrt(asin(Float64(1.0 - x))) return Float64(acos(Float64(1.0 - x)) + fma(Float64(-t_0), t_0, (t_0 ^ 2.0))) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[((-t$95$0) * t$95$0 + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\sin^{-1} \left(1 - x\right)}\\
\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t_0, t_0, {t_0}^{2}\right)
\end{array}
\end{array}
Initial program 8.6%
add-sqr-sqrt8.6%
pow28.6%
Applied egg-rr8.6%
unpow28.6%
add-sqr-sqrt8.6%
acos-asin8.6%
div-inv8.6%
metadata-eval8.6%
add-sqr-sqrt12.2%
prod-diff12.2%
add-sqr-sqrt12.3%
fma-neg12.3%
metadata-eval12.3%
div-inv12.3%
acos-asin12.3%
add-sqr-sqrt12.2%
Applied egg-rr12.2%
add-sqr-sqrt12.2%
pow212.2%
Applied egg-rr12.3%
Final simplification12.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))))
(/
(- (* (* PI 0.5) (* PI 0.5)) (+ (exp (log1p (pow t_0 2.0))) -1.0))
(+ t_0 (* PI 0.5)))))
double code(double x) {
double t_0 = asin((1.0 - x));
return (((((double) M_PI) * 0.5) * (((double) M_PI) * 0.5)) - (exp(log1p(pow(t_0, 2.0))) + -1.0)) / (t_0 + (((double) M_PI) * 0.5));
}
public static double code(double x) {
double t_0 = Math.asin((1.0 - x));
return (((Math.PI * 0.5) * (Math.PI * 0.5)) - (Math.exp(Math.log1p(Math.pow(t_0, 2.0))) + -1.0)) / (t_0 + (Math.PI * 0.5));
}
def code(x): t_0 = math.asin((1.0 - x)) return (((math.pi * 0.5) * (math.pi * 0.5)) - (math.exp(math.log1p(math.pow(t_0, 2.0))) + -1.0)) / (t_0 + (math.pi * 0.5))
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(Float64(Float64(Float64(pi * 0.5) * Float64(pi * 0.5)) - Float64(exp(log1p((t_0 ^ 2.0))) + -1.0)) / Float64(t_0 + Float64(pi * 0.5))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(Pi * 0.5), $MachinePrecision] * N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision] - N[(N[Exp[N[Log[1 + N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{\left(\pi \cdot 0.5\right) \cdot \left(\pi \cdot 0.5\right) - \left(e^{\mathsf{log1p}\left({t_0}^{2}\right)} + -1\right)}{t_0 + \pi \cdot 0.5}
\end{array}
\end{array}
Initial program 8.6%
acos-asin8.6%
flip--8.6%
div-inv8.6%
metadata-eval8.6%
div-inv8.6%
metadata-eval8.6%
div-inv8.6%
metadata-eval8.6%
Applied egg-rr8.6%
expm1-log1p-u8.6%
expm1-udef12.2%
pow212.2%
Applied egg-rr12.2%
Final simplification12.2%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0))) (+ (+ (+ 1.0 (acos (- 1.0 x))) -1.0) (fma (- t_1) t_1 t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt(t_0);
return ((1.0 + acos((1.0 - x))) + -1.0) + fma(-t_1, t_1, t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(t_0) return Float64(Float64(Float64(1.0 + acos(Float64(1.0 - x))) + -1.0) + fma(Float64(-t_1), t_1, t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, N[(N[(N[(1.0 + N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[((-t$95$1) * t$95$1 + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t_0}\\
\left(\left(1 + \cos^{-1} \left(1 - x\right)\right) + -1\right) + \mathsf{fma}\left(-t_1, t_1, t_0\right)
\end{array}
\end{array}
Initial program 8.6%
add-sqr-sqrt8.6%
pow28.6%
Applied egg-rr8.6%
unpow28.6%
add-sqr-sqrt8.6%
acos-asin8.6%
div-inv8.6%
metadata-eval8.6%
add-sqr-sqrt12.2%
prod-diff12.2%
add-sqr-sqrt12.3%
fma-neg12.3%
metadata-eval12.3%
div-inv12.3%
acos-asin12.3%
add-sqr-sqrt12.2%
Applied egg-rr12.2%
expm1-log1p-u12.2%
expm1-udef12.2%
log1p-udef12.2%
add-exp-log12.2%
Applied egg-rr12.2%
Final simplification12.2%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0))) (+ (acos (- 1.0 x)) (fma (- t_1) t_1 t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt(t_0);
return acos((1.0 - x)) + fma(-t_1, t_1, t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(t_0) return Float64(acos(Float64(1.0 - x)) + fma(Float64(-t_1), t_1, t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[((-t$95$1) * t$95$1 + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t_0}\\
\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t_1, t_1, t_0\right)
\end{array}
\end{array}
Initial program 8.6%
add-sqr-sqrt8.6%
pow28.6%
Applied egg-rr8.6%
unpow28.6%
add-sqr-sqrt8.6%
acos-asin8.6%
div-inv8.6%
metadata-eval8.6%
add-sqr-sqrt12.2%
prod-diff12.2%
add-sqr-sqrt12.3%
fma-neg12.3%
metadata-eval12.3%
div-inv12.3%
acos-asin12.3%
add-sqr-sqrt12.2%
Applied egg-rr12.2%
Final simplification12.2%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0))) (+ (acos (- 1.0 x)) (- t_0 (* t_1 t_1)))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt(t_0);
return acos((1.0 - x)) + (t_0 - (t_1 * t_1));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
t_0 = asin((1.0d0 - x))
t_1 = sqrt(t_0)
code = acos((1.0d0 - x)) + (t_0 - (t_1 * t_1))
end function
public static double code(double x) {
double t_0 = Math.asin((1.0 - x));
double t_1 = Math.sqrt(t_0);
return Math.acos((1.0 - x)) + (t_0 - (t_1 * t_1));
}
def code(x): t_0 = math.asin((1.0 - x)) t_1 = math.sqrt(t_0) return math.acos((1.0 - x)) + (t_0 - (t_1 * t_1))
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(t_0) return Float64(acos(Float64(1.0 - x)) + Float64(t_0 - Float64(t_1 * t_1))) end
function tmp = code(x) t_0 = asin((1.0 - x)); t_1 = sqrt(t_0); tmp = acos((1.0 - x)) + (t_0 - (t_1 * t_1)); end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 - N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t_0}\\
\cos^{-1} \left(1 - x\right) + \left(t_0 - t_1 \cdot t_1\right)
\end{array}
\end{array}
Initial program 8.6%
add-sqr-sqrt8.6%
pow28.6%
Applied egg-rr8.6%
unpow28.6%
add-sqr-sqrt8.6%
acos-asin8.6%
div-inv8.6%
metadata-eval8.6%
add-sqr-sqrt12.2%
prod-diff12.2%
add-sqr-sqrt12.3%
fma-neg12.3%
metadata-eval12.3%
div-inv12.3%
acos-asin12.3%
add-sqr-sqrt12.2%
Applied egg-rr12.2%
fma-udef12.2%
Applied egg-rr12.2%
Final simplification12.2%
(FPCore (x) :precision binary64 (exp (log (- (* PI 0.5) (pow (cbrt (asin (- 1.0 x))) 3.0)))))
double code(double x) {
return exp(log(((((double) M_PI) * 0.5) - pow(cbrt(asin((1.0 - x))), 3.0))));
}
public static double code(double x) {
return Math.exp(Math.log(((Math.PI * 0.5) - Math.pow(Math.cbrt(Math.asin((1.0 - x))), 3.0))));
}
function code(x) return exp(log(Float64(Float64(pi * 0.5) - (cbrt(asin(Float64(1.0 - x))) ^ 3.0)))) end
code[x_] := N[Exp[N[Log[N[(N[(Pi * 0.5), $MachinePrecision] - N[Power[N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\pi \cdot 0.5 - {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}\right)}
\end{array}
Initial program 8.6%
add-exp-log8.6%
Applied egg-rr8.6%
acos-asin8.6%
sub-neg8.6%
div-inv8.6%
metadata-eval8.6%
Applied egg-rr8.6%
sub-neg8.6%
Simplified8.6%
add-cube-cbrt12.2%
pow312.2%
Applied egg-rr12.2%
Final simplification12.2%
(FPCore (x) :precision binary64 (exp (log (- (* PI 0.5) (pow (sqrt (asin (- 1.0 x))) 2.0)))))
double code(double x) {
return exp(log(((((double) M_PI) * 0.5) - pow(sqrt(asin((1.0 - x))), 2.0))));
}
public static double code(double x) {
return Math.exp(Math.log(((Math.PI * 0.5) - Math.pow(Math.sqrt(Math.asin((1.0 - x))), 2.0))));
}
def code(x): return math.exp(math.log(((math.pi * 0.5) - math.pow(math.sqrt(math.asin((1.0 - x))), 2.0))))
function code(x) return exp(log(Float64(Float64(pi * 0.5) - (sqrt(asin(Float64(1.0 - x))) ^ 2.0)))) end
function tmp = code(x) tmp = exp(log(((pi * 0.5) - (sqrt(asin((1.0 - x))) ^ 2.0)))); end
code[x_] := N[Exp[N[Log[N[(N[(Pi * 0.5), $MachinePrecision] - N[Power[N[Sqrt[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\pi \cdot 0.5 - {\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)}
\end{array}
Initial program 8.6%
add-exp-log8.6%
Applied egg-rr8.6%
acos-asin8.6%
sub-neg8.6%
div-inv8.6%
metadata-eval8.6%
Applied egg-rr8.6%
sub-neg8.6%
Simplified8.6%
add-sqr-sqrt12.2%
pow212.2%
Applied egg-rr12.2%
Final simplification12.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- 1.0 x))) (t_1 (- 1.0 t_0)) (t_2 (+ t_0 -1.0)))
(if (<= t_0 0.0)
(+ 1.0 (sqrt (pow t_2 2.0)))
(/ (+ 1.0 (* t_2 t_1)) (+ 1.0 t_1)))))
double code(double x) {
double t_0 = acos((1.0 - x));
double t_1 = 1.0 - t_0;
double t_2 = t_0 + -1.0;
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0 + sqrt(pow(t_2, 2.0));
} else {
tmp = (1.0 + (t_2 * t_1)) / (1.0 + t_1);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = acos((1.0d0 - x))
t_1 = 1.0d0 - t_0
t_2 = t_0 + (-1.0d0)
if (t_0 <= 0.0d0) then
tmp = 1.0d0 + sqrt((t_2 ** 2.0d0))
else
tmp = (1.0d0 + (t_2 * t_1)) / (1.0d0 + t_1)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.acos((1.0 - x));
double t_1 = 1.0 - t_0;
double t_2 = t_0 + -1.0;
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0 + Math.sqrt(Math.pow(t_2, 2.0));
} else {
tmp = (1.0 + (t_2 * t_1)) / (1.0 + t_1);
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) t_1 = 1.0 - t_0 t_2 = t_0 + -1.0 tmp = 0 if t_0 <= 0.0: tmp = 1.0 + math.sqrt(math.pow(t_2, 2.0)) else: tmp = (1.0 + (t_2 * t_1)) / (1.0 + t_1) return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) t_1 = Float64(1.0 - t_0) t_2 = Float64(t_0 + -1.0) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(1.0 + sqrt((t_2 ^ 2.0))); else tmp = Float64(Float64(1.0 + Float64(t_2 * t_1)) / Float64(1.0 + t_1)); end return tmp end
function tmp_2 = code(x) t_0 = acos((1.0 - x)); t_1 = 1.0 - t_0; t_2 = t_0 + -1.0; tmp = 0.0; if (t_0 <= 0.0) tmp = 1.0 + sqrt((t_2 ^ 2.0)); else tmp = (1.0 + (t_2 * t_1)) / (1.0 + t_1); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 + -1.0), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(1.0 + N[Sqrt[N[Power[t$95$2, 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$2 * t$95$1), $MachinePrecision]), $MachinePrecision] / N[(1.0 + t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
t_1 := 1 - t_0\\
t_2 := t_0 + -1\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1 + \sqrt{{t_2}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + t_2 \cdot t_1}{1 + t_1}\\
\end{array}
\end{array}
if (acos.f64 (-.f64 1 x)) < 0.0Initial program 3.8%
add-sqr-sqrt3.8%
pow23.8%
Applied egg-rr3.8%
unpow23.8%
add-sqr-sqrt3.8%
expm1-log1p-u3.8%
expm1-udef3.8%
log1p-udef3.8%
add-exp-log3.8%
associate--l+3.8%
+-commutative3.8%
sub-neg3.8%
metadata-eval3.8%
Applied egg-rr3.8%
add-sqr-sqrt0.0%
sqrt-unprod6.8%
pow26.8%
Applied egg-rr6.8%
if 0.0 < (acos.f64 (-.f64 1 x)) Initial program 65.8%
add-sqr-sqrt65.9%
pow265.9%
Applied egg-rr65.9%
unpow265.9%
add-sqr-sqrt65.8%
expm1-log1p-u65.8%
expm1-udef65.8%
log1p-udef65.8%
add-exp-log65.8%
associate--l+65.9%
flip-+65.9%
metadata-eval65.9%
sub-neg65.9%
metadata-eval65.9%
sub-neg65.9%
metadata-eval65.9%
sub-neg65.9%
metadata-eval65.9%
Applied egg-rr65.9%
Final simplification11.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- 1.0 x))))
(if (<= t_0 0.0)
(+ 1.0 (sqrt (pow (+ t_0 -1.0) 2.0)))
(pow (sqrt t_0) 2.0))))
double code(double x) {
double t_0 = acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0 + sqrt(pow((t_0 + -1.0), 2.0));
} else {
tmp = pow(sqrt(t_0), 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = acos((1.0d0 - x))
if (t_0 <= 0.0d0) then
tmp = 1.0d0 + sqrt(((t_0 + (-1.0d0)) ** 2.0d0))
else
tmp = sqrt(t_0) ** 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0 + Math.sqrt(Math.pow((t_0 + -1.0), 2.0));
} else {
tmp = Math.pow(Math.sqrt(t_0), 2.0);
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) tmp = 0 if t_0 <= 0.0: tmp = 1.0 + math.sqrt(math.pow((t_0 + -1.0), 2.0)) else: tmp = math.pow(math.sqrt(t_0), 2.0) return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(1.0 + sqrt((Float64(t_0 + -1.0) ^ 2.0))); else tmp = sqrt(t_0) ^ 2.0; end return tmp end
function tmp_2 = code(x) t_0 = acos((1.0 - x)); tmp = 0.0; if (t_0 <= 0.0) tmp = 1.0 + sqrt(((t_0 + -1.0) ^ 2.0)); else tmp = sqrt(t_0) ^ 2.0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(1.0 + N[Sqrt[N[Power[N[(t$95$0 + -1.0), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Sqrt[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1 + \sqrt{{\left(t_0 + -1\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt{t_0}\right)}^{2}\\
\end{array}
\end{array}
if (acos.f64 (-.f64 1 x)) < 0.0Initial program 3.8%
add-sqr-sqrt3.8%
pow23.8%
Applied egg-rr3.8%
unpow23.8%
add-sqr-sqrt3.8%
expm1-log1p-u3.8%
expm1-udef3.8%
log1p-udef3.8%
add-exp-log3.8%
associate--l+3.8%
+-commutative3.8%
sub-neg3.8%
metadata-eval3.8%
Applied egg-rr3.8%
add-sqr-sqrt0.0%
sqrt-unprod6.8%
pow26.8%
Applied egg-rr6.8%
if 0.0 < (acos.f64 (-.f64 1 x)) Initial program 65.8%
add-sqr-sqrt65.9%
pow265.9%
Applied egg-rr65.9%
Final simplification11.4%
(FPCore (x) :precision binary64 (pow (sqrt (acos (- 1.0 x))) 2.0))
double code(double x) {
return pow(sqrt(acos((1.0 - x))), 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(acos((1.0d0 - x))) ** 2.0d0
end function
public static double code(double x) {
return Math.pow(Math.sqrt(Math.acos((1.0 - x))), 2.0);
}
def code(x): return math.pow(math.sqrt(math.acos((1.0 - x))), 2.0)
function code(x) return sqrt(acos(Float64(1.0 - x))) ^ 2.0 end
function tmp = code(x) tmp = sqrt(acos((1.0 - x))) ^ 2.0; end
code[x_] := N[Power[N[Sqrt[N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\sqrt{\cos^{-1} \left(1 - x\right)}\right)}^{2}
\end{array}
Initial program 8.6%
add-sqr-sqrt8.6%
pow28.6%
Applied egg-rr8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (log (exp (acos (- 1.0 x)))))
double code(double x) {
return log(exp(acos((1.0 - x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log(exp(acos((1.0d0 - x))))
end function
public static double code(double x) {
return Math.log(Math.exp(Math.acos((1.0 - x))));
}
def code(x): return math.log(math.exp(math.acos((1.0 - x))))
function code(x) return log(exp(acos(Float64(1.0 - x)))) end
function tmp = code(x) tmp = log(exp(acos((1.0 - x)))); end
code[x_] := N[Log[N[Exp[N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{\cos^{-1} \left(1 - x\right)}\right)
\end{array}
Initial program 8.6%
add-log-exp8.6%
Applied egg-rr8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (+ 1.0 (+ (acos (- 1.0 x)) -1.0)))
double code(double x) {
return 1.0 + (acos((1.0 - x)) + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + (acos((1.0d0 - x)) + (-1.0d0))
end function
public static double code(double x) {
return 1.0 + (Math.acos((1.0 - x)) + -1.0);
}
def code(x): return 1.0 + (math.acos((1.0 - x)) + -1.0)
function code(x) return Float64(1.0 + Float64(acos(Float64(1.0 - x)) + -1.0)) end
function tmp = code(x) tmp = 1.0 + (acos((1.0 - x)) + -1.0); end
code[x_] := N[(1.0 + N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(\cos^{-1} \left(1 - x\right) + -1\right)
\end{array}
Initial program 8.6%
add-sqr-sqrt8.6%
pow28.6%
Applied egg-rr8.6%
unpow28.6%
add-sqr-sqrt8.6%
expm1-log1p-u8.6%
expm1-udef8.6%
log1p-udef8.6%
add-exp-log8.6%
associate--l+8.6%
+-commutative8.6%
sub-neg8.6%
metadata-eval8.6%
Applied egg-rr8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos((1.0d0 - x))
end function
public static double code(double x) {
return Math.acos((1.0 - x));
}
def code(x): return math.acos((1.0 - x))
function code(x) return acos(Float64(1.0 - x)) end
function tmp = code(x) tmp = acos((1.0 - x)); end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(1 - x\right)
\end{array}
Initial program 8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (* 2.0 (asin (sqrt (/ x 2.0)))))
double code(double x) {
return 2.0 * asin(sqrt((x / 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 * asin(sqrt((x / 2.0d0)))
end function
public static double code(double x) {
return 2.0 * Math.asin(Math.sqrt((x / 2.0)));
}
def code(x): return 2.0 * math.asin(math.sqrt((x / 2.0)))
function code(x) return Float64(2.0 * asin(sqrt(Float64(x / 2.0)))) end
function tmp = code(x) tmp = 2.0 * asin(sqrt((x / 2.0))); end
code[x_] := N[(2.0 * N[ArcSin[N[Sqrt[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \sin^{-1} \left(\sqrt{\frac{x}{2}}\right)
\end{array}
herbie shell --seed 2023240
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
:herbie-target
(* 2.0 (asin (sqrt (/ x 2.0))))
(acos (- 1.0 x)))