
(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 (* (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) * Float64(-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 \left(-z\right)\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.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 (fma 1.0 x (/ 1.0 (/ -1.0 (* (sin y) z)))))) (if (<= z -1.05e+45) t_0 (if (<= z 1.05e-56) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, x, (1.0 / (-1.0 / (sin(y) * z))));
double tmp;
if (z <= -1.05e+45) {
tmp = t_0;
} else if (z <= 1.05e-56) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, x, Float64(1.0 / Float64(-1.0 / Float64(sin(y) * z)))) tmp = 0.0 if (z <= -1.05e+45) tmp = t_0; elseif (z <= 1.05e-56) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * x + N[(1.0 / N[(-1.0 / N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.05e+45], t$95$0, If[LessEqual[z, 1.05e-56], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, x, \frac{1}{\frac{-1}{\sin y \cdot z}}\right)\\
\mathbf{if}\;z \leq -1.05 \cdot 10^{+45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-56}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.04999999999999997e45 or 1.05000000000000003e-56 < z Initial program 99.7%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Applied rewrites99.6%
Taylor expanded in y around 0
Applied rewrites89.4%
if -1.04999999999999997e45 < z < 1.05000000000000003e-56Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6487.5
Applied rewrites87.5%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (sin y) (- z)))) (if (<= z -2.5e+135) t_0 (if (<= z 3.25e+84) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double tmp;
if (z <= -2.5e+135) {
tmp = t_0;
} else if (z <= 3.25e+84) {
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 = sin(y) * -z
if (z <= (-2.5d+135)) then
tmp = t_0
else if (z <= 3.25d+84) 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 = Math.sin(y) * -z;
double tmp;
if (z <= -2.5e+135) {
tmp = t_0;
} else if (z <= 3.25e+84) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z tmp = 0 if z <= -2.5e+135: tmp = t_0 elif z <= 3.25e+84: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (z <= -2.5e+135) tmp = t_0; elseif (z <= 3.25e+84) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; tmp = 0.0; if (z <= -2.5e+135) tmp = t_0; elseif (z <= 3.25e+84) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.5e+135], t$95$0, If[LessEqual[z, 3.25e+84], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.5 \cdot 10^{+135}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.25 \cdot 10^{+84}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.50000000000000015e135 or 3.25000000000000013e84 < z Initial program 99.8%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6479.4
Applied rewrites79.4%
if -2.50000000000000015e135 < z < 3.25000000000000013e84Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6480.7
Applied rewrites80.7%
Final simplification80.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -1620000.0)
t_0
(if (<= y 0.031) (fma (- (* -0.5 (* x y)) z) y x) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -1620000.0) {
tmp = t_0;
} else if (y <= 0.031) {
tmp = fma(((-0.5 * (x * y)) - z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1620000.0) tmp = t_0; elseif (y <= 0.031) tmp = fma(Float64(Float64(-0.5 * Float64(x * y)) - z), y, x); 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, -1620000.0], t$95$0, If[LessEqual[y, 0.031], N[(N[(N[(-0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1620000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.031:\\
\;\;\;\;\mathsf{fma}\left(-0.5 \cdot \left(x \cdot y\right) - z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.62e6 or 0.031 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6449.3
Applied rewrites49.3%
if -1.62e6 < y < 0.031Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y) z))) (if (<= z -1.86e+136) t_0 (if (<= z 4.4e+88) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = -y * z;
double tmp;
if (z <= -1.86e+136) {
tmp = t_0;
} else if (z <= 4.4e+88) {
tmp = 1.0 * 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.86d+136)) then
tmp = t_0
else if (z <= 4.4d+88) then
tmp = 1.0d0 * 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.86e+136) {
tmp = t_0;
} else if (z <= 4.4e+88) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -y * z tmp = 0 if z <= -1.86e+136: tmp = t_0 elif z <= 4.4e+88: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) * z) tmp = 0.0 if (z <= -1.86e+136) tmp = t_0; elseif (z <= 4.4e+88) tmp = Float64(1.0 * 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.86e+136) tmp = t_0; elseif (z <= 4.4e+88) tmp = 1.0 * 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.86e+136], t$95$0, If[LessEqual[z, 4.4e+88], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot z\\
\mathbf{if}\;z \leq -1.86 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{+88}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.86e136 or 4.40000000000000017e88 < z Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6453.6
Applied rewrites53.6%
Taylor expanded in z around inf
Applied rewrites40.7%
if -1.86e136 < z < 4.40000000000000017e88Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6479.9
Applied rewrites79.9%
Taylor expanded in y around 0
Applied rewrites54.4%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return x - (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 = x - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\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-*.f6456.8
Applied rewrites56.8%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6461.4
Applied rewrites61.4%
Taylor expanded in y around 0
Applied rewrites41.9%
herbie shell --seed 2024240
(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))))