
(FPCore (x) :precision binary64 (/ (- 1.0 (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.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{x \cdot x}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- 1.0 (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.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{x \cdot x}
\end{array}
(FPCore (x) :precision binary64 (* (sin x) (/ (/ (tan (/ x 2.0)) x) x)))
double code(double x) {
return sin(x) * ((tan((x / 2.0)) / 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 = sin(x) * ((tan((x / 2.0d0)) / x) / x)
end function
public static double code(double x) {
return Math.sin(x) * ((Math.tan((x / 2.0)) / x) / x);
}
def code(x): return math.sin(x) * ((math.tan((x / 2.0)) / x) / x)
function code(x) return Float64(sin(x) * Float64(Float64(tan(Float64(x / 2.0)) / x) / x)) end
function tmp = code(x) tmp = sin(x) * ((tan((x / 2.0)) / x) / x); end
code[x_] := N[(N[Sin[x], $MachinePrecision] * N[(N[(N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\frac{\tan \left(\frac{x}{2}\right)}{x}}{x}
\end{array}
Initial program 51.3%
lift-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
pow2N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
pow2N/A
lift-*.f6451.5
Applied rewrites51.5%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
pow2N/A
sub-divN/A
flip--N/A
metadata-evalN/A
1-sub-cosN/A
sqr-sin-a-revN/A
frac-2negN/A
+-commutativeN/A
associate-/l/N/A
distribute-lft-neg-inN/A
Applied rewrites75.8%
lift-/.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites99.4%
Taylor expanded in x around inf
hang-0p-tanN/A
lower-tan.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
(FPCore (x) :precision binary64 (if (<= x 4e-5) (fma (* x x) -0.041666666666666664 0.5) (* (/ (sin x) (* x x)) (tan (/ x 2.0)))))
double code(double x) {
double tmp;
if (x <= 4e-5) {
tmp = fma((x * x), -0.041666666666666664, 0.5);
} else {
tmp = (sin(x) / (x * x)) * tan((x / 2.0));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 4e-5) tmp = fma(Float64(x * x), -0.041666666666666664, 0.5); else tmp = Float64(Float64(sin(x) / Float64(x * x)) * tan(Float64(x / 2.0))); end return tmp end
code[x_] := If[LessEqual[x, 4e-5], N[(N[(x * x), $MachinePrecision] * -0.041666666666666664 + 0.5), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, -0.041666666666666664, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin x}{x \cdot x} \cdot \tan \left(\frac{x}{2}\right)\\
\end{array}
\end{array}
if x < 4.00000000000000033e-5Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6450.0
Applied rewrites50.0%
if 4.00000000000000033e-5 < x Initial program 51.3%
lift-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
pow2N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
pow2N/A
lift-*.f6451.5
Applied rewrites51.5%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
pow2N/A
sub-divN/A
flip--N/A
metadata-evalN/A
1-sub-cosN/A
sqr-sin-a-revN/A
frac-2negN/A
+-commutativeN/A
associate-/l/N/A
distribute-lft-neg-inN/A
Applied rewrites75.8%
lift-/.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites99.4%
Taylor expanded in x around inf
unpow2N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
pow2N/A
lift-*.f64N/A
hang-0p-tanN/A
lower-tan.f64N/A
lower-/.f6476.1
Applied rewrites76.1%
(FPCore (x) :precision binary64 (if (<= x 0.028) (fma (- (* 0.001388888888888889 (* x x)) 0.041666666666666664) (* x x) 0.5) (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
double tmp;
if (x <= 0.028) {
tmp = fma(((0.001388888888888889 * (x * x)) - 0.041666666666666664), (x * x), 0.5);
} else {
tmp = ((1.0 - cos(x)) / x) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 0.028) tmp = fma(Float64(Float64(0.001388888888888889 * Float64(x * x)) - 0.041666666666666664), Float64(x * x), 0.5); else tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x); end return tmp end
code[x_] := If[LessEqual[x, 0.028], N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.028:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889 \cdot \left(x \cdot x\right) - 0.041666666666666664, x \cdot x, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\
\end{array}
\end{array}
if x < 0.0280000000000000006Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6450.5
Applied rewrites50.5%
if 0.0280000000000000006 < x Initial program 51.3%
lift-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
lift--.f6452.6
Applied rewrites52.6%
(FPCore (x) :precision binary64 (if (<= x 0.028) (fma (- (* 0.001388888888888889 (* x x)) 0.041666666666666664) (* x x) 0.5) (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
double tmp;
if (x <= 0.028) {
tmp = fma(((0.001388888888888889 * (x * x)) - 0.041666666666666664), (x * x), 0.5);
} else {
tmp = (1.0 - cos(x)) / (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 0.028) tmp = fma(Float64(Float64(0.001388888888888889 * Float64(x * x)) - 0.041666666666666664), Float64(x * x), 0.5); else tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[x, 0.028], N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.028:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889 \cdot \left(x \cdot x\right) - 0.041666666666666664, x \cdot x, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.0280000000000000006Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6450.5
Applied rewrites50.5%
if 0.0280000000000000006 < x Initial program 51.3%
(FPCore (x) :precision binary64 (if (<= x 2e+23) (fma (- (* 0.001388888888888889 (* x x)) 0.041666666666666664) (* x x) 0.5) (fma (/ x (* x x)) (/ 1.0 x) (/ (- x) (* (* x x) x)))))
double code(double x) {
double tmp;
if (x <= 2e+23) {
tmp = fma(((0.001388888888888889 * (x * x)) - 0.041666666666666664), (x * x), 0.5);
} else {
tmp = fma((x / (x * x)), (1.0 / x), (-x / ((x * x) * x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 2e+23) tmp = fma(Float64(Float64(0.001388888888888889 * Float64(x * x)) - 0.041666666666666664), Float64(x * x), 0.5); else tmp = fma(Float64(x / Float64(x * x)), Float64(1.0 / x), Float64(Float64(-x) / Float64(Float64(x * x) * x))); end return tmp end
code[x_] := If[LessEqual[x, 2e+23], N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(x / N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / x), $MachinePrecision] + N[((-x) / N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+23}:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889 \cdot \left(x \cdot x\right) - 0.041666666666666664, x \cdot x, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{x \cdot x}, \frac{1}{x}, \frac{-x}{\left(x \cdot x\right) \cdot x}\right)\\
\end{array}
\end{array}
if x < 1.9999999999999998e23Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6450.5
Applied rewrites50.5%
if 1.9999999999999998e23 < x Initial program 51.3%
lift-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
pow2N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
pow2N/A
lift-*.f6451.5
Applied rewrites51.5%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
associate-/r*N/A
frac-subN/A
pow2N/A
unpow3N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
Applied rewrites19.3%
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-lft-identityN/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
div-addN/A
Applied rewrites19.5%
Taylor expanded in x around 0
mul-1-negN/A
lift-neg.f6428.3
Applied rewrites28.3%
(FPCore (x) :precision binary64 (if (<= x 9e+36) (fma (- (* 0.001388888888888889 (* x x)) 0.041666666666666664) (* x x) 0.5) (fma (/ x (* x x)) (/ 1.0 x) (/ -1.0 (* x x)))))
double code(double x) {
double tmp;
if (x <= 9e+36) {
tmp = fma(((0.001388888888888889 * (x * x)) - 0.041666666666666664), (x * x), 0.5);
} else {
tmp = fma((x / (x * x)), (1.0 / x), (-1.0 / (x * x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 9e+36) tmp = fma(Float64(Float64(0.001388888888888889 * Float64(x * x)) - 0.041666666666666664), Float64(x * x), 0.5); else tmp = fma(Float64(x / Float64(x * x)), Float64(1.0 / x), Float64(-1.0 / Float64(x * x))); end return tmp end
code[x_] := If[LessEqual[x, 9e+36], N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(x / N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / x), $MachinePrecision] + N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889 \cdot \left(x \cdot x\right) - 0.041666666666666664, x \cdot x, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{x \cdot x}, \frac{1}{x}, \frac{-1}{x \cdot x}\right)\\
\end{array}
\end{array}
if x < 8.99999999999999994e36Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6450.5
Applied rewrites50.5%
if 8.99999999999999994e36 < x Initial program 51.3%
lift-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
pow2N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
pow2N/A
lift-*.f6451.5
Applied rewrites51.5%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
associate-/r*N/A
frac-subN/A
pow2N/A
unpow3N/A
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f64N/A
lift-cos.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
Applied rewrites19.3%
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-lft-identityN/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
div-addN/A
Applied rewrites19.5%
Taylor expanded in x around 0
lower-/.f64N/A
pow2N/A
lift-*.f6427.5
Applied rewrites27.5%
(FPCore (x) :precision binary64 (if (<= x 7.5e+38) (fma (- (* 0.001388888888888889 (* x x)) 0.041666666666666664) (* x x) 0.5) (/ (- 1.0 1.0) (* x x))))
double code(double x) {
double tmp;
if (x <= 7.5e+38) {
tmp = fma(((0.001388888888888889 * (x * x)) - 0.041666666666666664), (x * x), 0.5);
} else {
tmp = (1.0 - 1.0) / (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 7.5e+38) tmp = fma(Float64(Float64(0.001388888888888889 * Float64(x * x)) - 0.041666666666666664), Float64(x * x), 0.5); else tmp = Float64(Float64(1.0 - 1.0) / Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[x, 7.5e+38], N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 - 1.0), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.5 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889 \cdot \left(x \cdot x\right) - 0.041666666666666664, x \cdot x, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - 1}{x \cdot x}\\
\end{array}
\end{array}
if x < 7.4999999999999999e38Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6450.5
Applied rewrites50.5%
if 7.4999999999999999e38 < x Initial program 51.3%
Taylor expanded in x around 0
Applied rewrites27.0%
(FPCore (x) :precision binary64 (if (<= x 3.45) (fma (* x x) -0.041666666666666664 0.5) (/ (- 1.0 1.0) (* x x))))
double code(double x) {
double tmp;
if (x <= 3.45) {
tmp = fma((x * x), -0.041666666666666664, 0.5);
} else {
tmp = (1.0 - 1.0) / (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 3.45) tmp = fma(Float64(x * x), -0.041666666666666664, 0.5); else tmp = Float64(Float64(1.0 - 1.0) / Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[x, 3.45], N[(N[(x * x), $MachinePrecision] * -0.041666666666666664 + 0.5), $MachinePrecision], N[(N[(1.0 - 1.0), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.45:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, -0.041666666666666664, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - 1}{x \cdot x}\\
\end{array}
\end{array}
if x < 3.4500000000000002Initial program 51.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6450.0
Applied rewrites50.0%
if 3.4500000000000002 < x Initial program 51.3%
Taylor expanded in x around 0
Applied rewrites27.0%
(FPCore (x) :precision binary64 0.5)
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_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 51.3%
Taylor expanded in x around 0
Applied rewrites51.0%
herbie shell --seed 2025131
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))