
(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) (* (cos y) x)))
double code(double x, double y, double z) {
return fma(sin(y), -z, (cos(y) * x));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(cos(y) * x)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, \cos y \cdot x\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
lift-*.f64N/A
*-commutativeN/A
lower-*.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 -2.3e-56) (not (<= x 4.5e+48))) (* (cos y) x) (fma (sin y) (- z) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-56) || !(x <= 4.5e+48)) {
tmp = cos(y) * x;
} else {
tmp = fma(sin(y), -z, (1.0 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e-56) || !(x <= 4.5e+48)) tmp = Float64(cos(y) * x); else tmp = fma(sin(y), Float64(-z), Float64(1.0 * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e-56], N[Not[LessEqual[x, 4.5e+48]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z) + N[(1.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-56} \lor \neg \left(x \leq 4.5 \cdot 10^{+48}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\
\end{array}
\end{array}
if x < -2.30000000000000002e-56 or 4.49999999999999995e48 < x Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6449.8
Applied rewrites49.8%
Taylor expanded in x around 0
Applied rewrites5.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites87.5%
if -2.30000000000000002e-56 < x < 4.49999999999999995e48Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites91.3%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-outN/A
lift-sin.f64N/A
+-commutativeN/A
lift-sin.f64N/A
lift-neg.f64N/A
lower-fma.f6491.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.4
Applied rewrites91.4%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e-56) (not (<= x 4.5e+48))) (* (cos y) x) (- (* x 1.0) (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-56) || !(x <= 4.5e+48)) {
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 <= (-2.3d-56)) .or. (.not. (x <= 4.5d+48))) 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 <= -2.3e-56) || !(x <= 4.5e+48)) {
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 <= -2.3e-56) or not (x <= 4.5e+48): 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 <= -2.3e-56) || !(x <= 4.5e+48)) 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 <= -2.3e-56) || ~((x <= 4.5e+48))) 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, -2.3e-56], N[Not[LessEqual[x, 4.5e+48]], $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 -2.3 \cdot 10^{-56} \lor \neg \left(x \leq 4.5 \cdot 10^{+48}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\end{array}
\end{array}
if x < -2.30000000000000002e-56 or 4.49999999999999995e48 < x Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6449.8
Applied rewrites49.8%
Taylor expanded in x around 0
Applied rewrites5.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites87.5%
if -2.30000000000000002e-56 < x < 4.49999999999999995e48Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites91.3%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e-59) (not (<= x 1.05e-182))) (* (cos y) x) (* (- z) (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-59) || !(x <= 1.05e-182)) {
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 <= (-1.55d-59)) .or. (.not. (x <= 1.05d-182))) 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 <= -1.55e-59) || !(x <= 1.05e-182)) {
tmp = Math.cos(y) * x;
} else {
tmp = -z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e-59) or not (x <= 1.05e-182): tmp = math.cos(y) * x else: tmp = -z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e-59) || !(x <= 1.05e-182)) 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 <= -1.55e-59) || ~((x <= 1.05e-182))) tmp = cos(y) * x; else tmp = -z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e-59], N[Not[LessEqual[x, 1.05e-182]], $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 -1.55 \cdot 10^{-59} \lor \neg \left(x \leq 1.05 \cdot 10^{-182}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\end{array}
\end{array}
if x < -1.55e-59 or 1.05e-182 < x Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6450.6
Applied rewrites50.6%
Taylor expanded in x around 0
Applied rewrites8.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-cos.f6498.6
Applied rewrites98.6%
Taylor expanded in x around inf
Applied rewrites79.4%
if -1.55e-59 < x < 1.05e-182Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6475.5
Applied rewrites75.5%
Final simplification78.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -0.055) (not (<= y 6300.0)))
(* (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 <= -0.055) || !(y <= 6300.0)) {
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 <= -0.055) || !(y <= 6300.0)) 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, -0.055], N[Not[LessEqual[y, 6300.0]], $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 -0.055 \lor \neg \left(y \leq 6300\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 < -0.0550000000000000003 or 6300 < y Initial program 99.6%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f647.2
Applied rewrites7.2%
Taylor expanded in x around 0
Applied rewrites3.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-cos.f6488.3
Applied rewrites88.3%
Taylor expanded in x around inf
Applied rewrites52.1%
if -0.0550000000000000003 < y < 6300Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.6%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.3e+201) (not (<= z 1.95e+86))) (* (- y) z) (* (- x) -1.0)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e+201) || !(z <= 1.95e+86)) {
tmp = -y * z;
} else {
tmp = -x * -1.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) :: tmp
if ((z <= (-2.3d+201)) .or. (.not. (z <= 1.95d+86))) then
tmp = -y * z
else
tmp = -x * (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e+201) || !(z <= 1.95e+86)) {
tmp = -y * z;
} else {
tmp = -x * -1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e+201) or not (z <= 1.95e+86): tmp = -y * z else: tmp = -x * -1.0 return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e+201) || !(z <= 1.95e+86)) tmp = Float64(Float64(-y) * z); else tmp = Float64(Float64(-x) * -1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.3e+201) || ~((z <= 1.95e+86))) tmp = -y * z; else tmp = -x * -1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e+201], N[Not[LessEqual[z, 1.95e+86]], $MachinePrecision]], N[((-y) * z), $MachinePrecision], N[((-x) * -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+201} \lor \neg \left(z \leq 1.95 \cdot 10^{+86}\right):\\
\;\;\;\;\left(-y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot -1\\
\end{array}
\end{array}
if z < -2.3000000000000001e201 or 1.9500000000000001e86 < z Initial program 99.7%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.6
Applied rewrites52.6%
Taylor expanded in x around 0
Applied rewrites36.5%
if -2.3000000000000001e201 < z < 1.9500000000000001e86Initial 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
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-cos.f6495.3
Applied rewrites95.3%
Taylor expanded in y around 0
Applied rewrites44.5%
Final simplification42.5%
(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-*.f6451.1
Applied rewrites51.1%
Applied rewrites51.1%
Final simplification51.1%
(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-*.f6451.1
Applied rewrites51.1%
Final simplification51.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(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}
\\
\left(-x\right) \cdot -1
\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
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-cos.f6488.3
Applied rewrites88.3%
Taylor expanded in y around 0
Applied rewrites37.9%
herbie shell --seed 2024311
(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))))