
(FPCore (x) :precision binary64 (/ (- 1 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * 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 = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\frac{1 - \cos x}{x \cdot x}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- 1 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * 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 = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\frac{1 - \cos x}{x \cdot x}
(FPCore (x) :precision binary64 (/ (* (/ (tan (/ x 2)) x) (sin x)) x))
double code(double x) {
return ((tan((x / 2.0)) / x) * sin(x)) / 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 = ((tan((x / 2.0d0)) / x) * sin(x)) / x
end function
public static double code(double x) {
return ((Math.tan((x / 2.0)) / x) * Math.sin(x)) / x;
}
def code(x): return ((math.tan((x / 2.0)) / x) * math.sin(x)) / x
function code(x) return Float64(Float64(Float64(tan(Float64(x / 2.0)) / x) * sin(x)) / x) end
function tmp = code(x) tmp = ((tan((x / 2.0)) / x) * sin(x)) / x; end
code[x_] := N[(N[(N[(N[Tan[N[(x / 2), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\frac{\frac{\tan \left(\frac{x}{2}\right)}{x} \cdot \sin x}{x}
Initial program 51.1%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f6451.2%
Applied rewrites51.2%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
sub-divN/A
flip--N/A
lower-unsound-+.f64N/A
metadata-evalN/A
lift-*.f64N/A
*-rgt-identityN/A
lift-*.f64N/A
lower-unsound-/.f64N/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
lift-*.f64N/A
*-rgt-identityN/A
Applied rewrites76.0%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites99.8%
(FPCore (x) :precision binary64 (if (<= (fabs x) 4980620899901579/36893488147419103232) (+ 1/2 (* -1/24 (pow (fabs x) 2))) (* (/ (- (cos (fabs x)) 1) (fabs x)) (/ -1 (fabs x)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.000135) {
tmp = 0.5 + (-0.041666666666666664 * pow(fabs(x), 2.0));
} else {
tmp = ((cos(fabs(x)) - 1.0) / fabs(x)) * (-1.0 / fabs(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 (abs(x) <= 0.000135d0) then
tmp = 0.5d0 + ((-0.041666666666666664d0) * (abs(x) ** 2.0d0))
else
tmp = ((cos(abs(x)) - 1.0d0) / abs(x)) * ((-1.0d0) / abs(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 0.000135) {
tmp = 0.5 + (-0.041666666666666664 * Math.pow(Math.abs(x), 2.0));
} else {
tmp = ((Math.cos(Math.abs(x)) - 1.0) / Math.abs(x)) * (-1.0 / Math.abs(x));
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 0.000135: tmp = 0.5 + (-0.041666666666666664 * math.pow(math.fabs(x), 2.0)) else: tmp = ((math.cos(math.fabs(x)) - 1.0) / math.fabs(x)) * (-1.0 / math.fabs(x)) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 0.000135) tmp = Float64(0.5 + Float64(-0.041666666666666664 * (abs(x) ^ 2.0))); else tmp = Float64(Float64(Float64(cos(abs(x)) - 1.0) / abs(x)) * Float64(-1.0 / abs(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 0.000135) tmp = 0.5 + (-0.041666666666666664 * (abs(x) ^ 2.0)); else tmp = ((cos(abs(x)) - 1.0) / abs(x)) * (-1.0 / abs(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 4980620899901579/36893488147419103232], N[(1/2 + N[(-1/24 * N[Power[N[Abs[x], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[(-1 / N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq \frac{4980620899901579}{36893488147419103232}:\\
\;\;\;\;\frac{1}{2} + \frac{-1}{24} \cdot {\left(\left|x\right|\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(\left|x\right|\right) - 1}{\left|x\right|} \cdot \frac{-1}{\left|x\right|}\\
\end{array}
if x < 1.35e-4Initial program 51.1%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6450.3%
Applied rewrites50.3%
if 1.35e-4 < x Initial program 51.1%
lift-/.f64N/A
lift-*.f64N/A
sqr-neg-revN/A
associate-/r*N/A
mult-flipN/A
lower-*.f64N/A
frac-2negN/A
remove-double-negN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6452.3%
Applied rewrites52.3%
(FPCore (x) :precision binary64 (if (<= (fabs x) 4980620899901579/36893488147419103232) (+ 1/2 (* -1/24 (pow (fabs x) 2))) (/ (/ (- 1 (cos (fabs x))) (fabs x)) (fabs x))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.000135) {
tmp = 0.5 + (-0.041666666666666664 * pow(fabs(x), 2.0));
} else {
tmp = ((1.0 - cos(fabs(x))) / fabs(x)) / fabs(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 (abs(x) <= 0.000135d0) then
tmp = 0.5d0 + ((-0.041666666666666664d0) * (abs(x) ** 2.0d0))
else
tmp = ((1.0d0 - cos(abs(x))) / abs(x)) / abs(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 0.000135) {
tmp = 0.5 + (-0.041666666666666664 * Math.pow(Math.abs(x), 2.0));
} else {
tmp = ((1.0 - Math.cos(Math.abs(x))) / Math.abs(x)) / Math.abs(x);
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 0.000135: tmp = 0.5 + (-0.041666666666666664 * math.pow(math.fabs(x), 2.0)) else: tmp = ((1.0 - math.cos(math.fabs(x))) / math.fabs(x)) / math.fabs(x) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 0.000135) tmp = Float64(0.5 + Float64(-0.041666666666666664 * (abs(x) ^ 2.0))); else tmp = Float64(Float64(Float64(1.0 - cos(abs(x))) / abs(x)) / abs(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 0.000135) tmp = 0.5 + (-0.041666666666666664 * (abs(x) ^ 2.0)); else tmp = ((1.0 - cos(abs(x))) / abs(x)) / abs(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 4980620899901579/36893488147419103232], N[(1/2 + N[(-1/24 * N[Power[N[Abs[x], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1 - N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq \frac{4980620899901579}{36893488147419103232}:\\
\;\;\;\;\frac{1}{2} + \frac{-1}{24} \cdot {\left(\left|x\right|\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos \left(\left|x\right|\right)}{\left|x\right|}}{\left|x\right|}\\
\end{array}
if x < 1.35e-4Initial program 51.1%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6450.3%
Applied rewrites50.3%
if 1.35e-4 < x Initial program 51.1%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6452.3%
Applied rewrites52.3%
(FPCore (x) :precision binary64 (if (<= (fabs x) 4980620899901579/36893488147419103232) (+ 1/2 (* -1/24 (pow (fabs x) 2))) (/ (- 1 (cos (fabs x))) (* (fabs x) (fabs x)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.000135) {
tmp = 0.5 + (-0.041666666666666664 * pow(fabs(x), 2.0));
} else {
tmp = (1.0 - cos(fabs(x))) / (fabs(x) * fabs(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 (abs(x) <= 0.000135d0) then
tmp = 0.5d0 + ((-0.041666666666666664d0) * (abs(x) ** 2.0d0))
else
tmp = (1.0d0 - cos(abs(x))) / (abs(x) * abs(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 0.000135) {
tmp = 0.5 + (-0.041666666666666664 * Math.pow(Math.abs(x), 2.0));
} else {
tmp = (1.0 - Math.cos(Math.abs(x))) / (Math.abs(x) * Math.abs(x));
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 0.000135: tmp = 0.5 + (-0.041666666666666664 * math.pow(math.fabs(x), 2.0)) else: tmp = (1.0 - math.cos(math.fabs(x))) / (math.fabs(x) * math.fabs(x)) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 0.000135) tmp = Float64(0.5 + Float64(-0.041666666666666664 * (abs(x) ^ 2.0))); else tmp = Float64(Float64(1.0 - cos(abs(x))) / Float64(abs(x) * abs(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 0.000135) tmp = 0.5 + (-0.041666666666666664 * (abs(x) ^ 2.0)); else tmp = (1.0 - cos(abs(x))) / (abs(x) * abs(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 4980620899901579/36893488147419103232], N[(1/2 + N[(-1/24 * N[Power[N[Abs[x], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1 - N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq \frac{4980620899901579}{36893488147419103232}:\\
\;\;\;\;\frac{1}{2} + \frac{-1}{24} \cdot {\left(\left|x\right|\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos \left(\left|x\right|\right)}{\left|x\right| \cdot \left|x\right|}\\
\end{array}
if x < 1.35e-4Initial program 51.1%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6450.3%
Applied rewrites50.3%
if 1.35e-4 < x Initial program 51.1%
(FPCore (x)
:precision binary64
(if (<=
(fabs x)
1050000000000000039771512955146801415361985593779020615116046538467559188987904)
1/2
(/ (- 1 1) (* (fabs x) (fabs x)))))double code(double x) {
double tmp;
if (fabs(x) <= 1.05e+78) {
tmp = 0.5;
} else {
tmp = (1.0 - 1.0) / (fabs(x) * fabs(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 (abs(x) <= 1.05d+78) then
tmp = 0.5d0
else
tmp = (1.0d0 - 1.0d0) / (abs(x) * abs(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 1.05e+78) {
tmp = 0.5;
} else {
tmp = (1.0 - 1.0) / (Math.abs(x) * Math.abs(x));
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 1.05e+78: tmp = 0.5 else: tmp = (1.0 - 1.0) / (math.fabs(x) * math.fabs(x)) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 1.05e+78) tmp = 0.5; else tmp = Float64(Float64(1.0 - 1.0) / Float64(abs(x) * abs(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 1.05e+78) tmp = 0.5; else tmp = (1.0 - 1.0) / (abs(x) * abs(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 1050000000000000039771512955146801415361985593779020615116046538467559188987904], 1/2, N[(N[(1 - 1), $MachinePrecision] / N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1050000000000000039771512955146801415361985593779020615116046538467559188987904:\\
\;\;\;\;\frac{1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - 1}{\left|x\right| \cdot \left|x\right|}\\
\end{array}
if x < 1.05e78Initial program 51.1%
Taylor expanded in x around 0
Applied rewrites51.3%
if 1.05e78 < x Initial program 51.1%
Taylor expanded in x around 0
Applied rewrites26.8%
(FPCore (x) :precision binary64 1/2)
double code(double x) {
return 0.5;
}
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 = 0.5d0
end function
public static double code(double x) {
return 0.5;
}
def code(x): return 0.5
function code(x) return 0.5 end
function tmp = code(x) tmp = 0.5; end
code[x_] := 1/2
\frac{1}{2}
Initial program 51.1%
Taylor expanded in x around 0
Applied rewrites51.3%
herbie shell --seed 2025285 -o generate:evaluate
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1 (cos x)) (* x x)))