
(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 10 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) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.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(-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
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(y) * z);
}
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)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -1.7e+17)
t_0
(if (<= y 2900.0)
(fma
(fma
(* y y)
(fma
(* y y)
(fma (* y y) -0.001388888888888889 0.041666666666666664)
-0.5)
1.0)
x
(* y (* z (fma 0.16666666666666666 (* y y) -1.0))))
(if (<= y 1.95e+42) t_0 (- (* (sin y) z)))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -1.7e+17) {
tmp = t_0;
} else if (y <= 2900.0) {
tmp = fma(fma((y * y), fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, (y * (z * fma(0.16666666666666666, (y * y), -1.0))));
} else if (y <= 1.95e+42) {
tmp = t_0;
} else {
tmp = -(sin(y) * z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1.7e+17) tmp = t_0; elseif (y <= 2900.0) tmp = fma(fma(Float64(y * y), fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, Float64(y * Float64(z * fma(0.16666666666666666, Float64(y * y), -1.0)))); elseif (y <= 1.95e+42) tmp = t_0; else tmp = Float64(-Float64(sin(y) * z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e+17], t$95$0, If[LessEqual[y, 2900.0], N[(N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * N[(z * N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.95e+42], t$95$0, (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2900:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+42}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-\sin y \cdot z\\
\end{array}
\end{array}
if y < -1.7e17 or 2900 < y < 1.94999999999999985e42Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6465.5
Applied rewrites65.5%
if -1.7e17 < y < 2900Initial program 99.9%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift-neg.f64N/A
neg-sub0N/A
flip--N/A
Applied rewrites34.6%
Taylor expanded in y around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6497.7
Applied rewrites97.7%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6497.8
Applied rewrites97.8%
if 1.94999999999999985e42 < y Initial program 99.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6471.7
Applied rewrites71.7%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x 1.0) (* (sin y) z)))) (if (<= z -9.2e-59) t_0 (if (<= z 2.7e-178) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 1.0) - (sin(y) * z);
double tmp;
if (z <= -9.2e-59) {
tmp = t_0;
} else if (z <= 2.7e-178) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (x * 1.0d0) - (sin(y) * z)
if (z <= (-9.2d-59)) then
tmp = t_0
else if (z <= 2.7d-178) then
tmp = x * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 1.0) - (Math.sin(y) * z);
double tmp;
if (z <= -9.2e-59) {
tmp = t_0;
} else if (z <= 2.7e-178) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 1.0) - (math.sin(y) * z) tmp = 0 if z <= -9.2e-59: tmp = t_0 elif z <= 2.7e-178: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 1.0) - Float64(sin(y) * z)) tmp = 0.0 if (z <= -9.2e-59) tmp = t_0; elseif (z <= 2.7e-178) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 1.0) - (sin(y) * z); tmp = 0.0; if (z <= -9.2e-59) tmp = t_0; elseif (z <= 2.7e-178) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 1.0), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.2e-59], t$95$0, If[LessEqual[z, 2.7e-178], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot 1 - \sin y \cdot z\\
\mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.19999999999999918e-59 or 2.70000000000000009e-178 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites85.0%
if -9.19999999999999918e-59 < z < 2.70000000000000009e-178Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6492.2
Applied rewrites92.2%
Final simplification87.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -1.7e+17)
t_0
(if (<= y 2900.0)
(fma
(fma
(* y y)
(fma
(* y y)
(fma (* y y) -0.001388888888888889 0.041666666666666664)
-0.5)
1.0)
x
(* y (* z (fma 0.16666666666666666 (* y y) -1.0))))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -1.7e+17) {
tmp = t_0;
} else if (y <= 2900.0) {
tmp = fma(fma((y * y), fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, (y * (z * fma(0.16666666666666666, (y * y), -1.0))));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1.7e+17) tmp = t_0; elseif (y <= 2900.0) tmp = fma(fma(Float64(y * y), fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, Float64(y * Float64(z * fma(0.16666666666666666, Float64(y * y), -1.0)))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e+17], t$95$0, If[LessEqual[y, 2900.0], N[(N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * N[(z * N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2900:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.7e17 or 2900 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6450.8
Applied rewrites50.8%
if -1.7e17 < y < 2900Initial program 99.9%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift-neg.f64N/A
neg-sub0N/A
flip--N/A
Applied rewrites34.6%
Taylor expanded in y around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6497.7
Applied rewrites97.7%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6497.8
Applied rewrites97.8%
(FPCore (x y z) :precision binary64 (if (<= z 6.5e+114) (* x 1.0) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 6.5e+114) {
tmp = x * 1.0;
} else {
tmp = 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 (z <= 6.5d+114) then
tmp = x * 1.0d0
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 6.5e+114) {
tmp = x * 1.0;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 6.5e+114: tmp = x * 1.0 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 6.5e+114) tmp = Float64(x * 1.0); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 6.5e+114) tmp = x * 1.0; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 6.5e+114], N[(x * 1.0), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.5 \cdot 10^{+114}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 6.5000000000000001e114Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f6495.8
Applied rewrites95.8%
Taylor expanded in y around 0
Applied rewrites40.3%
if 6.5000000000000001e114 < z Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6450.2
Applied rewrites50.2%
Taylor expanded in x around 0
Applied rewrites35.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(Float64(-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
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.1
Applied rewrites52.1%
Applied rewrites52.1%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (y * z);
}
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 * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.1
Applied rewrites52.1%
Final simplification52.1%
(FPCore (x y z) :precision binary64 (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\end{array}
Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f6493.2
Applied rewrites93.2%
Taylor expanded in y around 0
Applied rewrites36.4%
herbie shell --seed 2024220
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))