
(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 8 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 (cos y) x (- (* z (sin y)))))
double code(double x, double y, double z) {
return fma(cos(y), x, -(z * sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(-Float64(z * sin(y)))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + (-N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, -z \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* z (sin y))))
double code(double x, double y, double z) {
return (cos(y) * x) - (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 = (cos(y) * x) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (z * Math.sin(y));
}
def code(x, y, z): return (math.cos(y) * x) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* z (sin y)))))
(if (<= y -0.048)
t_0
(if (<= y 0.08)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
(if (<= y 6.2e+105) t_0 (* (cos y) x))))))
double code(double x, double y, double z) {
double t_0 = -(z * sin(y));
double tmp;
if (y <= -0.048) {
tmp = t_0;
} else if (y <= 0.08) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else if (y <= 6.2e+105) {
tmp = t_0;
} else {
tmp = cos(y) * x;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-Float64(z * sin(y))) tmp = 0.0 if (y <= -0.048) tmp = t_0; elseif (y <= 0.08) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), x); elseif (y <= 6.2e+105) tmp = t_0; else tmp = Float64(cos(y) * x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision])}, If[LessEqual[y, -0.048], t$95$0, If[LessEqual[y, 0.08], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 6.2e+105], t$95$0, N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -z \cdot \sin y\\
\mathbf{if}\;y \leq -0.048:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.08:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if y < -0.048000000000000001 or 0.0800000000000000017 < y < 6.20000000000000008e105Initial program 99.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6460.7
Simplified60.7%
if -0.048000000000000001 < y < 0.0800000000000000017Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.3
Simplified99.3%
if 6.20000000000000008e105 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6459.1
Simplified59.1%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) (- z) x))) (if (<= z -3e-16) t_0 (if (<= z 8.5e-147) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), -z, x);
double tmp;
if (z <= -3e-16) {
tmp = t_0;
} else if (z <= 8.5e-147) {
tmp = cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), Float64(-z), x) tmp = 0.0 if (z <= -3e-16) tmp = t_0; elseif (z <= 8.5e-147) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z) + x), $MachinePrecision]}, If[LessEqual[z, -3e-16], t$95$0, If[LessEqual[z, 8.5e-147], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, -z, x\right)\\
\mathbf{if}\;z \leq -3 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-147}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.99999999999999994e-16 or 8.5000000000000002e-147 < z Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
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.f6490.6
Simplified90.6%
Taylor expanded in y around 0
Simplified79.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-sin.f64N/A
mul-1-negN/A
lower-neg.f6489.0
Simplified89.0%
if -2.99999999999999994e-16 < z < 8.5000000000000002e-147Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6489.5
Simplified89.5%
Final simplification89.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -170000.0)
t_0
(if (<= y 0.045)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -170000.0) {
tmp = t_0;
} else if (y <= 0.045) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -170000.0) tmp = t_0; elseif (y <= 0.045) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -170000.0], t$95$0, If[LessEqual[y, 0.045], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -170000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.045:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.7e5 or 0.044999999999999998 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6446.9
Simplified46.9%
if -1.7e5 < y < 0.044999999999999998Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.0
Simplified99.0%
Final simplification74.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z)))) (if (<= z -1.18e+185) t_0 (if (<= z 4.6e+194) x t_0))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -1.18e+185) {
tmp = t_0;
} else if (z <= 4.6e+194) {
tmp = x;
} 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 = y * -z
if (z <= (-1.18d+185)) then
tmp = t_0
else if (z <= 4.6d+194) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -1.18e+185) {
tmp = t_0;
} else if (z <= 4.6e+194) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if z <= -1.18e+185: tmp = t_0 elif z <= 4.6e+194: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (z <= -1.18e+185) tmp = t_0; elseif (z <= 4.6e+194) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (z <= -1.18e+185) tmp = t_0; elseif (z <= 4.6e+194) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.18e+185], t$95$0, If[LessEqual[z, 4.6e+194], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.18 \cdot 10^{+185}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{+194}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.18e185 or 4.6000000000000001e194 < z Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6480.7
Simplified80.7%
Taylor expanded in y around 0
mul-1-negN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6437.7
Simplified37.7%
if -1.18e185 < z < 4.6000000000000001e194Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
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.f6496.5
Simplified96.5%
Taylor expanded in y around 0
Simplified50.1%
*-rgt-identity50.1
Applied egg-rr50.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-*.f6455.2
Simplified55.2%
Final simplification55.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
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.f6494.2
Simplified94.2%
Taylor expanded in y around 0
Simplified42.6%
*-rgt-identity42.6
Applied egg-rr42.6%
herbie shell --seed 2024208
(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))))