
(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 11 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 (fma x (cos y) (* (sin y) z)))
double code(double x, double y, double z) {
return fma(x, cos(y), (sin(y) * z));
}
function code(x, y, z) return fma(x, cos(y), Float64(sin(y) * z)) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, \sin y \cdot z\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e+149) (not (<= x 2.2e+112))) (* x (cos y)) (fma (sin y) z x)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+149) || !(x <= 2.2e+112)) {
tmp = x * cos(y);
} else {
tmp = fma(sin(y), z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e+149) || !(x <= 2.2e+112)) tmp = Float64(x * cos(y)); else tmp = fma(sin(y), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e+149], N[Not[LessEqual[x, 2.2e+112]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+149} \lor \neg \left(x \leq 2.2 \cdot 10^{+112}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\
\end{array}
\end{array}
if x < -1.95e149 or 2.1999999999999999e112 < x Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 92.8%
if -1.95e149 < x < 2.1999999999999999e112Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 87.4%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (+ (* (sin y) z) (* x (cos y))))
double code(double x, double y, double z) {
return (sin(y) * z) + (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 = (sin(y) * z) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (Math.sin(y) * z) + (x * Math.cos(y));
}
def code(x, y, z): return (math.sin(y) * z) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(sin(y) * z) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (sin(y) * z) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin y \cdot z + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e+149) (not (<= x 8.5e+113))) (* x (cos y)) (+ x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+149) || !(x <= 8.5e+113)) {
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 <= (-1.95d+149)) .or. (.not. (x <= 8.5d+113))) 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 <= -1.95e+149) || !(x <= 8.5e+113)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.95e+149) or not (x <= 8.5e+113): tmp = x * math.cos(y) else: tmp = x + (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e+149) || !(x <= 8.5e+113)) 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 <= -1.95e+149) || ~((x <= 8.5e+113))) tmp = x * cos(y); else tmp = x + (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e+149], N[Not[LessEqual[x, 8.5e+113]], $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 -1.95 \cdot 10^{+149} \lor \neg \left(x \leq 8.5 \cdot 10^{+113}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y \cdot z\\
\end{array}
\end{array}
if x < -1.95e149 or 8.5000000000000001e113 < x Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 92.8%
if -1.95e149 < x < 8.5000000000000001e113Initial program 99.8%
Taylor expanded in y around 0 87.4%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.6e-8) (not (<= y 6.5e-5))) (* (sin y) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.6e-8) || !(y <= 6.5e-5)) {
tmp = sin(y) * z;
} 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 <= (-5.6d-8)) .or. (.not. (y <= 6.5d-5))) then
tmp = sin(y) * z
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 <= -5.6e-8) || !(y <= 6.5e-5)) {
tmp = Math.sin(y) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.6e-8) or not (y <= 6.5e-5): tmp = math.sin(y) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.6e-8) || !(y <= 6.5e-5)) tmp = Float64(sin(y) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.6e-8) || ~((y <= 6.5e-5))) tmp = sin(y) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.6e-8], N[Not[LessEqual[y, 6.5e-5]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.6 \cdot 10^{-8} \lor \neg \left(y \leq 6.5 \cdot 10^{-5}\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -5.5999999999999999e-8 or 6.49999999999999943e-5 < y Initial program 99.6%
Taylor expanded in x around 0 54.8%
if -5.5999999999999999e-8 < y < 6.49999999999999943e-5Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= y -65.0) (* x (cos y)) (if (<= y 0.000205) (+ x (* y z)) (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -65.0) {
tmp = x * cos(y);
} else if (y <= 0.000205) {
tmp = x + (y * z);
} 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 (y <= (-65.0d0)) then
tmp = x * cos(y)
else if (y <= 0.000205d0) then
tmp = x + (y * z)
else
tmp = sin(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -65.0) {
tmp = x * Math.cos(y);
} else if (y <= 0.000205) {
tmp = x + (y * z);
} else {
tmp = Math.sin(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -65.0: tmp = x * math.cos(y) elif y <= 0.000205: tmp = x + (y * z) else: tmp = math.sin(y) * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -65.0) tmp = Float64(x * cos(y)); elseif (y <= 0.000205) tmp = Float64(x + Float64(y * z)); else tmp = Float64(sin(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -65.0) tmp = x * cos(y); elseif (y <= 0.000205) tmp = x + (y * z); else tmp = sin(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -65.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.000205], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -65:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq 0.000205:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot z\\
\end{array}
\end{array}
if y < -65Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 57.7%
if -65 < y < 2.05e-4Initial program 100.0%
Taylor expanded in y around 0 97.4%
if 2.05e-4 < y Initial program 99.6%
Taylor expanded in x around 0 62.8%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (<= y -65.0) (* x (cos y)) (if (<= y 0.000235) (fma y z x) (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -65.0) {
tmp = x * cos(y);
} else if (y <= 0.000235) {
tmp = fma(y, z, x);
} else {
tmp = sin(y) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -65.0) tmp = Float64(x * cos(y)); elseif (y <= 0.000235) tmp = fma(y, z, x); else tmp = Float64(sin(y) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -65.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.000235], N[(y * z + x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -65:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq 0.000235:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot z\\
\end{array}
\end{array}
if y < -65Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 57.7%
if -65 < y < 2.34999999999999993e-4Initial program 100.0%
Taylor expanded in y around 0 97.4%
fma-def97.5%
Simplified97.5%
if 2.34999999999999993e-4 < y Initial program 99.6%
Taylor expanded in x around 0 62.8%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.8e+142) (* y z) (if (<= z 8.6e-29) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e+142) {
tmp = y * z;
} else if (z <= 8.6e-29) {
tmp = x;
} else {
tmp = 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 (z <= (-1.8d+142)) then
tmp = y * z
else if (z <= 8.6d-29) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e+142) {
tmp = y * z;
} else if (z <= 8.6e-29) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.8e+142: tmp = y * z elif z <= 8.6e-29: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.8e+142) tmp = Float64(y * z); elseif (z <= 8.6e-29) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.8e+142) tmp = y * z; elseif (z <= 8.6e-29) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.8e+142], N[(y * z), $MachinePrecision], If[LessEqual[z, 8.6e-29], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 8.6 \cdot 10^{-29}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.8000000000000001e142 or 8.5999999999999996e-29 < z Initial program 99.8%
Taylor expanded in x around 0 72.4%
Taylor expanded in y around 0 36.9%
if -1.8000000000000001e142 < z < 8.5999999999999996e-29Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 42.7%
Final simplification40.5%
(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 33.1%
Final simplification33.1%
herbie shell --seed 2023229
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))