
(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 79.9%
+-commutative79.9%
Simplified79.9%
cos-sum99.6%
Applied egg-rr99.6%
(FPCore (r a b) :precision binary64 (if (or (<= b -2.3e-5) (not (<= b 34000.0))) (* r (tan b)) (* r (/ (sin b) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -2.3e-5) || !(b <= 34000.0)) {
tmp = r * tan(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 <= (-2.3d-5)) .or. (.not. (b <= 34000.0d0))) then
tmp = r * tan(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 <= -2.3e-5) || !(b <= 34000.0)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (Math.sin(b) / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -2.3e-5) or not (b <= 34000.0): tmp = r * math.tan(b) else: tmp = r * (math.sin(b) / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -2.3e-5) || !(b <= 34000.0)) tmp = Float64(r * tan(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 <= -2.3e-5) || ~((b <= 34000.0))) tmp = r * tan(b); else tmp = r * (sin(b) / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.3e-5], N[Not[LessEqual[b, 34000.0]], $MachinePrecision]], N[(r * N[Tan[b], $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 -2.3 \cdot 10^{-5} \lor \neg \left(b \leq 34000\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\end{array}
\end{array}
if b < -2.3e-5 or 34000 < b Initial program 59.8%
associate-*r/59.8%
+-commutative59.8%
Simplified59.8%
associate-*r/59.8%
*-commutative59.8%
div-inv59.7%
associate-*l*59.8%
Applied egg-rr59.8%
Taylor expanded in a around 0 59.8%
add-exp-log24.8%
associate-*r*24.8%
*-commutative24.8%
un-div-inv24.8%
Applied egg-rr24.8%
rem-exp-log59.7%
*-commutative59.7%
quot-tan59.8%
Applied egg-rr59.8%
if -2.3e-5 < b < 34000Initial program 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in b around 0 97.7%
Final simplification79.9%
(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 79.9%
Final simplification79.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -6e-5) (not (<= b 740.0))) (* r (tan b)) (* r (/ b (cos (+ b a))))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -6e-5) || !(b <= 740.0)) {
tmp = r * tan(b);
} else {
tmp = r * (b / 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 <= (-6d-5)) .or. (.not. (b <= 740.0d0))) then
tmp = r * tan(b)
else
tmp = r * (b / cos((b + a)))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -6e-5) || !(b <= 740.0)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos((b + a)));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -6e-5) or not (b <= 740.0): tmp = r * math.tan(b) else: tmp = r * (b / math.cos((b + a))) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -6e-5) || !(b <= 740.0)) tmp = Float64(r * tan(b)); else tmp = Float64(r * Float64(b / cos(Float64(b + a)))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -6e-5) || ~((b <= 740.0))) tmp = r * tan(b); else tmp = r * (b / cos((b + a))); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -6e-5], N[Not[LessEqual[b, 740.0]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{-5} \lor \neg \left(b \leq 740\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\
\end{array}
\end{array}
if b < -6.00000000000000015e-5 or 740 < b Initial program 59.3%
associate-*r/59.3%
+-commutative59.3%
Simplified59.3%
associate-*r/59.3%
*-commutative59.3%
div-inv59.3%
associate-*l*59.4%
Applied egg-rr59.4%
Taylor expanded in a around 0 59.3%
add-exp-log24.6%
associate-*r*24.6%
*-commutative24.6%
un-div-inv24.6%
Applied egg-rr24.6%
rem-exp-log59.2%
*-commutative59.2%
quot-tan59.3%
Applied egg-rr59.3%
if -6.00000000000000015e-5 < b < 740Initial program 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in b around 0 98.4%
Final simplification79.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -9.6e-6) (not (<= b 740.0))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -9.6e-6) || !(b <= 740.0)) {
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 <= (-9.6d-6)) .or. (.not. (b <= 740.0d0))) 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 <= -9.6e-6) || !(b <= 740.0)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -9.6e-6) or not (b <= 740.0): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -9.6e-6) || !(b <= 740.0)) 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 <= -9.6e-6) || ~((b <= 740.0))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -9.6e-6], N[Not[LessEqual[b, 740.0]], $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 -9.6 \cdot 10^{-6} \lor \neg \left(b \leq 740\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -9.5999999999999996e-6 or 740 < b Initial program 59.3%
associate-*r/59.3%
+-commutative59.3%
Simplified59.3%
associate-*r/59.3%
*-commutative59.3%
div-inv59.3%
associate-*l*59.4%
Applied egg-rr59.4%
Taylor expanded in a around 0 59.3%
add-exp-log24.6%
associate-*r*24.6%
*-commutative24.6%
un-div-inv24.6%
Applied egg-rr24.6%
rem-exp-log59.2%
*-commutative59.2%
quot-tan59.3%
Applied egg-rr59.3%
if -9.5999999999999996e-6 < b < 740Initial program 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in b around 0 98.3%
*-commutative98.3%
associate-/l*98.4%
Simplified98.4%
Final simplification79.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -1.8e-5) (not (<= b 740.0))) (* r (tan b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -1.8e-5) || !(b <= 740.0)) {
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 <= (-1.8d-5)) .or. (.not. (b <= 740.0d0))) 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 <= -1.8e-5) || !(b <= 740.0)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -1.8e-5) or not (b <= 740.0): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -1.8e-5) || !(b <= 740.0)) 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 <= -1.8e-5) || ~((b <= 740.0))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -1.8e-5], N[Not[LessEqual[b, 740.0]], $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 -1.8 \cdot 10^{-5} \lor \neg \left(b \leq 740\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -1.80000000000000005e-5 or 740 < b Initial program 59.3%
associate-*r/59.3%
+-commutative59.3%
Simplified59.3%
associate-*r/59.3%
*-commutative59.3%
div-inv59.3%
associate-*l*59.4%
Applied egg-rr59.4%
Taylor expanded in a around 0 59.3%
add-exp-log24.6%
associate-*r*24.6%
*-commutative24.6%
un-div-inv24.6%
Applied egg-rr24.6%
rem-exp-log59.2%
*-commutative59.2%
quot-tan59.3%
Applied egg-rr59.3%
if -1.80000000000000005e-5 < b < 740Initial program 98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in b around 0 98.3%
associate-/l*98.3%
Simplified98.3%
Final simplification79.9%
(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 79.9%
associate-*r/79.9%
+-commutative79.9%
Simplified79.9%
associate-*r/79.9%
*-commutative79.9%
div-inv79.9%
associate-*l*79.9%
Applied egg-rr79.9%
Taylor expanded in a around 0 61.2%
add-exp-log32.8%
associate-*r*32.8%
*-commutative32.8%
un-div-inv32.8%
Applied egg-rr32.8%
rem-exp-log61.1%
*-commutative61.1%
quot-tan61.2%
Applied egg-rr61.2%
Final simplification61.2%
(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 79.9%
associate-*r/79.9%
+-commutative79.9%
Simplified79.9%
associate-*r/79.9%
*-commutative79.9%
div-inv79.9%
associate-*l*79.9%
Applied egg-rr79.9%
Taylor expanded in a around 0 61.2%
Taylor expanded in b around 0 40.4%
Final simplification40.4%
(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 79.9%
+-commutative79.9%
Simplified79.9%
Taylor expanded in b around 0 54.1%
associate-/l*54.1%
Simplified54.1%
Taylor expanded in a around 0 35.6%
*-commutative35.6%
Simplified35.6%
herbie shell --seed 2024157
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))