
(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 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(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 (/ (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(sin(b) / Float64(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[Sin[b], $MachinePrecision] / N[(N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\frac{\cos b \cdot \cos a - \sin b \cdot \sin a}{r}}
\end{array}
Initial program 75.7%
remove-double-neg75.7%
remove-double-neg75.7%
+-commutative75.7%
Simplified75.7%
associate-*r/75.6%
*-commutative75.6%
associate-/l*75.7%
Applied egg-rr75.7%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(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 75.7%
remove-double-neg75.7%
remove-double-neg75.7%
+-commutative75.7%
Simplified75.7%
cos-sum99.5%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.00092) (not (<= a 0.00012))) (* r (/ (sin b) (cos a))) (* r (tan b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00092) || !(a <= 0.00012)) {
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.00092d0)) .or. (.not. (a <= 0.00012d0))) 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.00092) || !(a <= 0.00012)) {
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.00092) or not (a <= 0.00012): 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.00092) || !(a <= 0.00012)) 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.00092) || ~((a <= 0.00012))) 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.00092], N[Not[LessEqual[a, 0.00012]], $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.00092 \lor \neg \left(a \leq 0.00012\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \tan b\\
\end{array}
\end{array}
if a < -9.2000000000000003e-4 or 1.20000000000000003e-4 < a Initial program 57.1%
remove-double-neg57.1%
remove-double-neg57.1%
+-commutative57.1%
Simplified57.1%
Taylor expanded in b around 0 57.1%
if -9.2000000000000003e-4 < a < 1.20000000000000003e-4Initial program 98.4%
remove-double-neg98.4%
remove-double-neg98.4%
+-commutative98.4%
Simplified98.4%
associate-*r/98.4%
*-commutative98.4%
associate-/l*98.4%
Applied egg-rr98.4%
Taylor expanded in a around 0 98.4%
associate-/r/98.4%
quot-tan98.5%
Applied egg-rr98.5%
Final simplification75.7%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.0048) (not (<= a 0.0009))) (/ (sin b) (/ (cos a) r)) (* r (tan b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.0048) || !(a <= 0.0009)) {
tmp = sin(b) / (cos(a) / r);
} 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.0048d0)) .or. (.not. (a <= 0.0009d0))) then
tmp = sin(b) / (cos(a) / r)
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.0048) || !(a <= 0.0009)) {
tmp = Math.sin(b) / (Math.cos(a) / r);
} else {
tmp = r * Math.tan(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -0.0048) or not (a <= 0.0009): tmp = math.sin(b) / (math.cos(a) / r) else: tmp = r * math.tan(b) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -0.0048) || !(a <= 0.0009)) tmp = Float64(sin(b) / Float64(cos(a) / r)); else tmp = Float64(r * tan(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -0.0048) || ~((a <= 0.0009))) tmp = sin(b) / (cos(a) / r); else tmp = r * tan(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.0048], N[Not[LessEqual[a, 0.0009]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0048 \lor \neg \left(a \leq 0.0009\right):\\
\;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \tan b\\
\end{array}
\end{array}
if a < -0.00479999999999999958 or 8.9999999999999998e-4 < a Initial program 57.1%
remove-double-neg57.1%
remove-double-neg57.1%
+-commutative57.1%
Simplified57.1%
associate-*r/57.1%
*-commutative57.1%
associate-/l*57.2%
Applied egg-rr57.2%
Taylor expanded in b around 0 57.1%
if -0.00479999999999999958 < a < 8.9999999999999998e-4Initial program 98.4%
remove-double-neg98.4%
remove-double-neg98.4%
+-commutative98.4%
Simplified98.4%
associate-*r/98.4%
*-commutative98.4%
associate-/l*98.4%
Applied egg-rr98.4%
Taylor expanded in a around 0 98.4%
associate-/r/98.4%
quot-tan98.5%
Applied egg-rr98.5%
Final simplification75.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 75.7%
Final simplification75.7%
(FPCore (r a b) :precision binary64 (/ (sin b) (/ (cos (+ b a)) r)))
double code(double r, double a, double b) {
return sin(b) / (cos((b + 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 + a)) / r)
end function
public static double code(double r, double a, double b) {
return Math.sin(b) / (Math.cos((b + a)) / r);
}
def code(r, a, b): return math.sin(b) / (math.cos((b + a)) / r)
function code(r, a, b) return Float64(sin(b) / Float64(cos(Float64(b + a)) / r)) end
function tmp = code(r, a, b) tmp = sin(b) / (cos((b + a)) / r); end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}
\end{array}
Initial program 75.7%
remove-double-neg75.7%
remove-double-neg75.7%
+-commutative75.7%
Simplified75.7%
associate-*r/75.6%
*-commutative75.6%
associate-/l*75.7%
Applied egg-rr75.7%
Final simplification75.7%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.00015) (not (<= b 1050000.0))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.00015) || !(b <= 1050000.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 <= (-0.00015d0)) .or. (.not. (b <= 1050000.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 <= -0.00015) || !(b <= 1050000.0)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.00015) or not (b <= 1050000.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 <= -0.00015) || !(b <= 1050000.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 <= -0.00015) || ~((b <= 1050000.0))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.00015], N[Not[LessEqual[b, 1050000.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 -0.00015 \lor \neg \left(b \leq 1050000\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -1.49999999999999987e-4 or 1.05e6 < b Initial program 51.8%
remove-double-neg51.8%
remove-double-neg51.8%
+-commutative51.8%
Simplified51.8%
associate-*r/51.8%
*-commutative51.8%
associate-/l*51.9%
Applied egg-rr51.9%
Taylor expanded in a around 0 50.7%
associate-/r/50.7%
quot-tan50.8%
Applied egg-rr50.8%
if -1.49999999999999987e-4 < b < 1.05e6Initial program 99.1%
remove-double-neg99.1%
remove-double-neg99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in b around 0 99.0%
Final simplification75.1%
(FPCore (r a b) :precision binary64 (if (or (<= b -2.4e-27) (not (<= b 1050000.0))) (* r (tan b)) (/ b (/ (cos a) r))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -2.4e-27) || !(b <= 1050000.0)) {
tmp = r * tan(b);
} else {
tmp = b / (cos(a) / r);
}
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.4d-27)) .or. (.not. (b <= 1050000.0d0))) then
tmp = r * tan(b)
else
tmp = b / (cos(a) / r)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -2.4e-27) || !(b <= 1050000.0)) {
tmp = r * Math.tan(b);
} else {
tmp = b / (Math.cos(a) / r);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -2.4e-27) or not (b <= 1050000.0): tmp = r * math.tan(b) else: tmp = b / (math.cos(a) / r) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -2.4e-27) || !(b <= 1050000.0)) tmp = Float64(r * tan(b)); else tmp = Float64(b / Float64(cos(a) / r)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -2.4e-27) || ~((b <= 1050000.0))) tmp = r * tan(b); else tmp = b / (cos(a) / r); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.4e-27], N[Not[LessEqual[b, 1050000.0]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(b / N[(N[Cos[a], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-27} \lor \neg \left(b \leq 1050000\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\frac{\cos a}{r}}\\
\end{array}
\end{array}
if b < -2.40000000000000002e-27 or 1.05e6 < b Initial program 52.6%
remove-double-neg52.6%
remove-double-neg52.6%
+-commutative52.6%
Simplified52.6%
associate-*r/52.6%
*-commutative52.6%
associate-/l*52.7%
Applied egg-rr52.7%
Taylor expanded in a around 0 51.5%
associate-/r/51.4%
quot-tan51.6%
Applied egg-rr51.6%
if -2.40000000000000002e-27 < b < 1.05e6Initial program 99.1%
remove-double-neg99.1%
remove-double-neg99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in b around 0 99.0%
associate-/l*99.1%
Simplified99.1%
Final simplification75.1%
(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 75.7%
remove-double-neg75.7%
remove-double-neg75.7%
+-commutative75.7%
Simplified75.7%
associate-*r/75.6%
*-commutative75.6%
associate-/l*75.7%
Applied egg-rr75.7%
Taylor expanded in a around 0 57.1%
associate-/r/57.1%
quot-tan57.2%
Applied egg-rr57.2%
Final simplification57.2%
(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}
Initial program 75.7%
remove-double-neg75.7%
remove-double-neg75.7%
+-commutative75.7%
Simplified75.7%
Taylor expanded in b around 0 51.8%
Taylor expanded in a around 0 33.9%
Final simplification33.9%
herbie shell --seed 2024027
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))