
(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 9 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 (- (* 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%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x (cos y)) (pow 1.0 0.3333333333333333)))) (if (<= x -5.8e+223) t_0 (if (<= x 6.5e+112) (fma (sin y) (- z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * cos(y)) * pow(1.0, 0.3333333333333333);
double tmp;
if (x <= -5.8e+223) {
tmp = t_0;
} else if (x <= 6.5e+112) {
tmp = fma(sin(y), -z, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x * cos(y)) * (1.0 ^ 0.3333333333333333)) tmp = 0.0 if (x <= -5.8e+223) tmp = t_0; elseif (x <= 6.5e+112) tmp = fma(sin(y), Float64(-z), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] * N[Power[1.0, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.8e+223], t$95$0, If[LessEqual[x, 6.5e+112], N[(N[Sin[y], $MachinePrecision] * (-z) + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot \cos y\right) \cdot {1}^{0.3333333333333333}\\
\mathbf{if}\;x \leq -5.8 \cdot 10^{+223}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+112}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -5.8000000000000004e223 or 6.4999999999999998e112 < x Initial program 99.8%
add-cube-cbrt98.1%
pow398.1%
Applied egg-rr98.1%
Taylor expanded in y around 0 80.6%
Taylor expanded in z around 0 94.5%
if -5.8000000000000004e223 < x < 6.4999999999999998e112Initial program 99.8%
Taylor expanded in y around 0 86.1%
Taylor expanded in x around 0 86.1%
mul-1-neg86.1%
*-commutative86.1%
distribute-rgt-neg-in86.1%
fma-udef86.1%
Simplified86.1%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (<= x 2.8e+160) (fma (sin y) (- z) x) (- (* x (cos y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 2.8e+160) {
tmp = fma(sin(y), -z, x);
} else {
tmp = (x * cos(y)) - (y * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= 2.8e+160) tmp = fma(sin(y), Float64(-z), x); else tmp = Float64(Float64(x * cos(y)) - Float64(y * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, 2.8e+160], N[(N[Sin[y], $MachinePrecision] * (-z) + x), $MachinePrecision], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.8 \cdot 10^{+160}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y - y \cdot z\\
\end{array}
\end{array}
if x < 2.8e160Initial program 99.8%
Taylor expanded in y around 0 84.2%
Taylor expanded in x around 0 84.2%
mul-1-neg84.2%
*-commutative84.2%
distribute-rgt-neg-in84.2%
fma-udef84.2%
Simplified84.2%
if 2.8e160 < x Initial program 99.9%
Taylor expanded in y around 0 82.2%
Final simplification84.0%
(FPCore (x y z) :precision binary64 (if (<= x 5.5e+156) (- x (* z (sin y))) (- (* x (cos y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 5.5e+156) {
tmp = x - (z * sin(y));
} else {
tmp = (x * cos(y)) - (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 <= 5.5d+156) then
tmp = x - (z * sin(y))
else
tmp = (x * cos(y)) - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 5.5e+156) {
tmp = x - (z * Math.sin(y));
} else {
tmp = (x * Math.cos(y)) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 5.5e+156: tmp = x - (z * math.sin(y)) else: tmp = (x * math.cos(y)) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 5.5e+156) tmp = Float64(x - Float64(z * sin(y))); else tmp = Float64(Float64(x * cos(y)) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 5.5e+156) tmp = x - (z * sin(y)); else tmp = (x * cos(y)) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 5.5e+156], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{+156}:\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y - y \cdot z\\
\end{array}
\end{array}
if x < 5.5000000000000003e156Initial program 99.8%
Taylor expanded in y around 0 84.2%
if 5.5000000000000003e156 < x Initial program 99.9%
Taylor expanded in y around 0 82.2%
Final simplification84.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.2e-6) (not (<= y 0.00062))) (* (sin y) (- z)) (- (+ x (* (* y y) (* x -0.5))) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-6) || !(y <= 0.00062)) {
tmp = sin(y) * -z;
} else {
tmp = (x + ((y * y) * (x * -0.5))) - (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 <= (-6.2d-6)) .or. (.not. (y <= 0.00062d0))) then
tmp = sin(y) * -z
else
tmp = (x + ((y * y) * (x * (-0.5d0)))) - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-6) || !(y <= 0.00062)) {
tmp = Math.sin(y) * -z;
} else {
tmp = (x + ((y * y) * (x * -0.5))) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-6) or not (y <= 0.00062): tmp = math.sin(y) * -z else: tmp = (x + ((y * y) * (x * -0.5))) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-6) || !(y <= 0.00062)) tmp = Float64(sin(y) * Float64(-z)); else tmp = Float64(Float64(x + Float64(Float64(y * y) * Float64(x * -0.5))) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e-6) || ~((y <= 0.00062))) tmp = sin(y) * -z; else tmp = (x + ((y * y) * (x * -0.5))) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-6], N[Not[LessEqual[y, 0.00062]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], N[(N[(x + N[(N[(y * y), $MachinePrecision] * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-6} \lor \neg \left(y \leq 0.00062\right):\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + \left(y \cdot y\right) \cdot \left(x \cdot -0.5\right)\right) - y \cdot z\\
\end{array}
\end{array}
if y < -6.1999999999999999e-6 or 6.2e-4 < y Initial program 99.7%
Taylor expanded in y around 0 62.1%
Taylor expanded in x around 0 58.8%
mul-1-neg58.8%
*-commutative58.8%
distribute-rgt-neg-in58.8%
Simplified58.8%
if -6.1999999999999999e-6 < y < 6.2e-4Initial program 100.0%
add-cube-cbrt98.3%
pow398.3%
Applied egg-rr98.3%
Taylor expanded in y around 0 97.9%
Taylor expanded in y around 0 99.6%
pow-base-199.6%
*-lft-identity99.6%
*-commutative99.6%
unpow299.6%
distribute-rgt-out99.6%
pow-base-199.6%
*-lft-identity99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (- x (* z (sin y))))
double code(double x, double y, double z) {
return 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 = x - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return x - (z * Math.sin(y));
}
def code(x, y, z): return x - (z * math.sin(y))
function code(x, y, z) return Float64(x - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = x - (z * sin(y)); end
code[x_, y_, z_] := N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot \sin y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 81.8%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e+91) (and (not (<= z 1.3e+118)) (<= z 3.6e+303))) (* y (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+91) || (!(z <= 1.3e+118) && (z <= 3.6e+303))) {
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 ((z <= (-3.2d+91)) .or. (.not. (z <= 1.3d+118)) .and. (z <= 3.6d+303)) 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 ((z <= -3.2e+91) || (!(z <= 1.3e+118) && (z <= 3.6e+303))) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e+91) or (not (z <= 1.3e+118) and (z <= 3.6e+303)): tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e+91) || (!(z <= 1.3e+118) && (z <= 3.6e+303))) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e+91) || (~((z <= 1.3e+118)) && (z <= 3.6e+303))) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e+91], And[N[Not[LessEqual[z, 1.3e+118]], $MachinePrecision], LessEqual[z, 3.6e+303]]], N[(y * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+91} \lor \neg \left(z \leq 1.3 \cdot 10^{+118}\right) \land z \leq 3.6 \cdot 10^{+303}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.19999999999999989e91 or 1.30000000000000008e118 < z < 3.6000000000000001e303Initial program 99.9%
add-cube-cbrt99.3%
pow399.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 49.4%
Taylor expanded in x around 0 34.9%
associate-*r*34.9%
neg-mul-134.9%
*-commutative34.9%
Simplified34.9%
if -3.19999999999999989e91 < z < 1.30000000000000008e118 or 3.6000000000000001e303 < z Initial program 99.8%
Taylor expanded in y around 0 78.5%
Taylor expanded in x around inf 51.2%
Final simplification46.7%
(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 81.8%
Taylor expanded in y around 0 55.0%
+-commutative55.0%
mul-1-neg55.0%
unsub-neg55.0%
*-commutative55.0%
Simplified55.0%
Final simplification55.0%
(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 y around 0 81.8%
Taylor expanded in x around inf 41.4%
Final simplification41.4%
herbie shell --seed 2023185
(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))))