
(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 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(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}
Initial program 76.9%
*-commutative76.9%
associate-/l*76.8%
+-commutative76.8%
Simplified76.8%
associate-/r/76.9%
Applied egg-rr76.9%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.059) (not (<= b 4.2e-13))) (* (sin b) (/ r (cos b))) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.059) || !(b <= 4.2e-13)) {
tmp = sin(b) * (r / 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 <= (-0.059d0)) .or. (.not. (b <= 4.2d-13))) then
tmp = sin(b) * (r / 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 <= -0.059) || !(b <= 4.2e-13)) {
tmp = Math.sin(b) * (r / Math.cos(b));
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.059) or not (b <= 4.2e-13): tmp = math.sin(b) * (r / math.cos(b)) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.059) || !(b <= 4.2e-13)) tmp = Float64(sin(b) * Float64(r / 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 <= -0.059) || ~((b <= 4.2e-13))) tmp = sin(b) * (r / cos(b)); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.059], N[Not[LessEqual[b, 4.2e-13]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * N[(r / 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 -0.059 \lor \neg \left(b \leq 4.2 \cdot 10^{-13}\right):\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -0.058999999999999997 or 4.19999999999999977e-13 < b Initial program 53.1%
*-commutative53.1%
associate-/l*53.1%
+-commutative53.1%
Simplified53.1%
Taylor expanded in a around 0 52.9%
associate-/l*52.9%
associate-/r/53.0%
Simplified53.0%
if -0.058999999999999997 < b < 4.19999999999999977e-13Initial program 98.8%
*-commutative98.8%
associate-/l*98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around 0 98.8%
associate-/l*98.7%
associate-/r/98.8%
Simplified98.8%
Final simplification76.8%
(FPCore (r a b) :precision binary64 (if (or (<= a -3200.0) (not (<= a 6.8e-5))) (* r (/ (sin b) (cos a))) (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -3200.0) || !(a <= 6.8e-5)) {
tmp = r * (sin(b) / cos(a));
} else {
tmp = sin(b) * (r / cos(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 <= (-3200.0d0)) .or. (.not. (a <= 6.8d-5))) then
tmp = r * (sin(b) / cos(a))
else
tmp = sin(b) * (r / cos(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -3200.0) || !(a <= 6.8e-5)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -3200.0) or not (a <= 6.8e-5): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -3200.0) || !(a <= 6.8e-5)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(sin(b) * Float64(r / cos(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -3200.0) || ~((a <= 6.8e-5))) tmp = r * (sin(b) / cos(a)); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -3200.0], N[Not[LessEqual[a, 6.8e-5]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3200 \lor \neg \left(a \leq 6.8 \cdot 10^{-5}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if a < -3200 or 6.7999999999999999e-5 < a Initial program 56.2%
+-commutative56.2%
Simplified56.2%
add-exp-log33.4%
*-commutative33.4%
Applied egg-rr33.4%
add-exp-log24.2%
add-exp-log34.9%
Applied egg-rr34.9%
Taylor expanded in b around 0 35.4%
Taylor expanded in b around inf 56.6%
*-commutative56.6%
associate-/l*56.6%
associate-/r/56.6%
Simplified56.6%
if -3200 < a < 6.7999999999999999e-5Initial program 98.6%
*-commutative98.6%
associate-/l*98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in a around 0 98.6%
associate-/l*98.4%
associate-/r/98.6%
Simplified98.6%
Final simplification77.1%
(FPCore (r a b) :precision binary64 (if (<= a -3200.0) (/ r (/ (cos a) (sin b))) (if (<= a 5.2e-5) (* (sin b) (/ r (cos b))) (* r (/ (sin b) (cos a))))))
double code(double r, double a, double b) {
double tmp;
if (a <= -3200.0) {
tmp = r / (cos(a) / sin(b));
} else if (a <= 5.2e-5) {
tmp = sin(b) * (r / 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 (a <= (-3200.0d0)) then
tmp = r / (cos(a) / sin(b))
else if (a <= 5.2d-5) then
tmp = sin(b) * (r / 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 (a <= -3200.0) {
tmp = r / (Math.cos(a) / Math.sin(b));
} else if (a <= 5.2e-5) {
tmp = Math.sin(b) * (r / Math.cos(b));
} else {
tmp = r * (Math.sin(b) / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if a <= -3200.0: tmp = r / (math.cos(a) / math.sin(b)) elif a <= 5.2e-5: tmp = math.sin(b) * (r / math.cos(b)) else: tmp = r * (math.sin(b) / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if (a <= -3200.0) tmp = Float64(r / Float64(cos(a) / sin(b))); elseif (a <= 5.2e-5) tmp = Float64(sin(b) * Float64(r / 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 (a <= -3200.0) tmp = r / (cos(a) / sin(b)); elseif (a <= 5.2e-5) tmp = sin(b) * (r / cos(b)); else tmp = r * (sin(b) / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[a, -3200.0], N[(r / N[(N[Cos[a], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 5.2e-5], N[(N[Sin[b], $MachinePrecision] * N[(r / 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}\;a \leq -3200:\\
\;\;\;\;\frac{r}{\frac{\cos a}{\sin b}}\\
\mathbf{elif}\;a \leq 5.2 \cdot 10^{-5}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\end{array}
\end{array}
if a < -3200Initial program 56.9%
+-commutative56.9%
Simplified56.9%
add-exp-log40.9%
*-commutative40.9%
Applied egg-rr40.9%
add-exp-log31.9%
add-exp-log37.3%
Applied egg-rr37.3%
Taylor expanded in b around 0 37.8%
Taylor expanded in b around inf 56.9%
associate-/l*57.0%
Simplified57.0%
if -3200 < a < 5.19999999999999968e-5Initial program 98.6%
*-commutative98.6%
associate-/l*98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in a around 0 98.6%
associate-/l*98.4%
associate-/r/98.6%
Simplified98.6%
if 5.19999999999999968e-5 < a Initial program 55.6%
+-commutative55.6%
Simplified55.6%
add-exp-log27.1%
*-commutative27.1%
Applied egg-rr27.1%
add-exp-log17.7%
add-exp-log32.9%
Applied egg-rr32.9%
Taylor expanded in b around 0 33.3%
Taylor expanded in b around inf 56.3%
*-commutative56.3%
associate-/l*56.4%
associate-/r/56.4%
Simplified56.4%
Final simplification77.1%
(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}
Initial program 76.9%
*-commutative76.9%
associate-/l*76.8%
+-commutative76.8%
Simplified76.8%
clear-num76.5%
associate-/r/76.8%
clear-num76.9%
Applied egg-rr76.9%
Final simplification76.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 76.9%
*-commutative76.9%
associate-/l*76.8%
+-commutative76.8%
Simplified76.8%
associate-/r/76.9%
Applied egg-rr76.9%
Final simplification76.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -11500000000.0) (not (<= b 1.95))) (* (sin b) r) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -11500000000.0) || !(b <= 1.95)) {
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 <= (-11500000000.0d0)) .or. (.not. (b <= 1.95d0))) 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 <= -11500000000.0) || !(b <= 1.95)) {
tmp = Math.sin(b) * r;
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -11500000000.0) or not (b <= 1.95): tmp = math.sin(b) * r else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -11500000000.0) || !(b <= 1.95)) 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 <= -11500000000.0) || ~((b <= 1.95))) tmp = sin(b) * r; else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -11500000000.0], N[Not[LessEqual[b, 1.95]], $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 -11500000000 \lor \neg \left(b \leq 1.95\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -1.15e10 or 1.94999999999999996 < b Initial program 51.6%
+-commutative51.6%
Simplified51.6%
add-exp-log22.1%
*-commutative22.1%
Applied egg-rr22.1%
add-exp-log12.5%
add-exp-log22.0%
Applied egg-rr22.0%
Taylor expanded in b around 0 5.9%
Taylor expanded in a around 0 12.8%
if -1.15e10 < b < 1.94999999999999996Initial program 98.4%
*-commutative98.4%
associate-/l*98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in b around 0 97.6%
associate-/l*97.4%
associate-/r/97.6%
Simplified97.6%
Final simplification58.5%
(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}
Initial program 76.9%
+-commutative76.9%
Simplified76.9%
add-exp-log42.3%
*-commutative42.3%
Applied egg-rr42.3%
add-exp-log33.8%
add-exp-log43.1%
Applied egg-rr43.1%
Taylor expanded in b around 0 35.6%
Taylor expanded in a around 0 41.9%
Final simplification41.9%
(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 76.9%
*-commutative76.9%
associate-/l*76.8%
+-commutative76.8%
Simplified76.8%
Taylor expanded in b around 0 54.3%
associate-/l*54.3%
associate-/r/54.3%
Simplified54.3%
Taylor expanded in a around 0 37.7%
*-commutative37.7%
Simplified37.7%
Final simplification37.7%
herbie shell --seed 2023271
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))