
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
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}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
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 (- x 1.0)))
(t_1 (+ (/ PI -2.0) t_0))
(t_2 (asin (- 1.0 x)))
(t_3 (+ (pow t_2 3.0) (pow (/ PI 2.0) 3.0))))
(/
(fma
(* (* (fma (* 0.5 PI) (acos (- 1.0 x)) (pow t_2 2.0)) (* PI PI)) 0.25)
t_1
(* t_3 (pow t_0 2.0)))
(* t_3 t_1))))
double code(double x) {
double t_0 = asin((x - 1.0));
double t_1 = (((double) M_PI) / -2.0) + t_0;
double t_2 = asin((1.0 - x));
double t_3 = pow(t_2, 3.0) + pow((((double) M_PI) / 2.0), 3.0);
return fma(((fma((0.5 * ((double) M_PI)), acos((1.0 - x)), pow(t_2, 2.0)) * (((double) M_PI) * ((double) M_PI))) * 0.25), t_1, (t_3 * pow(t_0, 2.0))) / (t_3 * t_1);
}
function code(x) t_0 = asin(Float64(x - 1.0)) t_1 = Float64(Float64(pi / -2.0) + t_0) t_2 = asin(Float64(1.0 - x)) t_3 = Float64((t_2 ^ 3.0) + (Float64(pi / 2.0) ^ 3.0)) return Float64(fma(Float64(Float64(fma(Float64(0.5 * pi), acos(Float64(1.0 - x)), (t_2 ^ 2.0)) * Float64(pi * pi)) * 0.25), t_1, Float64(t_3 * (t_0 ^ 2.0))) / Float64(t_3 * t_1)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(Pi / -2.0), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[t$95$2, 3.0], $MachinePrecision] + N[Power[N[(Pi / 2.0), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(N[(N[(0.5 * Pi), $MachinePrecision] * N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[Power[t$95$2, 2.0], $MachinePrecision]), $MachinePrecision] * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] * 0.25), $MachinePrecision] * t$95$1 + N[(t$95$3 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$3 * t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(x - 1\right)\\
t_1 := \frac{\pi}{-2} + t\_0\\
t_2 := \sin^{-1} \left(1 - x\right)\\
t_3 := {t\_2}^{3} + {\left(\frac{\pi}{2}\right)}^{3}\\
\frac{\mathsf{fma}\left(\left(\mathsf{fma}\left(0.5 \cdot \pi, \cos^{-1} \left(1 - x\right), {t\_2}^{2}\right) \cdot \left(\pi \cdot \pi\right)\right) \cdot 0.25, t\_1, t\_3 \cdot {t\_0}^{2}\right)}{t\_3 \cdot t\_1}
\end{array}
\end{array}
Initial program 6.8%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
lower--.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-asin.f64N/A
lift--.f646.8
Applied rewrites6.8%
Applied rewrites10.3%
Applied rewrites10.3%
Taylor expanded in x around 0
Applied rewrites10.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- x 1.0))))
(fma
(* PI PI)
(/ 0.25 (fma PI 0.5 (asin (- 1.0 x))))
(/ (pow t_0 2.0) (fma -0.5 PI t_0)))))
double code(double x) {
double t_0 = asin((x - 1.0));
return fma((((double) M_PI) * ((double) M_PI)), (0.25 / fma(((double) M_PI), 0.5, asin((1.0 - x)))), (pow(t_0, 2.0) / fma(-0.5, ((double) M_PI), t_0)));
}
function code(x) t_0 = asin(Float64(x - 1.0)) return fma(Float64(pi * pi), Float64(0.25 / fma(pi, 0.5, asin(Float64(1.0 - x)))), Float64((t_0 ^ 2.0) / fma(-0.5, pi, t_0))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(Pi * Pi), $MachinePrecision] * N[(0.25 / N[(Pi * 0.5 + N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[t$95$0, 2.0], $MachinePrecision] / N[(-0.5 * Pi + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(x - 1\right)\\
\mathsf{fma}\left(\pi \cdot \pi, \frac{0.25}{\mathsf{fma}\left(\pi, 0.5, \sin^{-1} \left(1 - x\right)\right)}, \frac{{t\_0}^{2}}{\mathsf{fma}\left(-0.5, \pi, t\_0\right)}\right)
\end{array}
\end{array}
Initial program 6.8%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
lower--.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-asin.f64N/A
lift--.f646.8
Applied rewrites6.8%
Taylor expanded in x around 0
acos-asin-revN/A
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-asin.f64N/A
lift--.f646.8
Applied rewrites6.8%
Applied rewrites10.3%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (/ (fma t_0 (asin (+ -1.0 x)) (pow (/ PI 2.0) 2.0)) (+ (/ PI 2.0) t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
return fma(t_0, asin((-1.0 + x)), pow((((double) M_PI) / 2.0), 2.0)) / ((((double) M_PI) / 2.0) + t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(fma(t_0, asin(Float64(-1.0 + x)), (Float64(pi / 2.0) ^ 2.0)) / Float64(Float64(pi / 2.0) + t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * N[ArcSin[N[(-1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Power[N[(Pi / 2.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(Pi / 2.0), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{\mathsf{fma}\left(t\_0, \sin^{-1} \left(-1 + x\right), {\left(\frac{\pi}{2}\right)}^{2}\right)}{\frac{\pi}{2} + t\_0}
\end{array}
\end{array}
Initial program 6.8%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites6.8%
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-asin.f64N/A
lift--.f64N/A
lift-asin.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites10.3%
(FPCore (x) :precision binary64 (let* ((t_0 (pow (asin (- 1.0 x)) 0.5))) (- (/ PI 2.0) (* t_0 t_0))))
double code(double x) {
double t_0 = pow(asin((1.0 - x)), 0.5);
return (((double) M_PI) / 2.0) - (t_0 * t_0);
}
public static double code(double x) {
double t_0 = Math.pow(Math.asin((1.0 - x)), 0.5);
return (Math.PI / 2.0) - (t_0 * t_0);
}
def code(x): t_0 = math.pow(math.asin((1.0 - x)), 0.5) return (math.pi / 2.0) - (t_0 * t_0)
function code(x) t_0 = asin(Float64(1.0 - x)) ^ 0.5 return Float64(Float64(pi / 2.0) - Float64(t_0 * t_0)) end
function tmp = code(x) t_0 = asin((1.0 - x)) ^ 0.5; tmp = (pi / 2.0) - (t_0 * t_0); end
code[x_] := Block[{t$95$0 = N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 0.5], $MachinePrecision]}, N[(N[(Pi / 2.0), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin^{-1} \left(1 - x\right)}^{0.5}\\
\frac{\pi}{2} - t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 6.8%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
lower--.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-asin.f64N/A
lift--.f646.8
Applied rewrites6.8%
lift--.f64N/A
lift-asin.f64N/A
unpow1N/A
sqr-powN/A
lower-*.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-asin.f64N/A
lift--.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-asin.f64N/A
lift--.f6410.2
Applied rewrites10.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))))
(if (<= x 5.5e-17)
(/
(fma (/ PI 2.0) (/ PI 2.0) (* (asin (- x 1.0)) (asin (- x))))
(+ (/ PI 2.0) t_0))
(/
(- (* (/ PI 2.0) (/ PI 2.0)) (* t_0 t_0))
(+ (/ PI 2.0) (asin (/ (- 1.0 (* x x)) (+ x 1.0))))))))
double code(double x) {
double t_0 = asin((1.0 - x));
double tmp;
if (x <= 5.5e-17) {
tmp = fma((((double) M_PI) / 2.0), (((double) M_PI) / 2.0), (asin((x - 1.0)) * asin(-x))) / ((((double) M_PI) / 2.0) + t_0);
} else {
tmp = (((((double) M_PI) / 2.0) * (((double) M_PI) / 2.0)) - (t_0 * t_0)) / ((((double) M_PI) / 2.0) + asin(((1.0 - (x * x)) / (x + 1.0))));
}
return tmp;
}
function code(x) t_0 = asin(Float64(1.0 - x)) tmp = 0.0 if (x <= 5.5e-17) tmp = Float64(fma(Float64(pi / 2.0), Float64(pi / 2.0), Float64(asin(Float64(x - 1.0)) * asin(Float64(-x)))) / Float64(Float64(pi / 2.0) + t_0)); else tmp = Float64(Float64(Float64(Float64(pi / 2.0) * Float64(pi / 2.0)) - Float64(t_0 * t_0)) / Float64(Float64(pi / 2.0) + asin(Float64(Float64(1.0 - Float64(x * x)) / Float64(x + 1.0))))); end return tmp end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 5.5e-17], N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(Pi / 2.0), $MachinePrecision] + N[(N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[ArcSin[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(Pi / 2.0), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[(Pi / 2.0), $MachinePrecision] + N[ArcSin[N[(N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\pi}{2}, \frac{\pi}{2}, \sin^{-1} \left(x - 1\right) \cdot \sin^{-1} \left(-x\right)\right)}{\frac{\pi}{2} + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi}{2} \cdot \frac{\pi}{2} - t\_0 \cdot t\_0}{\frac{\pi}{2} + \sin^{-1} \left(\frac{1 - x \cdot x}{x + 1}\right)}\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites3.9%
lift--.f64N/A
flip--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
+-commutativeN/A
lower-+.f643.9
Applied rewrites3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.6
Applied rewrites6.6%
Applied rewrites6.6%
if 5.50000000000000001e-17 < x Initial program 62.1%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites62.0%
lift--.f64N/A
flip--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
+-commutativeN/A
lower-+.f6462.1
Applied rewrites62.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (/ PI 2.0) (asin (- 1.0 x)))))
(if (<= x 5.5e-17)
(/ (fma (/ PI 2.0) (/ PI 2.0) (* (asin (- x 1.0)) (asin (- x)))) t_0)
(/ (fma PI (/ PI 4.0) (- (pow (asin (+ -1.0 x)) 2.0))) t_0))))
double code(double x) {
double t_0 = (((double) M_PI) / 2.0) + asin((1.0 - x));
double tmp;
if (x <= 5.5e-17) {
tmp = fma((((double) M_PI) / 2.0), (((double) M_PI) / 2.0), (asin((x - 1.0)) * asin(-x))) / t_0;
} else {
tmp = fma(((double) M_PI), (((double) M_PI) / 4.0), -pow(asin((-1.0 + x)), 2.0)) / t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(pi / 2.0) + asin(Float64(1.0 - x))) tmp = 0.0 if (x <= 5.5e-17) tmp = Float64(fma(Float64(pi / 2.0), Float64(pi / 2.0), Float64(asin(Float64(x - 1.0)) * asin(Float64(-x)))) / t_0); else tmp = Float64(fma(pi, Float64(pi / 4.0), Float64(-(asin(Float64(-1.0 + x)) ^ 2.0))) / t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(Pi / 2.0), $MachinePrecision] + N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 5.5e-17], N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(Pi / 2.0), $MachinePrecision] + N[(N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[ArcSin[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(Pi * N[(Pi / 4.0), $MachinePrecision] + (-N[Power[N[ArcSin[N[(-1.0 + x), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\pi}{2} + \sin^{-1} \left(1 - x\right)\\
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\pi}{2}, \frac{\pi}{2}, \sin^{-1} \left(x - 1\right) \cdot \sin^{-1} \left(-x\right)\right)}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\pi, \frac{\pi}{4}, -{\sin^{-1} \left(-1 + x\right)}^{2}\right)}{t\_0}\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites3.9%
lift--.f64N/A
flip--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
+-commutativeN/A
lower-+.f643.9
Applied rewrites3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.6
Applied rewrites6.6%
Applied rewrites6.6%
if 5.50000000000000001e-17 < x Initial program 62.1%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites62.0%
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-asin.f64N/A
lift--.f64N/A
lift-asin.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites62.0%
(FPCore (x)
:precision binary64
(if (<= x 5.5e-17)
(acos (- x))
(/
(fma PI (/ PI 4.0) (- (pow (asin (+ -1.0 x)) 2.0)))
(+ (/ PI 2.0) (asin (- 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = acos(-x);
} else {
tmp = fma(((double) M_PI), (((double) M_PI) / 4.0), -pow(asin((-1.0 + x)), 2.0)) / ((((double) M_PI) / 2.0) + asin((1.0 - x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = acos(Float64(-x)); else tmp = Float64(fma(pi, Float64(pi / 4.0), Float64(-(asin(Float64(-1.0 + x)) ^ 2.0))) / Float64(Float64(pi / 2.0) + asin(Float64(1.0 - x)))); end return tmp end
code[x_] := If[LessEqual[x, 5.5e-17], N[ArcCos[(-x)], $MachinePrecision], N[(N[(Pi * N[(Pi / 4.0), $MachinePrecision] + (-N[Power[N[ArcSin[N[(-1.0 + x), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision] / N[(N[(Pi / 2.0), $MachinePrecision] + N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\pi, \frac{\pi}{4}, -{\sin^{-1} \left(-1 + x\right)}^{2}\right)}{\frac{\pi}{2} + \sin^{-1} \left(1 - x\right)}\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.6
Applied rewrites6.6%
if 5.50000000000000001e-17 < x Initial program 62.1%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites62.0%
lift--.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-asin.f64N/A
lift--.f64N/A
lift-asin.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites62.0%
(FPCore (x)
:precision binary64
(if (<= x 5.5e-17)
(acos (- x))
(/
(fma -0.25 (* PI PI) (pow (asin (- 1.0 x)) 2.0))
(fma -0.5 PI (asin (- x 1.0))))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = acos(-x);
} else {
tmp = fma(-0.25, (((double) M_PI) * ((double) M_PI)), pow(asin((1.0 - x)), 2.0)) / fma(-0.5, ((double) M_PI), asin((x - 1.0)));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = acos(Float64(-x)); else tmp = Float64(fma(-0.25, Float64(pi * pi), (asin(Float64(1.0 - x)) ^ 2.0)) / fma(-0.5, pi, asin(Float64(x - 1.0)))); end return tmp end
code[x_] := If[LessEqual[x, 5.5e-17], N[ArcCos[(-x)], $MachinePrecision], N[(N[(-0.25 * N[(Pi * Pi), $MachinePrecision] + N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(-0.5 * Pi + N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.25, \pi \cdot \pi, {\sin^{-1} \left(1 - x\right)}^{2}\right)}{\mathsf{fma}\left(-0.5, \pi, \sin^{-1} \left(x - 1\right)\right)}\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.6
Applied rewrites6.6%
if 5.50000000000000001e-17 < x Initial program 62.1%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-asin.f64N/A
lift--.f64N/A
lower-+.f64N/A
Applied rewrites62.0%
lift--.f64N/A
flip--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
+-commutativeN/A
lower-+.f6462.0
Applied rewrites62.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6413.6
Applied rewrites13.6%
Taylor expanded in x around 0
Applied rewrites62.0%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (acos (- x)) (- (* 0.5 PI) (asin (- 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = acos(-x);
} else {
tmp = (0.5 * ((double) M_PI)) - asin((1.0 - x));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = Math.acos(-x);
} else {
tmp = (0.5 * Math.PI) - Math.asin((1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.5e-17: tmp = math.acos(-x) else: tmp = (0.5 * math.pi) - math.asin((1.0 - x)) return tmp
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = acos(Float64(-x)); else tmp = Float64(Float64(0.5 * pi) - asin(Float64(1.0 - x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.5e-17) tmp = acos(-x); else tmp = (0.5 * pi) - asin((1.0 - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.5e-17], N[ArcCos[(-x)], $MachinePrecision], N[(N[(0.5 * Pi), $MachinePrecision] - N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \pi - \sin^{-1} \left(1 - x\right)\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.6
Applied rewrites6.6%
if 5.50000000000000001e-17 < x Initial program 62.1%
lift--.f64N/A
lift-acos.f64N/A
acos-asinN/A
lower--.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-asin.f64N/A
lift--.f6462.0
Applied rewrites62.0%
Taylor expanded in x around 0
acos-asin-revN/A
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-asin.f64N/A
lift--.f6462.0
Applied rewrites62.0%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (acos (- x)) (acos (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = acos(-x);
} else {
tmp = acos((1.0 - x));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5.5d-17) then
tmp = acos(-x)
else
tmp = acos((1.0d0 - x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = Math.acos(-x);
} else {
tmp = Math.acos((1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.5e-17: tmp = math.acos(-x) else: tmp = math.acos((1.0 - x)) return tmp
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = acos(Float64(-x)); else tmp = acos(Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.5e-17) tmp = acos(-x); else tmp = acos((1.0 - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.5e-17], N[ArcCos[(-x)], $MachinePrecision], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.6
Applied rewrites6.6%
if 5.50000000000000001e-17 < x Initial program 62.1%
(FPCore (x) :precision binary64 (acos (- x)))
double code(double x) {
return acos(-x);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = acos(-x)
end function
public static double code(double x) {
return Math.acos(-x);
}
def code(x): return math.acos(-x)
function code(x) return acos(Float64(-x)) end
function tmp = code(x) tmp = acos(-x); end
code[x_] := N[ArcCos[(-x)], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(-x\right)
\end{array}
Initial program 6.8%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.9
Applied rewrites6.9%
(FPCore (x) :precision binary64 (acos 1.0))
double code(double x) {
return acos(1.0);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = acos(1.0d0)
end function
public static double code(double x) {
return Math.acos(1.0);
}
def code(x): return math.acos(1.0)
function code(x) return acos(1.0) end
function tmp = code(x) tmp = acos(1.0); end
code[x_] := N[ArcCos[1.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} 1
\end{array}
Initial program 6.8%
Taylor expanded in x around 0
Applied rewrites3.8%
(FPCore (x) :precision binary64 (* 2.0 (asin (sqrt (/ x 2.0)))))
double code(double x) {
return 2.0 * asin(sqrt((x / 2.0)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
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 2025103
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
:alt
(! :herbie-platform default (* 2 (asin (sqrt (/ x 2)))))
(acos (- 1.0 x)))