
(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]
\cos^{-1} \left(1 - x\right)
Herbie found 11 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]
\cos^{-1} \left(1 - x\right)
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- x 1.0)))
(t_1 (asin (- x 1.0)))
(t_2 (/ 1.0 (fma (fma 1.5 PI t_1) t_1 (* (* 1.5 PI) (* 1.5 PI)))))
(t_3 (+ PI t_0)))
(/
(fma
(/ (* PI PI) (fma 3.375 (* (* PI PI) PI) (pow (asin (- 1.0 x)) 3.0)))
t_3
(* t_2 (* (- t_0) t_0)))
(* t_2 t_3))))double code(double x) {
double t_0 = acos((x - 1.0));
double t_1 = asin((x - 1.0));
double t_2 = 1.0 / fma(fma(1.5, ((double) M_PI), t_1), t_1, ((1.5 * ((double) M_PI)) * (1.5 * ((double) M_PI))));
double t_3 = ((double) M_PI) + t_0;
return fma(((((double) M_PI) * ((double) M_PI)) / fma(3.375, ((((double) M_PI) * ((double) M_PI)) * ((double) M_PI)), pow(asin((1.0 - x)), 3.0))), t_3, (t_2 * (-t_0 * t_0))) / (t_2 * t_3);
}
function code(x) t_0 = acos(Float64(x - 1.0)) t_1 = asin(Float64(x - 1.0)) t_2 = Float64(1.0 / fma(fma(1.5, pi, t_1), t_1, Float64(Float64(1.5 * pi) * Float64(1.5 * pi)))) t_3 = Float64(pi + t_0) return Float64(fma(Float64(Float64(pi * pi) / fma(3.375, Float64(Float64(pi * pi) * pi), (asin(Float64(1.0 - x)) ^ 3.0))), t_3, Float64(t_2 * Float64(Float64(-t_0) * t_0))) / Float64(t_2 * t_3)) end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(N[(1.5 * Pi + t$95$1), $MachinePrecision] * t$95$1 + N[(N[(1.5 * Pi), $MachinePrecision] * N[(1.5 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(Pi + t$95$0), $MachinePrecision]}, N[(N[(N[(N[(Pi * Pi), $MachinePrecision] / N[(3.375 * N[(N[(Pi * Pi), $MachinePrecision] * Pi), $MachinePrecision] + N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$3 + N[(t$95$2 * N[((-t$95$0) * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 * t$95$3), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \cos^{-1} \left(x - 1\right)\\
t_1 := \sin^{-1} \left(x - 1\right)\\
t_2 := \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(1.5, \pi, t\_1\right), t\_1, \left(1.5 \cdot \pi\right) \cdot \left(1.5 \cdot \pi\right)\right)}\\
t_3 := \pi + t\_0\\
\frac{\mathsf{fma}\left(\frac{\pi \cdot \pi}{\mathsf{fma}\left(3.375, \left(\pi \cdot \pi\right) \cdot \pi, {\sin^{-1} \left(1 - x\right)}^{3}\right)}, t\_3, t\_2 \cdot \left(\left(-t\_0\right) \cdot t\_0\right)\right)}{t\_2 \cdot t\_3}
\end{array}
Initial program 6.8%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
flip--N/A
lower-unsound-/.f64N/A
lower-unsound-*.f32N/A
lower-*.f32N/A
lower-unsound--.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f64N/A
lower-unsound-*.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-unsound-+.f64N/A
lower-PI.f64N/A
lower-acos.f64N/A
lower--.f646.8%
Applied rewrites6.8%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
lower-neg.f6410.4%
Applied rewrites10.4%
lift-+.f64N/A
lift-acos.f64N/A
acos-asinN/A
lift-asin.f64N/A
associate-+r-N/A
flip3--N/A
lower-unsound-/.f64N/A
Applied rewrites10.4%
Applied rewrites10.4%
(FPCore (x) :precision binary64 (if (<= x 7e-16) (/ (fma (- (acos -1.0)) (acos -1.0) 9.869604401089358) (+ PI (acos -1.0))) (* (fma (asin (- x 1.0)) (/ 2.0 PI) 1.0) (* 0.5 PI))))
double code(double x) {
double tmp;
if (x <= 7e-16) {
tmp = fma(-acos(-1.0), acos(-1.0), 9.869604401089358) / (((double) M_PI) + acos(-1.0));
} else {
tmp = fma(asin((x - 1.0)), (2.0 / ((double) M_PI)), 1.0) * (0.5 * ((double) M_PI));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 7e-16) tmp = Float64(fma(Float64(-acos(-1.0)), acos(-1.0), 9.869604401089358) / Float64(pi + acos(-1.0))); else tmp = Float64(fma(asin(Float64(x - 1.0)), Float64(2.0 / pi), 1.0) * Float64(0.5 * pi)); end return tmp end
code[x_] := If[LessEqual[x, 7e-16], N[(N[((-N[ArcCos[-1.0], $MachinePrecision]) * N[ArcCos[-1.0], $MachinePrecision] + 9.869604401089358), $MachinePrecision] / N[(Pi + N[ArcCos[-1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[(2.0 / Pi), $MachinePrecision] + 1.0), $MachinePrecision] * N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 7 \cdot 10^{-16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-\cos^{-1} -1, \cos^{-1} -1, 9.869604401089358\right)}{\pi + \cos^{-1} -1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin^{-1} \left(x - 1\right), \frac{2}{\pi}, 1\right) \cdot \left(0.5 \cdot \pi\right)\\
\end{array}
if x < 7.0000000000000003e-16Initial program 6.8%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
flip--N/A
lower-unsound-/.f64N/A
lower-unsound-*.f32N/A
lower-*.f32N/A
lower-unsound--.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f64N/A
lower-unsound-*.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-unsound-+.f64N/A
lower-PI.f64N/A
lower-acos.f64N/A
lower--.f646.8%
Applied rewrites6.8%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
lower-neg.f6410.4%
Applied rewrites10.4%
Taylor expanded in x around 0
Applied rewrites8.1%
Taylor expanded in x around 0
Applied rewrites7.7%
Taylor expanded in x around 0
Applied rewrites7.7%
Evaluated real constant7.7%
if 7.0000000000000003e-16 < x Initial program 6.8%
lift-acos.f64N/A
acos-asinN/A
sub-to-multN/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-/.f64N/A
lower-asin.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f646.8%
Applied rewrites6.8%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-/.f64N/A
mult-flipN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift--.f64N/A
lift-asin.f64N/A
asin-neg-revN/A
sub-negate-revN/A
lift--.f64N/A
lower-asin.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
div-flip-revN/A
lower-/.f645.0%
Applied rewrites5.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- x 1.0))) (t_1 (asin (- x 1.0))))
(/
(fma (- t_0) t_0 (* PI PI))
(/
(- (pow t_1 3.0) (* 3.375 (* (* PI PI) PI)))
(- (* (asin (- 1.0 x)) (fma 1.5 PI t_1)) (* (* 1.5 PI) (* 1.5 PI)))))))double code(double x) {
double t_0 = acos((x - 1.0));
double t_1 = asin((x - 1.0));
return fma(-t_0, t_0, (((double) M_PI) * ((double) M_PI))) / ((pow(t_1, 3.0) - (3.375 * ((((double) M_PI) * ((double) M_PI)) * ((double) M_PI)))) / ((asin((1.0 - x)) * fma(1.5, ((double) M_PI), t_1)) - ((1.5 * ((double) M_PI)) * (1.5 * ((double) M_PI)))));
}
function code(x) t_0 = acos(Float64(x - 1.0)) t_1 = asin(Float64(x - 1.0)) return Float64(fma(Float64(-t_0), t_0, Float64(pi * pi)) / Float64(Float64((t_1 ^ 3.0) - Float64(3.375 * Float64(Float64(pi * pi) * pi))) / Float64(Float64(asin(Float64(1.0 - x)) * fma(1.5, pi, t_1)) - Float64(Float64(1.5 * pi) * Float64(1.5 * pi))))) end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, N[(N[((-t$95$0) * t$95$0 + N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Power[t$95$1, 3.0], $MachinePrecision] - N[(3.375 * N[(N[(Pi * Pi), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] * N[(1.5 * Pi + t$95$1), $MachinePrecision]), $MachinePrecision] - N[(N[(1.5 * Pi), $MachinePrecision] * N[(1.5 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \cos^{-1} \left(x - 1\right)\\
t_1 := \sin^{-1} \left(x - 1\right)\\
\frac{\mathsf{fma}\left(-t\_0, t\_0, \pi \cdot \pi\right)}{\frac{{t\_1}^{3} - 3.375 \cdot \left(\left(\pi \cdot \pi\right) \cdot \pi\right)}{\sin^{-1} \left(1 - x\right) \cdot \mathsf{fma}\left(1.5, \pi, t\_1\right) - \left(1.5 \cdot \pi\right) \cdot \left(1.5 \cdot \pi\right)}}
\end{array}
Initial program 6.8%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
flip--N/A
lower-unsound-/.f64N/A
lower-unsound-*.f32N/A
lower-*.f32N/A
lower-unsound--.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f64N/A
lower-unsound-*.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-unsound-+.f64N/A
lower-PI.f64N/A
lower-acos.f64N/A
lower--.f646.8%
Applied rewrites6.8%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
lower-neg.f6410.4%
Applied rewrites10.4%
lift-+.f64N/A
lift-acos.f64N/A
acos-asinN/A
lift-asin.f64N/A
associate-+r-N/A
flip3--N/A
lower-unsound-/.f64N/A
Applied rewrites10.4%
Applied rewrites10.4%
(FPCore (x) :precision binary64 (let* ((t_0 (acos (- x 1.0)))) (/ (fma (- t_0) t_0 (* PI PI)) (+ PI t_0))))
double code(double x) {
double t_0 = acos((x - 1.0));
return fma(-t_0, t_0, (((double) M_PI) * ((double) M_PI))) / (((double) M_PI) + t_0);
}
function code(x) t_0 = acos(Float64(x - 1.0)) return Float64(fma(Float64(-t_0), t_0, Float64(pi * pi)) / Float64(pi + t_0)) end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]}, N[(N[((-t$95$0) * t$95$0 + N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] / N[(Pi + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \cos^{-1} \left(x - 1\right)\\
\frac{\mathsf{fma}\left(-t\_0, t\_0, \pi \cdot \pi\right)}{\pi + t\_0}
\end{array}
Initial program 6.8%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
flip--N/A
lower-unsound-/.f64N/A
lower-unsound-*.f32N/A
lower-*.f32N/A
lower-unsound--.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f64N/A
lower-unsound-*.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-unsound-+.f64N/A
lower-PI.f64N/A
lower-acos.f64N/A
lower--.f646.8%
Applied rewrites6.8%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
lower-neg.f6410.4%
Applied rewrites10.4%
(FPCore (x) :precision binary64 (* (fma (* 0.5 PI) (/ 2.0 PI) (* (asin (- x 1.0)) (/ 2.0 PI))) (* 0.5 PI)))
double code(double x) {
return fma((0.5 * ((double) M_PI)), (2.0 / ((double) M_PI)), (asin((x - 1.0)) * (2.0 / ((double) M_PI)))) * (0.5 * ((double) M_PI));
}
function code(x) return Float64(fma(Float64(0.5 * pi), Float64(2.0 / pi), Float64(asin(Float64(x - 1.0)) * Float64(2.0 / pi))) * Float64(0.5 * pi)) end
code[x_] := N[(N[(N[(0.5 * Pi), $MachinePrecision] * N[(2.0 / Pi), $MachinePrecision] + N[(N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[(2.0 / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(0.5 \cdot \pi, \frac{2}{\pi}, \sin^{-1} \left(x - 1\right) \cdot \frac{2}{\pi}\right) \cdot \left(0.5 \cdot \pi\right)
Initial program 6.8%
lift-acos.f64N/A
acos-asinN/A
sub-to-multN/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-/.f64N/A
lower-asin.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f646.8%
Applied rewrites6.8%
lift--.f64N/A
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lift-PI.f64N/A
mult-flipN/A
sub-to-fraction-revN/A
*-lft-identityN/A
sub-flipN/A
div-addN/A
Applied rewrites10.3%
(FPCore (x) :precision binary64 (* (fma PI (/ -0.5 (asin (- 1.0 x))) 1.0) (asin (- x 1.0))))
double code(double x) {
return fma(((double) M_PI), (-0.5 / asin((1.0 - x))), 1.0) * asin((x - 1.0));
}
function code(x) return Float64(fma(pi, Float64(-0.5 / asin(Float64(1.0 - x))), 1.0) * asin(Float64(x - 1.0))) end
code[x_] := N[(N[(Pi * N[(-0.5 / N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\pi, \frac{-0.5}{\sin^{-1} \left(1 - x\right)}, 1\right) \cdot \sin^{-1} \left(x - 1\right)
Initial program 6.8%
lift-acos.f64N/A
acos-asinN/A
sub-flipN/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f64N/A
asin-neg-revN/A
lift--.f64N/A
sub-negate-revN/A
lower-asin.f64N/A
lower--.f64N/A
asin-neg-revN/A
lift--.f64N/A
sub-negate-revN/A
Applied rewrites6.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
lift-asin.f64N/A
asin-neg-revN/A
lift--.f64N/A
sub-negate-revN/A
lower-asin.f64N/A
lower--.f6410.3%
Applied rewrites10.3%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (acos (- x)) (* (fma (asin (- x 1.0)) (/ 2.0 PI) 1.0) (* 0.5 PI))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = acos(-x);
} else {
tmp = fma(asin((x - 1.0)), (2.0 / ((double) M_PI)), 1.0) * (0.5 * ((double) M_PI));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = acos(Float64(-x)); else tmp = Float64(fma(asin(Float64(x - 1.0)), Float64(2.0 / pi), 1.0) * Float64(0.5 * pi)); end return tmp end
code[x_] := If[LessEqual[x, 5.5e-17], N[ArcCos[(-x)], $MachinePrecision], N[(N[(N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[(2.0 / Pi), $MachinePrecision] + 1.0), $MachinePrecision] * N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin^{-1} \left(x - 1\right), \frac{2}{\pi}, 1\right) \cdot \left(0.5 \cdot \pi\right)\\
\end{array}
if x < 5.5e-17Initial program 6.8%
Taylor expanded in x around inf
lower-*.f646.9%
Applied rewrites6.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f646.9%
Applied rewrites6.9%
if 5.5e-17 < x Initial program 6.8%
lift-acos.f64N/A
acos-asinN/A
sub-to-multN/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-/.f64N/A
lower-asin.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lower-PI.f646.8%
Applied rewrites6.8%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-/.f64N/A
mult-flipN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift--.f64N/A
lift-asin.f64N/A
asin-neg-revN/A
sub-negate-revN/A
lift--.f64N/A
lower-asin.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
div-flip-revN/A
lower-/.f645.0%
Applied rewrites5.0%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (acos (- x)) (- PI (acos (- x 1.0)))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = acos(-x);
} else {
tmp = ((double) M_PI) - acos((x - 1.0));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = Math.acos(-x);
} else {
tmp = Math.PI - Math.acos((x - 1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.5e-17: tmp = math.acos(-x) else: tmp = math.pi - math.acos((x - 1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = acos(Float64(-x)); else tmp = Float64(pi - acos(Float64(x - 1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.5e-17) tmp = acos(-x); else tmp = pi - acos((x - 1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.5e-17], N[ArcCos[(-x)], $MachinePrecision], N[(Pi - N[ArcCos[N[(x - 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\pi - \cos^{-1} \left(x - 1\right)\\
\end{array}
if x < 5.5e-17Initial program 6.8%
Taylor expanded in x around inf
lower-*.f646.9%
Applied rewrites6.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f646.9%
Applied rewrites6.9%
if 5.5e-17 < x Initial program 6.8%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
lower--.f64N/A
lower-PI.f64N/A
lower-acos.f64N/A
lower--.f646.8%
Applied rewrites6.8%
(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}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\
\end{array}
if x < 5.5e-17Initial program 6.8%
Taylor expanded in x around inf
lower-*.f646.9%
Applied rewrites6.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f646.9%
Applied rewrites6.9%
if 5.5e-17 < x Initial program 6.8%
(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]
\cos^{-1} \left(-x\right)
Initial program 6.8%
Taylor expanded in x around inf
lower-*.f646.9%
Applied rewrites6.9%
lift-*.f64N/A
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]
\cos^{-1} 1
Initial program 6.8%
Taylor expanded in x around 0
Applied rewrites3.8%
herbie shell --seed 2025192
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
(acos (- 1.0 x)))