
(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 (/ (* r (sin b)) (fma (cos b) (cos a) (- (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(b), cos(a), -(sin(b) * sin(a)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(b), cos(a), Float64(-Float64(sin(b) * sin(a))))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + (-N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, -\sin b \cdot \sin a\right)}
\end{array}
Initial program 76.4%
+-commutative76.4%
Simplified76.4%
cos-sum99.5%
fma-neg99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (* r (/ 1.0 (- (/ (cos a) (tan b)) (sin a)))))
double code(double r, double a, double b) {
return r * (1.0 / ((cos(a) / tan(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 * (1.0d0 / ((cos(a) / tan(b)) - sin(a)))
end function
public static double code(double r, double a, double b) {
return r * (1.0 / ((Math.cos(a) / Math.tan(b)) - Math.sin(a)));
}
def code(r, a, b): return r * (1.0 / ((math.cos(a) / math.tan(b)) - math.sin(a)))
function code(r, a, b) return Float64(r * Float64(1.0 / Float64(Float64(cos(a) / tan(b)) - sin(a)))) end
function tmp = code(r, a, b) tmp = r * (1.0 / ((cos(a) / tan(b)) - sin(a))); end
code[r_, a_, b_] := N[(r * N[(1.0 / N[(N[(N[Cos[a], $MachinePrecision] / N[Tan[b], $MachinePrecision]), $MachinePrecision] - N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{1}{\frac{\cos a}{\tan b} - \sin a}
\end{array}
Initial program 76.4%
associate-/l*76.3%
+-commutative76.3%
Simplified76.3%
cos-sum99.5%
Applied egg-rr99.4%
div-sub99.4%
sub-neg99.4%
*-commutative99.4%
*-un-lft-identity99.4%
times-frac99.3%
clear-num99.3%
quot-tan99.4%
Applied egg-rr99.4%
sub-neg99.4%
/-rgt-identity99.4%
associate-*r/99.4%
*-rgt-identity99.4%
associate-/l*99.4%
Simplified99.4%
div-inv99.5%
associate-/r/99.5%
pow199.5%
pow199.5%
pow-div99.5%
metadata-eval99.5%
metadata-eval99.5%
*-un-lft-identity99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (/ r (- (/ (cos a) (tan b)) (sin a))))
double code(double r, double a, double b) {
return r / ((cos(a) / tan(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 / ((cos(a) / tan(b)) - sin(a))
end function
public static double code(double r, double a, double b) {
return r / ((Math.cos(a) / Math.tan(b)) - Math.sin(a));
}
def code(r, a, b): return r / ((math.cos(a) / math.tan(b)) - math.sin(a))
function code(r, a, b) return Float64(r / Float64(Float64(cos(a) / tan(b)) - sin(a))) end
function tmp = code(r, a, b) tmp = r / ((cos(a) / tan(b)) - sin(a)); end
code[r_, a_, b_] := N[(r / N[(N[(N[Cos[a], $MachinePrecision] / N[Tan[b], $MachinePrecision]), $MachinePrecision] - N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\frac{\cos a}{\tan b} - \sin a}
\end{array}
Initial program 76.4%
associate-/l*76.3%
+-commutative76.3%
Simplified76.3%
cos-sum99.5%
Applied egg-rr99.4%
div-sub99.4%
sub-neg99.4%
*-commutative99.4%
*-un-lft-identity99.4%
times-frac99.3%
clear-num99.3%
quot-tan99.4%
Applied egg-rr99.4%
sub-neg99.4%
/-rgt-identity99.4%
associate-*r/99.4%
*-rgt-identity99.4%
associate-/l*99.4%
Simplified99.4%
Taylor expanded in b around 0 99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (* (tan b) (/ r (cos a))))
double code(double r, double a, double b) {
return tan(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 = tan(b) * (r / cos(a))
end function
public static double code(double r, double a, double b) {
return Math.tan(b) * (r / Math.cos(a));
}
def code(r, a, b): return math.tan(b) * (r / math.cos(a))
function code(r, a, b) return Float64(tan(b) * Float64(r / cos(a))) end
function tmp = code(r, a, b) tmp = tan(b) * (r / cos(a)); end
code[r_, a_, b_] := N[(N[Tan[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan b \cdot \frac{r}{\cos a}
\end{array}
Initial program 76.4%
+-commutative76.4%
Simplified76.4%
cos-sum99.5%
Applied egg-rr99.5%
sin-mult77.5%
cos-sum78.0%
div-sub78.0%
cos-diff99.4%
add-sqr-sqrt55.6%
sqrt-unprod87.8%
sqr-neg87.8%
sqrt-unprod48.2%
add-sqr-sqrt77.5%
sub-neg77.5%
cos-sum78.2%
cos-sum77.5%
Applied egg-rr77.5%
+-inverses77.5%
Simplified77.5%
expm1-log1p-u67.4%
expm1-udef27.2%
*-commutative27.2%
--rgt-identity27.2%
times-frac27.2%
tan-quot27.2%
Applied egg-rr27.2%
expm1-def67.4%
expm1-log1p77.6%
*-commutative77.6%
Simplified77.6%
Final simplification77.6%
(FPCore (r a b) :precision binary64 (if (or (<= b -4.8e-6) (not (<= b 1.65e-38))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -4.8e-6) || !(b <= 1.65e-38)) {
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 <= (-4.8d-6)) .or. (.not. (b <= 1.65d-38))) 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 <= -4.8e-6) || !(b <= 1.65e-38)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -4.8e-6) or not (b <= 1.65e-38): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -4.8e-6) || !(b <= 1.65e-38)) 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 <= -4.8e-6) || ~((b <= 1.65e-38))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -4.8e-6], N[Not[LessEqual[b, 1.65e-38]], $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 -4.8 \cdot 10^{-6} \lor \neg \left(b \leq 1.65 \cdot 10^{-38}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -4.7999999999999998e-6 or 1.6500000000000001e-38 < b Initial program 54.4%
associate-/l*54.3%
+-commutative54.3%
Simplified54.3%
Taylor expanded in a around 0 54.9%
associate-/l*54.8%
associate-/r/54.9%
Simplified54.9%
expm1-log1p-u41.4%
expm1-udef19.0%
associate-*l/19.0%
*-un-lft-identity19.0%
times-frac19.0%
tan-quot19.0%
Applied egg-rr19.0%
expm1-def41.4%
expm1-log1p54.9%
/-rgt-identity54.9%
Simplified54.9%
if -4.7999999999999998e-6 < b < 1.6500000000000001e-38Initial program 99.8%
+-commutative99.8%
Simplified99.8%
cos-sum99.8%
fma-neg99.8%
Applied egg-rr99.8%
Taylor expanded in b around 0 99.8%
*-commutative99.8%
associate-*r/99.8%
Simplified99.8%
Final simplification76.7%
(FPCore (r a b) :precision binary64 (if (or (<= b -9.5e-7) (not (<= b 1.65e-38))) (* r (tan b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -9.5e-7) || !(b <= 1.65e-38)) {
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 <= (-9.5d-7)) .or. (.not. (b <= 1.65d-38))) 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 <= -9.5e-7) || !(b <= 1.65e-38)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -9.5e-7) or not (b <= 1.65e-38): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -9.5e-7) || !(b <= 1.65e-38)) 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 <= -9.5e-7) || ~((b <= 1.65e-38))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -9.5e-7], N[Not[LessEqual[b, 1.65e-38]], $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 -9.5 \cdot 10^{-7} \lor \neg \left(b \leq 1.65 \cdot 10^{-38}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -9.5000000000000001e-7 or 1.6500000000000001e-38 < b Initial program 54.4%
associate-/l*54.3%
+-commutative54.3%
Simplified54.3%
Taylor expanded in a around 0 54.9%
associate-/l*54.8%
associate-/r/54.9%
Simplified54.9%
expm1-log1p-u41.4%
expm1-udef19.0%
associate-*l/19.0%
*-un-lft-identity19.0%
times-frac19.0%
tan-quot19.0%
Applied egg-rr19.0%
expm1-def41.4%
expm1-log1p54.9%
/-rgt-identity54.9%
Simplified54.9%
if -9.5000000000000001e-7 < b < 1.6500000000000001e-38Initial program 99.8%
associate-/l*99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in b around 0 99.6%
associate-/r/99.8%
Applied egg-rr99.8%
Final simplification76.7%
(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 76.4%
associate-/l*76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in a around 0 62.0%
associate-/l*61.9%
associate-/r/62.0%
Simplified62.0%
Taylor expanded in b around 0 41.1%
Final simplification41.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 76.4%
associate-/l*76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in a around 0 62.0%
associate-/l*61.9%
associate-/r/62.0%
Simplified62.0%
expm1-log1p-u53.3%
expm1-udef24.5%
associate-*l/24.5%
*-un-lft-identity24.5%
times-frac24.5%
tan-quot24.5%
Applied egg-rr24.5%
expm1-def53.3%
expm1-log1p62.1%
/-rgt-identity62.1%
Simplified62.1%
Final simplification62.1%
(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 76.4%
associate-/l*76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in b around 0 51.8%
Taylor expanded in a around 0 37.6%
*-commutative37.6%
Simplified37.6%
Final simplification37.6%
herbie shell --seed 2023310
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))