
(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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}
(FPCore (r a b) :precision binary64 (* (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a)))) r))
double code(double r, double a, double b) {
return (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))) * r;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))) * r
end function
public static double code(double r, double a, double b) {
return (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a)))) * r;
}
def code(r, a, b): return (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a)))) * r
function code(r, a, b) return Float64(Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))) * r) end
function tmp = code(r, a, b) tmp = (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))) * r; end
code[r_, a_, b_] := N[(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] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \cdot r
\end{array}
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (+ (* (* (sin b) (sin a)) -2.0) (cos (- b a))))))
double code(double r, double a, double b) {
return r * (sin(b) / (((sin(b) * sin(a)) * -2.0) + 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) / (((sin(b) * sin(a)) * (-2.0d0)) + cos((b - a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / (((Math.sin(b) * Math.sin(a)) * -2.0) + Math.cos((b - a))));
}
def code(r, a, b): return r * (math.sin(b) / (((math.sin(b) * math.sin(a)) * -2.0) + math.cos((b - a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(Float64(sin(b) * sin(a)) * -2.0) + cos(Float64(b - a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / (((sin(b) * sin(a)) * -2.0) + cos((b - a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision] + N[Cos[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\left(\sin b \cdot \sin a\right) \cdot -2 + \cos \left(b - a\right)}
\end{array}
(FPCore (r a b) :precision binary64 (if (or (<= b -61000.0) (not (<= b 1.2e-10))) (* r (/ (sin b) (cos b))) (* r (/ (sin b) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -61000.0) || !(b <= 1.2e-10)) {
tmp = r * (sin(b) / cos(b));
} else {
tmp = r * (sin(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 <= (-61000.0d0)) .or. (.not. (b <= 1.2d-10))) then
tmp = r * (sin(b) / cos(b))
else
tmp = r * (sin(b) / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -61000.0) || !(b <= 1.2e-10)) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else {
tmp = r * (Math.sin(b) / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -61000.0) or not (b <= 1.2e-10): tmp = r * (math.sin(b) / math.cos(b)) else: tmp = r * (math.sin(b) / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -61000.0) || !(b <= 1.2e-10)) tmp = Float64(r * Float64(sin(b) / cos(b))); else tmp = Float64(r * Float64(sin(b) / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -61000.0) || ~((b <= 1.2e-10))) tmp = r * (sin(b) / cos(b)); else tmp = r * (sin(b) / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -61000.0], N[Not[LessEqual[b, 1.2e-10]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -61000 \lor \neg \left(b \leq 1.2 \cdot 10^{-10}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\end{array}
\end{array}
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos (+ b a)))))
double code(double r, double a, double b) {
return sin(b) * (r / 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 = sin(b) * (r / cos((b + a)))
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * (r / Math.cos((b + a)));
}
def code(r, a, b): return math.sin(b) * (r / math.cos((b + a)))
function code(r, a, b) return Float64(sin(b) * Float64(r / cos(Float64(b + a)))) end
function tmp = code(r, a, b) tmp = sin(b) * (r / cos((b + a))); end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot \frac{r}{\cos \left(b + a\right)}
\end{array}
(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}
(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}
(FPCore (r a b) :precision binary64 (if (or (<= b -125000.0) (not (<= b 2700.0))) (* (sin b) r) (/ (* b r) (cos (+ b a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -125000.0) || !(b <= 2700.0)) {
tmp = sin(b) * r;
} else {
tmp = (b * r) / cos((b + 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 <= (-125000.0d0)) .or. (.not. (b <= 2700.0d0))) then
tmp = sin(b) * r
else
tmp = (b * r) / cos((b + a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -125000.0) || !(b <= 2700.0)) {
tmp = Math.sin(b) * r;
} else {
tmp = (b * r) / Math.cos((b + a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -125000.0) or not (b <= 2700.0): tmp = math.sin(b) * r else: tmp = (b * r) / math.cos((b + a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -125000.0) || !(b <= 2700.0)) tmp = Float64(sin(b) * r); else tmp = Float64(Float64(b * r) / cos(Float64(b + a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -125000.0) || ~((b <= 2700.0))) tmp = sin(b) * r; else tmp = (b * r) / cos((b + a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -125000.0], N[Not[LessEqual[b, 2700.0]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(b * r), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -125000 \lor \neg \left(b \leq 2700\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\
\end{array}
\end{array}
(FPCore (r a b) :precision binary64 (if (or (<= b -61000.0) (not (<= b 1.2e-10))) (* (sin b) r) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -61000.0) || !(b <= 1.2e-10)) {
tmp = sin(b) * r;
} 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 <= (-61000.0d0)) .or. (.not. (b <= 1.2d-10))) then
tmp = sin(b) * r
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 <= -61000.0) || !(b <= 1.2e-10)) {
tmp = Math.sin(b) * r;
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -61000.0) or not (b <= 1.2e-10): tmp = math.sin(b) * r else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -61000.0) || !(b <= 1.2e-10)) tmp = Float64(sin(b) * r); else tmp = Float64(r * Float64(b / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -61000.0) || ~((b <= 1.2e-10))) tmp = sin(b) * r; else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -61000.0], N[Not[LessEqual[b, 1.2e-10]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -61000 \lor \neg \left(b \leq 1.2 \cdot 10^{-10}\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
(FPCore (r a b) :precision binary64 (* (sin b) r))
double code(double r, double a, double b) {
return sin(b) * r;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = sin(b) * r
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * r;
}
def code(r, a, b): return math.sin(b) * r
function code(r, a, b) return Float64(sin(b) * r) end
function tmp = code(r, a, b) tmp = sin(b) * r; end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot r
\end{array}
(FPCore (r a b) :precision binary64 (* b r))
double code(double r, double a, double b) {
return b * r;
}
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
end function
public static double code(double r, double a, double b) {
return b * r;
}
def code(r, a, b): return b * r
function code(r, a, b) return Float64(b * r) end
function tmp = code(r, a, b) tmp = b * r; end
code[r_, a_, b_] := N[(b * r), $MachinePrecision]
\begin{array}{l}
\\
b \cdot r
\end{array}
herbie shell --seed 2024008
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))