
(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 (+ (* 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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (<= y -6.2e-6)
t_0
(if (<= y 0.00062)
(+ (* y z) (+ x (* -0.5 (* y (* x y)))))
(if (or (<= y 3.45e+47) (and (not (<= y 1.6e+83)) (<= y 8.4e+245)))
t_0
(* x (cos y)))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (y <= -6.2e-6) {
tmp = t_0;
} else if (y <= 0.00062) {
tmp = (y * z) + (x + (-0.5 * (y * (x * y))));
} else if ((y <= 3.45e+47) || (!(y <= 1.6e+83) && (y <= 8.4e+245))) {
tmp = t_0;
} else {
tmp = x * cos(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) :: t_0
real(8) :: tmp
t_0 = z * sin(y)
if (y <= (-6.2d-6)) then
tmp = t_0
else if (y <= 0.00062d0) then
tmp = (y * z) + (x + ((-0.5d0) * (y * (x * y))))
else if ((y <= 3.45d+47) .or. (.not. (y <= 1.6d+83)) .and. (y <= 8.4d+245)) then
tmp = t_0
else
tmp = x * cos(y)
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 <= -6.2e-6) {
tmp = t_0;
} else if (y <= 0.00062) {
tmp = (y * z) + (x + (-0.5 * (y * (x * y))));
} else if ((y <= 3.45e+47) || (!(y <= 1.6e+83) && (y <= 8.4e+245))) {
tmp = t_0;
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) tmp = 0 if y <= -6.2e-6: tmp = t_0 elif y <= 0.00062: tmp = (y * z) + (x + (-0.5 * (y * (x * y)))) elif (y <= 3.45e+47) or (not (y <= 1.6e+83) and (y <= 8.4e+245)): tmp = t_0 else: tmp = x * math.cos(y) return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (y <= -6.2e-6) tmp = t_0; elseif (y <= 0.00062) tmp = Float64(Float64(y * z) + Float64(x + Float64(-0.5 * Float64(y * Float64(x * y))))); elseif ((y <= 3.45e+47) || (!(y <= 1.6e+83) && (y <= 8.4e+245))) tmp = t_0; else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); tmp = 0.0; if (y <= -6.2e-6) tmp = t_0; elseif (y <= 0.00062) tmp = (y * z) + (x + (-0.5 * (y * (x * y)))); elseif ((y <= 3.45e+47) || (~((y <= 1.6e+83)) && (y <= 8.4e+245))) tmp = t_0; else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.2e-6], t$95$0, If[LessEqual[y, 0.00062], N[(N[(y * z), $MachinePrecision] + N[(x + N[(-0.5 * N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.45e+47], And[N[Not[LessEqual[y, 1.6e+83]], $MachinePrecision], LessEqual[y, 8.4e+245]]], t$95$0, N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;y \leq -6.2 \cdot 10^{-6}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.00062:\\
\;\;\;\;y \cdot z + \left(x + -0.5 \cdot \left(y \cdot \left(x \cdot y\right)\right)\right)\\
\mathbf{elif}\;y \leq 3.45 \cdot 10^{+47} \lor \neg \left(y \leq 1.6 \cdot 10^{+83}\right) \land y \leq 8.4 \cdot 10^{+245}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if y < -6.1999999999999999e-6 or 6.2e-4 < y < 3.4500000000000002e47 or 1.5999999999999999e83 < y < 8.39999999999999984e245Initial program 99.7%
Taylor expanded in x around 0 68.7%
if -6.1999999999999999e-6 < y < 6.2e-4Initial program 100.0%
Taylor expanded in y around 0 99.6%
expm1-log1p-u91.4%
expm1-udef91.4%
unpow291.4%
associate-*l*91.4%
Applied egg-rr91.4%
expm1-def91.4%
expm1-log1p99.6%
Simplified99.6%
if 3.4500000000000002e47 < y < 1.5999999999999999e83 or 8.39999999999999984e245 < y Initial program 99.6%
*-commutative99.6%
add-cube-cbrt98.2%
associate-*r*98.2%
fma-def98.2%
pow298.2%
Applied egg-rr98.2%
Taylor expanded in z around 0 81.3%
pow-base-181.3%
*-lft-identity81.3%
Simplified81.3%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e+223) (not (<= x 6.5e+112))) (* x (cos y)) (+ x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e+223) || !(x <= 6.5e+112)) {
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 <= (-5.8d+223)) .or. (.not. (x <= 6.5d+112))) 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 <= -5.8e+223) || !(x <= 6.5e+112)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e+223) or not (x <= 6.5e+112): tmp = x * math.cos(y) else: tmp = x + (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e+223) || !(x <= 6.5e+112)) 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 <= -5.8e+223) || ~((x <= 6.5e+112))) tmp = x * cos(y); else tmp = x + (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e+223], N[Not[LessEqual[x, 6.5e+112]], $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 -5.8 \cdot 10^{+223} \lor \neg \left(x \leq 6.5 \cdot 10^{+112}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \sin y\\
\end{array}
\end{array}
if x < -5.8000000000000004e223 or 6.4999999999999998e112 < x Initial program 99.8%
*-commutative99.8%
add-cube-cbrt98.0%
associate-*r*98.0%
fma-def98.0%
pow298.0%
Applied egg-rr98.0%
Taylor expanded in z around 0 94.7%
pow-base-194.7%
*-lft-identity94.7%
Simplified94.7%
if -5.8000000000000004e223 < x < 6.4999999999999998e112Initial program 99.9%
Taylor expanded in y around 0 86.1%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.2e-6) (not (<= y 0.00062))) (* z (sin y)) (+ (* y z) (+ x (* -0.5 (* y (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-6) || !(y <= 0.00062)) {
tmp = z * sin(y);
} else {
tmp = (y * z) + (x + (-0.5 * (y * (x * 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 <= (-6.2d-6)) .or. (.not. (y <= 0.00062d0))) then
tmp = z * sin(y)
else
tmp = (y * z) + (x + ((-0.5d0) * (y * (x * y))))
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 = z * Math.sin(y);
} else {
tmp = (y * z) + (x + (-0.5 * (y * (x * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-6) or not (y <= 0.00062): tmp = z * math.sin(y) else: tmp = (y * z) + (x + (-0.5 * (y * (x * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-6) || !(y <= 0.00062)) tmp = Float64(z * sin(y)); else tmp = Float64(Float64(y * z) + Float64(x + Float64(-0.5 * Float64(y * Float64(x * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e-6) || ~((y <= 0.00062))) tmp = z * sin(y); else tmp = (y * z) + (x + (-0.5 * (y * (x * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-6], N[Not[LessEqual[y, 0.00062]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] + N[(x + N[(-0.5 * N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z + \left(x + -0.5 \cdot \left(y \cdot \left(x \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -6.1999999999999999e-6 or 6.2e-4 < y Initial program 99.7%
Taylor expanded in x around 0 58.7%
if -6.1999999999999999e-6 < y < 6.2e-4Initial program 100.0%
Taylor expanded in y around 0 99.6%
expm1-log1p-u91.4%
expm1-udef91.4%
unpow291.4%
associate-*l*91.4%
Applied egg-rr91.4%
expm1-def91.4%
expm1-log1p99.6%
Simplified99.6%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (<= z -3e+94) (* y z) (if (<= z 1.9e+93) x (if (<= z 1.6e+303) (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3e+94) {
tmp = y * z;
} else if (z <= 1.9e+93) {
tmp = x;
} else if (z <= 1.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 <= (-3d+94)) then
tmp = y * z
else if (z <= 1.9d+93) then
tmp = x
else if (z <= 1.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 <= -3e+94) {
tmp = y * z;
} else if (z <= 1.9e+93) {
tmp = x;
} else if (z <= 1.6e+303) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3e+94: tmp = y * z elif z <= 1.9e+93: tmp = x elif z <= 1.6e+303: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3e+94) tmp = Float64(y * z); elseif (z <= 1.9e+93) tmp = x; elseif (z <= 1.6e+303) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3e+94) tmp = y * z; elseif (z <= 1.9e+93) tmp = x; elseif (z <= 1.6e+303) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3e+94], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.9e+93], x, If[LessEqual[z, 1.6e+303], N[(y * z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{+94}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{+93}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+303}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.0000000000000001e94 or 1.8999999999999999e93 < z < 1.6000000000000001e303Initial program 99.9%
Taylor expanded in y around 0 49.4%
Taylor expanded in z around inf 35.2%
if -3.0000000000000001e94 < z < 1.8999999999999999e93 or 1.6000000000000001e303 < z Initial program 99.8%
+-commutative99.8%
add-cube-cbrt99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 51.3%
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 55.3%
Final simplification55.3%
(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%
add-cube-cbrt99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 41.3%
Final simplification41.3%
herbie shell --seed 2023185
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))