
(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 (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-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
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 (- (* 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 (- (* (sin y) z))))
(if (<= y -2.15e+232)
t_0
(if (<= y -0.017)
(* x (cos y))
(if (<= y 0.0065)
(fma y (fma y (fma x -0.5 (* 0.16666666666666666 (* y z))) (- z)) x)
t_0)))))
double code(double x, double y, double z) {
double t_0 = -(sin(y) * z);
double tmp;
if (y <= -2.15e+232) {
tmp = t_0;
} else if (y <= -0.017) {
tmp = x * cos(y);
} else if (y <= 0.0065) {
tmp = fma(y, fma(y, fma(x, -0.5, (0.16666666666666666 * (y * z))), -z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-Float64(sin(y) * z)) tmp = 0.0 if (y <= -2.15e+232) tmp = t_0; elseif (y <= -0.017) tmp = Float64(x * cos(y)); elseif (y <= 0.0065) tmp = fma(y, fma(y, fma(x, -0.5, Float64(0.16666666666666666 * Float64(y * z))), Float64(-z)), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])}, If[LessEqual[y, -2.15e+232], t$95$0, If[LessEqual[y, -0.017], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.0065], N[(y * N[(y * N[(x * -0.5 + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin y \cdot z\\
\mathbf{if}\;y \leq -2.15 \cdot 10^{+232}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.017:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq 0.0065:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, -0.5, 0.16666666666666666 \cdot \left(y \cdot z\right)\right), -z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.1500000000000001e232 or 0.0064999999999999997 < y Initial program 99.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6458.0
Applied rewrites58.0%
if -2.1500000000000001e232 < y < -0.017000000000000001Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6461.1
Applied rewrites61.1%
if -0.017000000000000001 < y < 0.0064999999999999997Initial program 100.0%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (* (sin y) z)))) (if (<= z -7.8e-185) t_0 (if (<= z 4.6e+48) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (sin(y) * z);
double tmp;
if (z <= -7.8e-185) {
tmp = t_0;
} else if (z <= 4.6e+48) {
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 - (sin(y) * z)
if (z <= (-7.8d-185)) then
tmp = t_0
else if (z <= 4.6d+48) 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 - (Math.sin(y) * z);
double tmp;
if (z <= -7.8e-185) {
tmp = t_0;
} else if (z <= 4.6e+48) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (math.sin(y) * z) tmp = 0 if z <= -7.8e-185: tmp = t_0 elif z <= 4.6e+48: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(sin(y) * z)) tmp = 0.0 if (z <= -7.8e-185) tmp = t_0; elseif (z <= 4.6e+48) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (sin(y) * z); tmp = 0.0; if (z <= -7.8e-185) tmp = t_0; elseif (z <= 4.6e+48) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.8e-185], t$95$0, If[LessEqual[z, 4.6e+48], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sin y \cdot z\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{-185}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{+48}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.7999999999999999e-185 or 4.6e48 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites85.5%
if -7.7999999999999999e-185 < z < 4.6e48Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6490.2
Applied rewrites90.2%
Final simplification87.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.017)
t_0
(if (<= y 1850000.0)
(fma y (fma y (fma x -0.5 (* 0.16666666666666666 (* y z))) (- z)) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.017) {
tmp = t_0;
} else if (y <= 1850000.0) {
tmp = fma(y, fma(y, fma(x, -0.5, (0.16666666666666666 * (y * z))), -z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.017) tmp = t_0; elseif (y <= 1850000.0) tmp = fma(y, fma(y, fma(x, -0.5, Float64(0.16666666666666666 * Float64(y * z))), Float64(-z)), 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, -0.017], t$95$0, If[LessEqual[y, 1850000.0], N[(y * N[(y * N[(x * -0.5 + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.017:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1850000:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(x, -0.5, 0.16666666666666666 \cdot \left(y \cdot z\right)\right), -z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.017000000000000001 or 1.85e6 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6451.1
Applied rewrites51.1%
if -0.017000000000000001 < y < 1.85e6Initial program 100.0%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6497.2
Applied rewrites97.2%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (<= z 3.2e+115) x (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.2e+115) {
tmp = x;
} 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 <= 3.2d+115) then
tmp = x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3.2e+115) {
tmp = x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.2e+115: tmp = x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.2e+115) tmp = x; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.2e+115) tmp = x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.2e+115], x, N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.2 \cdot 10^{+115}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 3.2e115Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6468.7
Applied rewrites68.7%
Taylor expanded in y around 0
Applied rewrites43.2%
*-rgt-identity43.2
Applied rewrites43.2%
if 3.2e115 < z Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6442.9
Applied rewrites42.9%
Taylor expanded in x around 0
mul-1-negN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6431.1
Applied rewrites31.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-*.f6451.8
Applied rewrites51.8%
Final simplification51.8%
(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%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6458.4
Applied rewrites58.4%
Taylor expanded in y around 0
Applied rewrites36.7%
*-rgt-identity36.7
Applied rewrites36.7%
herbie shell --seed 2024216
(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))))