
(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 z (sin y) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, sin(y), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * N[Sin[y], $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -8e+242)
t_0
(if (<= y -0.18)
t_1
(if (<= y 30500.0)
(+ (* z y) (+ x (* -0.5 (* x (* y y)))))
(if (or (<= y 3.05e+209) (not (<= y 3.6e+233))) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -8e+242) {
tmp = t_0;
} else if (y <= -0.18) {
tmp = t_1;
} else if (y <= 30500.0) {
tmp = (z * y) + (x + (-0.5 * (x * (y * y))));
} else if ((y <= 3.05e+209) || !(y <= 3.6e+233)) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = z * sin(y)
t_1 = x * cos(y)
if (y <= (-8d+242)) then
tmp = t_0
else if (y <= (-0.18d0)) then
tmp = t_1
else if (y <= 30500.0d0) then
tmp = (z * y) + (x + ((-0.5d0) * (x * (y * y))))
else if ((y <= 3.05d+209) .or. (.not. (y <= 3.6d+233))) then
tmp = t_1
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 t_1 = x * Math.cos(y);
double tmp;
if (y <= -8e+242) {
tmp = t_0;
} else if (y <= -0.18) {
tmp = t_1;
} else if (y <= 30500.0) {
tmp = (z * y) + (x + (-0.5 * (x * (y * y))));
} else if ((y <= 3.05e+209) || !(y <= 3.6e+233)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -8e+242: tmp = t_0 elif y <= -0.18: tmp = t_1 elif y <= 30500.0: tmp = (z * y) + (x + (-0.5 * (x * (y * y)))) elif (y <= 3.05e+209) or not (y <= 3.6e+233): tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -8e+242) tmp = t_0; elseif (y <= -0.18) tmp = t_1; elseif (y <= 30500.0) tmp = Float64(Float64(z * y) + Float64(x + Float64(-0.5 * Float64(x * Float64(y * y))))); elseif ((y <= 3.05e+209) || !(y <= 3.6e+233)) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -8e+242) tmp = t_0; elseif (y <= -0.18) tmp = t_1; elseif (y <= 30500.0) tmp = (z * y) + (x + (-0.5 * (x * (y * y)))); elseif ((y <= 3.05e+209) || ~((y <= 3.6e+233))) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8e+242], t$95$0, If[LessEqual[y, -0.18], t$95$1, If[LessEqual[y, 30500.0], N[(N[(z * y), $MachinePrecision] + N[(x + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.05e+209], N[Not[LessEqual[y, 3.6e+233]], $MachinePrecision]], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -8 \cdot 10^{+242}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.18:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 30500:\\
\;\;\;\;z \cdot y + \left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right)\\
\mathbf{elif}\;y \leq 3.05 \cdot 10^{+209} \lor \neg \left(y \leq 3.6 \cdot 10^{+233}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -8.00000000000000041e242 or 3.05000000000000015e209 < y < 3.5999999999999998e233Initial program 99.6%
Taylor expanded in x around 0 75.1%
if -8.00000000000000041e242 < y < -0.17999999999999999 or 30500 < y < 3.05000000000000015e209 or 3.5999999999999998e233 < y Initial program 99.7%
*-commutative99.7%
add-cube-cbrt98.7%
associate-*l*98.6%
fma-def98.6%
pow298.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 63.9%
pow-base-163.9%
*-lft-identity63.9%
Simplified63.9%
if -0.17999999999999999 < y < 30500Initial program 100.0%
Taylor expanded in y around 0 97.7%
expm1-log1p-u90.3%
expm1-udef90.3%
*-commutative90.3%
unpow290.3%
Applied egg-rr90.3%
expm1-def90.3%
expm1-log1p97.7%
unpow297.7%
*-commutative97.7%
unpow297.7%
Simplified97.7%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e+140) (not (<= x 6.8e-12))) (* x (cos y)) (+ x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+140) || !(x <= 6.8e-12)) {
tmp = x * cos(y);
} 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.95d+140)) .or. (.not. (x <= 6.8d-12))) then
tmp = x * cos(y)
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.95e+140) || !(x <= 6.8e-12)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.95e+140) or not (x <= 6.8e-12): tmp = x * math.cos(y) else: tmp = x + (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e+140) || !(x <= 6.8e-12)) tmp = Float64(x * cos(y)); 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.95e+140) || ~((x <= 6.8e-12))) tmp = x * cos(y); else tmp = x + (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e+140], N[Not[LessEqual[x, 6.8e-12]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+140} \lor \neg \left(x \leq 6.8 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \sin y\\
\end{array}
\end{array}
if x < -1.94999999999999987e140 or 6.8000000000000001e-12 < x Initial program 99.8%
*-commutative99.8%
add-cube-cbrt99.1%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in x around inf 92.3%
pow-base-192.3%
*-lft-identity92.3%
Simplified92.3%
if -1.94999999999999987e140 < x < 6.8000000000000001e-12Initial program 99.9%
Taylor expanded in y around 0 90.7%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -7e-5) (not (<= y 0.0064))) (* z (sin y)) (+ (* z y) (+ x (* -0.5 (* x (* y y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-5) || !(y <= 0.0064)) {
tmp = z * sin(y);
} else {
tmp = (z * y) + (x + (-0.5 * (x * (y * 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 ((y <= (-7d-5)) .or. (.not. (y <= 0.0064d0))) then
tmp = z * sin(y)
else
tmp = (z * y) + (x + ((-0.5d0) * (x * (y * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-5) || !(y <= 0.0064)) {
tmp = z * Math.sin(y);
} else {
tmp = (z * y) + (x + (-0.5 * (x * (y * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7e-5) or not (y <= 0.0064): tmp = z * math.sin(y) else: tmp = (z * y) + (x + (-0.5 * (x * (y * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7e-5) || !(y <= 0.0064)) tmp = Float64(z * sin(y)); else tmp = Float64(Float64(z * y) + Float64(x + Float64(-0.5 * Float64(x * Float64(y * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7e-5) || ~((y <= 0.0064))) tmp = z * sin(y); else tmp = (z * y) + (x + (-0.5 * (x * (y * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7e-5], N[Not[LessEqual[y, 0.0064]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[(z * y), $MachinePrecision] + N[(x + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-5} \lor \neg \left(y \leq 0.0064\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y + \left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -6.9999999999999994e-5 or 0.00640000000000000031 < y Initial program 99.7%
Taylor expanded in x around 0 47.9%
if -6.9999999999999994e-5 < y < 0.00640000000000000031Initial program 100.0%
Taylor expanded in y around 0 100.0%
expm1-log1p-u92.9%
expm1-udef92.8%
*-commutative92.8%
unpow292.8%
Applied egg-rr92.8%
expm1-def92.9%
expm1-log1p100.0%
unpow2100.0%
*-commutative100.0%
unpow2100.0%
Simplified100.0%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (<= z -1e+165) (* z y) (if (<= z 3.2e+150) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+165) {
tmp = z * y;
} else if (z <= 3.2e+150) {
tmp = x;
} else {
tmp = z * 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 (z <= (-1d+165)) then
tmp = z * y
else if (z <= 3.2d+150) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1e+165) {
tmp = z * y;
} else if (z <= 3.2e+150) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e+165: tmp = z * y elif z <= 3.2e+150: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e+165) tmp = Float64(z * y); elseif (z <= 3.2e+150) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e+165) tmp = z * y; elseif (z <= 3.2e+150) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e+165], N[(z * y), $MachinePrecision], If[LessEqual[z, 3.2e+150], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+165}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+150}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -9.99999999999999899e164 or 3.20000000000000016e150 < z Initial program 99.9%
Taylor expanded in y around 0 62.0%
Taylor expanded in z around inf 46.2%
if -9.99999999999999899e164 < z < 3.20000000000000016e150Initial program 99.8%
*-commutative99.8%
add-cube-cbrt99.4%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 48.4%
Final simplification47.9%
(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.9%
Taylor expanded in y around 0 58.1%
Final simplification58.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.9%
*-commutative99.9%
add-cube-cbrt99.5%
associate-*l*99.5%
fma-def99.5%
pow299.5%
Applied egg-rr99.5%
Taylor expanded in y around 0 41.8%
Final simplification41.8%
herbie shell --seed 2023268
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))