
(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 73.4%
+-commutative73.4%
cos-sum99.4%
fma-neg99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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 73.4%
+-commutative73.4%
cos-sum99.4%
sub-neg99.4%
Applied egg-rr99.4%
sub-neg99.4%
Simplified99.4%
(FPCore (r a b) :precision binary64 (/ r (fma (cos a) (/ (cos b) (sin b)) (- (sin a)))))
double code(double r, double a, double b) {
return r / fma(cos(a), (cos(b) / sin(b)), -sin(a));
}
function code(r, a, b) return Float64(r / fma(cos(a), Float64(cos(b) / sin(b)), Float64(-sin(a)))) end
code[r_, a_, b_] := N[(r / N[(N[Cos[a], $MachinePrecision] * N[(N[Cos[b], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision] + (-N[Sin[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\mathsf{fma}\left(\cos a, \frac{\cos b}{\sin b}, -\sin a\right)}
\end{array}
Initial program 73.4%
+-commutative73.4%
associate-/l*73.4%
clear-num72.2%
+-commutative72.2%
*-commutative72.2%
Applied egg-rr72.2%
+-commutative72.2%
cos-sum98.3%
div-sub92.3%
Applied egg-rr92.3%
Taylor expanded in r around 0 99.3%
associate-/l*99.4%
fma-neg99.4%
Simplified99.4%
(FPCore (r a b) :precision binary64 (/ r (- (/ (* (cos b) (cos a)) (sin b)) (sin a))))
double code(double r, double a, double b) {
return r / (((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 / (((cos(b) * cos(a)) / sin(b)) - sin(a))
end function
public static double code(double r, double a, double b) {
return r / (((Math.cos(b) * Math.cos(a)) / Math.sin(b)) - Math.sin(a));
}
def code(r, a, b): return r / (((math.cos(b) * math.cos(a)) / math.sin(b)) - math.sin(a))
function code(r, a, b) return Float64(r / Float64(Float64(Float64(cos(b) * cos(a)) / sin(b)) - sin(a))) end
function tmp = code(r, a, b) tmp = r / (((cos(b) * cos(a)) / sin(b)) - sin(a)); end
code[r_, a_, b_] := N[(r / N[(N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision] - N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\frac{\cos b \cdot \cos a}{\sin b} - \sin a}
\end{array}
Initial program 73.4%
+-commutative73.4%
associate-/l*73.4%
clear-num72.2%
+-commutative72.2%
*-commutative72.2%
Applied egg-rr72.2%
+-commutative72.2%
cos-sum98.3%
div-sub92.3%
Applied egg-rr92.3%
Taylor expanded in r around 0 99.3%
Final simplification99.3%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (* (cos b) (cos a)))))
double code(double r, double a, double b) {
return r * (sin(b) / (cos(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(b) * cos(a)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / (Math.cos(b) * Math.cos(a)));
}
def code(r, a, b): return r * (math.sin(b) / (math.cos(b) * math.cos(a)))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(cos(b) * cos(a)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / (cos(b) * cos(a))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a}
\end{array}
Initial program 73.4%
+-commutative73.4%
cos-sum99.4%
sub-neg99.4%
Applied egg-rr99.4%
sub-neg99.4%
Simplified99.4%
sin-mult74.7%
+-commutative74.7%
div-sub74.7%
cos-diff74.6%
add-sqr-sqrt40.6%
sqrt-unprod73.3%
sqr-neg73.3%
sqrt-unprod44.4%
add-sqr-sqrt72.6%
sub-neg72.6%
cos-sum74.7%
+-commutative74.7%
Applied egg-rr74.7%
+-inverses74.7%
Simplified74.7%
Final simplification74.7%
(FPCore (r a b) :precision binary64 (if (or (<= a -5400000000000.0) (not (<= a 3.1e-8))) (* r (/ (sin b) (cos a))) (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) {
tmp = r * (sin(b) / cos(a));
} else {
tmp = sin(b) * (r / cos(b));
}
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 ((a <= (-5400000000000.0d0)) .or. (.not. (a <= 3.1d-8))) then
tmp = r * (sin(b) / cos(a))
else
tmp = sin(b) * (r / cos(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -5400000000000.0) or not (a <= 3.1e-8): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(sin(b) * Float64(r / cos(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -5400000000000.0) || ~((a <= 3.1e-8))) tmp = r * (sin(b) / cos(a)); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -5400000000000.0], N[Not[LessEqual[a, 3.1e-8]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5400000000000 \lor \neg \left(a \leq 3.1 \cdot 10^{-8}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if a < -5.4e12 or 3.1e-8 < a Initial program 47.4%
Taylor expanded in b around 0 48.2%
if -5.4e12 < a < 3.1e-8Initial program 98.1%
cos-sum99.6%
*-un-lft-identity99.6%
prod-diff99.6%
*-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in a around 0 98.1%
*-commutative98.1%
associate-/l*98.2%
Simplified98.2%
Final simplification73.8%
(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 73.4%
+-commutative73.4%
cos-sum99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-undefine99.4%
add-sqr-sqrt61.3%
sqrt-unprod90.0%
sqr-neg90.0%
sqrt-unprod40.3%
add-sqr-sqrt73.6%
cos-diff73.5%
Applied egg-rr73.5%
(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 73.4%
Final simplification73.4%
(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 73.4%
Taylor expanded in b around 0 51.7%
(FPCore (r a b) :precision binary64 (* b (/ r (cos a))))
double code(double r, double a, double b) {
return b * (r / 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 = b * (r / cos(a))
end function
public static double code(double r, double a, double b) {
return b * (r / Math.cos(a));
}
def code(r, a, b): return b * (r / math.cos(a))
function code(r, a, b) return Float64(b * Float64(r / cos(a))) end
function tmp = code(r, a, b) tmp = b * (r / cos(a)); end
code[r_, a_, b_] := N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b \cdot \frac{r}{\cos a}
\end{array}
Initial program 73.4%
Taylor expanded in b around 0 47.7%
associate-/l*47.7%
Simplified47.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 73.4%
Taylor expanded in b around 0 47.7%
associate-/l*47.7%
Simplified47.7%
Taylor expanded in a around 0 33.5%
Final simplification33.5%
herbie shell --seed 2024096
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))