
(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 6 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 (- (asin (- x 1.0)) (/ -27.130492095262344 (- (* 1.25 (* PI PI)) (* (* -0.5 PI) PI)))))
double code(double x) {
return asin((x - 1.0)) - (-27.130492095262344 / ((1.25 * (((double) M_PI) * ((double) M_PI))) - ((-0.5 * ((double) M_PI)) * ((double) M_PI))));
}
public static double code(double x) {
return Math.asin((x - 1.0)) - (-27.130492095262344 / ((1.25 * (Math.PI * Math.PI)) - ((-0.5 * Math.PI) * Math.PI)));
}
def code(x): return math.asin((x - 1.0)) - (-27.130492095262344 / ((1.25 * (math.pi * math.pi)) - ((-0.5 * math.pi) * math.pi)))
function code(x) return Float64(asin(Float64(x - 1.0)) - Float64(-27.130492095262344 / Float64(Float64(1.25 * Float64(pi * pi)) - Float64(Float64(-0.5 * pi) * pi)))) end
function tmp = code(x) tmp = asin((x - 1.0)) - (-27.130492095262344 / ((1.25 * (pi * pi)) - ((-0.5 * pi) * pi))); end
code[x_] := N[(N[ArcSin[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] - N[(-27.130492095262344 / N[(N[(1.25 * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] - N[(N[(-0.5 * Pi), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sin^{-1} \left(x - 1\right) - \frac{-27.130492095262344}{1.25 \cdot \left(\pi \cdot \pi\right) - \left(-0.5 \cdot \pi\right) \cdot \pi}
Initial program 7.1%
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 rewrites7.1%
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-out--N/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lift-PI.f64N/A
flip3--N/A
lower-unsound-/.f64N/A
Applied rewrites10.6%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
Applied rewrites10.6%
Evaluated real constant10.6%
(FPCore (x) :precision binary64 (* (/ (- 29.608813203268078 (* 3.0 (* (acos (- x 1.0)) PI))) 29.608813203268078) PI))
double code(double x) {
return ((29.608813203268078 - (3.0 * (acos((x - 1.0)) * ((double) M_PI)))) / 29.608813203268078) * ((double) M_PI);
}
public static double code(double x) {
return ((29.608813203268078 - (3.0 * (Math.acos((x - 1.0)) * Math.PI))) / 29.608813203268078) * Math.PI;
}
def code(x): return ((29.608813203268078 - (3.0 * (math.acos((x - 1.0)) * math.pi))) / 29.608813203268078) * math.pi
function code(x) return Float64(Float64(Float64(29.608813203268078 - Float64(3.0 * Float64(acos(Float64(x - 1.0)) * pi))) / 29.608813203268078) * pi) end
function tmp = code(x) tmp = ((29.608813203268078 - (3.0 * (acos((x - 1.0)) * pi))) / 29.608813203268078) * pi; end
code[x_] := N[(N[(N[(29.608813203268078 - N[(3.0 * N[(N[ArcCos[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 29.608813203268078), $MachinePrecision] * Pi), $MachinePrecision]
\frac{29.608813203268078 - 3 \cdot \left(\cos^{-1} \left(x - 1\right) \cdot \pi\right)}{29.608813203268078} \cdot \pi
Initial program 7.1%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
sub-to-multN/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-/.f64N/A
lower-acos.f64N/A
lower--.f64N/A
lower-PI.f64N/A
lower-PI.f647.1%
Applied rewrites7.1%
lift--.f64N/A
lift-/.f64N/A
sub-to-fractionN/A
*-lft-identityN/A
sub-divN/A
frac-subN/A
lift-PI.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
Applied rewrites7.1%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
*-inversesN/A
metadata-evalN/A
frac-subN/A
lower-/.f64N/A
Applied rewrites7.1%
Evaluated real constant10.6%
Evaluated real constant10.6%
(FPCore (x) :precision binary64 (let* ((t_0 (acos (- 1.0 x)))) (if (<= t_0 0.0) (acos (- x)) (- PI (- PI t_0)))))
double code(double x) {
double t_0 = acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = acos(-x);
} else {
tmp = ((double) M_PI) - (((double) M_PI) - t_0);
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = Math.acos(-x);
} else {
tmp = Math.PI - (Math.PI - t_0);
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) tmp = 0 if t_0 <= 0.0: tmp = math.acos(-x) else: tmp = math.pi - (math.pi - t_0) return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) tmp = 0.0 if (t_0 <= 0.0) tmp = acos(Float64(-x)); else tmp = Float64(pi - Float64(pi - t_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 = acos(-x); else tmp = pi - (pi - t_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[ArcCos[(-x)], $MachinePrecision], N[(Pi - N[(Pi - t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\pi - \left(\pi - t\_0\right)\\
\end{array}
if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0Initial program 7.1%
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 0.0 < (acos.f64 (-.f64 #s(literal 1 binary64) x)) Initial program 7.1%
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--.f647.1%
Applied rewrites7.1%
lift-acos.f64N/A
lift--.f64N/A
sub-negate-revN/A
acos-negN/A
lift-PI.f64N/A
acos-asinN/A
sub-negate-revN/A
lift--.f64N/A
asin-neg-revN/A
lift-asin.f64N/A
add-flip-revN/A
+-commutativeN/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
*-lft-identityN/A
*-commutativeN/A
lift-*.f64N/A
lower--.f64N/A
*-lft-identityN/A
lift-*.f64N/A
Applied rewrites7.1%
(FPCore (x) :precision binary64 (let* ((t_0 (acos (- 1.0 x)))) (if (<= t_0 0.0) (acos (- x)) t_0)))
double code(double x) {
double t_0 = acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = acos(-x);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = acos((1.0d0 - x))
if (t_0 <= 0.0d0) then
tmp = acos(-x)
else
tmp = t_0
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 = Math.acos(-x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) tmp = 0 if t_0 <= 0.0: tmp = math.acos(-x) else: tmp = t_0 return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) tmp = 0.0 if (t_0 <= 0.0) tmp = acos(Float64(-x)); else tmp = t_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 = acos(-x); else tmp = t_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[ArcCos[(-x)], $MachinePrecision], t$95$0]]
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0Initial program 7.1%
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 0.0 < (acos.f64 (-.f64 #s(literal 1 binary64) x)) Initial program 7.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]
\cos^{-1} \left(-x\right)
Initial program 7.1%
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 7.1%
Taylor expanded in x around 0
Applied rewrites3.8%
herbie shell --seed 2025258
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
(acos (- 1.0 x)))