
(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 6 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 z (sin y) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, sin(y), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * N[Sin[y], $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -54.0) (not (<= y 4e-23))) (* x (cos y)) (+ x (* y (+ z (* x (* y -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -54.0) || !(y <= 4e-23)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (x * (y * -0.5))));
}
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 <= (-54.0d0)) .or. (.not. (y <= 4d-23))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (x * (y * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -54.0) || !(y <= 4e-23)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (x * (y * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -54.0) or not (y <= 4e-23): tmp = x * math.cos(y) else: tmp = x + (y * (z + (x * (y * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -54.0) || !(y <= 4e-23)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(x * Float64(y * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -54.0) || ~((y <= 4e-23))) tmp = x * cos(y); else tmp = x + (y * (z + (x * (y * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -54.0], N[Not[LessEqual[y, 4e-23]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(x * N[(y * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -54 \lor \neg \left(y \leq 4 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + x \cdot \left(y \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -54 or 3.99999999999999984e-23 < y Initial program 99.6%
Taylor expanded in x around inf 60.4%
if -54 < y < 3.99999999999999984e-23Initial program 100.0%
add-cube-cbrt99.4%
pow399.5%
Applied egg-rr99.5%
rem-cube-cbrt100.0%
*-commutative100.0%
add-sqr-sqrt52.6%
associate-*r*52.6%
Applied egg-rr52.6%
add-sqr-sqrt51.1%
associate-*r*51.1%
associate-*l*51.1%
add-sqr-sqrt98.5%
fma-def98.5%
Applied egg-rr98.5%
Taylor expanded in y around 0 98.6%
+-commutative98.6%
associate-*r*98.6%
*-commutative98.6%
unpow298.6%
associate-*r*98.6%
*-commutative98.6%
distribute-lft-out98.6%
associate-*l*98.6%
*-commutative98.6%
Simplified98.6%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -8e+137) (not (<= z 1.55e+122))) (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e+137) || !(z <= 1.55e+122)) {
tmp = z * sin(y);
} else {
tmp = x * 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 ((z <= (-8d+137)) .or. (.not. (z <= 1.55d+122))) then
tmp = z * sin(y)
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8e+137) || !(z <= 1.55e+122)) {
tmp = z * Math.sin(y);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e+137) or not (z <= 1.55e+122): tmp = z * math.sin(y) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e+137) || !(z <= 1.55e+122)) tmp = Float64(z * sin(y)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8e+137) || ~((z <= 1.55e+122))) tmp = z * sin(y); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e+137], N[Not[LessEqual[z, 1.55e+122]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+137} \lor \neg \left(z \leq 1.55 \cdot 10^{+122}\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -8.0000000000000003e137 or 1.54999999999999999e122 < z Initial program 99.8%
Taylor expanded in x around 0 70.6%
if -8.0000000000000003e137 < z < 1.54999999999999999e122Initial program 99.8%
Taylor expanded in x around inf 84.9%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (+ x (* z y)))
double code(double x, double y, double z) {
return x + (z * 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 + (z * y)
end function
public static double code(double x, double y, double z) {
return x + (z * y);
}
def code(x, y, z): return x + (z * y)
function code(x, y, z) return Float64(x + Float64(z * y)) end
function tmp = code(x, y, z) tmp = x + (z * y); end
code[x_, y_, z_] := N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 54.5%
+-commutative54.5%
Simplified54.5%
Final simplification54.5%
(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%
add-sqr-sqrt47.3%
associate-*r*47.3%
fma-def47.3%
Applied egg-rr47.3%
Taylor expanded in y around 0 43.5%
Final simplification43.5%
herbie shell --seed 2023280
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))