
(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 (fma (sin y) z (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), z, Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * z + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) + (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 = (x * cos(y)) + (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) + (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)) (t_1 (* x (cos y))))
(if (<= y -4.3e+83)
t_0
(if (<= y -8.8e+21)
t_1
(if (<= y -0.0036)
t_0
(if (<= y 0.23)
(+ x (* y z))
(if (or (<= y 1.15e+134) (not (<= y 4.2e+219))) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double t_1 = x * cos(y);
double tmp;
if (y <= -4.3e+83) {
tmp = t_0;
} else if (y <= -8.8e+21) {
tmp = t_1;
} else if (y <= -0.0036) {
tmp = t_0;
} else if (y <= 0.23) {
tmp = x + (y * z);
} else if ((y <= 1.15e+134) || !(y <= 4.2e+219)) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = sin(y) * z
t_1 = x * cos(y)
if (y <= (-4.3d+83)) then
tmp = t_0
else if (y <= (-8.8d+21)) then
tmp = t_1
else if (y <= (-0.0036d0)) then
tmp = t_0
else if (y <= 0.23d0) then
tmp = x + (y * z)
else if ((y <= 1.15d+134) .or. (.not. (y <= 4.2d+219))) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) * z;
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -4.3e+83) {
tmp = t_0;
} else if (y <= -8.8e+21) {
tmp = t_1;
} else if (y <= -0.0036) {
tmp = t_0;
} else if (y <= 0.23) {
tmp = x + (y * z);
} else if ((y <= 1.15e+134) || !(y <= 4.2e+219)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * z t_1 = x * math.cos(y) tmp = 0 if y <= -4.3e+83: tmp = t_0 elif y <= -8.8e+21: tmp = t_1 elif y <= -0.0036: tmp = t_0 elif y <= 0.23: tmp = x + (y * z) elif (y <= 1.15e+134) or not (y <= 4.2e+219): tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * z) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -4.3e+83) tmp = t_0; elseif (y <= -8.8e+21) tmp = t_1; elseif (y <= -0.0036) tmp = t_0; elseif (y <= 0.23) tmp = Float64(x + Float64(y * z)); elseif ((y <= 1.15e+134) || !(y <= 4.2e+219)) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * z; t_1 = x * cos(y); tmp = 0.0; if (y <= -4.3e+83) tmp = t_0; elseif (y <= -8.8e+21) tmp = t_1; elseif (y <= -0.0036) tmp = t_0; elseif (y <= 0.23) tmp = x + (y * z); elseif ((y <= 1.15e+134) || ~((y <= 4.2e+219))) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.3e+83], t$95$0, If[LessEqual[y, -8.8e+21], t$95$1, If[LessEqual[y, -0.0036], t$95$0, If[LessEqual[y, 0.23], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.15e+134], N[Not[LessEqual[y, 4.2e+219]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -4.3 \cdot 10^{+83}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8.8 \cdot 10^{+21}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -0.0036:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.23:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+134} \lor \neg \left(y \leq 4.2 \cdot 10^{+219}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -4.3e83 or -8.8e21 < y < -0.0035999999999999999 or 0.23000000000000001 < y < 1.1499999999999999e134 or 4.19999999999999976e219 < y Initial program 99.6%
Taylor expanded in x around 0 62.8%
if -4.3e83 < y < -8.8e21 or 1.1499999999999999e134 < y < 4.19999999999999976e219Initial program 99.6%
Taylor expanded in x around inf 70.3%
if -0.0035999999999999999 < y < 0.23000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification81.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)) (t_1 (* x (cos y))))
(if (<= y -1e+84)
t_0
(if (<= y -5e+21)
t_1
(if (<= y -0.000108)
t_0
(if (<= y 0.23)
(fma y z x)
(if (or (<= y 1.7e+135) (not (<= y 3e+221))) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double t_1 = x * cos(y);
double tmp;
if (y <= -1e+84) {
tmp = t_0;
} else if (y <= -5e+21) {
tmp = t_1;
} else if (y <= -0.000108) {
tmp = t_0;
} else if (y <= 0.23) {
tmp = fma(y, z, x);
} else if ((y <= 1.7e+135) || !(y <= 3e+221)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * z) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1e+84) tmp = t_0; elseif (y <= -5e+21) tmp = t_1; elseif (y <= -0.000108) tmp = t_0; elseif (y <= 0.23) tmp = fma(y, z, x); elseif ((y <= 1.7e+135) || !(y <= 3e+221)) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e+84], t$95$0, If[LessEqual[y, -5e+21], t$95$1, If[LessEqual[y, -0.000108], t$95$0, If[LessEqual[y, 0.23], N[(y * z + x), $MachinePrecision], If[Or[LessEqual[y, 1.7e+135], N[Not[LessEqual[y, 3e+221]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1 \cdot 10^{+84}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -5 \cdot 10^{+21}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -0.000108:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.23:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+135} \lor \neg \left(y \leq 3 \cdot 10^{+221}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.00000000000000006e84 or -5e21 < y < -1.08e-4 or 0.23000000000000001 < y < 1.70000000000000005e135 or 3.0000000000000001e221 < y Initial program 99.6%
Taylor expanded in x around 0 62.8%
if -1.00000000000000006e84 < y < -5e21 or 1.70000000000000005e135 < y < 3.0000000000000001e221Initial program 99.6%
Taylor expanded in x around inf 70.3%
if -1.08e-4 < y < 0.23000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.9%
+-commutative98.9%
fma-def99.0%
Simplified99.0%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e+36) (not (<= x 1.3e+129))) (* x (cos y)) (+ x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e+36) || !(x <= 1.3e+129)) {
tmp = x * cos(y);
} 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 <= (-3.3d+36)) .or. (.not. (x <= 1.3d+129))) then
tmp = x * cos(y)
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 <= -3.3e+36) || !(x <= 1.3e+129)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e+36) or not (x <= 1.3e+129): tmp = x * math.cos(y) else: tmp = x + (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e+36) || !(x <= 1.3e+129)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(sin(y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.3e+36) || ~((x <= 1.3e+129))) tmp = x * cos(y); else tmp = x + (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e+36], N[Not[LessEqual[x, 1.3e+129]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+36} \lor \neg \left(x \leq 1.3 \cdot 10^{+129}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y \cdot z\\
\end{array}
\end{array}
if x < -3.2999999999999999e36 or 1.30000000000000006e129 < x Initial program 99.8%
Taylor expanded in x around inf 90.4%
if -3.2999999999999999e36 < x < 1.30000000000000006e129Initial program 99.8%
Taylor expanded in y around 0 86.3%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0152) (not (<= y 0.034))) (* x (cos y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0152) || !(y <= 0.034)) {
tmp = x * cos(y);
} 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 <= (-0.0152d0)) .or. (.not. (y <= 0.034d0))) then
tmp = x * cos(y)
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 <= -0.0152) || !(y <= 0.034)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0152) or not (y <= 0.034): tmp = x * math.cos(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0152) || !(y <= 0.034)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0152) || ~((y <= 0.034))) tmp = x * cos(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0152], N[Not[LessEqual[y, 0.034]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0152 \lor \neg \left(y \leq 0.034\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -0.0152 or 0.034000000000000002 < y Initial program 99.6%
Taylor expanded in x around inf 47.0%
if -0.0152 < y < 0.034000000000000002Initial program 100.0%
Taylor expanded in y around 0 99.5%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e+178) (not (<= z 3.6e+182))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e+178) || !(z <= 3.6e+182)) {
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+178)) .or. (.not. (z <= 3.6d+182))) 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+178) || !(z <= 3.6e+182)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e+178) or not (z <= 3.6e+182): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e+178) || !(z <= 3.6e+182)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e+178) || ~((z <= 3.6e+182))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e+178], N[Not[LessEqual[z, 3.6e+182]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{+178} \lor \neg \left(z \leq 3.6 \cdot 10^{+182}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.00000000000000016e178 or 3.6e182 < z Initial program 99.9%
Taylor expanded in y around 0 50.0%
Taylor expanded in x around 0 36.0%
if -3.00000000000000016e178 < z < 3.6e182Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 46.7%
Final simplification44.6%
(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 51.0%
Final simplification51.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%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 40.5%
Final simplification40.5%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))