
(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 (+ (* 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))))
(if (<= y -3600000000.0)
t_0
(if (<= y 31000.0)
(+ z (* x y))
(if (or (<= y 2.75e+146) (and (not (<= y 1.08e+186)) (<= y 1.35e+230)))
t_0
(* z (cos y)))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -3600000000.0) {
tmp = t_0;
} else if (y <= 31000.0) {
tmp = z + (x * y);
} else if ((y <= 2.75e+146) || (!(y <= 1.08e+186) && (y <= 1.35e+230))) {
tmp = t_0;
} else {
tmp = z * 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) :: t_0
real(8) :: tmp
t_0 = x * sin(y)
if (y <= (-3600000000.0d0)) then
tmp = t_0
else if (y <= 31000.0d0) then
tmp = z + (x * y)
else if ((y <= 2.75d+146) .or. (.not. (y <= 1.08d+186)) .and. (y <= 1.35d+230)) then
tmp = t_0
else
tmp = z * cos(y)
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 <= -3600000000.0) {
tmp = t_0;
} else if (y <= 31000.0) {
tmp = z + (x * y);
} else if ((y <= 2.75e+146) || (!(y <= 1.08e+186) && (y <= 1.35e+230))) {
tmp = t_0;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if y <= -3600000000.0: tmp = t_0 elif y <= 31000.0: tmp = z + (x * y) elif (y <= 2.75e+146) or (not (y <= 1.08e+186) and (y <= 1.35e+230)): tmp = t_0 else: tmp = z * math.cos(y) return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -3600000000.0) tmp = t_0; elseif (y <= 31000.0) tmp = Float64(z + Float64(x * y)); elseif ((y <= 2.75e+146) || (!(y <= 1.08e+186) && (y <= 1.35e+230))) tmp = t_0; else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (y <= -3600000000.0) tmp = t_0; elseif (y <= 31000.0) tmp = z + (x * y); elseif ((y <= 2.75e+146) || (~((y <= 1.08e+186)) && (y <= 1.35e+230))) tmp = t_0; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3600000000.0], t$95$0, If[LessEqual[y, 31000.0], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.75e+146], And[N[Not[LessEqual[y, 1.08e+186]], $MachinePrecision], LessEqual[y, 1.35e+230]]], t$95$0, N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -3600000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 31000:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+146} \lor \neg \left(y \leq 1.08 \cdot 10^{+186}\right) \land y \leq 1.35 \cdot 10^{+230}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if y < -3.6e9 or 31000 < y < 2.7500000000000002e146 or 1.08000000000000003e186 < y < 1.35000000000000002e230Initial program 99.6%
Taylor expanded in x around inf 62.7%
if -3.6e9 < y < 31000Initial program 100.0%
Taylor expanded in y around 0 98.5%
+-commutative98.5%
Simplified98.5%
if 2.7500000000000002e146 < y < 1.08000000000000003e186 or 1.35000000000000002e230 < y Initial program 99.5%
Taylor expanded in x around 0 69.6%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.3e+191) (not (<= z 0.455))) (* z (cos y)) (+ (* x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.3e+191) || !(z <= 0.455)) {
tmp = z * cos(y);
} else {
tmp = (x * sin(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 ((z <= (-1.3d+191)) .or. (.not. (z <= 0.455d0))) then
tmp = z * cos(y)
else
tmp = (x * sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.3e+191) || !(z <= 0.455)) {
tmp = z * Math.cos(y);
} else {
tmp = (x * Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.3e+191) or not (z <= 0.455): tmp = z * math.cos(y) else: tmp = (x * math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.3e+191) || !(z <= 0.455)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(x * sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.3e+191) || ~((z <= 0.455))) tmp = z * cos(y); else tmp = (x * sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.3e+191], N[Not[LessEqual[z, 0.455]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{+191} \lor \neg \left(z \leq 0.455\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\
\end{array}
\end{array}
if z < -1.3e191 or 0.455000000000000016 < z Initial program 99.8%
Taylor expanded in x around 0 90.2%
if -1.3e191 < z < 0.455000000000000016Initial program 99.8%
Taylor expanded in y around 0 88.9%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -3600000000.0) (not (<= y 31000.0))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3600000000.0) || !(y <= 31000.0)) {
tmp = x * sin(y);
} else {
tmp = z + (x * 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 ((y <= (-3600000000.0d0)) .or. (.not. (y <= 31000.0d0))) then
tmp = x * sin(y)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3600000000.0) || !(y <= 31000.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3600000000.0) or not (y <= 31000.0): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3600000000.0) || !(y <= 31000.0)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3600000000.0) || ~((y <= 31000.0))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3600000000.0], N[Not[LessEqual[y, 31000.0]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3600000000 \lor \neg \left(y \leq 31000\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -3.6e9 or 31000 < y Initial program 99.6%
Taylor expanded in x around inf 56.0%
if -3.6e9 < y < 31000Initial program 100.0%
Taylor expanded in y around 0 98.5%
+-commutative98.5%
Simplified98.5%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (<= x 1.5e+142) z (* x y)))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.5e+142) {
tmp = z;
} else {
tmp = x * 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.5d+142) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 1.5e+142) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.5e+142: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.5e+142) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 1.5e+142) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.5e+142], z, N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{+142}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 1.49999999999999987e142Initial program 99.8%
add-cube-cbrt99.1%
pow399.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 76.2%
Taylor expanded in x around 0 45.6%
if 1.49999999999999987e142 < x Initial program 99.9%
Taylor expanded in x around inf 82.0%
Taylor expanded in y around 0 37.6%
Final simplification44.3%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * 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 + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 52.4%
+-commutative52.4%
Simplified52.4%
Final simplification52.4%
(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.8%
add-cube-cbrt99.0%
pow399.0%
Applied egg-rr99.0%
Taylor expanded in y around 0 78.8%
Taylor expanded in x around 0 40.5%
Final simplification40.5%
herbie shell --seed 2024039
(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))))