
(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 77.9%
*-commutative77.9%
associate-/l*77.9%
+-commutative77.9%
Simplified77.9%
associate-/r/78.0%
Applied egg-rr78.0%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.00066) (not (<= a 1.15e-14))) (* (sin b) (/ r (cos a))) (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00066) || !(a <= 1.15e-14)) {
tmp = sin(b) * (r / 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 <= (-0.00066d0)) .or. (.not. (a <= 1.15d-14))) then
tmp = sin(b) * (r / 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 <= -0.00066) || !(a <= 1.15e-14)) {
tmp = Math.sin(b) * (r / Math.cos(a));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -0.00066) or not (a <= 1.15e-14): tmp = math.sin(b) * (r / math.cos(a)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -0.00066) || !(a <= 1.15e-14)) tmp = Float64(sin(b) * Float64(r / 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 <= -0.00066) || ~((a <= 1.15e-14))) tmp = sin(b) * (r / cos(a)); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00066], N[Not[LessEqual[a, 1.15e-14]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * N[(r / 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 -0.00066 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\
\;\;\;\;\sin b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if a < -6.6e-4 or 1.14999999999999999e-14 < a Initial program 58.7%
*-commutative58.7%
associate-/l*58.8%
+-commutative58.8%
Simplified58.8%
add-exp-log25.9%
Applied egg-rr25.9%
div-inv25.9%
add-exp-log58.6%
Applied egg-rr58.6%
Taylor expanded in b around 0 58.7%
if -6.6e-4 < a < 1.14999999999999999e-14Initial program 98.7%
*-commutative98.7%
associate-/l*98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in a around 0 98.6%
associate-/l*98.5%
associate-/r/98.7%
Simplified98.7%
Final simplification77.9%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.00136) (not (<= a 1.15e-14))) (/ (sin b) (/ (cos a) r)) (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00136) || !(a <= 1.15e-14)) {
tmp = sin(b) / (cos(a) / r);
} 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 <= (-0.00136d0)) .or. (.not. (a <= 1.15d-14))) then
tmp = sin(b) / (cos(a) / r)
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 <= -0.00136) || !(a <= 1.15e-14)) {
tmp = Math.sin(b) / (Math.cos(a) / r);
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -0.00136) or not (a <= 1.15e-14): tmp = math.sin(b) / (math.cos(a) / r) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -0.00136) || !(a <= 1.15e-14)) tmp = Float64(sin(b) / Float64(cos(a) / r)); 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 <= -0.00136) || ~((a <= 1.15e-14))) tmp = sin(b) / (cos(a) / r); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00136], N[Not[LessEqual[a, 1.15e-14]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] / r), $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 -0.00136 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\
\;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if a < -0.00136 or 1.14999999999999999e-14 < a Initial program 58.7%
*-commutative58.7%
associate-/l*58.8%
+-commutative58.8%
Simplified58.8%
Taylor expanded in b around 0 58.7%
if -0.00136 < a < 1.14999999999999999e-14Initial program 98.7%
*-commutative98.7%
associate-/l*98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in a around 0 98.6%
associate-/l*98.5%
associate-/r/98.7%
Simplified98.7%
Final simplification77.9%
(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 77.9%
*-commutative77.9%
associate-/l*77.9%
+-commutative77.9%
Simplified77.9%
clear-num77.3%
associate-/r/77.8%
clear-num78.0%
Applied egg-rr78.0%
Final simplification78.0%
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos a))))
double code(double r, double a, double b) {
return sin(b) * (r / 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 = sin(b) * (r / cos(a))
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * (r / Math.cos(a));
}
def code(r, a, b): return math.sin(b) * (r / math.cos(a))
function code(r, a, b) return Float64(sin(b) * Float64(r / cos(a))) end
function tmp = code(r, a, b) tmp = sin(b) * (r / cos(a)); end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot \frac{r}{\cos a}
\end{array}
Initial program 77.9%
*-commutative77.9%
associate-/l*77.9%
+-commutative77.9%
Simplified77.9%
add-exp-log35.2%
Applied egg-rr35.2%
div-inv35.2%
add-exp-log77.8%
Applied egg-rr77.8%
Taylor expanded in b around 0 55.8%
Final simplification55.8%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.68) (not (<= b 9200000.0))) (* (sin b) r) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.68) || !(b <= 9200000.0)) {
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 <= (-0.68d0)) .or. (.not. (b <= 9200000.0d0))) 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 <= -0.68) || !(b <= 9200000.0)) {
tmp = Math.sin(b) * r;
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.68) or not (b <= 9200000.0): tmp = math.sin(b) * r else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.68) || !(b <= 9200000.0)) 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 <= -0.68) || ~((b <= 9200000.0))) tmp = sin(b) * r; else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.68], N[Not[LessEqual[b, 9200000.0]], $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 -0.68 \lor \neg \left(b \leq 9200000\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -0.680000000000000049 or 9.2e6 < b Initial program 55.7%
*-commutative55.7%
associate-/l*55.7%
+-commutative55.7%
Simplified55.7%
add-exp-log26.8%
Applied egg-rr26.8%
Taylor expanded in b around 0 5.8%
+-commutative5.8%
mul-1-neg5.8%
unsub-neg5.8%
associate-/l*6.1%
Simplified6.1%
Taylor expanded in a around 0 11.1%
*-commutative11.1%
Simplified11.1%
if -0.680000000000000049 < b < 9.2e6Initial program 98.8%
*-commutative98.8%
associate-/l*98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in b around 0 97.6%
associate-/l*97.5%
associate-/r/97.6%
Simplified97.6%
Final simplification55.7%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.68) (not (<= b 9200000.0))) (* (sin b) r) (/ (* b r) (cos a))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.68) || !(b <= 9200000.0)) {
tmp = sin(b) * r;
} 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 <= (-0.68d0)) .or. (.not. (b <= 9200000.0d0))) then
tmp = sin(b) * r
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 <= -0.68) || !(b <= 9200000.0)) {
tmp = Math.sin(b) * r;
} else {
tmp = (b * r) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.68) or not (b <= 9200000.0): tmp = math.sin(b) * r else: tmp = (b * r) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.68) || !(b <= 9200000.0)) tmp = Float64(sin(b) * r); else tmp = Float64(Float64(b * r) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -0.68) || ~((b <= 9200000.0))) tmp = sin(b) * r; else tmp = (b * r) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.68], N[Not[LessEqual[b, 9200000.0]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(b * r), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot r}{\cos a}\\
\end{array}
\end{array}
if b < -0.680000000000000049 or 9.2e6 < b Initial program 55.7%
*-commutative55.7%
associate-/l*55.7%
+-commutative55.7%
Simplified55.7%
add-exp-log26.8%
Applied egg-rr26.8%
Taylor expanded in b around 0 5.8%
+-commutative5.8%
mul-1-neg5.8%
unsub-neg5.8%
associate-/l*6.1%
Simplified6.1%
Taylor expanded in a around 0 11.1%
*-commutative11.1%
Simplified11.1%
if -0.680000000000000049 < b < 9.2e6Initial program 98.8%
*-commutative98.8%
associate-/l*98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in b around 0 97.6%
Final simplification55.7%
(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 77.9%
*-commutative77.9%
associate-/l*77.9%
+-commutative77.9%
Simplified77.9%
add-exp-log35.2%
Applied egg-rr35.2%
Taylor expanded in b around 0 53.2%
+-commutative53.2%
mul-1-neg53.2%
unsub-neg53.2%
associate-/l*53.4%
Simplified53.4%
Taylor expanded in a around 0 37.4%
*-commutative37.4%
Simplified37.4%
Final simplification37.4%
(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 77.9%
*-commutative77.9%
associate-/l*77.9%
+-commutative77.9%
Simplified77.9%
Taylor expanded in b around 0 52.0%
associate-/l*51.9%
associate-/r/52.0%
Simplified52.0%
Taylor expanded in a around 0 33.8%
*-commutative33.8%
Simplified33.8%
Final simplification33.8%
herbie shell --seed 2023279
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))