# Fractions and Binomials

Using fractions and binomial coefficients in an expression is straightforward.

```
The binomial coefficient is defined by the next expression:

\[
    \binom{n}{k} = \frac{n!}{k!(n-k)!}
\]
```

![FractionsBinomialEx1edit.PNG](https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/a/ab/FractionsBinomialEx1edit.PNG)

For these commands to work you must import the package **amsmath** by adding the next line to the preamble of your file

```
\usepackage{amsmath}
```

### Displaying fractions

The appearance of the fraction may change depending on the context

```
Fractions can be used alongside the text, for 
example \( \frac{1}{2} \), and in a mathematical 
display style like the one below:

\[\frac{1}{2}\]
```

![FractionsBinomialsEx2.png](https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/b/b5/FractionsBinomialsEx2.png)

As you may have guessed, the command `\frac{1}{2}` is the one that displays the fraction. The text inside the first pair of braces is the numerator and the text inside the second pair is the denominator.

Also, the text size of the fraction changes according to the text around it. You can set this manually if you want.

```
When displaying fractions in-line, for example \(\frac{3x}{2}\) 
you can set a different display style: 
\( \displaystyle \frac{3x}{2} \).

This is also true the other way around

\[ f(x)=\frac{P(x)}{Q(x)} \ \ \textrm{and} 
\ \ f(x)=\textstyle\frac{P(x)}{Q(x)} \]
```

![FractionsBinomialsEx3.png](https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/b/bf/FractionsBinomialsEx3.png)

The command `\displaystyle` will format the fraction as if it were in mathematical display mode. On the other side, `\textstyle` will change the style of the fraction as if it were part of the text.

### Continued fractions

The usage of fractions is quite flexible, they can be nested to obtain more complex expressions.

```
The fractions can be nested

\[ \frac{1+\frac{a}{b}}{1+\frac{1}{1+\frac{1}{a}}} \]

Now a wild example

\[
  a_0+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}
\]
```

![FractionsBinomialsEx4.png](https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/2/26/FractionsBinomialsEx4.png)

The second fraction displayed in the previous example uses the command `\cfrac{}{}` provided by the package **amsmath** (see the [introduction](https://www.overleaf.com/learn/latex/Fractions_and_Binomials#Introduction)), this command displays nested fractions without changing the size of the font. Specially useful for continued fractions.

### Binomial coefficients

Binomial coefficients are common elements in mathematical expressions, the command to display them in LATEX is very similar to the one used for fractions.

```
The binomial coefficient is defined by the next expression:

\[
    \binom{n}{k} = \frac{n!}{k!(n-k)!}
\]

And of course this command can be included in the normal 
text flow \(\binom{n}{k}\).
```

![](https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/0/0d/FractionsBinomialsEx5.png)

As you see, the command `\binom{}{}` will print the binomial coefficient using the parameters passed inside the braces.

### Reference guide

**A slightly different and more complex example of continued fractions**

```
Final example

\newcommand*{\contfrac}[2]{%
{
  \rlap{$\dfrac{1}{\phantom{#1}}$}%
  \genfrac{}{}{0pt}{0}{}{#1+#2}%
}
}
\[
  a_0 +
  \contfrac{a_1}{
  \contfrac{a_2}{
  \contfrac{a_3}{
  \genfrac{}{}{0pt}{0}{}{\ddots}
  }}}
\]
```

![FractionsBinomialsEx6.png](https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/e/ea/FractionsBinomialsEx6.png)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://marlborough-college.gitbook.io/attic-lab/latex/mathematics/fractions-and-binomials.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
