
(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%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
return (cos(y) * x) - (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 = (cos(y) * x) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (Math.sin(y) * z);
}
def code(x, y, z): return (math.cos(y) * x) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e+90) (not (<= x 1.2e+25))) (* (cos y) x) (- x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+90) || !(x <= 1.2e+25)) {
tmp = cos(y) * x;
} else {
tmp = x - (sin(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 <= (-4.1d+90)) .or. (.not. (x <= 1.2d+25))) then
tmp = cos(y) * x
else
tmp = x - (sin(y) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e+90) || !(x <= 1.2e+25)) {
tmp = Math.cos(y) * x;
} else {
tmp = x - (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e+90) or not (x <= 1.2e+25): tmp = math.cos(y) * x else: tmp = x - (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e+90) || !(x <= 1.2e+25)) tmp = Float64(cos(y) * x); else tmp = Float64(x - Float64(sin(y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.1e+90) || ~((x <= 1.2e+25))) tmp = cos(y) * x; else tmp = x - (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e+90], N[Not[LessEqual[x, 1.2e+25]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+90} \lor \neg \left(x \leq 1.2 \cdot 10^{+25}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - \sin y \cdot z\\
\end{array}
\end{array}
if x < -4.10000000000000042e90 or 1.19999999999999998e25 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in x around inf 85.6%
if -4.10000000000000042e90 < x < 1.19999999999999998e25Initial program 99.8%
Taylor expanded in y around 0 88.8%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e-56) (not (<= x 6.5e-136))) (* (cos y) x) (* (sin y) (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-56) || !(x <= 6.5e-136)) {
tmp = cos(y) * x;
} else {
tmp = sin(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 <= (-9.5d-56)) .or. (.not. (x <= 6.5d-136))) then
tmp = cos(y) * x
else
tmp = sin(y) * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-56) || !(x <= 6.5e-136)) {
tmp = Math.cos(y) * x;
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e-56) or not (x <= 6.5e-136): tmp = math.cos(y) * x else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e-56) || !(x <= 6.5e-136)) tmp = Float64(cos(y) * x); else tmp = Float64(sin(y) * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.5e-56) || ~((x <= 6.5e-136))) tmp = cos(y) * x; else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e-56], N[Not[LessEqual[x, 6.5e-136]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-56} \lor \neg \left(x \leq 6.5 \cdot 10^{-136}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -9.4999999999999991e-56 or 6.50000000000000011e-136 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in x around inf 77.3%
if -9.4999999999999991e-56 < x < 6.50000000000000011e-136Initial program 99.8%
Taylor expanded in x around 0 81.8%
mul-1-neg81.8%
*-commutative81.8%
distribute-rgt-neg-in81.8%
Simplified81.8%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.05) (not (<= y 5200000000.0))) (* (cos y) x) (+ x (* y (- (* y (* x -0.5)) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.05) || !(y <= 5200000000.0)) {
tmp = cos(y) * x;
} else {
tmp = x + (y * ((y * (x * -0.5)) - 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 <= (-0.05d0)) .or. (.not. (y <= 5200000000.0d0))) then
tmp = cos(y) * x
else
tmp = x + (y * ((y * (x * (-0.5d0))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.05) || !(y <= 5200000000.0)) {
tmp = Math.cos(y) * x;
} else {
tmp = x + (y * ((y * (x * -0.5)) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.05) or not (y <= 5200000000.0): tmp = math.cos(y) * x else: tmp = x + (y * ((y * (x * -0.5)) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.05) || !(y <= 5200000000.0)) tmp = Float64(cos(y) * x); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(x * -0.5)) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.05) || ~((y <= 5200000000.0))) tmp = cos(y) * x; else tmp = x + (y * ((y * (x * -0.5)) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.05], N[Not[LessEqual[y, 5200000000.0]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.05 \lor \neg \left(y \leq 5200000000\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5\right) - z\right)\\
\end{array}
\end{array}
if y < -0.050000000000000003 or 5.2e9 < y Initial program 99.5%
Taylor expanded in x around 0 99.5%
mul-1-neg99.5%
distribute-rgt-neg-out99.5%
+-commutative99.5%
fma-udef99.5%
distribute-rgt-neg-out99.5%
*-commutative99.5%
distribute-rgt-neg-in99.5%
Simplified99.5%
Taylor expanded in x around inf 54.2%
if -0.050000000000000003 < y < 5.2e9Initial program 100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in y around 0 98.1%
distribute-rgt-in98.1%
*-un-lft-identity98.1%
flip-+66.0%
*-commutative66.0%
*-commutative66.0%
*-commutative66.0%
associate-*l*66.0%
*-commutative66.0%
associate-*l*66.0%
*-commutative66.0%
*-commutative66.0%
associate-*l*66.0%
Applied egg-rr66.0%
Taylor expanded in y around 0 98.1%
mul-1-neg98.1%
distribute-rgt-neg-out98.1%
+-commutative98.1%
+-commutative98.1%
associate-*r*98.1%
*-commutative98.1%
unpow298.1%
associate-*r*98.1%
associate-*r*98.1%
distribute-rgt-neg-out98.1%
sub-neg98.1%
associate--l+98.1%
distribute-lft-out--98.1%
associate-*l*98.1%
Simplified98.1%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.55e-69) x (if (<= x 2.2e-174) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.55e-69) {
tmp = x;
} else if (x <= 2.2e-174) {
tmp = y * -z;
} else {
tmp = x;
}
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-69)) then
tmp = x
else if (x <= 2.2d-174) then
tmp = y * -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.55e-69) {
tmp = x;
} else if (x <= 2.2e-174) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.55e-69: tmp = x elif x <= 2.2e-174: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.55e-69) tmp = x; elseif (x <= 2.2e-174) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.55e-69) tmp = x; elseif (x <= 2.2e-174) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.55e-69], x, If[LessEqual[x, 2.2e-174], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-69}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-174}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.55e-69 or 2.20000000000000022e-174 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in y around 0 44.5%
if -1.55e-69 < x < 2.20000000000000022e-174Initial program 99.8%
Taylor expanded in y around 0 78.0%
unpow278.0%
Simplified78.0%
Taylor expanded in y around 0 64.5%
Taylor expanded in x around 0 53.7%
associate-*r*53.7%
neg-mul-153.7%
Simplified53.7%
Final simplification47.2%
(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 56.1%
+-commutative56.1%
mul-1-neg56.1%
unsub-neg56.1%
Simplified56.1%
Final simplification56.1%
(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 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in y around 0 35.7%
Final simplification35.7%
herbie shell --seed 2023182
(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))))