
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (fma (cos b) (cos a) (* (sin b) (- (sin a)))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(cos(b), cos(a), (sin(b) * -sin(a))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(cos(b), cos(a), Float64(sin(b) * Float64(-sin(a)))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)}
\end{array}
Initial program 76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.6%
cancel-sign-sub-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (- (* (cos b) (cos a)) (* (sin b) (sin a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a)));
}
def code(r, a, b): return (r * math.sin(b)) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a)))
function code(r, a, b) return Float64(Float64(r * sin(b)) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a))); end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.6%
cancel-sign-sub-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in r around 0 99.6%
*-commutative99.6%
+-commutative99.6%
mul-1-neg99.6%
*-commutative99.6%
sub-neg99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (if (or (<= b -3.1e-5) (not (<= b 1.65e-44))) (* r (/ (sin b) (cos b))) (/ (* r b) (cos a))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -3.1e-5) || !(b <= 1.65e-44)) {
tmp = r * (sin(b) / cos(b));
} else {
tmp = (r * b) / cos(a);
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-3.1d-5)) .or. (.not. (b <= 1.65d-44))) then
tmp = r * (sin(b) / cos(b))
else
tmp = (r * b) / cos(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -3.1e-5) || !(b <= 1.65e-44)) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else {
tmp = (r * b) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -3.1e-5) or not (b <= 1.65e-44): tmp = r * (math.sin(b) / math.cos(b)) else: tmp = (r * b) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -3.1e-5) || !(b <= 1.65e-44)) tmp = Float64(r * Float64(sin(b) / cos(b))); else tmp = Float64(Float64(r * b) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -3.1e-5) || ~((b <= 1.65e-44))) tmp = r * (sin(b) / cos(b)); else tmp = (r * b) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -3.1e-5], N[Not[LessEqual[b, 1.65e-44]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r * b), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.1 \cdot 10^{-5} \lor \neg \left(b \leq 1.65 \cdot 10^{-44}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot b}{\cos a}\\
\end{array}
\end{array}
if b < -3.10000000000000014e-5 or 1.65000000000000003e-44 < b Initial program 54.6%
+-commutative54.6%
Simplified54.6%
Taylor expanded in a around 0 54.9%
if -3.10000000000000014e-5 < b < 1.65000000000000003e-44Initial program 99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in b around 0 99.4%
Final simplification76.2%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ b a)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((b + a)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((b + a)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((b + a)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((b + a)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(b + a)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((b + a))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(b + a\right)}
\end{array}
Initial program 76.1%
Final simplification76.1%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos a))))
double code(double r, double a, double b) {
return r * (sin(b) / cos(a));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos(a))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos(a));
}
def code(r, a, b): return r * (math.sin(b) / math.cos(a))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(a))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos(a)); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos a}
\end{array}
Initial program 76.1%
+-commutative76.1%
Simplified76.1%
Taylor expanded in b around 0 55.0%
Final simplification55.0%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* r (sin b))))
(if (<= b -2.8e+15)
t_0
(if (<= b 160.0) (/ (* r b) (cos a)) (/ 1.0 (/ 1.0 t_0))))))
double code(double r, double a, double b) {
double t_0 = r * sin(b);
double tmp;
if (b <= -2.8e+15) {
tmp = t_0;
} else if (b <= 160.0) {
tmp = (r * b) / cos(a);
} else {
tmp = 1.0 / (1.0 / t_0);
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = r * sin(b)
if (b <= (-2.8d+15)) then
tmp = t_0
else if (b <= 160.0d0) then
tmp = (r * b) / cos(a)
else
tmp = 1.0d0 / (1.0d0 / t_0)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = r * Math.sin(b);
double tmp;
if (b <= -2.8e+15) {
tmp = t_0;
} else if (b <= 160.0) {
tmp = (r * b) / Math.cos(a);
} else {
tmp = 1.0 / (1.0 / t_0);
}
return tmp;
}
def code(r, a, b): t_0 = r * math.sin(b) tmp = 0 if b <= -2.8e+15: tmp = t_0 elif b <= 160.0: tmp = (r * b) / math.cos(a) else: tmp = 1.0 / (1.0 / t_0) return tmp
function code(r, a, b) t_0 = Float64(r * sin(b)) tmp = 0.0 if (b <= -2.8e+15) tmp = t_0; elseif (b <= 160.0) tmp = Float64(Float64(r * b) / cos(a)); else tmp = Float64(1.0 / Float64(1.0 / t_0)); end return tmp end
function tmp_2 = code(r, a, b) t_0 = r * sin(b); tmp = 0.0; if (b <= -2.8e+15) tmp = t_0; elseif (b <= 160.0) tmp = (r * b) / cos(a); else tmp = 1.0 / (1.0 / t_0); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.8e+15], t$95$0, If[LessEqual[b, 160.0], N[(N[(r * b), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \sin b\\
\mathbf{if}\;b \leq -2.8 \cdot 10^{+15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 160:\\
\;\;\;\;\frac{r \cdot b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{t_0}}\\
\end{array}
\end{array}
if b < -2.8e15Initial program 57.7%
+-commutative57.7%
Simplified57.7%
associate-*r/57.6%
clear-num57.4%
*-commutative57.4%
Applied egg-rr57.4%
Taylor expanded in b around 0 13.6%
Taylor expanded in a around 0 14.7%
*-commutative14.7%
Simplified14.7%
if -2.8e15 < b < 160Initial program 97.2%
+-commutative97.2%
Simplified97.2%
Taylor expanded in b around 0 96.2%
if 160 < b Initial program 50.6%
+-commutative50.6%
Simplified50.6%
associate-*r/50.5%
clear-num50.4%
*-commutative50.4%
Applied egg-rr50.4%
Taylor expanded in b around 0 10.8%
Taylor expanded in a around 0 10.5%
Final simplification55.3%
(FPCore (r a b) :precision binary64 (if (or (<= b -2.8e+15) (not (<= b 160.0))) (* r (sin b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -2.8e+15) || !(b <= 160.0)) {
tmp = r * sin(b);
} else {
tmp = r * (b / cos(a));
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-2.8d+15)) .or. (.not. (b <= 160.0d0))) then
tmp = r * sin(b)
else
tmp = r * (b / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -2.8e+15) || !(b <= 160.0)) {
tmp = r * Math.sin(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -2.8e+15) or not (b <= 160.0): tmp = r * math.sin(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -2.8e+15) || !(b <= 160.0)) tmp = Float64(r * sin(b)); else tmp = Float64(r * Float64(b / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -2.8e+15) || ~((b <= 160.0))) tmp = r * sin(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.8e+15], N[Not[LessEqual[b, 160.0]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+15} \lor \neg \left(b \leq 160\right):\\
\;\;\;\;r \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -2.8e15 or 160 < b Initial program 53.9%
+-commutative53.9%
Simplified53.9%
associate-*r/53.9%
clear-num53.7%
*-commutative53.7%
Applied egg-rr53.7%
Taylor expanded in b around 0 12.1%
Taylor expanded in a around 0 12.5%
*-commutative12.5%
Simplified12.5%
if -2.8e15 < b < 160Initial program 97.2%
+-commutative97.2%
Simplified97.2%
Taylor expanded in b around 0 96.2%
associate-/l*96.1%
associate-/r/96.2%
Simplified96.2%
Final simplification55.3%
(FPCore (r a b) :precision binary64 (if (or (<= b -2.8e+15) (not (<= b 160.0))) (* r (sin b)) (/ (* r b) (cos a))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -2.8e+15) || !(b <= 160.0)) {
tmp = r * sin(b);
} else {
tmp = (r * b) / cos(a);
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-2.8d+15)) .or. (.not. (b <= 160.0d0))) then
tmp = r * sin(b)
else
tmp = (r * b) / cos(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -2.8e+15) || !(b <= 160.0)) {
tmp = r * Math.sin(b);
} else {
tmp = (r * b) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -2.8e+15) or not (b <= 160.0): tmp = r * math.sin(b) else: tmp = (r * b) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -2.8e+15) || !(b <= 160.0)) tmp = Float64(r * sin(b)); else tmp = Float64(Float64(r * b) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -2.8e+15) || ~((b <= 160.0))) tmp = r * sin(b); else tmp = (r * b) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.8e+15], N[Not[LessEqual[b, 160.0]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(N[(r * b), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+15} \lor \neg \left(b \leq 160\right):\\
\;\;\;\;r \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot b}{\cos a}\\
\end{array}
\end{array}
if b < -2.8e15 or 160 < b Initial program 53.9%
+-commutative53.9%
Simplified53.9%
associate-*r/53.9%
clear-num53.7%
*-commutative53.7%
Applied egg-rr53.7%
Taylor expanded in b around 0 12.1%
Taylor expanded in a around 0 12.5%
*-commutative12.5%
Simplified12.5%
if -2.8e15 < b < 160Initial program 97.2%
+-commutative97.2%
Simplified97.2%
Taylor expanded in b around 0 96.2%
Final simplification55.3%
(FPCore (r a b) :precision binary64 (* r (sin b)))
double code(double r, double a, double b) {
return r * sin(b);
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * sin(b)
end function
public static double code(double r, double a, double b) {
return r * Math.sin(b);
}
def code(r, a, b): return r * math.sin(b)
function code(r, a, b) return Float64(r * sin(b)) end
function tmp = code(r, a, b) tmp = r * sin(b); end
code[r_, a_, b_] := N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \sin b
\end{array}
Initial program 76.1%
+-commutative76.1%
Simplified76.1%
associate-*r/76.1%
clear-num75.4%
*-commutative75.4%
Applied egg-rr75.4%
Taylor expanded in b around 0 54.5%
Taylor expanded in a around 0 39.7%
*-commutative39.7%
Simplified39.7%
Final simplification39.7%
(FPCore (r a b) :precision binary64 (* r b))
double code(double r, double a, double b) {
return r * b;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * b
end function
public static double code(double r, double a, double b) {
return r * b;
}
def code(r, a, b): return r * b
function code(r, a, b) return Float64(r * b) end
function tmp = code(r, a, b) tmp = r * b; end
code[r_, a_, b_] := N[(r * b), $MachinePrecision]
\begin{array}{l}
\\
r \cdot b
\end{array}
Initial program 76.1%
+-commutative76.1%
Simplified76.1%
Taylor expanded in b around 0 51.2%
associate-/l*51.1%
associate-/r/51.1%
Simplified51.1%
Taylor expanded in a around 0 35.8%
Final simplification35.8%
herbie shell --seed 2023293
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))