
(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 (fma (cos y) x (* (sin y) z)))
double code(double x, double y, double z) {
return fma(cos(y), x, (sin(y) * z));
}
function code(x, y, z) return fma(cos(y), x, Float64(sin(y) * z)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, \sin 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 -5.8e-23) (not (<= x 8.5e+62))) (* (cos y) x) (fma (sin y) z (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-23) || !(x <= 8.5e+62)) {
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 <= -5.8e-23) || !(x <= 8.5e+62)) 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, -5.8e-23], N[Not[LessEqual[x, 8.5e+62]], $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 -5.8 \cdot 10^{-23} \lor \neg \left(x \leq 8.5 \cdot 10^{+62}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\
\end{array}
\end{array}
if x < -5.8000000000000003e-23 or 8.4999999999999997e62 < x Initial program 99.8%
lift-+.f64N/A
flip3-+N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
Applied rewrites28.0%
Taylor expanded in x around inf
*-commutativeN/A
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites85.2%
if -5.8000000000000003e-23 < x < 8.4999999999999997e62Initial 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.4%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.9e-67) (not (<= x 3.5e-46))) (* (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-67) || !(x <= 3.5e-46)) {
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 <= (-4.9d-67)) .or. (.not. (x <= 3.5d-46))) 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 <= -4.9e-67) || !(x <= 3.5e-46)) {
tmp = Math.cos(y) * x;
} else {
tmp = Math.sin(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.9e-67) or not (x <= 3.5e-46): tmp = math.cos(y) * x else: tmp = math.sin(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.9e-67) || !(x <= 3.5e-46)) 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 <= -4.9e-67) || ~((x <= 3.5e-46))) tmp = cos(y) * x; else tmp = sin(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.9e-67], N[Not[LessEqual[x, 3.5e-46]], $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 -4.9 \cdot 10^{-67} \lor \neg \left(x \leq 3.5 \cdot 10^{-46}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot z\\
\end{array}
\end{array}
if x < -4.89999999999999993e-67 or 3.5000000000000002e-46 < x Initial program 99.8%
lift-+.f64N/A
flip3-+N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
Applied rewrites37.0%
Taylor expanded in x around inf
*-commutativeN/A
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites80.4%
if -4.89999999999999993e-67 < x < 3.5000000000000002e-46Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6473.9
Applied rewrites73.9%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0038) (not (<= y 0.0042))) (* (sin y) z) (fma 1.0 x (* (* (fma (* -0.16666666666666666 y) y 1.0) z) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0038) || !(y <= 0.0042)) {
tmp = sin(y) * z;
} else {
tmp = fma(1.0, x, ((fma((-0.16666666666666666 * y), y, 1.0) * z) * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.0038) || !(y <= 0.0042)) tmp = Float64(sin(y) * z); else tmp = fma(1.0, x, Float64(Float64(fma(Float64(-0.16666666666666666 * y), y, 1.0) * z) * y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0038], N[Not[LessEqual[y, 0.0042]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(1.0 * x + N[(N[(N[(N[(-0.16666666666666666 * y), $MachinePrecision] * y + 1.0), $MachinePrecision] * z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0038 \lor \neg \left(y \leq 0.0042\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, x, \left(\mathsf{fma}\left(-0.16666666666666666 \cdot y, y, 1\right) \cdot z\right) \cdot y\right)\\
\end{array}
\end{array}
if y < -0.00379999999999999999 or 0.00419999999999999974 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6454.3
Applied rewrites54.3%
if -0.00379999999999999999 < y < 0.00419999999999999974Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Final simplification77.0%
(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.f6452.1
Applied rewrites52.1%
(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.f6452.1
Applied rewrites52.1%
Taylor expanded in x around 0
Applied rewrites17.3%
herbie shell --seed 2024324
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))