
(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 (+ (* 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
(let* ((t_0 (* z (sin y))))
(if (<= y -0.0055)
t_0
(if (<= y 0.0105)
(+ x (* y z))
(if (or (<= y 6e+96) (not (<= y 1.05e+253))) (* x (cos y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (y <= -0.0055) {
tmp = t_0;
} else if (y <= 0.0105) {
tmp = x + (y * z);
} else if ((y <= 6e+96) || !(y <= 1.05e+253)) {
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 (y <= (-0.0055d0)) then
tmp = t_0
else if (y <= 0.0105d0) then
tmp = x + (y * z)
else if ((y <= 6d+96) .or. (.not. (y <= 1.05d+253))) 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 (y <= -0.0055) {
tmp = t_0;
} else if (y <= 0.0105) {
tmp = x + (y * z);
} else if ((y <= 6e+96) || !(y <= 1.05e+253)) {
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 y <= -0.0055: tmp = t_0 elif y <= 0.0105: tmp = x + (y * z) elif (y <= 6e+96) or not (y <= 1.05e+253): 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 (y <= -0.0055) tmp = t_0; elseif (y <= 0.0105) tmp = Float64(x + Float64(y * z)); elseif ((y <= 6e+96) || !(y <= 1.05e+253)) 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 (y <= -0.0055) tmp = t_0; elseif (y <= 0.0105) tmp = x + (y * z); elseif ((y <= 6e+96) || ~((y <= 1.05e+253))) 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[y, -0.0055], t$95$0, If[LessEqual[y, 0.0105], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 6e+96], N[Not[LessEqual[y, 1.05e+253]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;y \leq -0.0055:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+96} \lor \neg \left(y \leq 1.05 \cdot 10^{+253}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0054999999999999997 or 6.0000000000000001e96 < y < 1.0500000000000001e253Initial program 99.6%
Taylor expanded in x around 0 58.9%
if -0.0054999999999999997 < y < 0.0105000000000000007Initial program 100.0%
Taylor expanded in y around 0 98.5%
+-commutative98.5%
Simplified98.5%
if 0.0105000000000000007 < y < 6.0000000000000001e96 or 1.0500000000000001e253 < y Initial program 99.6%
Taylor expanded in x around inf 75.1%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.22e-27) (not (<= x 2.2e+203))) (* x (cos y)) (+ x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.22e-27) || !(x <= 2.2e+203)) {
tmp = x * cos(y);
} else {
tmp = x + (z * 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 ((x <= (-1.22d-27)) .or. (.not. (x <= 2.2d+203))) then
tmp = x * cos(y)
else
tmp = x + (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.22e-27) || !(x <= 2.2e+203)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.22e-27) or not (x <= 2.2e+203): tmp = x * math.cos(y) else: tmp = x + (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.22e-27) || !(x <= 2.2e+203)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.22e-27) || ~((x <= 2.2e+203))) tmp = x * cos(y); else tmp = x + (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.22e-27], N[Not[LessEqual[x, 2.2e+203]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{-27} \lor \neg \left(x \leq 2.2 \cdot 10^{+203}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \sin y\\
\end{array}
\end{array}
if x < -1.22e-27 or 2.20000000000000004e203 < x Initial program 99.8%
Taylor expanded in x around inf 91.0%
if -1.22e-27 < x < 2.20000000000000004e203Initial program 99.8%
Taylor expanded in y around 0 88.8%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e-8) (not (<= y 0.0049))) (* x (cos y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e-8) || !(y <= 0.0049)) {
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 <= (-7.2d-8)) .or. (.not. (y <= 0.0049d0))) 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 <= -7.2e-8) || !(y <= 0.0049)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.2e-8) or not (y <= 0.0049): tmp = x * math.cos(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e-8) || !(y <= 0.0049)) 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 <= -7.2e-8) || ~((y <= 0.0049))) tmp = x * cos(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e-8], N[Not[LessEqual[y, 0.0049]], $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 -7.2 \cdot 10^{-8} \lor \neg \left(y \leq 0.0049\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -7.19999999999999962e-8 or 0.0048999999999999998 < y Initial program 99.6%
Taylor expanded in x around inf 53.1%
if -7.19999999999999962e-8 < y < 0.0048999999999999998Initial program 100.0%
Taylor expanded in y around 0 99.3%
+-commutative99.3%
Simplified99.3%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.6e-9) (not (<= z 2.3e+209))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.6e-9) || !(z <= 2.3e+209)) {
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 ((z <= (-6.6d-9)) .or. (.not. (z <= 2.3d+209))) 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 ((z <= -6.6e-9) || !(z <= 2.3e+209)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.6e-9) or not (z <= 2.3e+209): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.6e-9) || !(z <= 2.3e+209)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.6e-9) || ~((z <= 2.3e+209))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.6e-9], N[Not[LessEqual[z, 2.3e+209]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{-9} \lor \neg \left(z \leq 2.3 \cdot 10^{+209}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.60000000000000037e-9 or 2.3000000000000001e209 < z Initial program 99.8%
add-sqr-sqrt79.9%
associate-*r*79.9%
fma-def79.9%
Applied egg-rr79.9%
Taylor expanded in y around 0 57.6%
Taylor expanded in x around 0 36.8%
if -6.60000000000000037e-9 < z < 2.3000000000000001e209Initial program 99.8%
add-cube-cbrt98.2%
associate-*l*98.2%
fma-def98.2%
pow298.2%
Applied egg-rr98.2%
Taylor expanded in y around 0 49.4%
pow-base-149.4%
*-lft-identity49.4%
Simplified49.4%
Final simplification45.0%
(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 54.8%
+-commutative54.8%
Simplified54.8%
Final simplification54.8%
(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%
add-cube-cbrt98.6%
associate-*l*98.6%
fma-def98.6%
pow298.6%
Applied egg-rr98.6%
Taylor expanded in y around 0 39.4%
pow-base-139.4%
*-lft-identity39.4%
Simplified39.4%
Final simplification39.4%
herbie shell --seed 2024031
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))