
(FPCore (z1 z0) :precision binary64 (sin (* PI (* z1 (- z0)))))
double code(double z1, double z0) {
return sin((((double) M_PI) * (z1 * -z0)));
}
public static double code(double z1, double z0) {
return Math.sin((Math.PI * (z1 * -z0)));
}
def code(z1, z0): return math.sin((math.pi * (z1 * -z0)))
function code(z1, z0) return sin(Float64(pi * Float64(z1 * Float64(-z0)))) end
function tmp = code(z1, z0) tmp = sin((pi * (z1 * -z0))); end
code[z1_, z0_] := N[Sin[N[(Pi * N[(z1 * (-z0)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z1 z0) :precision binary64 (sin (* PI (* z1 (- z0)))))
double code(double z1, double z0) {
return sin((((double) M_PI) * (z1 * -z0)));
}
public static double code(double z1, double z0) {
return Math.sin((Math.PI * (z1 * -z0)));
}
def code(z1, z0): return math.sin((math.pi * (z1 * -z0)))
function code(z1, z0) return sin(Float64(pi * Float64(z1 * Float64(-z0)))) end
function tmp = code(z1, z0) tmp = sin((pi * (z1 * -z0))); end
code[z1_, z0_] := N[Sin[N[(Pi * N[(z1 * (-z0)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)
(FPCore (z1 z0)
:precision binary64
(*
(copysign 1.0 z1)
(*
(copysign 1.0 z0)
(if (<= (* PI (* (fabs z1) (- (fabs z0)))) -2e+32)
(sin (- (- 1.5707963267948966) (* -0.5 PI)))
(sin (* -3.141592653589793 (* (fabs z0) (fabs z1))))))))double code(double z1, double z0) {
double tmp;
if ((((double) M_PI) * (fabs(z1) * -fabs(z0))) <= -2e+32) {
tmp = sin((-1.5707963267948966 - (-0.5 * ((double) M_PI))));
} else {
tmp = sin((-3.141592653589793 * (fabs(z0) * fabs(z1))));
}
return copysign(1.0, z1) * (copysign(1.0, z0) * tmp);
}
public static double code(double z1, double z0) {
double tmp;
if ((Math.PI * (Math.abs(z1) * -Math.abs(z0))) <= -2e+32) {
tmp = Math.sin((-1.5707963267948966 - (-0.5 * Math.PI)));
} else {
tmp = Math.sin((-3.141592653589793 * (Math.abs(z0) * Math.abs(z1))));
}
return Math.copySign(1.0, z1) * (Math.copySign(1.0, z0) * tmp);
}
def code(z1, z0): tmp = 0 if (math.pi * (math.fabs(z1) * -math.fabs(z0))) <= -2e+32: tmp = math.sin((-1.5707963267948966 - (-0.5 * math.pi))) else: tmp = math.sin((-3.141592653589793 * (math.fabs(z0) * math.fabs(z1)))) return math.copysign(1.0, z1) * (math.copysign(1.0, z0) * tmp)
function code(z1, z0) tmp = 0.0 if (Float64(pi * Float64(abs(z1) * Float64(-abs(z0)))) <= -2e+32) tmp = sin(Float64(Float64(-1.5707963267948966) - Float64(-0.5 * pi))); else tmp = sin(Float64(-3.141592653589793 * Float64(abs(z0) * abs(z1)))); end return Float64(copysign(1.0, z1) * Float64(copysign(1.0, z0) * tmp)) end
function tmp_2 = code(z1, z0) tmp = 0.0; if ((pi * (abs(z1) * -abs(z0))) <= -2e+32) tmp = sin((-1.5707963267948966 - (-0.5 * pi))); else tmp = sin((-3.141592653589793 * (abs(z0) * abs(z1)))); end tmp_2 = (sign(z1) * abs(1.0)) * ((sign(z0) * abs(1.0)) * tmp); end
code[z1_, z0_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(Pi * N[(N[Abs[z1], $MachinePrecision] * (-N[Abs[z0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], -2e+32], N[Sin[N[((-1.5707963267948966) - N[(-0.5 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sin[N[(-3.141592653589793 * N[(N[Abs[z0], $MachinePrecision] * N[Abs[z1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, z1\right) \cdot \left(\mathsf{copysign}\left(1, z0\right) \cdot \begin{array}{l}
\mathbf{if}\;\pi \cdot \left(\left|z1\right| \cdot \left(-\left|z0\right|\right)\right) \leq -2 \cdot 10^{+32}:\\
\;\;\;\;\sin \left(\left(-1.5707963267948966\right) - -0.5 \cdot \pi\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(-3.141592653589793 \cdot \left(\left|z0\right| \cdot \left|z1\right|\right)\right)\\
\end{array}\right)
if (*.f64 (PI.f64) (*.f64 z1 (neg.f64 z0))) < -2.0000000000000001e32Initial program 52.1%
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
sin-negN/A
cos-+PI/2-revN/A
lower-cos.f64N/A
lower-+.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
metadata-evalN/A
lower-/.f64N/A
metadata-eval6.1%
Applied rewrites6.1%
Taylor expanded in z1 around 0
lower-*.f64N/A
lower-PI.f643.8%
Applied rewrites3.8%
Evaluated real constant3.8%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lift-*.f64N/A
lower--.f64N/A
lower-neg.f6459.1%
Applied rewrites59.1%
if -2.0000000000000001e32 < (*.f64 (PI.f64) (*.f64 z1 (neg.f64 z0))) Initial program 52.1%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
pow1/3N/A
lift-PI.f64N/A
pow1/3N/A
pow-prod-upN/A
lower-pow.f64N/A
metadata-evalN/A
Applied rewrites51.8%
Evaluated real constant51.8%
Evaluated real constant52.2%
Taylor expanded in z1 around 0
lower-*.f64N/A
lower-*.f6452.1%
Applied rewrites52.1%
(FPCore (z1 z0) :precision binary64 (sin (* -3.141592653589793 (* z0 z1))))
double code(double z1, double z0) {
return sin((-3.141592653589793 * (z0 * z1)));
}
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(z1, z0)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
code = sin(((-3.141592653589793d0) * (z0 * z1)))
end function
public static double code(double z1, double z0) {
return Math.sin((-3.141592653589793 * (z0 * z1)));
}
def code(z1, z0): return math.sin((-3.141592653589793 * (z0 * z1)))
function code(z1, z0) return sin(Float64(-3.141592653589793 * Float64(z0 * z1))) end
function tmp = code(z1, z0) tmp = sin((-3.141592653589793 * (z0 * z1))); end
code[z1_, z0_] := N[Sin[N[(-3.141592653589793 * N[(z0 * z1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sin \left(-3.141592653589793 \cdot \left(z0 \cdot z1\right)\right)
Initial program 52.1%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
pow1/3N/A
lift-PI.f64N/A
pow1/3N/A
pow-prod-upN/A
lower-pow.f64N/A
metadata-evalN/A
Applied rewrites51.8%
Evaluated real constant51.8%
Evaluated real constant52.2%
Taylor expanded in z1 around 0
lower-*.f64N/A
lower-*.f6452.1%
Applied rewrites52.1%
(FPCore (z1 z0) :precision binary64 (* (copysign 1.0 z0) (cos 1.5707963267948966)))
double code(double z1, double z0) {
return copysign(1.0, z0) * cos(1.5707963267948966);
}
public static double code(double z1, double z0) {
return Math.copySign(1.0, z0) * Math.cos(1.5707963267948966);
}
def code(z1, z0): return math.copysign(1.0, z0) * math.cos(1.5707963267948966)
function code(z1, z0) return Float64(copysign(1.0, z0) * cos(1.5707963267948966)) end
function tmp = code(z1, z0) tmp = (sign(z0) * abs(1.0)) * cos(1.5707963267948966); end
code[z1_, z0_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[Cos[1.5707963267948966], $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, z0\right) \cdot \cos 1.5707963267948966
Initial program 52.1%
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
sin-negN/A
cos-+PI/2-revN/A
lower-cos.f64N/A
lower-+.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
metadata-evalN/A
lower-/.f64N/A
metadata-eval6.1%
Applied rewrites6.1%
Taylor expanded in z1 around 0
lower-*.f64N/A
lower-PI.f643.8%
Applied rewrites3.8%
Evaluated real constant3.8%
herbie shell --seed 2025250
(FPCore (z1 z0)
:name "(sin (* PI (* z1 (- z0))))"
:precision binary64
(sin (* PI (* z1 (- z0)))))