
(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, \left(-z\right) \cdot \sin y\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%
(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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-23) (not (<= x 8.5e+62))) (* (cos y) x) (- (* x 1.0) (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-23) || !(x <= 8.5e+62)) {
tmp = cos(y) * x;
} else {
tmp = (x * 1.0) - (z * sin(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-23)) .or. (.not. (x <= 8.5d+62))) then
tmp = cos(y) * x
else
tmp = (x * 1.0d0) - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-23) || !(x <= 8.5e+62)) {
tmp = Math.cos(y) * x;
} else {
tmp = (x * 1.0) - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-23) or not (x <= 8.5e+62): tmp = math.cos(y) * x else: tmp = (x * 1.0) - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-23) || !(x <= 8.5e+62)) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-23) || ~((x <= 8.5e+62))) tmp = cos(y) * x; else tmp = (x * 1.0) - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-23], N[Not[LessEqual[x, 8.5e+62]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-23} \lor \neg \left(x \leq 8.5 \cdot 10^{+62}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\end{array}
\end{array}
if x < -5.8000000000000003e-23 or 8.4999999999999997e62 < x 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%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites85.0%
if -5.8000000000000003e-23 < x < 8.4999999999999997e62Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites90.4%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.9e-67) (not (<= x 3.5e-46))) (* (cos y) x) (* (- z) (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-67) || !(x <= 3.5e-46)) {
tmp = cos(y) * x;
} else {
tmp = -z * sin(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 <= (-4.9d-67)) .or. (.not. (x <= 3.5d-46))) then
tmp = cos(y) * x
else
tmp = -z * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-67) || !(x <= 3.5e-46)) {
tmp = Math.cos(y) * x;
} else {
tmp = -z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.9e-67) or not (x <= 3.5e-46): tmp = math.cos(y) * x else: tmp = -z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.9e-67) || !(x <= 3.5e-46)) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(-z) * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.9e-67) || ~((x <= 3.5e-46))) tmp = cos(y) * x; else tmp = -z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.9e-67], N[Not[LessEqual[x, 3.5e-46]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-67} \lor \neg \left(x \leq 3.5 \cdot 10^{-46}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\end{array}
\end{array}
if x < -4.89999999999999993e-67 or 3.5000000000000002e-46 < x 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%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites80.3%
if -4.89999999999999993e-67 < x < 3.5000000000000002e-46Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6473.7
Applied rewrites73.7%
Final simplification77.5%
(FPCore (x y z)
:precision binary64
(if (or (<= y -380.0) (not (<= y 2.6)))
(* (cos y) x)
(-
(* x 1.0)
(*
(fma
(* z (fma 0.008333333333333333 (* y y) -0.16666666666666666))
(* y y)
z)
y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -380.0) || !(y <= 2.6)) {
tmp = cos(y) * x;
} else {
tmp = (x * 1.0) - (fma((z * fma(0.008333333333333333, (y * y), -0.16666666666666666)), (y * y), z) * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -380.0) || !(y <= 2.6)) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(x * 1.0) - Float64(fma(Float64(z * fma(0.008333333333333333, Float64(y * y), -0.16666666666666666)), Float64(y * y), z) * y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -380.0], N[Not[LessEqual[y, 2.6]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(x * 1.0), $MachinePrecision] - N[(N[(N[(z * N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -380 \lor \neg \left(y \leq 2.6\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1 - \mathsf{fma}\left(z \cdot \mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, z\right) \cdot y\\
\end{array}
\end{array}
if y < -380 or 2.60000000000000009 < y Initial program 99.6%
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.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6492.1
Applied rewrites92.1%
Taylor expanded in x around inf
Applied rewrites46.9%
if -380 < y < 2.60000000000000009Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.7
Applied rewrites98.7%
Final simplification73.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e-104) (not (<= x 1.15e-249))) (* 1.0 x) (* (- y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-104) || !(x <= 1.15e-249)) {
tmp = 1.0 * 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 ((x <= (-2.8d-104)) .or. (.not. (x <= 1.15d-249))) then
tmp = 1.0d0 * x
else
tmp = -y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-104) || !(x <= 1.15e-249)) {
tmp = 1.0 * x;
} else {
tmp = -y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e-104) or not (x <= 1.15e-249): tmp = 1.0 * x else: tmp = -y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e-104) || !(x <= 1.15e-249)) tmp = Float64(1.0 * x); else tmp = Float64(Float64(-y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.8e-104) || ~((x <= 1.15e-249))) tmp = 1.0 * x; else tmp = -y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e-104], N[Not[LessEqual[x, 1.15e-249]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[((-y) * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-104} \lor \neg \left(x \leq 1.15 \cdot 10^{-249}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot z\\
\end{array}
\end{array}
if x < -2.8e-104 or 1.1499999999999999e-249 < x 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%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6498.8
Applied rewrites98.8%
Taylor expanded in y around 0
Applied rewrites45.2%
if -2.8e-104 < x < 1.1499999999999999e-249Initial program 99.7%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6451.0
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites39.0%
Final simplification43.7%
(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-*.f6452.0
Applied rewrites52.0%
(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%
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%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6494.5
Applied rewrites94.5%
Taylor expanded in y around 0
Applied rewrites38.2%
Final simplification38.2%
herbie shell --seed 2024324
(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))))