
(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}
Sampling outcomes in binary64 precision:
Herbie found 9 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 (/ (PI) 2.0)))
(/
(fma
(- t_0 (acos (- 1.0 x)))
(asin (* (- 1.0 (pow x -1.0)) x))
(pow t_0 2.0))
(+ t_0 (asin (- 1.0 x))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{2}\\
\frac{\mathsf{fma}\left(t\_0 - \cos^{-1} \left(1 - x\right), \sin^{-1} \left(\left(1 - {x}^{-1}\right) \cdot x\right), {t\_0}^{2}\right)}{t\_0 + \sin^{-1} \left(1 - x\right)}
\end{array}
\end{array}
Initial program 7.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 rewrites7.9%
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 rewrites11.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
inv-powN/A
lower-pow.f6411.0
Applied rewrites11.0%
lift--.f64N/A
lift-asin.f64N/A
asin-acosN/A
lift-/.f64N/A
lift-PI.f64N/A
acos-asin-revN/A
lower--.f64N/A
acos-asin-revN/A
lower-acos.f64N/A
lift--.f6411.1
Applied rewrites11.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))))
(/
(fma t_0 (asin (* (- 1.0 (pow x -1.0)) x)) (/ (* (PI) (PI)) 4.0))
(+ (/ (PI) 2.0) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{\mathsf{fma}\left(t\_0, \sin^{-1} \left(\left(1 - {x}^{-1}\right) \cdot x\right), \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{4}\right)}{\frac{\mathsf{PI}\left(\right)}{2} + t\_0}
\end{array}
\end{array}
Initial program 7.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 rewrites7.9%
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 rewrites11.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
inv-powN/A
lower-pow.f6411.0
Applied rewrites11.0%
lift-pow.f64N/A
unpow2N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
frac-timesN/A
pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-PI.f64N/A
metadata-eval11.0
Applied rewrites11.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ (PI) 2.0)))
(if (<= x 2.1e-12)
(/
(fma (asin (- 1.0 x)) (asin (+ -1.0 x)) (/ (* (PI) (PI)) 4.0))
(+ t_0 (asin 1.0)))
(- t_0 (+ (acos (- x 1.0)) (* -0.5 (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{2}\\
\mathbf{if}\;x \leq 2.1 \cdot 10^{-12}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sin^{-1} \left(1 - x\right), \sin^{-1} \left(-1 + x\right), \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{4}\right)}{t\_0 + \sin^{-1} 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0 - \left(\cos^{-1} \left(x - 1\right) + -0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if x < 2.09999999999999994e-12Initial program 4.5%
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 rewrites4.5%
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 rewrites7.8%
Taylor expanded in x around 0
Applied rewrites7.8%
lift-pow.f64N/A
unpow2N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
frac-timesN/A
pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-PI.f64N/A
metadata-eval7.8
Applied rewrites7.8%
if 2.09999999999999994e-12 < x Initial program 76.7%
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--.f6476.7
Applied rewrites76.7%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-asin.f64N/A
lift--.f6476.7
Applied rewrites76.7%
Applied rewrites76.0%
Applied rewrites76.8%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (/ (fma t_0 (asin (+ -1.0 x)) (/ (* (PI) (PI)) 4.0)) (+ (/ (PI) 2.0) t_0))))
\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), \frac{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}{4}\right)}{\frac{\mathsf{PI}\left(\right)}{2} + t\_0}
\end{array}
\end{array}
Initial program 7.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 rewrites7.9%
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 rewrites11.0%
lift-pow.f64N/A
pow2N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
frac-timesN/A
unpow2N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-PI.f64N/A
metadata-eval11.0
Applied rewrites11.0%
(FPCore (x) :precision binary64 (if (<= x 5.6e-17) (acos (- x)) (- (/ (PI) 2.0) (+ (acos (- x 1.0)) (* -0.5 (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{PI}\left(\right)}{2} - \left(\cos^{-1} \left(x - 1\right) + -0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.4
Applied rewrites6.4%
if 5.5999999999999998e-17 < x Initial program 64.0%
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--.f6463.9
Applied rewrites63.9%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-asin.f64N/A
lift--.f6463.9
Applied rewrites63.9%
Applied rewrites63.8%
Applied rewrites64.0%
(FPCore (x) :precision binary64 (if (<= x 5.6e-17) (acos (- x)) (- (* 0.5 (PI)) (- (/ (PI) 2.0) (acos (- 1.0 x))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{PI}\left(\right) - \left(\frac{\mathsf{PI}\left(\right)}{2} - \cos^{-1} \left(1 - x\right)\right)\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.4
Applied rewrites6.4%
if 5.5999999999999998e-17 < x Initial program 64.0%
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--.f6463.9
Applied rewrites63.9%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-asin.f64N/A
lift--.f6463.9
Applied rewrites63.9%
lift--.f64N/A
lift-asin.f64N/A
asin-acosN/A
lift-/.f64N/A
lift-PI.f64N/A
acos-asin-revN/A
lower--.f64N/A
acos-asin-revN/A
lower-acos.f64N/A
lift--.f6464.0
Applied rewrites64.0%
(FPCore (x) :precision binary64 (if (<= x 5.6e-17) (acos (- x)) (acos (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= 5.6e-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.6d-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.6e-17) {
tmp = Math.acos(-x);
} else {
tmp = Math.acos((1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.6e-17: tmp = math.acos(-x) else: tmp = math.acos((1.0 - x)) return tmp
function code(x) tmp = 0.0 if (x <= 5.6e-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.6e-17) tmp = acos(-x); else tmp = acos((1.0 - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.6e-17], N[ArcCos[(-x)], $MachinePrecision], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f646.4
Applied rewrites6.4%
if 5.5999999999999998e-17 < x Initial program 64.0%
(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 7.9%
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 7.9%
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 2025051
(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)))