
(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 8 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 (if (or (<= z -4.4e+96) (not (<= z 2.7e+141))) (* z (cos y)) (fma (sin y) x z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4e+96) || !(z <= 2.7e+141)) {
tmp = z * cos(y);
} else {
tmp = fma(sin(y), x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -4.4e+96) || !(z <= 2.7e+141)) tmp = Float64(z * cos(y)); else tmp = fma(sin(y), x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.4e+96], N[Not[LessEqual[z, 2.7e+141]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{+96} \lor \neg \left(z \leq 2.7 \cdot 10^{+141}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z\right)\\
\end{array}
\end{array}
if z < -4.3999999999999998e96 or 2.7000000000000001e141 < z Initial program 99.8%
Taylor expanded in y around 0 75.0%
*-commutative75.0%
Simplified75.0%
Taylor expanded in x around 0 90.1%
if -4.3999999999999998e96 < z < 2.7000000000000001e141Initial program 99.8%
Taylor expanded in y around 0 90.3%
*-commutative90.3%
fma-def90.3%
Applied egg-rr90.3%
Final simplification90.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.0019)
t_0
(if (<= y 7.9e-16)
(+ z (* x y))
(if (or (<= y 3.15e+131) (and (not (<= y 3e+156)) (<= y 4.8e+248)))
(* z (cos y))
t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.0019) {
tmp = t_0;
} else if (y <= 7.9e-16) {
tmp = z + (x * y);
} else if ((y <= 3.15e+131) || (!(y <= 3e+156) && (y <= 4.8e+248))) {
tmp = z * 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 = x * sin(y)
if (y <= (-0.0019d0)) then
tmp = t_0
else if (y <= 7.9d-16) then
tmp = z + (x * y)
else if ((y <= 3.15d+131) .or. (.not. (y <= 3d+156)) .and. (y <= 4.8d+248)) then
tmp = z * 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 = x * Math.sin(y);
double tmp;
if (y <= -0.0019) {
tmp = t_0;
} else if (y <= 7.9e-16) {
tmp = z + (x * y);
} else if ((y <= 3.15e+131) || (!(y <= 3e+156) && (y <= 4.8e+248))) {
tmp = z * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if y <= -0.0019: tmp = t_0 elif y <= 7.9e-16: tmp = z + (x * y) elif (y <= 3.15e+131) or (not (y <= 3e+156) and (y <= 4.8e+248)): tmp = z * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.0019) tmp = t_0; elseif (y <= 7.9e-16) tmp = Float64(z + Float64(x * y)); elseif ((y <= 3.15e+131) || (!(y <= 3e+156) && (y <= 4.8e+248))) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (y <= -0.0019) tmp = t_0; elseif (y <= 7.9e-16) tmp = z + (x * y); elseif ((y <= 3.15e+131) || (~((y <= 3e+156)) && (y <= 4.8e+248))) tmp = z * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0019], t$95$0, If[LessEqual[y, 7.9e-16], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.15e+131], And[N[Not[LessEqual[y, 3e+156]], $MachinePrecision], LessEqual[y, 4.8e+248]]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.0019:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 7.9 \cdot 10^{-16}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;y \leq 3.15 \cdot 10^{+131} \lor \neg \left(y \leq 3 \cdot 10^{+156}\right) \land y \leq 4.8 \cdot 10^{+248}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -0.0019 or 3.14999999999999998e131 < y < 3e156 or 4.8e248 < y Initial program 99.5%
add-cube-cbrt98.4%
pow398.4%
Applied egg-rr98.4%
Taylor expanded in y around 0 66.6%
Taylor expanded in z around 0 64.6%
pow-base-164.6%
*-lft-identity64.6%
Simplified64.6%
if -0.0019 < y < 7.9000000000000002e-16Initial program 100.0%
Taylor expanded in y around 0 99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in y around 0 99.1%
if 7.9000000000000002e-16 < y < 3.14999999999999998e131 or 3e156 < y < 4.8e248Initial program 99.7%
Taylor expanded in y around 0 46.3%
*-commutative46.3%
Simplified46.3%
Taylor expanded in x around 0 64.4%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.8e+96) (not (<= z 2.9e+140))) (* z (cos y)) (+ (* x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.8e+96) || !(z <= 2.9e+140)) {
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.8d+96)) .or. (.not. (z <= 2.9d+140))) 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.8e+96) || !(z <= 2.9e+140)) {
tmp = z * Math.cos(y);
} else {
tmp = (x * Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.8e+96) or not (z <= 2.9e+140): 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.8e+96) || !(z <= 2.9e+140)) 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.8e+96) || ~((z <= 2.9e+140))) tmp = z * cos(y); else tmp = (x * sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.8e+96], N[Not[LessEqual[z, 2.9e+140]], $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.8 \cdot 10^{+96} \lor \neg \left(z \leq 2.9 \cdot 10^{+140}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\
\end{array}
\end{array}
if z < -1.80000000000000007e96 or 2.8999999999999999e140 < z Initial program 99.8%
Taylor expanded in y around 0 75.0%
*-commutative75.0%
Simplified75.0%
Taylor expanded in x around 0 90.1%
if -1.80000000000000007e96 < z < 2.8999999999999999e140Initial program 99.8%
Taylor expanded in y around 0 90.3%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0076) (not (<= y 550.0))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0076) || !(y <= 550.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 <= (-0.0076d0)) .or. (.not. (y <= 550.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 <= -0.0076) || !(y <= 550.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0076) or not (y <= 550.0): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0076) || !(y <= 550.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 <= -0.0076) || ~((y <= 550.0))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0076], N[Not[LessEqual[y, 550.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 -0.0076 \lor \neg \left(y \leq 550\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -0.00759999999999999998 or 550 < y Initial program 99.6%
add-cube-cbrt98.6%
pow398.6%
Applied egg-rr98.6%
Taylor expanded in y around 0 61.1%
Taylor expanded in z around 0 58.0%
pow-base-158.0%
*-lft-identity58.0%
Simplified58.0%
if -0.00759999999999999998 < y < 550Initial program 100.0%
Taylor expanded in y around 0 99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in y around 0 97.7%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.4e+149) (not (<= x 2.45e+113))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.4e+149) || !(x <= 2.45e+113)) {
tmp = x * y;
} 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 <= (-4.4d+149)) .or. (.not. (x <= 2.45d+113))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.4e+149) || !(x <= 2.45e+113)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.4e+149) or not (x <= 2.45e+113): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.4e+149) || !(x <= 2.45e+113)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.4e+149) || ~((x <= 2.45e+113))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.4e+149], N[Not[LessEqual[x, 2.45e+113]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+149} \lor \neg \left(x \leq 2.45 \cdot 10^{+113}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.4e149 or 2.45000000000000011e113 < x Initial program 99.7%
Taylor expanded in y around 0 47.1%
*-commutative47.1%
Simplified47.1%
Taylor expanded in y around inf 32.5%
if -4.4e149 < x < 2.45000000000000011e113Initial program 99.8%
Taylor expanded in y around 0 73.6%
Taylor expanded in x around 0 49.3%
Final simplification43.7%
(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 63.8%
*-commutative63.8%
Simplified63.8%
Taylor expanded in y around 0 52.1%
Final simplification52.1%
(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%
Taylor expanded in y around 0 80.0%
Taylor expanded in x around 0 38.8%
Final simplification38.8%
herbie shell --seed 2024023
(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))))