
(FPCore (z0) :precision binary64 (sin (* z0 (- PI))))
double code(double z0) {
return sin((z0 * -((double) M_PI)));
}
public static double code(double z0) {
return Math.sin((z0 * -Math.PI));
}
def code(z0): return math.sin((z0 * -math.pi))
function code(z0) return sin(Float64(z0 * Float64(-pi))) end
function tmp = code(z0) tmp = sin((z0 * -pi)); end
code[z0_] := N[Sin[N[(z0 * (-Pi)), $MachinePrecision]], $MachinePrecision]
\sin \left(z0 \cdot \left(-\pi\right)\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z0) :precision binary64 (sin (* z0 (- PI))))
double code(double z0) {
return sin((z0 * -((double) M_PI)));
}
public static double code(double z0) {
return Math.sin((z0 * -Math.PI));
}
def code(z0): return math.sin((z0 * -math.pi))
function code(z0) return sin(Float64(z0 * Float64(-pi))) end
function tmp = code(z0) tmp = sin((z0 * -pi)); end
code[z0_] := N[Sin[N[(z0 * (-Pi)), $MachinePrecision]], $MachinePrecision]
\sin \left(z0 \cdot \left(-\pi\right)\right)
(FPCore (z0)
:precision binary64
(let* ((t_0 (* (fabs z0) PI)))
(*
(copysign 1.0 z0)
(if (<= (fabs z0) 4e-5)
(sin (* (fabs z0) -3.141592653589793))
(* 0.5 (- (sin (- t_0 PI)) (sin t_0)))))))double code(double z0) {
double t_0 = fabs(z0) * ((double) M_PI);
double tmp;
if (fabs(z0) <= 4e-5) {
tmp = sin((fabs(z0) * -3.141592653589793));
} else {
tmp = 0.5 * (sin((t_0 - ((double) M_PI))) - sin(t_0));
}
return copysign(1.0, z0) * tmp;
}
public static double code(double z0) {
double t_0 = Math.abs(z0) * Math.PI;
double tmp;
if (Math.abs(z0) <= 4e-5) {
tmp = Math.sin((Math.abs(z0) * -3.141592653589793));
} else {
tmp = 0.5 * (Math.sin((t_0 - Math.PI)) - Math.sin(t_0));
}
return Math.copySign(1.0, z0) * tmp;
}
def code(z0): t_0 = math.fabs(z0) * math.pi tmp = 0 if math.fabs(z0) <= 4e-5: tmp = math.sin((math.fabs(z0) * -3.141592653589793)) else: tmp = 0.5 * (math.sin((t_0 - math.pi)) - math.sin(t_0)) return math.copysign(1.0, z0) * tmp
function code(z0) t_0 = Float64(abs(z0) * pi) tmp = 0.0 if (abs(z0) <= 4e-5) tmp = sin(Float64(abs(z0) * -3.141592653589793)); else tmp = Float64(0.5 * Float64(sin(Float64(t_0 - pi)) - sin(t_0))); end return Float64(copysign(1.0, z0) * tmp) end
function tmp_2 = code(z0) t_0 = abs(z0) * pi; tmp = 0.0; if (abs(z0) <= 4e-5) tmp = sin((abs(z0) * -3.141592653589793)); else tmp = 0.5 * (sin((t_0 - pi)) - sin(t_0)); end tmp_2 = (sign(z0) * abs(1.0)) * tmp; end
code[z0_] := Block[{t$95$0 = N[(N[Abs[z0], $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[z0], $MachinePrecision], 4e-5], N[Sin[N[(N[Abs[z0], $MachinePrecision] * -3.141592653589793), $MachinePrecision]], $MachinePrecision], N[(0.5 * N[(N[Sin[N[(t$95$0 - Pi), $MachinePrecision]], $MachinePrecision] - N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|z0\right| \cdot \pi\\
\mathsf{copysign}\left(1, z0\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|z0\right| \leq 4 \cdot 10^{-5}:\\
\;\;\;\;\sin \left(\left|z0\right| \cdot -3.141592653589793\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\sin \left(t\_0 - \pi\right) - \sin t\_0\right)\\
\end{array}
\end{array}
if z0 < 4.0000000000000003e-5Initial program 53.5%
Evaluated real constant53.5%
if 4.0000000000000003e-5 < z0 Initial program 53.5%
lift-sin.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
sin-negN/A
sin-+PI-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f646.4%
Applied rewrites6.4%
lift-sin.f64N/A
lift-+.f64N/A
lift-PI.f64N/A
sin-+PIN/A
mul-1-negN/A
cos-PIN/A
lift-PI.f64N/A
cos-neg-revN/A
lift-neg.f64N/A
sin-+PI/2-revN/A
sin-multN/A
lower-/.f64N/A
Applied rewrites52.4%
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
sin-mult-revN/A
*-commutativeN/A
Applied rewrites51.6%
Taylor expanded in z0 around inf
lower-*.f64N/A
lower--.f64N/A
lower-sin.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-PI.f6451.6%
Applied rewrites51.6%
(FPCore (z0) :precision binary64 (sin (* z0 -3.141592653589793)))
double code(double z0) {
return sin((z0 * -3.141592653589793));
}
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 = sin((z0 * (-3.141592653589793d0)))
end function
public static double code(double z0) {
return Math.sin((z0 * -3.141592653589793));
}
def code(z0): return math.sin((z0 * -3.141592653589793))
function code(z0) return sin(Float64(z0 * -3.141592653589793)) end
function tmp = code(z0) tmp = sin((z0 * -3.141592653589793)); end
code[z0_] := N[Sin[N[(z0 * -3.141592653589793), $MachinePrecision]], $MachinePrecision]
\sin \left(z0 \cdot -3.141592653589793\right)
Initial program 53.5%
Evaluated real constant53.5%
(FPCore (z0) :precision binary64 (cos (- 1.5707963267948966 PI)))
double code(double z0) {
return cos((1.5707963267948966 - ((double) M_PI)));
}
public static double code(double z0) {
return Math.cos((1.5707963267948966 - Math.PI));
}
def code(z0): return math.cos((1.5707963267948966 - math.pi))
function code(z0) return cos(Float64(1.5707963267948966 - pi)) end
function tmp = code(z0) tmp = cos((1.5707963267948966 - pi)); end
code[z0_] := N[Cos[N[(1.5707963267948966 - Pi), $MachinePrecision]], $MachinePrecision]
\cos \left(1.5707963267948966 - \pi\right)
Initial program 53.5%
lift-sin.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
sin-negN/A
sin-+PI-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f646.4%
Applied rewrites6.4%
lift-sin.f64N/A
lift-+.f64N/A
add-flipN/A
lift-neg.f64N/A
sub-negate-revN/A
sin-negN/A
cos-+PI/2-revN/A
lower-cos.f64N/A
lower-+.f64N/A
sub-negate-revN/A
lift-neg.f64N/A
add-flipN/A
lift-+.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
mult-flipN/A
lower-*.f64N/A
metadata-eval6.4%
Applied rewrites6.4%
Evaluated real constant6.4%
Taylor expanded in z0 around 0
lower--.f64N/A
lower-PI.f643.7%
Applied rewrites3.7%
(FPCore (z0) :precision binary64 (sin PI))
double code(double z0) {
return sin(((double) M_PI));
}
public static double code(double z0) {
return Math.sin(Math.PI);
}
def code(z0): return math.sin(math.pi)
function code(z0) return sin(pi) end
function tmp = code(z0) tmp = sin(pi); end
code[z0_] := N[Sin[Pi], $MachinePrecision]
\sin \pi
Initial program 53.5%
lift-sin.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
sin-negN/A
sin-+PI-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f646.4%
Applied rewrites6.4%
Taylor expanded in z0 around 0
lower-PI.f643.7%
Applied rewrites3.7%
herbie shell --seed 2025250
(FPCore (z0)
:name "(sin (* z0 (- PI)))"
:precision binary64
(sin (* z0 (- PI))))