
(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 6 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 (+ (* 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.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.76e-172) (not (<= x 4.7e-76))) (+ (* x (sin y)) z) (+ (* z (cos y)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.76e-172) || !(x <= 4.7e-76)) {
tmp = (x * sin(y)) + z;
} else {
tmp = (z * cos(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 ((x <= (-1.76d-172)) .or. (.not. (x <= 4.7d-76))) then
tmp = (x * sin(y)) + z
else
tmp = (z * cos(y)) + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.76e-172) || !(x <= 4.7e-76)) {
tmp = (x * Math.sin(y)) + z;
} else {
tmp = (z * Math.cos(y)) + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.76e-172) or not (x <= 4.7e-76): tmp = (x * math.sin(y)) + z else: tmp = (z * math.cos(y)) + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.76e-172) || !(x <= 4.7e-76)) tmp = Float64(Float64(x * sin(y)) + z); else tmp = Float64(Float64(z * cos(y)) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.76e-172) || ~((x <= 4.7e-76))) tmp = (x * sin(y)) + z; else tmp = (z * cos(y)) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.76e-172], N[Not[LessEqual[x, 4.7e-76]], $MachinePrecision]], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision], N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.76 \cdot 10^{-172} \lor \neg \left(x \leq 4.7 \cdot 10^{-76}\right):\\
\;\;\;\;x \cdot \sin y + z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y + x \cdot y\\
\end{array}
\end{array}
if x < -1.76e-172 or 4.7000000000000002e-76 < x Initial program 99.7%
Taylor expanded in y around 0 85.2%
if -1.76e-172 < x < 4.7000000000000002e-76Initial program 99.7%
Taylor expanded in y around 0 81.1%
Final simplification84.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.216) (not (<= y 5e-13))) (* x (sin y)) (+ (* x y) (* z (+ 1.0 (* -0.5 (* y y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.216) || !(y <= 5e-13)) {
tmp = x * sin(y);
} else {
tmp = (x * y) + (z * (1.0 + (-0.5 * (y * 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.216d0)) .or. (.not. (y <= 5d-13))) then
tmp = x * sin(y)
else
tmp = (x * y) + (z * (1.0d0 + ((-0.5d0) * (y * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.216) || !(y <= 5e-13)) {
tmp = x * Math.sin(y);
} else {
tmp = (x * y) + (z * (1.0 + (-0.5 * (y * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.216) or not (y <= 5e-13): tmp = x * math.sin(y) else: tmp = (x * y) + (z * (1.0 + (-0.5 * (y * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.216) || !(y <= 5e-13)) tmp = Float64(x * sin(y)); else tmp = Float64(Float64(x * y) + Float64(z * Float64(1.0 + Float64(-0.5 * Float64(y * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.216) || ~((y <= 5e-13))) tmp = x * sin(y); else tmp = (x * y) + (z * (1.0 + (-0.5 * (y * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.216], N[Not[LessEqual[y, 5e-13]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.216 \lor \neg \left(y \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + z \cdot \left(1 + -0.5 \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -0.215999999999999998 or 4.9999999999999999e-13 < y Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
add-sqr-sqrt57.9%
associate-*r*57.8%
fma-def57.8%
Applied egg-rr57.8%
Taylor expanded in z around 0 56.7%
if -0.215999999999999998 < y < 4.9999999999999999e-13Initial program 100.0%
add-log-exp100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 99.9%
Taylor expanded in y around 0 99.4%
unpow299.4%
Simplified99.4%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) z))
double code(double x, double y, double z) {
return (x * 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 * sin(y)) + z
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + z;
}
def code(x, y, z): return (x * math.sin(y)) + z
function code(x, y, z) return Float64(Float64(x * sin(y)) + z) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + z; end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 76.5%
Final simplification76.5%
(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.7%
Taylor expanded in y around 0 46.2%
Final simplification46.2%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return 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 = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.7%
add-log-exp99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 58.1%
Taylor expanded in y around inf 15.3%
Final simplification15.3%
herbie shell --seed 2023207
(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))))