
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* z (cos y))))
(if (<= y -6.1e+147)
t_0
(if (<= y -1.15e+103)
t_1
(if (<= y -4000000.0)
t_0
(if (<= y 0.035)
(+ (* -0.5 (* y (* y z))) (+ z (* x y)))
(if (<= y 1.95e+144) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = z * cos(y);
double tmp;
if (y <= -6.1e+147) {
tmp = t_0;
} else if (y <= -1.15e+103) {
tmp = t_1;
} else if (y <= -4000000.0) {
tmp = t_0;
} else if (y <= 0.035) {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
} else if (y <= 1.95e+144) {
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 = x * sin(y)
t_1 = z * cos(y)
if (y <= (-6.1d+147)) then
tmp = t_0
else if (y <= (-1.15d+103)) then
tmp = t_1
else if (y <= (-4000000.0d0)) then
tmp = t_0
else if (y <= 0.035d0) then
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
else if (y <= 1.95d+144) 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 = x * Math.sin(y);
double t_1 = z * Math.cos(y);
double tmp;
if (y <= -6.1e+147) {
tmp = t_0;
} else if (y <= -1.15e+103) {
tmp = t_1;
} else if (y <= -4000000.0) {
tmp = t_0;
} else if (y <= 0.035) {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
} else if (y <= 1.95e+144) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = z * math.cos(y) tmp = 0 if y <= -6.1e+147: tmp = t_0 elif y <= -1.15e+103: tmp = t_1 elif y <= -4000000.0: tmp = t_0 elif y <= 0.035: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) elif y <= 1.95e+144: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(z * cos(y)) tmp = 0.0 if (y <= -6.1e+147) tmp = t_0; elseif (y <= -1.15e+103) tmp = t_1; elseif (y <= -4000000.0) tmp = t_0; elseif (y <= 0.035) tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); elseif (y <= 1.95e+144) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); t_1 = z * cos(y); tmp = 0.0; if (y <= -6.1e+147) tmp = t_0; elseif (y <= -1.15e+103) tmp = t_1; elseif (y <= -4000000.0) tmp = t_0; elseif (y <= 0.035) tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); elseif (y <= 1.95e+144) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.1e+147], t$95$0, If[LessEqual[y, -1.15e+103], t$95$1, If[LessEqual[y, -4000000.0], t$95$0, If[LessEqual[y, 0.035], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.95e+144], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := z \cdot \cos y\\
\mathbf{if}\;y \leq -6.1 \cdot 10^{+147}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{+103}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -4000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.035:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+144}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -6.10000000000000033e147 or -1.15000000000000004e103 < y < -4e6 or 0.035000000000000003 < y < 1.95000000000000009e144Initial program 99.7%
add-sqr-sqrt50.1%
associate-*r*50.2%
fma-def50.2%
Applied egg-rr50.2%
add-cube-cbrt49.4%
pow349.5%
fma-udef49.5%
associate-*r*49.5%
add-sqr-sqrt97.9%
*-commutative97.9%
Applied egg-rr97.9%
Taylor expanded in z around 0 66.1%
pow-base-166.1%
*-lft-identity66.1%
Simplified66.1%
if -6.10000000000000033e147 < y < -1.15000000000000004e103 or 1.95000000000000009e144 < y Initial program 99.5%
add-sqr-sqrt41.2%
associate-*r*41.2%
fma-def41.2%
Applied egg-rr41.2%
Taylor expanded in x around 0 70.5%
if -4e6 < y < 0.035000000000000003Initial program 100.0%
Taylor expanded in y around 0 97.8%
expm1-log1p-u94.5%
expm1-udef93.9%
unpow293.9%
associate-*l*93.9%
Applied egg-rr93.9%
expm1-def94.5%
expm1-log1p97.8%
Simplified97.8%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.4e-159) (not (<= x 1.25e-122))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-159) || !(x <= 1.25e-122)) {
tmp = z + (x * sin(y));
} else {
tmp = z * 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) :: tmp
if ((x <= (-3.4d-159)) .or. (.not. (x <= 1.25d-122))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-159) || !(x <= 1.25e-122)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e-159) or not (x <= 1.25e-122): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e-159) || !(x <= 1.25e-122)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.4e-159) || ~((x <= 1.25e-122))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e-159], N[Not[LessEqual[x, 1.25e-122]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-159} \lor \neg \left(x \leq 1.25 \cdot 10^{-122}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -3.39999999999999984e-159 or 1.25e-122 < x Initial program 99.8%
Taylor expanded in y around 0 86.0%
if -3.39999999999999984e-159 < x < 1.25e-122Initial program 99.7%
add-sqr-sqrt54.7%
associate-*r*54.8%
fma-def54.8%
Applied egg-rr54.8%
Taylor expanded in x around 0 95.2%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0275) (not (<= y 0.85))) (* z (cos y)) (+ (* -0.5 (* y (* y z))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0275) || !(y <= 0.85)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (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 <= (-0.0275d0)) .or. (.not. (y <= 0.85d0))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0275) || !(y <= 0.85)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0275) or not (y <= 0.85): tmp = z * math.cos(y) else: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0275) || !(y <= 0.85)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0275) || ~((y <= 0.85))) tmp = z * cos(y); else tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0275], N[Not[LessEqual[y, 0.85]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0275 \lor \neg \left(y \leq 0.85\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -0.0275000000000000001 or 0.849999999999999978 < y Initial program 99.7%
add-sqr-sqrt46.7%
associate-*r*46.7%
fma-def46.7%
Applied egg-rr46.7%
Taylor expanded in x around 0 47.3%
if -0.0275000000000000001 < y < 0.849999999999999978Initial program 100.0%
Taylor expanded in y around 0 99.3%
expm1-log1p-u95.8%
expm1-udef95.3%
unpow295.3%
associate-*l*95.3%
Applied egg-rr95.3%
expm1-def95.8%
expm1-log1p99.3%
Simplified99.3%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (<= x -3.2e+201) (* x y) (if (<= x 2.45e+79) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e+201) {
tmp = x * y;
} else if (x <= 2.45e+79) {
tmp = z;
} else {
tmp = 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 (x <= (-3.2d+201)) then
tmp = x * y
else if (x <= 2.45d+79) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e+201) {
tmp = x * y;
} else if (x <= 2.45e+79) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.2e+201: tmp = x * y elif x <= 2.45e+79: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.2e+201) tmp = Float64(x * y); elseif (x <= 2.45e+79) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.2e+201) tmp = x * y; elseif (x <= 2.45e+79) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.2e+201], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.45e+79], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+201}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.45 \cdot 10^{+79}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.1999999999999999e201 or 2.4499999999999999e79 < x Initial program 99.9%
Taylor expanded in y around 0 56.0%
Taylor expanded in z around 0 42.0%
if -3.1999999999999999e201 < x < 2.4499999999999999e79Initial program 99.8%
add-sqr-sqrt50.6%
associate-*r*50.6%
fma-def50.6%
Applied egg-rr50.6%
Taylor expanded in x around 0 69.6%
Taylor expanded in y around 0 42.3%
Final simplification42.2%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * 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 + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 49.7%
Final simplification49.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
add-sqr-sqrt49.4%
associate-*r*49.4%
fma-def49.4%
Applied egg-rr49.4%
Taylor expanded in x around 0 56.2%
Taylor expanded in y around 0 35.1%
Final simplification35.1%
herbie shell --seed 2023258
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))