
(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 (+ (* (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
(let* ((t_0 (* (sin y) z)) (t_1 (* x (cos y))))
(if (<= y -2.95e+158)
t_0
(if (<= y -2.6e+97)
t_1
(if (<= y -960000000000.0)
t_0
(if (<= y 2e-41) (+ x (* y z)) (if (<= y 2e+275) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double t_1 = x * cos(y);
double tmp;
if (y <= -2.95e+158) {
tmp = t_0;
} else if (y <= -2.6e+97) {
tmp = t_1;
} else if (y <= -960000000000.0) {
tmp = t_0;
} else if (y <= 2e-41) {
tmp = x + (y * z);
} else if (y <= 2e+275) {
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 = sin(y) * z
t_1 = x * cos(y)
if (y <= (-2.95d+158)) then
tmp = t_0
else if (y <= (-2.6d+97)) then
tmp = t_1
else if (y <= (-960000000000.0d0)) then
tmp = t_0
else if (y <= 2d-41) then
tmp = x + (y * z)
else if (y <= 2d+275) 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 = Math.sin(y) * z;
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -2.95e+158) {
tmp = t_0;
} else if (y <= -2.6e+97) {
tmp = t_1;
} else if (y <= -960000000000.0) {
tmp = t_0;
} else if (y <= 2e-41) {
tmp = x + (y * z);
} else if (y <= 2e+275) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * z t_1 = x * math.cos(y) tmp = 0 if y <= -2.95e+158: tmp = t_0 elif y <= -2.6e+97: tmp = t_1 elif y <= -960000000000.0: tmp = t_0 elif y <= 2e-41: tmp = x + (y * z) elif y <= 2e+275: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * z) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -2.95e+158) tmp = t_0; elseif (y <= -2.6e+97) tmp = t_1; elseif (y <= -960000000000.0) tmp = t_0; elseif (y <= 2e-41) tmp = Float64(x + Float64(y * z)); elseif (y <= 2e+275) tmp = t_1; else tmp = t_0; 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 <= -2.95e+158) tmp = t_0; elseif (y <= -2.6e+97) tmp = t_1; elseif (y <= -960000000000.0) tmp = t_0; elseif (y <= 2e-41) tmp = x + (y * z); elseif (y <= 2e+275) tmp = t_1; else tmp = t_0; 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, -2.95e+158], t$95$0, If[LessEqual[y, -2.6e+97], t$95$1, If[LessEqual[y, -960000000000.0], t$95$0, If[LessEqual[y, 2e-41], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2e+275], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -2.95 \cdot 10^{+158}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -960000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-41}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+275}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.94999999999999987e158 or -2.6e97 < y < -9.6e11 or 1.99999999999999992e275 < y Initial program 99.6%
Taylor expanded in x around 0 65.8%
if -2.94999999999999987e158 < y < -2.6e97 or 2.00000000000000001e-41 < y < 1.99999999999999992e275Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 70.7%
if -9.6e11 < y < 2.00000000000000001e-41Initial program 100.0%
Taylor expanded in y around 0 98.6%
Final simplification82.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)) (t_1 (* x (cos y))))
(if (<= y -3.6e+152)
t_0
(if (<= y -1.9e+97)
t_1
(if (<= y -960000000000.0)
t_0
(if (<= y 2e-41) (fma y z x) (if (<= y 2.2e+275) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double t_1 = x * cos(y);
double tmp;
if (y <= -3.6e+152) {
tmp = t_0;
} else if (y <= -1.9e+97) {
tmp = t_1;
} else if (y <= -960000000000.0) {
tmp = t_0;
} else if (y <= 2e-41) {
tmp = fma(y, z, x);
} else if (y <= 2.2e+275) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * z) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -3.6e+152) tmp = t_0; elseif (y <= -1.9e+97) tmp = t_1; elseif (y <= -960000000000.0) tmp = t_0; elseif (y <= 2e-41) tmp = fma(y, z, x); elseif (y <= 2.2e+275) tmp = t_1; else tmp = t_0; 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, -3.6e+152], t$95$0, If[LessEqual[y, -1.9e+97], t$95$1, If[LessEqual[y, -960000000000.0], t$95$0, If[LessEqual[y, 2e-41], N[(y * z + x), $MachinePrecision], If[LessEqual[y, 2.2e+275], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+152}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -960000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-41}:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+275}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.5999999999999999e152 or -1.90000000000000018e97 < y < -9.6e11 or 2.1999999999999999e275 < y Initial program 99.6%
Taylor expanded in x around 0 65.8%
if -3.5999999999999999e152 < y < -1.90000000000000018e97 or 2.00000000000000001e-41 < y < 2.1999999999999999e275Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 70.7%
if -9.6e11 < y < 2.00000000000000001e-41Initial program 100.0%
Taylor expanded in y around 0 98.6%
fma-def98.6%
Simplified98.6%
Final simplification82.6%
(FPCore (x y z)
:precision binary64
(if (or (<= x -8e+120)
(not (or (<= x 4.6e+73) (and (not (<= x 2.7e+148)) (<= x 6.2e+177)))))
(* x (cos y))
(+ x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e+120) || !((x <= 4.6e+73) || (!(x <= 2.7e+148) && (x <= 6.2e+177)))) {
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 <= (-8d+120)) .or. (.not. (x <= 4.6d+73) .or. (.not. (x <= 2.7d+148)) .and. (x <= 6.2d+177))) 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 <= -8e+120) || !((x <= 4.6e+73) || (!(x <= 2.7e+148) && (x <= 6.2e+177)))) {
tmp = x * Math.cos(y);
} else {
tmp = x + (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e+120) or not ((x <= 4.6e+73) or (not (x <= 2.7e+148) and (x <= 6.2e+177))): tmp = x * math.cos(y) else: tmp = x + (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e+120) || !((x <= 4.6e+73) || (!(x <= 2.7e+148) && (x <= 6.2e+177)))) 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 <= -8e+120) || ~(((x <= 4.6e+73) || (~((x <= 2.7e+148)) && (x <= 6.2e+177))))) tmp = x * cos(y); else tmp = x + (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e+120], N[Not[Or[LessEqual[x, 4.6e+73], And[N[Not[LessEqual[x, 2.7e+148]], $MachinePrecision], LessEqual[x, 6.2e+177]]]], $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 -8 \cdot 10^{+120} \lor \neg \left(x \leq 4.6 \cdot 10^{+73} \lor \neg \left(x \leq 2.7 \cdot 10^{+148}\right) \land x \leq 6.2 \cdot 10^{+177}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y \cdot z\\
\end{array}
\end{array}
if x < -7.9999999999999998e120 or 4.6e73 < x < 2.70000000000000019e148 or 6.1999999999999998e177 < x Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 96.6%
if -7.9999999999999998e120 < x < 4.6e73 or 2.70000000000000019e148 < x < 6.1999999999999998e177Initial program 99.8%
Taylor expanded in y around 0 88.7%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -960000000000.0) (not (<= y 0.0062))) (* (sin y) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -960000000000.0) || !(y <= 0.0062)) {
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 <= (-960000000000.0d0)) .or. (.not. (y <= 0.0062d0))) 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 <= -960000000000.0) || !(y <= 0.0062)) {
tmp = Math.sin(y) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -960000000000.0) or not (y <= 0.0062): tmp = math.sin(y) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -960000000000.0) || !(y <= 0.0062)) 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 <= -960000000000.0) || ~((y <= 0.0062))) tmp = sin(y) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -960000000000.0], N[Not[LessEqual[y, 0.0062]], $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 -960000000000 \lor \neg \left(y \leq 0.0062\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -9.6e11 or 0.00619999999999999978 < y Initial program 99.6%
Taylor expanded in x around 0 51.8%
if -9.6e11 < y < 0.00619999999999999978Initial program 100.0%
Taylor expanded in y around 0 98.4%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (<= z 1.25e+169) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.25e+169) {
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.25d+169) 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.25e+169) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.25e+169: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.25e+169) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.25e+169) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.25e+169], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.25 \cdot 10^{+169}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 1.25000000000000004e169Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 42.9%
if 1.25000000000000004e169 < z Initial program 99.8%
Taylor expanded in y around 0 61.7%
Taylor expanded in y around inf 45.7%
Final simplification43.1%
(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 52.7%
Final simplification52.7%
(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.9%
Final simplification40.9%
herbie shell --seed 2023240
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))