
(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 5 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 (/ r (fma (/ (cos b) (sin b)) (cos a) (- (sin a)))))
double code(double r, double a, double b) {
return r / fma((cos(b) / sin(b)), cos(a), -sin(a));
}
function code(r, a, b) return Float64(r / fma(Float64(cos(b) / sin(b)), cos(a), Float64(-sin(a)))) end
code[r_, a_, b_] := N[(r / N[(N[(N[Cos[b], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision] * N[Cos[a], $MachinePrecision] + (-N[Sin[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, -\sin a\right)}
\end{array}
Initial program 80.7%
associate-/l*80.6%
+-commutative80.6%
Simplified80.6%
cos-sum99.4%
div-sub99.4%
Applied egg-rr99.4%
associate-/l*99.4%
associate-/r/99.4%
fma-neg99.4%
associate-/l*99.4%
associate-/r/99.4%
*-inverses99.4%
distribute-lft-neg-in99.4%
metadata-eval99.4%
mul-1-neg99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (r a b) :precision binary64 (if (or (<= b -7.4e-6) (not (<= b 4.5e-7))) (* r (/ (sin b) (cos b))) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -7.4e-6) || !(b <= 4.5e-7)) {
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 <= (-7.4d-6)) .or. (.not. (b <= 4.5d-7))) 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 <= -7.4e-6) || !(b <= 4.5e-7)) {
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 <= -7.4e-6) or not (b <= 4.5e-7): 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 <= -7.4e-6) || !(b <= 4.5e-7)) tmp = Float64(r * Float64(sin(b) / cos(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 <= -7.4e-6) || ~((b <= 4.5e-7))) 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, -7.4e-6], N[Not[LessEqual[b, 4.5e-7]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.4 \cdot 10^{-6} \lor \neg \left(b \leq 4.5 \cdot 10^{-7}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -7.4000000000000003e-6 or 4.4999999999999998e-7 < b Initial program 58.7%
associate-/l*58.7%
remove-double-neg58.7%
sin-neg58.7%
neg-mul-158.7%
associate-/r*58.7%
associate-/l*58.7%
*-commutative58.7%
associate-*l/58.8%
associate-/l*58.8%
sin-neg58.8%
distribute-lft-neg-in58.8%
distribute-rgt-neg-in58.8%
associate-/l*58.8%
metadata-eval58.8%
/-rgt-identity58.8%
+-commutative58.8%
Simplified58.8%
Taylor expanded in a around 0 58.3%
if -7.4000000000000003e-6 < b < 4.4999999999999998e-7Initial program 99.2%
associate-/l*99.0%
remove-double-neg99.0%
sin-neg99.0%
neg-mul-199.0%
associate-/r*99.0%
associate-/l*99.2%
*-commutative99.2%
associate-*l/99.2%
associate-/l*99.2%
sin-neg99.2%
distribute-lft-neg-in99.2%
distribute-rgt-neg-in99.2%
associate-/l*99.2%
metadata-eval99.2%
/-rgt-identity99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 99.2%
Final simplification80.5%
(FPCore (r a b) :precision binary64 (if (<= b -0.00018) (* r (/ (sin b) (cos b))) (if (<= b 1.75e-6) (* r (/ b (cos a))) (/ r (/ (cos b) (sin b))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -0.00018) {
tmp = r * (sin(b) / cos(b));
} else if (b <= 1.75e-6) {
tmp = r * (b / cos(a));
} else {
tmp = r / (cos(b) / sin(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 (b <= (-0.00018d0)) then
tmp = r * (sin(b) / cos(b))
else if (b <= 1.75d-6) then
tmp = r * (b / cos(a))
else
tmp = r / (cos(b) / sin(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -0.00018) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else if (b <= 1.75e-6) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r / (Math.cos(b) / Math.sin(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -0.00018: tmp = r * (math.sin(b) / math.cos(b)) elif b <= 1.75e-6: tmp = r * (b / math.cos(a)) else: tmp = r / (math.cos(b) / math.sin(b)) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -0.00018) tmp = Float64(r * Float64(sin(b) / cos(b))); elseif (b <= 1.75e-6) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r / Float64(cos(b) / sin(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -0.00018) tmp = r * (sin(b) / cos(b)); elseif (b <= 1.75e-6) tmp = r * (b / cos(a)); else tmp = r / (cos(b) / sin(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -0.00018], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.75e-6], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / N[(N[Cos[b], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00018:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{\cos b}{\sin b}}\\
\end{array}
\end{array}
if b < -1.80000000000000011e-4Initial program 64.7%
associate-/l*64.5%
remove-double-neg64.5%
sin-neg64.5%
neg-mul-164.5%
associate-/r*64.5%
associate-/l*64.7%
*-commutative64.7%
associate-*l/64.7%
associate-/l*64.7%
sin-neg64.7%
distribute-lft-neg-in64.7%
distribute-rgt-neg-in64.7%
associate-/l*64.7%
metadata-eval64.7%
/-rgt-identity64.7%
+-commutative64.7%
Simplified64.7%
Taylor expanded in a around 0 64.0%
if -1.80000000000000011e-4 < b < 1.74999999999999997e-6Initial program 99.2%
associate-/l*99.0%
remove-double-neg99.0%
sin-neg99.0%
neg-mul-199.0%
associate-/r*99.0%
associate-/l*99.2%
*-commutative99.2%
associate-*l/99.2%
associate-/l*99.2%
sin-neg99.2%
distribute-lft-neg-in99.2%
distribute-rgt-neg-in99.2%
associate-/l*99.2%
metadata-eval99.2%
/-rgt-identity99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 99.2%
if 1.74999999999999997e-6 < b Initial program 55.0%
associate-/l*55.1%
+-commutative55.1%
Simplified55.1%
Taylor expanded in a around 0 54.8%
Final simplification80.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 80.7%
associate-/l*80.6%
remove-double-neg80.6%
sin-neg80.6%
neg-mul-180.6%
associate-/r*80.6%
associate-/l*80.7%
*-commutative80.7%
associate-*l/80.7%
associate-/l*80.7%
sin-neg80.7%
distribute-lft-neg-in80.7%
distribute-rgt-neg-in80.7%
associate-/l*80.7%
metadata-eval80.7%
/-rgt-identity80.7%
+-commutative80.7%
Simplified80.7%
Final simplification80.7%
(FPCore (r a b) :precision binary64 (* r (/ b (cos a))))
double code(double r, double a, double b) {
return r * (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 * (b / cos(a))
end function
public static double code(double r, double a, double b) {
return r * (b / Math.cos(a));
}
def code(r, a, b): return r * (b / math.cos(a))
function code(r, a, b) return Float64(r * Float64(b / cos(a))) end
function tmp = code(r, a, b) tmp = r * (b / cos(a)); end
code[r_, a_, b_] := N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{b}{\cos a}
\end{array}
Initial program 80.7%
associate-/l*80.6%
remove-double-neg80.6%
sin-neg80.6%
neg-mul-180.6%
associate-/r*80.6%
associate-/l*80.7%
*-commutative80.7%
associate-*l/80.7%
associate-/l*80.7%
sin-neg80.7%
distribute-lft-neg-in80.7%
distribute-rgt-neg-in80.7%
associate-/l*80.7%
metadata-eval80.7%
/-rgt-identity80.7%
+-commutative80.7%
Simplified80.7%
Taylor expanded in b around 0 56.1%
Final simplification56.1%
herbie shell --seed 2024039
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))