
(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 (fma z (cos y) (* x (sin y))))
double code(double x, double y, double z) {
return fma(z, cos(y), (x * sin(y)));
}
function code(x, y, z) return fma(z, cos(y), Float64(x * sin(y))) end
code[x_, y_, z_] := N[(z * N[Cos[y], $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \cos y, x \cdot \sin 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 (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 -1.95e+114)
t_0
(if (<= y -0.062)
t_1
(if (<= y 3600000000000.0)
(+ z (* y (+ x (* (* z y) -0.5))))
(if (<= y 6.6e+75) 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 <= -1.95e+114) {
tmp = t_0;
} else if (y <= -0.062) {
tmp = t_1;
} else if (y <= 3600000000000.0) {
tmp = z + (y * (x + ((z * y) * -0.5)));
} else if (y <= 6.6e+75) {
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 <= (-1.95d+114)) then
tmp = t_0
else if (y <= (-0.062d0)) then
tmp = t_1
else if (y <= 3600000000000.0d0) then
tmp = z + (y * (x + ((z * y) * (-0.5d0))))
else if (y <= 6.6d+75) 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 <= -1.95e+114) {
tmp = t_0;
} else if (y <= -0.062) {
tmp = t_1;
} else if (y <= 3600000000000.0) {
tmp = z + (y * (x + ((z * y) * -0.5)));
} else if (y <= 6.6e+75) {
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 <= -1.95e+114: tmp = t_0 elif y <= -0.062: tmp = t_1 elif y <= 3600000000000.0: tmp = z + (y * (x + ((z * y) * -0.5))) elif y <= 6.6e+75: 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 <= -1.95e+114) tmp = t_0; elseif (y <= -0.062) tmp = t_1; elseif (y <= 3600000000000.0) tmp = Float64(z + Float64(y * Float64(x + Float64(Float64(z * y) * -0.5)))); elseif (y <= 6.6e+75) 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 <= -1.95e+114) tmp = t_0; elseif (y <= -0.062) tmp = t_1; elseif (y <= 3600000000000.0) tmp = z + (y * (x + ((z * y) * -0.5))); elseif (y <= 6.6e+75) 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, -1.95e+114], t$95$0, If[LessEqual[y, -0.062], t$95$1, If[LessEqual[y, 3600000000000.0], N[(z + N[(y * N[(x + N[(N[(z * y), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.6e+75], 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 -1.95 \cdot 10^{+114}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.062:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 3600000000000:\\
\;\;\;\;z + y \cdot \left(x + \left(z \cdot y\right) \cdot -0.5\right)\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+75}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.95e114 or 3.6e12 < y < 6.59999999999999996e75Initial program 99.7%
Taylor expanded in x around inf 66.9%
if -1.95e114 < y < -0.062 or 6.59999999999999996e75 < y Initial program 99.5%
Taylor expanded in x around 0 57.6%
if -0.062 < y < 3.6e12Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
add-sqr-sqrt60.9%
associate-*r*60.9%
fma-def60.9%
Applied egg-rr60.9%
Taylor expanded in y around 0 98.1%
unpow298.1%
associate-*r*98.1%
*-commutative98.1%
associate-*l*98.1%
*-commutative98.1%
distribute-lft-out98.1%
Simplified98.1%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -900000000.0) (not (<= z 2.1e+136))) (* z (cos y)) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -900000000.0) || !(z <= 2.1e+136)) {
tmp = z * cos(y);
} else {
tmp = z + (x * sin(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 <= (-900000000.0d0)) .or. (.not. (z <= 2.1d+136))) then
tmp = z * cos(y)
else
tmp = z + (x * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -900000000.0) || !(z <= 2.1e+136)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -900000000.0) or not (z <= 2.1e+136): tmp = z * math.cos(y) else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -900000000.0) || !(z <= 2.1e+136)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -900000000.0) || ~((z <= 2.1e+136))) tmp = z * cos(y); else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -900000000.0], N[Not[LessEqual[z, 2.1e+136]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -900000000 \lor \neg \left(z \leq 2.1 \cdot 10^{+136}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -9e8 or 2.0999999999999999e136 < z Initial program 99.8%
Taylor expanded in x around 0 87.0%
if -9e8 < z < 2.0999999999999999e136Initial program 99.8%
Taylor expanded in y around 0 88.4%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3100000000000.0) (not (<= y 3600000000000.0))) (* x (sin y)) (+ z (* y (+ x (* (* z y) -0.5))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3100000000000.0) || !(y <= 3600000000000.0)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + ((z * 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 <= (-3100000000000.0d0)) .or. (.not. (y <= 3600000000000.0d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + ((z * y) * (-0.5d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3100000000000.0) || !(y <= 3600000000000.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + ((z * y) * -0.5)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3100000000000.0) or not (y <= 3600000000000.0): tmp = x * math.sin(y) else: tmp = z + (y * (x + ((z * y) * -0.5))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3100000000000.0) || !(y <= 3600000000000.0)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(Float64(z * y) * -0.5)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3100000000000.0) || ~((y <= 3600000000000.0))) tmp = x * sin(y); else tmp = z + (y * (x + ((z * y) * -0.5))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3100000000000.0], N[Not[LessEqual[y, 3600000000000.0]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(N[(z * y), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3100000000000 \lor \neg \left(y \leq 3600000000000\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + \left(z \cdot y\right) \cdot -0.5\right)\\
\end{array}
\end{array}
if y < -3.1e12 or 3.6e12 < y Initial program 99.6%
Taylor expanded in x around inf 54.9%
if -3.1e12 < y < 3.6e12Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
add-sqr-sqrt59.5%
associate-*r*59.5%
fma-def59.5%
Applied egg-rr59.5%
Taylor expanded in y around 0 96.1%
unpow296.1%
associate-*r*96.1%
*-commutative96.1%
associate-*l*96.1%
*-commutative96.1%
distribute-lft-out96.1%
Simplified96.1%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 51.4%
*-commutative51.4%
Simplified51.4%
Final simplification51.4%
herbie shell --seed 2023297
(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))))