
(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 9 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) (- (* (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 81.3%
+-commutative81.3%
Simplified81.3%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.00013) (not (<= a 0.0033))) (* r (/ (sin b) (cos a))) (* r (tan b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00013) || !(a <= 0.0033)) {
tmp = r * (sin(b) / cos(a));
} else {
tmp = r * tan(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 <= (-0.00013d0)) .or. (.not. (a <= 0.0033d0))) then
tmp = r * (sin(b) / cos(a))
else
tmp = r * tan(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00013) || !(a <= 0.0033)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = r * Math.tan(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -0.00013) or not (a <= 0.0033): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = r * math.tan(b) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -0.00013) || !(a <= 0.0033)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(r * tan(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -0.00013) || ~((a <= 0.0033))) tmp = r * (sin(b) / cos(a)); else tmp = r * tan(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00013], N[Not[LessEqual[a, 0.0033]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00013 \lor \neg \left(a \leq 0.0033\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \tan b\\
\end{array}
\end{array}
if a < -1.29999999999999989e-4 or 0.0033 < a Initial program 61.8%
+-commutative61.8%
Simplified61.8%
Taylor expanded in b around 0 62.5%
if -1.29999999999999989e-4 < a < 0.0033Initial program 98.7%
associate-*r/98.7%
+-commutative98.7%
Simplified98.7%
clear-num98.1%
associate-/r/98.6%
Applied egg-rr98.6%
Taylor expanded in a around 0 98.6%
*-commutative98.6%
associate-*r*98.7%
div-inv98.7%
clear-num98.6%
un-div-inv98.6%
clear-num98.6%
quot-tan98.6%
Applied egg-rr98.6%
Simplified98.8%
Final simplification81.7%
(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 81.3%
Final simplification81.3%
(FPCore (r a b) :precision binary64 (if (or (<= b -4.2e-5) (not (<= b 7.9e-16))) (* r (tan b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -4.2e-5) || !(b <= 7.9e-16)) {
tmp = r * tan(b);
} else {
tmp = b * (r / 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 <= (-4.2d-5)) .or. (.not. (b <= 7.9d-16))) then
tmp = r * tan(b)
else
tmp = b * (r / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -4.2e-5) || !(b <= 7.9e-16)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -4.2e-5) or not (b <= 7.9e-16): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -4.2e-5) || !(b <= 7.9e-16)) tmp = Float64(r * tan(b)); else tmp = Float64(b * Float64(r / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -4.2e-5) || ~((b <= 7.9e-16))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -4.2e-5], N[Not[LessEqual[b, 7.9e-16]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.2 \cdot 10^{-5} \lor \neg \left(b \leq 7.9 \cdot 10^{-16}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -4.19999999999999977e-5 or 7.9000000000000002e-16 < b Initial program 61.8%
associate-*r/61.8%
+-commutative61.8%
Simplified61.8%
clear-num61.7%
associate-/r/61.7%
Applied egg-rr61.7%
Taylor expanded in a around 0 61.9%
*-commutative61.9%
associate-*r*61.9%
div-inv62.0%
clear-num61.9%
un-div-inv62.0%
clear-num61.9%
quot-tan62.0%
Applied egg-rr62.0%
Simplified62.1%
if -4.19999999999999977e-5 < b < 7.9000000000000002e-16Initial program 99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in b around 0 99.5%
associate-/l*99.5%
Simplified99.5%
Final simplification81.4%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.00014) (not (<= b 7.9e-16))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.00014) || !(b <= 7.9e-16)) {
tmp = r * tan(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 <= (-0.00014d0)) .or. (.not. (b <= 7.9d-16))) then
tmp = r * tan(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 <= -0.00014) || !(b <= 7.9e-16)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.00014) or not (b <= 7.9e-16): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.00014) || !(b <= 7.9e-16)) tmp = Float64(r * tan(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 <= -0.00014) || ~((b <= 7.9e-16))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.00014], N[Not[LessEqual[b, 7.9e-16]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00014 \lor \neg \left(b \leq 7.9 \cdot 10^{-16}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -1.3999999999999999e-4 or 7.9000000000000002e-16 < b Initial program 61.8%
associate-*r/61.8%
+-commutative61.8%
Simplified61.8%
clear-num61.7%
associate-/r/61.7%
Applied egg-rr61.7%
Taylor expanded in a around 0 61.9%
*-commutative61.9%
associate-*r*61.9%
div-inv62.0%
clear-num61.9%
un-div-inv62.0%
clear-num61.9%
quot-tan62.0%
Applied egg-rr62.0%
Simplified62.1%
if -1.3999999999999999e-4 < b < 7.9000000000000002e-16Initial program 99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in b around 0 99.6%
Final simplification81.4%
(FPCore (r a b) :precision binary64 (if (<= b -2.55e-5) (* r (tan b)) (if (<= b 7.9e-16) (* r (/ b (cos a))) (/ r (/ 1.0 (tan b))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -2.55e-5) {
tmp = r * tan(b);
} else if (b <= 7.9e-16) {
tmp = r * (b / cos(a));
} else {
tmp = r / (1.0 / tan(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 <= (-2.55d-5)) then
tmp = r * tan(b)
else if (b <= 7.9d-16) then
tmp = r * (b / cos(a))
else
tmp = r / (1.0d0 / tan(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= -2.55e-5) {
tmp = r * Math.tan(b);
} else if (b <= 7.9e-16) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r / (1.0 / Math.tan(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -2.55e-5: tmp = r * math.tan(b) elif b <= 7.9e-16: tmp = r * (b / math.cos(a)) else: tmp = r / (1.0 / math.tan(b)) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -2.55e-5) tmp = Float64(r * tan(b)); elseif (b <= 7.9e-16) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r / Float64(1.0 / tan(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -2.55e-5) tmp = r * tan(b); elseif (b <= 7.9e-16) tmp = r * (b / cos(a)); else tmp = r / (1.0 / tan(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -2.55e-5], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.9e-16], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / N[(1.0 / N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.55 \cdot 10^{-5}:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{elif}\;b \leq 7.9 \cdot 10^{-16}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{1}{\tan b}}\\
\end{array}
\end{array}
if b < -2.54999999999999998e-5Initial program 60.9%
associate-*r/60.8%
+-commutative60.8%
Simplified60.8%
clear-num60.7%
associate-/r/60.7%
Applied egg-rr60.7%
Taylor expanded in a around 0 61.4%
*-commutative61.4%
associate-*r*61.6%
div-inv61.6%
clear-num61.6%
un-div-inv61.6%
clear-num61.5%
quot-tan61.5%
Applied egg-rr61.5%
Simplified61.7%
if -2.54999999999999998e-5 < b < 7.9000000000000002e-16Initial program 99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in b around 0 99.6%
if 7.9000000000000002e-16 < b Initial program 62.8%
associate-*r/62.9%
+-commutative62.9%
Simplified62.9%
clear-num62.8%
associate-/r/62.8%
Applied egg-rr62.8%
Taylor expanded in a around 0 62.3%
*-commutative62.3%
associate-*r*62.3%
div-inv62.3%
clear-num62.2%
un-div-inv62.4%
clear-num62.4%
quot-tan62.5%
Applied egg-rr62.5%
Final simplification81.4%
(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 81.3%
+-commutative81.3%
Simplified81.3%
add-cbrt-cube59.4%
add-cbrt-cube59.3%
cbrt-undiv59.4%
pow359.4%
pow359.4%
Applied egg-rr59.4%
Taylor expanded in b around 0 36.6%
Taylor expanded in a around 0 41.3%
Final simplification41.3%
(FPCore (r a b) :precision binary64 (* r (tan b)))
double code(double r, double a, double b) {
return r * tan(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 * tan(b)
end function
public static double code(double r, double a, double b) {
return r * Math.tan(b);
}
def code(r, a, b): return r * math.tan(b)
function code(r, a, b) return Float64(r * tan(b)) end
function tmp = code(r, a, b) tmp = r * tan(b); end
code[r_, a_, b_] := N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \tan b
\end{array}
Initial program 81.3%
associate-*r/81.3%
+-commutative81.3%
Simplified81.3%
clear-num80.7%
associate-/r/81.2%
Applied egg-rr81.2%
Taylor expanded in a around 0 63.9%
*-commutative63.9%
associate-*r*63.9%
div-inv64.0%
clear-num63.9%
un-div-inv63.9%
clear-num63.9%
quot-tan63.9%
Applied egg-rr63.9%
Simplified64.0%
Final simplification64.0%
(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 81.3%
+-commutative81.3%
Simplified81.3%
Taylor expanded in b around 0 54.3%
associate-/l*54.3%
Simplified54.3%
Taylor expanded in a around 0 36.9%
*-commutative36.9%
Simplified36.9%
Final simplification36.9%
herbie shell --seed 2024074
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))