
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) x (* (cos y) z)))
double code(double x, double y, double z) {
return fma(sin(y), x, (cos(y) * z));
}
function code(x, y, z) return fma(sin(y), x, Float64(cos(y) * z)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, \cos y \cdot z\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.9e-143) (not (<= x 4.4e-74))) (fma (sin y) x (* 1.0 z)) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.9e-143) || !(x <= 4.4e-74)) {
tmp = fma(sin(y), x, (1.0 * z));
} else {
tmp = cos(y) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -6.9e-143) || !(x <= 4.4e-74)) tmp = fma(sin(y), x, Float64(1.0 * z)); else tmp = Float64(cos(y) * z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.9e-143], N[Not[LessEqual[x, 4.4e-74]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.9 \cdot 10^{-143} \lor \neg \left(x \leq 4.4 \cdot 10^{-74}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -6.89999999999999989e-143 or 4.40000000000000021e-74 < x Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites86.5%
if -6.89999999999999989e-143 < x < 4.40000000000000021e-74Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6490.6
Applied rewrites90.6%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e+103) (not (<= x 7.2e+108))) (* (sin y) x) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+103) || !(x <= 7.2e+108)) {
tmp = sin(y) * x;
} else {
tmp = cos(y) * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-1.6d+103)) .or. (.not. (x <= 7.2d+108))) then
tmp = sin(y) * x
else
tmp = cos(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+103) || !(x <= 7.2e+108)) {
tmp = Math.sin(y) * x;
} else {
tmp = Math.cos(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+103) or not (x <= 7.2e+108): tmp = math.sin(y) * x else: tmp = math.cos(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+103) || !(x <= 7.2e+108)) tmp = Float64(sin(y) * x); else tmp = Float64(cos(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e+103) || ~((x <= 7.2e+108))) tmp = sin(y) * x; else tmp = cos(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+103], N[Not[LessEqual[x, 7.2e+108]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+103} \lor \neg \left(x \leq 7.2 \cdot 10^{+108}\right):\\
\;\;\;\;\sin y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -1.59999999999999996e103 or 7.2e108 < x Initial program 99.8%
lift-+.f64N/A
flip-+N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites77.7%
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-frac2N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*r*N/A
neg-mul-1N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites91.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6479.8
Applied rewrites79.8%
if -1.59999999999999996e103 < x < 7.2e108Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6477.3
Applied rewrites77.3%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000335) (not (<= y 0.028))) (* (cos y) z) (fma (fma (* -0.16666666666666666 (* x y)) y x) y z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000335) || !(y <= 0.028)) {
tmp = cos(y) * z;
} else {
tmp = fma(fma((-0.16666666666666666 * (x * y)), y, x), y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.000335) || !(y <= 0.028)) tmp = Float64(cos(y) * z); else tmp = fma(fma(Float64(-0.16666666666666666 * Float64(x * y)), y, x), y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000335], N[Not[LessEqual[y, 0.028]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000335 \lor \neg \left(y \leq 0.028\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left(x \cdot y\right), y, x\right), y, z\right)\\
\end{array}
\end{array}
if y < -3.3500000000000001e-4 or 0.0280000000000000006 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6449.3
Applied rewrites49.3%
if -3.3500000000000001e-4 < y < 0.0280000000000000006Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
Applied rewrites99.6%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.6e-205) (not (<= z 3.2e-184))) (* 1.0 z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e-205) || !(z <= 3.2e-184)) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.6d-205)) .or. (.not. (z <= 3.2d-184))) then
tmp = 1.0d0 * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e-205) || !(z <= 3.2e-184)) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.6e-205) or not (z <= 3.2e-184): tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.6e-205) || !(z <= 3.2e-184)) tmp = Float64(1.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.6e-205) || ~((z <= 3.2e-184))) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.6e-205], N[Not[LessEqual[z, 3.2e-184]], $MachinePrecision]], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{-205} \lor \neg \left(z \leq 3.2 \cdot 10^{-184}\right):\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -1.60000000000000005e-205 or 3.2e-184 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6471.1
Applied rewrites71.1%
Taylor expanded in y around 0
Applied rewrites44.2%
if -1.60000000000000005e-205 < z < 3.2e-184Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6446.3
Applied rewrites46.3%
Taylor expanded in x around inf
Applied rewrites35.4%
Final simplification42.4%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6449.2
Applied rewrites49.2%
Final simplification49.2%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6449.2
Applied rewrites49.2%
Taylor expanded in x around inf
Applied rewrites14.1%
Final simplification14.1%
herbie shell --seed 2024314
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))