
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) z (* (cos y) x)))
double code(double x, double y, double z) {
return fma(sin(y), z, (cos(y) * x));
}
function code(x, y, z) return fma(sin(y), z, Float64(cos(y) * x)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * z + N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, z, \cos y \cdot x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/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 -1.1e+52) (not (<= x 1.35e+69))) (* (cos y) x) (fma (sin y) z (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e+52) || !(x <= 1.35e+69)) {
tmp = cos(y) * x;
} else {
tmp = fma(sin(y), z, (1.0 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e+52) || !(x <= 1.35e+69)) tmp = Float64(cos(y) * x); else tmp = fma(sin(y), z, Float64(1.0 * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e+52], N[Not[LessEqual[x, 1.35e+69]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + N[(1.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+52} \lor \neg \left(x \leq 1.35 \cdot 10^{+69}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\
\end{array}
\end{array}
if x < -1.1e52 or 1.3499999999999999e69 < x Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites90.7%
if -1.1e52 < x < 1.3499999999999999e69Initial program 99.8%
lift-+.f64N/A
+-commutativeN/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 rewrites90.2%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.46) (not (<= x 1.52e-47))) (* (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.46) || !(x <= 1.52e-47)) {
tmp = cos(y) * x;
} else {
tmp = sin(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 <= (-0.46d0)) .or. (.not. (x <= 1.52d-47))) then
tmp = cos(y) * x
else
tmp = sin(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.46) || !(x <= 1.52e-47)) {
tmp = Math.cos(y) * x;
} else {
tmp = Math.sin(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.46) or not (x <= 1.52e-47): tmp = math.cos(y) * x else: tmp = math.sin(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.46) || !(x <= 1.52e-47)) tmp = Float64(cos(y) * x); else tmp = Float64(sin(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.46) || ~((x <= 1.52e-47))) tmp = cos(y) * x; else tmp = sin(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.46], N[Not[LessEqual[x, 1.52e-47]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.46 \lor \neg \left(x \leq 1.52 \cdot 10^{-47}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot z\\
\end{array}
\end{array}
if x < -0.46000000000000002 or 1.52000000000000001e-47 < x Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites85.2%
if -0.46000000000000002 < x < 1.52000000000000001e-47Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6474.6
Applied rewrites74.6%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0027) (not (<= y 5500000.0))) (* (sin y) z) (fma (fma (* y x) -0.5 z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0027) || !(y <= 5500000.0)) {
tmp = sin(y) * z;
} else {
tmp = fma(fma((y * x), -0.5, z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.0027) || !(y <= 5500000.0)) tmp = Float64(sin(y) * z); else tmp = fma(fma(Float64(y * x), -0.5, z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0027], N[Not[LessEqual[y, 5500000.0]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(y * x), $MachinePrecision] * -0.5 + z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0027 \lor \neg \left(y \leq 5500000\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot x, -0.5, z\right), y, x\right)\\
\end{array}
\end{array}
if y < -0.0027000000000000001 or 5.5e6 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6457.8
Applied rewrites57.8%
if -0.0027000000000000001 < y < 5.5e6Initial program 100.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-*.f6496.4
Applied rewrites96.4%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-164) (not (<= x 1.75e-158))) (* 1.0 x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-164) || !(x <= 1.75e-158)) {
tmp = 1.0 * x;
} else {
tmp = z * 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 ((x <= (-3.8d-164)) .or. (.not. (x <= 1.75d-158))) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-164) || !(x <= 1.75e-158)) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-164) or not (x <= 1.75e-158): tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-164) || !(x <= 1.75e-158)) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e-164) || ~((x <= 1.75e-158))) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-164], N[Not[LessEqual[x, 1.75e-158]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-164} \lor \neg \left(x \leq 1.75 \cdot 10^{-158}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -3.79999999999999989e-164 or 1.75000000000000006e-158 < x Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6497.4
Applied rewrites97.4%
Taylor expanded in y around 0
Applied rewrites47.0%
if -3.79999999999999989e-164 < x < 1.75000000000000006e-158Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6442.5
Applied rewrites42.5%
Taylor expanded in x around 0
Applied rewrites33.2%
Final simplification43.8%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6448.8
Applied rewrites48.8%
Final simplification48.8%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6448.8
Applied rewrites48.8%
Taylor expanded in x around 0
Applied rewrites14.0%
Final simplification14.0%
herbie shell --seed 2024313
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))