
(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 7 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.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(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.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -1.65e+255)
t_0
(if (<= y -1.9e+105)
(* z (cos y))
(if (or (<= y -2.6e-8) (not (<= y 0.0039))) t_0 (+ z (* y x)))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -1.65e+255) {
tmp = t_0;
} else if (y <= -1.9e+105) {
tmp = z * cos(y);
} else if ((y <= -2.6e-8) || !(y <= 0.0039)) {
tmp = t_0;
} else {
tmp = z + (y * x);
}
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) :: tmp
t_0 = x * sin(y)
if (y <= (-1.65d+255)) then
tmp = t_0
else if (y <= (-1.9d+105)) then
tmp = z * cos(y)
else if ((y <= (-2.6d-8)) .or. (.not. (y <= 0.0039d0))) then
tmp = t_0
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.sin(y);
double tmp;
if (y <= -1.65e+255) {
tmp = t_0;
} else if (y <= -1.9e+105) {
tmp = z * Math.cos(y);
} else if ((y <= -2.6e-8) || !(y <= 0.0039)) {
tmp = t_0;
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if y <= -1.65e+255: tmp = t_0 elif y <= -1.9e+105: tmp = z * math.cos(y) elif (y <= -2.6e-8) or not (y <= 0.0039): tmp = t_0 else: tmp = z + (y * x) return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -1.65e+255) tmp = t_0; elseif (y <= -1.9e+105) tmp = Float64(z * cos(y)); elseif ((y <= -2.6e-8) || !(y <= 0.0039)) tmp = t_0; else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (y <= -1.65e+255) tmp = t_0; elseif (y <= -1.9e+105) tmp = z * cos(y); elseif ((y <= -2.6e-8) || ~((y <= 0.0039))) tmp = t_0; else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.65e+255], t$95$0, If[LessEqual[y, -1.9e+105], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -2.6e-8], N[Not[LessEqual[y, 0.0039]], $MachinePrecision]], t$95$0, N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{+255}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{+105}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-8} \lor \neg \left(y \leq 0.0039\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1.64999999999999991e255 or -1.9e105 < y < -2.6000000000000001e-8 or 0.0038999999999999998 < y Initial program 99.7%
Taylor expanded in x around inf 61.3%
if -1.64999999999999991e255 < y < -1.9e105Initial program 99.7%
Taylor expanded in x around 0 65.7%
if -2.6000000000000001e-8 < y < 0.0038999999999999998Initial program 100.0%
Taylor expanded in y around 0 99.6%
+-commutative99.6%
Simplified99.6%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e-8) (not (<= y 0.0092))) (* x (sin y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e-8) || !(y <= 0.0092)) {
tmp = x * sin(y);
} else {
tmp = z + (y * x);
}
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 <= (-2.6d-8)) .or. (.not. (y <= 0.0092d0))) then
tmp = x * sin(y)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e-8) || !(y <= 0.0092)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e-8) or not (y <= 0.0092): tmp = x * math.sin(y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e-8) || !(y <= 0.0092)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.6e-8) || ~((y <= 0.0092))) tmp = x * sin(y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e-8], N[Not[LessEqual[y, 0.0092]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-8} \lor \neg \left(y \leq 0.0092\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -2.6000000000000001e-8 or 0.0091999999999999998 < y Initial program 99.7%
Taylor expanded in x around inf 55.2%
if -2.6000000000000001e-8 < y < 0.0091999999999999998Initial program 100.0%
Taylor expanded in y around 0 99.6%
+-commutative99.6%
Simplified99.6%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (<= x -2.8e+190) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e+190) {
tmp = y * x;
} else {
tmp = 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 <= (-2.8d+190)) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e+190) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.8e+190: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.8e+190) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.8e+190) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.8e+190], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+190}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.79999999999999997e190Initial program 99.9%
Taylor expanded in x around inf 95.1%
Taylor expanded in y around 0 48.5%
if -2.79999999999999997e190 < x Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
add-sqr-sqrt44.3%
associate-*r*44.3%
fma-def44.3%
Applied egg-rr44.3%
Taylor expanded in y around 0 45.6%
Final simplification45.8%
(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.9%
Taylor expanded in y around 0 53.3%
+-commutative53.3%
Simplified53.3%
Final simplification53.3%
(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.9%
+-commutative99.9%
*-commutative99.9%
add-sqr-sqrt44.6%
associate-*r*44.6%
fma-def44.6%
Applied egg-rr44.6%
Taylor expanded in y around 0 41.7%
Final simplification41.7%
herbie shell --seed 2023279
(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))))