
(FPCore (z0) :precision binary64 (cos (* (+ PI PI) z0)))
double code(double z0) {
return cos(((((double) M_PI) + ((double) M_PI)) * z0));
}
public static double code(double z0) {
return Math.cos(((Math.PI + Math.PI) * z0));
}
def code(z0): return math.cos(((math.pi + math.pi) * z0))
function code(z0) return cos(Float64(Float64(pi + pi) * z0)) end
function tmp = code(z0) tmp = cos(((pi + pi) * z0)); end
code[z0_] := N[Cos[N[(N[(Pi + Pi), $MachinePrecision] * z0), $MachinePrecision]], $MachinePrecision]
\cos \left(\left(\pi + \pi\right) \cdot z0\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z0) :precision binary64 (cos (* (+ PI PI) z0)))
double code(double z0) {
return cos(((((double) M_PI) + ((double) M_PI)) * z0));
}
public static double code(double z0) {
return Math.cos(((Math.PI + Math.PI) * z0));
}
def code(z0): return math.cos(((math.pi + math.pi) * z0))
function code(z0) return cos(Float64(Float64(pi + pi) * z0)) end
function tmp = code(z0) tmp = cos(((pi + pi) * z0)); end
code[z0_] := N[Cos[N[(N[(Pi + Pi), $MachinePrecision] * z0), $MachinePrecision]], $MachinePrecision]
\cos \left(\left(\pi + \pi\right) \cdot z0\right)
(FPCore (z0) :precision binary64 (if (<= (fabs z0) 85000.0) (+ (* (sin (* PI (fabs z0))) (cos (* PI (- -0.5 (fabs z0))))) (+ 0.5 (* 0.5 (sin (* PI (+ (fabs z0) (- (fabs z0) -0.5))))))) 1.0))
double code(double z0) {
double tmp;
if (fabs(z0) <= 85000.0) {
tmp = (sin((((double) M_PI) * fabs(z0))) * cos((((double) M_PI) * (-0.5 - fabs(z0))))) + (0.5 + (0.5 * sin((((double) M_PI) * (fabs(z0) + (fabs(z0) - -0.5))))));
} else {
tmp = 1.0;
}
return tmp;
}
public static double code(double z0) {
double tmp;
if (Math.abs(z0) <= 85000.0) {
tmp = (Math.sin((Math.PI * Math.abs(z0))) * Math.cos((Math.PI * (-0.5 - Math.abs(z0))))) + (0.5 + (0.5 * Math.sin((Math.PI * (Math.abs(z0) + (Math.abs(z0) - -0.5))))));
} else {
tmp = 1.0;
}
return tmp;
}
def code(z0): tmp = 0 if math.fabs(z0) <= 85000.0: tmp = (math.sin((math.pi * math.fabs(z0))) * math.cos((math.pi * (-0.5 - math.fabs(z0))))) + (0.5 + (0.5 * math.sin((math.pi * (math.fabs(z0) + (math.fabs(z0) - -0.5)))))) else: tmp = 1.0 return tmp
function code(z0) tmp = 0.0 if (abs(z0) <= 85000.0) tmp = Float64(Float64(sin(Float64(pi * abs(z0))) * cos(Float64(pi * Float64(-0.5 - abs(z0))))) + Float64(0.5 + Float64(0.5 * sin(Float64(pi * Float64(abs(z0) + Float64(abs(z0) - -0.5))))))); else tmp = 1.0; end return tmp end
function tmp_2 = code(z0) tmp = 0.0; if (abs(z0) <= 85000.0) tmp = (sin((pi * abs(z0))) * cos((pi * (-0.5 - abs(z0))))) + (0.5 + (0.5 * sin((pi * (abs(z0) + (abs(z0) - -0.5)))))); else tmp = 1.0; end tmp_2 = tmp; end
code[z0_] := If[LessEqual[N[Abs[z0], $MachinePrecision], 85000.0], N[(N[(N[Sin[N[(Pi * N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(Pi * N[(-0.5 - N[Abs[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(0.5 * N[Sin[N[(Pi * N[(N[Abs[z0], $MachinePrecision] + N[(N[Abs[z0], $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\mathbf{if}\;\left|z0\right| \leq 85000:\\
\;\;\;\;\sin \left(\pi \cdot \left|z0\right|\right) \cdot \cos \left(\pi \cdot \left(-0.5 - \left|z0\right|\right)\right) + \left(0.5 + 0.5 \cdot \sin \left(\pi \cdot \left(\left|z0\right| + \left(\left|z0\right| - -0.5\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if z0 < 85000Initial program 57.5%
lift-cos.f64N/A
sin-+PI/2-revN/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
sin-sumN/A
sin-+PI/2-revN/A
lower-+.f64N/A
Applied rewrites59.6%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
distribute-lft-outN/A
lower-*.f64N/A
Applied rewrites58.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6458.7%
lift-cos.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
metadata-evalN/A
sub-flipN/A
lift--.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6458.7%
Applied rewrites58.7%
if 85000 < z0 Initial program 57.5%
Taylor expanded in z0 around 0
Applied rewrites97.2%
(FPCore (z0) :precision binary64 (if (<= (fabs z0) 85000.0) (sin (- (* (* -2.0 PI) (fabs z0)) -1.5707963267948966)) 1.0))
double code(double z0) {
double tmp;
if (fabs(z0) <= 85000.0) {
tmp = sin((((-2.0 * ((double) M_PI)) * fabs(z0)) - -1.5707963267948966));
} else {
tmp = 1.0;
}
return tmp;
}
public static double code(double z0) {
double tmp;
if (Math.abs(z0) <= 85000.0) {
tmp = Math.sin((((-2.0 * Math.PI) * Math.abs(z0)) - -1.5707963267948966));
} else {
tmp = 1.0;
}
return tmp;
}
def code(z0): tmp = 0 if math.fabs(z0) <= 85000.0: tmp = math.sin((((-2.0 * math.pi) * math.fabs(z0)) - -1.5707963267948966)) else: tmp = 1.0 return tmp
function code(z0) tmp = 0.0 if (abs(z0) <= 85000.0) tmp = sin(Float64(Float64(Float64(-2.0 * pi) * abs(z0)) - -1.5707963267948966)); else tmp = 1.0; end return tmp end
function tmp_2 = code(z0) tmp = 0.0; if (abs(z0) <= 85000.0) tmp = sin((((-2.0 * pi) * abs(z0)) - -1.5707963267948966)); else tmp = 1.0; end tmp_2 = tmp; end
code[z0_] := If[LessEqual[N[Abs[z0], $MachinePrecision], 85000.0], N[Sin[N[(N[(N[(-2.0 * Pi), $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision] - -1.5707963267948966), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\mathbf{if}\;\left|z0\right| \leq 85000:\\
\;\;\;\;\sin \left(\left(-2 \cdot \pi\right) \cdot \left|z0\right| - -1.5707963267948966\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if z0 < 85000Initial program 57.5%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lift-+.f64N/A
count-2N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lift-PI.f64N/A
mult-flipN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites57.5%
Evaluated real constant57.5%
if 85000 < z0 Initial program 57.5%
Taylor expanded in z0 around 0
Applied rewrites97.2%
(FPCore (z0) :precision binary64 (if (<= (fabs z0) 85000.0) (cos (* 6.283185307179586 (fabs z0))) 1.0))
double code(double z0) {
double tmp;
if (fabs(z0) <= 85000.0) {
tmp = cos((6.283185307179586 * fabs(z0)));
} else {
tmp = 1.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(z0)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8) :: tmp
if (abs(z0) <= 85000.0d0) then
tmp = cos((6.283185307179586d0 * abs(z0)))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double z0) {
double tmp;
if (Math.abs(z0) <= 85000.0) {
tmp = Math.cos((6.283185307179586 * Math.abs(z0)));
} else {
tmp = 1.0;
}
return tmp;
}
def code(z0): tmp = 0 if math.fabs(z0) <= 85000.0: tmp = math.cos((6.283185307179586 * math.fabs(z0))) else: tmp = 1.0 return tmp
function code(z0) tmp = 0.0 if (abs(z0) <= 85000.0) tmp = cos(Float64(6.283185307179586 * abs(z0))); else tmp = 1.0; end return tmp end
function tmp_2 = code(z0) tmp = 0.0; if (abs(z0) <= 85000.0) tmp = cos((6.283185307179586 * abs(z0))); else tmp = 1.0; end tmp_2 = tmp; end
code[z0_] := If[LessEqual[N[Abs[z0], $MachinePrecision], 85000.0], N[Cos[N[(6.283185307179586 * N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\mathbf{if}\;\left|z0\right| \leq 85000:\\
\;\;\;\;\cos \left(6.283185307179586 \cdot \left|z0\right|\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if z0 < 85000Initial program 57.5%
Evaluated real constant57.5%
if 85000 < z0 Initial program 57.5%
Taylor expanded in z0 around 0
Applied rewrites97.2%
(FPCore (z0) :precision binary64 1.0)
double code(double z0) {
return 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(z0)
use fmin_fmax_functions
real(8), intent (in) :: z0
code = 1.0d0
end function
public static double code(double z0) {
return 1.0;
}
def code(z0): return 1.0
function code(z0) return 1.0 end
function tmp = code(z0) tmp = 1.0; end
code[z0_] := 1.0
1
Initial program 57.5%
Taylor expanded in z0 around 0
Applied rewrites97.2%
herbie shell --seed 2025250
(FPCore (z0)
:name "(cos (* (+ PI PI) z0))"
:precision binary64
(cos (* (+ PI PI) z0)))