
(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 (<= z -1.45e-176) (not (<= z 1.35e-35))) (fma (sin y) z (* 1.0 x)) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e-176) || !(z <= 1.35e-35)) {
tmp = fma(sin(y), z, (1.0 * x));
} else {
tmp = cos(y) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -1.45e-176) || !(z <= 1.35e-35)) tmp = fma(sin(y), z, Float64(1.0 * x)); else tmp = Float64(cos(y) * x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.45e-176], N[Not[LessEqual[z, 1.35e-35]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z + N[(1.0 * x), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-176} \lor \neg \left(z \leq 1.35 \cdot 10^{-35}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -1.45000000000000003e-176 or 1.3499999999999999e-35 < z Initial program 99.9%
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 y around 0
Applied rewrites87.4%
if -1.45000000000000003e-176 < z < 1.3499999999999999e-35Initial 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.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites91.0%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.45) (not (<= x 1.6e-110))) (* (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.45) || !(x <= 1.6e-110)) {
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.45d0)) .or. (.not. (x <= 1.6d-110))) 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.45) || !(x <= 1.6e-110)) {
tmp = Math.cos(y) * x;
} else {
tmp = Math.sin(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.45) or not (x <= 1.6e-110): tmp = math.cos(y) * x else: tmp = math.sin(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.45) || !(x <= 1.6e-110)) 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.45) || ~((x <= 1.6e-110))) tmp = cos(y) * x; else tmp = sin(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.45], N[Not[LessEqual[x, 1.6e-110]], $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.45 \lor \neg \left(x \leq 1.6 \cdot 10^{-110}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot z\\
\end{array}
\end{array}
if x < -0.450000000000000011 or 1.60000000000000014e-110 < x Initial program 99.9%
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.2
Applied rewrites99.2%
Taylor expanded in x around inf
Applied rewrites82.0%
if -0.450000000000000011 < x < 1.60000000000000014e-110Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6474.7
Applied rewrites74.7%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00365) (not (<= y 8e-10))) (* (sin y) z) (fma (fma (fma -0.16666666666666666 (* z y) (* -0.5 x)) y z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00365) || !(y <= 8e-10)) {
tmp = sin(y) * z;
} else {
tmp = fma(fma(fma(-0.16666666666666666, (z * y), (-0.5 * x)), y, z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.00365) || !(y <= 8e-10)) tmp = Float64(sin(y) * z); else tmp = fma(fma(fma(-0.16666666666666666, Float64(z * y), Float64(-0.5 * x)), y, z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00365], N[Not[LessEqual[y, 8e-10]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y + z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00365 \lor \neg \left(y \leq 8 \cdot 10^{-10}\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, z \cdot y, -0.5 \cdot x\right), y, z\right), y, x\right)\\
\end{array}
\end{array}
if y < -0.00365000000000000003 or 8.00000000000000029e-10 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6452.6
Applied rewrites52.6%
if -0.00365000000000000003 < y < 8.00000000000000029e-10Initial 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-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-38) (not (<= x 2.2e-219))) (* 1.0 x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-38) || !(x <= 2.2e-219)) {
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 <= (-5.8d-38)) .or. (.not. (x <= 2.2d-219))) 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 <= -5.8e-38) || !(x <= 2.2e-219)) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-38) or not (x <= 2.2e-219): tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-38) || !(x <= 2.2e-219)) 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 <= -5.8e-38) || ~((x <= 2.2e-219))) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-38], N[Not[LessEqual[x, 2.2e-219]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-38} \lor \neg \left(x \leq 2.2 \cdot 10^{-219}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -5.79999999999999988e-38 or 2.1999999999999999e-219 < x Initial program 99.9%
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.f6496.8
Applied rewrites96.8%
Taylor expanded in y around 0
Applied rewrites47.2%
if -5.79999999999999988e-38 < x < 2.1999999999999999e-219Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6457.1
Applied rewrites57.1%
Taylor expanded in x around 0
Applied rewrites43.4%
Final simplification46.2%
(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.f6453.2
Applied rewrites53.2%
Final simplification53.2%
(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.f6453.2
Applied rewrites53.2%
Taylor expanded in x around 0
Applied rewrites17.8%
Final simplification17.8%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))