
(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 7 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 x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * 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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (<= z -2.1e+134)
t_0
(if (<= z -6.5e+37)
(+ x (* y z))
(if (<= z 2.9e+154) (* x (cos y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (z <= -2.1e+134) {
tmp = t_0;
} else if (z <= -6.5e+37) {
tmp = x + (y * z);
} else if (z <= 2.9e+154) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
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 = z * sin(y)
if (z <= (-2.1d+134)) then
tmp = t_0
else if (z <= (-6.5d+37)) then
tmp = x + (y * z)
else if (z <= 2.9d+154) then
tmp = x * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.sin(y);
double tmp;
if (z <= -2.1e+134) {
tmp = t_0;
} else if (z <= -6.5e+37) {
tmp = x + (y * z);
} else if (z <= 2.9e+154) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) tmp = 0 if z <= -2.1e+134: tmp = t_0 elif z <= -6.5e+37: tmp = x + (y * z) elif z <= 2.9e+154: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (z <= -2.1e+134) tmp = t_0; elseif (z <= -6.5e+37) tmp = Float64(x + Float64(y * z)); elseif (z <= 2.9e+154) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); tmp = 0.0; if (z <= -2.1e+134) tmp = t_0; elseif (z <= -6.5e+37) tmp = x + (y * z); elseif (z <= 2.9e+154) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.1e+134], t$95$0, If[LessEqual[z, -6.5e+37], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.9e+154], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+134}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{+37}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+154}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.1000000000000001e134 or 2.89999999999999979e154 < z Initial program 99.7%
Taylor expanded in x around 0 78.4%
if -2.1000000000000001e134 < z < -6.4999999999999998e37Initial program 100.0%
Taylor expanded in y around 0 84.8%
+-commutative84.8%
Simplified84.8%
if -6.4999999999999998e37 < z < 2.89999999999999979e154Initial program 99.8%
Taylor expanded in x around inf 81.5%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00021) (not (<= y 1.6e+29))) (* x (cos y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00021) || !(y <= 1.6e+29)) {
tmp = x * cos(y);
} else {
tmp = x + (y * 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 ((y <= (-0.00021d0)) .or. (.not. (y <= 1.6d+29))) then
tmp = x * cos(y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00021) || !(y <= 1.6e+29)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00021) or not (y <= 1.6e+29): tmp = x * math.cos(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00021) || !(y <= 1.6e+29)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00021) || ~((y <= 1.6e+29))) tmp = x * cos(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00021], N[Not[LessEqual[y, 1.6e+29]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00021 \lor \neg \left(y \leq 1.6 \cdot 10^{+29}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -2.1000000000000001e-4 or 1.59999999999999993e29 < y Initial program 99.6%
Taylor expanded in x around inf 51.4%
if -2.1000000000000001e-4 < y < 1.59999999999999993e29Initial program 100.0%
Taylor expanded in y around 0 97.8%
+-commutative97.8%
Simplified97.8%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e-191) x (if (<= x 1.25e-192) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-191) {
tmp = x;
} else if (x <= 1.25e-192) {
tmp = y * z;
} else {
tmp = 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 (x <= (-1.65d-191)) then
tmp = x
else if (x <= 1.25d-192) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-191) {
tmp = x;
} else if (x <= 1.25e-192) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e-191: tmp = x elif x <= 1.25e-192: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e-191) tmp = x; elseif (x <= 1.25e-192) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.65e-191) tmp = x; elseif (x <= 1.25e-192) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e-191], x, If[LessEqual[x, 1.25e-192], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-191}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-192}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.64999999999999991e-191 or 1.25e-192 < x Initial program 99.8%
Taylor expanded in x around inf 70.2%
Taylor expanded in y around 0 45.0%
if -1.64999999999999991e-191 < x < 1.25e-192Initial program 99.8%
Taylor expanded in x around 0 83.2%
Taylor expanded in y around 0 43.0%
Final simplification44.6%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (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 + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 53.4%
+-commutative53.4%
Simplified53.4%
Final simplification53.4%
(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%
Taylor expanded in x around inf 61.7%
Taylor expanded in y around 0 40.3%
Final simplification40.3%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))