
(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 7 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(z * Float64(-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 \left(-\sin y\right)\right)
\end{array}
Initial program 99.8%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Final simplification99.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 -64000.0)
t_0
(if (<= y 0.0108)
(+ x (* y (- (* y (* x -0.5)) z)))
(if (or (<= y 7.8e+93) (not (<= y 1.35e+256))) (* (cos y) x) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * -sin(y);
double tmp;
if (y <= -64000.0) {
tmp = t_0;
} else if (y <= 0.0108) {
tmp = x + (y * ((y * (x * -0.5)) - z));
} else if ((y <= 7.8e+93) || !(y <= 1.35e+256)) {
tmp = cos(y) * 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 = z * -sin(y)
if (y <= (-64000.0d0)) then
tmp = t_0
else if (y <= 0.0108d0) then
tmp = x + (y * ((y * (x * (-0.5d0))) - z))
else if ((y <= 7.8d+93) .or. (.not. (y <= 1.35d+256))) then
tmp = cos(y) * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -Math.sin(y);
double tmp;
if (y <= -64000.0) {
tmp = t_0;
} else if (y <= 0.0108) {
tmp = x + (y * ((y * (x * -0.5)) - z));
} else if ((y <= 7.8e+93) || !(y <= 1.35e+256)) {
tmp = Math.cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -math.sin(y) tmp = 0 if y <= -64000.0: tmp = t_0 elif y <= 0.0108: tmp = x + (y * ((y * (x * -0.5)) - z)) elif (y <= 7.8e+93) or not (y <= 1.35e+256): tmp = math.cos(y) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-sin(y))) tmp = 0.0 if (y <= -64000.0) tmp = t_0; elseif (y <= 0.0108) tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(x * -0.5)) - z))); elseif ((y <= 7.8e+93) || !(y <= 1.35e+256)) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -sin(y); tmp = 0.0; if (y <= -64000.0) tmp = t_0; elseif (y <= 0.0108) tmp = x + (y * ((y * (x * -0.5)) - z)); elseif ((y <= 7.8e+93) || ~((y <= 1.35e+256))) tmp = cos(y) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[y, -64000.0], t$95$0, If[LessEqual[y, 0.0108], N[(x + N[(y * N[(N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 7.8e+93], N[Not[LessEqual[y, 1.35e+256]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-\sin y\right)\\
\mathbf{if}\;y \leq -64000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0108:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5\right) - z\right)\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+93} \lor \neg \left(y \leq 1.35 \cdot 10^{+256}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -64000 or 7.8000000000000005e93 < y < 1.34999999999999997e256Initial program 99.6%
Taylor expanded in x around 0 59.6%
mul-1-neg59.6%
*-commutative59.6%
distribute-rgt-neg-in59.6%
Simplified59.6%
if -64000 < y < 0.010800000000000001Initial program 100.0%
*-commutative100.0%
fma-neg100.0%
distribute-rgt-neg-in100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
associate-*r*98.4%
unpow298.4%
associate-*r*98.4%
*-commutative98.4%
distribute-rgt-out--98.4%
*-commutative98.4%
Simplified98.4%
if 0.010800000000000001 < y < 7.8000000000000005e93 or 1.34999999999999997e256 < y Initial program 99.6%
Taylor expanded in x around inf 76.8%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.22e-27) (not (<= x 2.2e+203))) (* (cos y) x) (- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.22e-27) || !(x <= 2.2e+203)) {
tmp = cos(y) * x;
} else {
tmp = x - (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.22d-27)) .or. (.not. (x <= 2.2d+203))) then
tmp = cos(y) * x
else
tmp = x - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.22e-27) || !(x <= 2.2e+203)) {
tmp = Math.cos(y) * x;
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.22e-27) or not (x <= 2.2e+203): tmp = math.cos(y) * x else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.22e-27) || !(x <= 2.2e+203)) tmp = Float64(cos(y) * x); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.22e-27) || ~((x <= 2.2e+203))) tmp = cos(y) * x; else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.22e-27], N[Not[LessEqual[x, 2.2e+203]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{-27} \lor \neg \left(x \leq 2.2 \cdot 10^{+203}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -1.22e-27 or 2.20000000000000004e203 < x Initial program 99.8%
Taylor expanded in x around inf 91.1%
if -1.22e-27 < x < 2.20000000000000004e203Initial program 99.8%
Taylor expanded in y around 0 88.8%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e-8) (not (<= y 0.007))) (* (cos y) x) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e-8) || !(y <= 0.007)) {
tmp = cos(y) * x;
} else {
tmp = x - (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 ((y <= (-7.2d-8)) .or. (.not. (y <= 0.007d0))) then
tmp = cos(y) * x
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e-8) || !(y <= 0.007)) {
tmp = Math.cos(y) * x;
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.2e-8) or not (y <= 0.007): tmp = math.cos(y) * x else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e-8) || !(y <= 0.007)) tmp = Float64(cos(y) * x); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.2e-8) || ~((y <= 0.007))) tmp = cos(y) * x; else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e-8], N[Not[LessEqual[y, 0.007]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-8} \lor \neg \left(y \leq 0.007\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -7.19999999999999962e-8 or 0.00700000000000000015 < y Initial program 99.6%
Taylor expanded in x around inf 53.0%
if -7.19999999999999962e-8 < y < 0.00700000000000000015Initial program 100.0%
Taylor expanded in y around 0 99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
Final simplification76.9%
(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 54.8%
mul-1-neg54.8%
unsub-neg54.8%
Simplified54.8%
Final simplification54.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%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 39.5%
Final simplification39.5%
herbie shell --seed 2024031
(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))))