# 12.5 Operations for Rationals

`q1 + q2`
`q1 - q2`
`q1 * q2`
`q1 / q2`

The operators `+`, `-`, `*` and `/` evaluate to the sum, difference, product, and quotient of the two rationals q1 and q2. For the quotient `/` q2 must of course be nonzero, otherwise an error is signalled. Either operand may also be an integer i, which is interpreted as a rational with denominator 1. The result of those operations is always reduced. If, after the reduction, the denominator is 1, the rational is in fact an integer, and is represented as such.

```    gap> 2/3 + 4/5;
22/15
gap> 7/6 * 2/3;
7/9    # note how the result is cancelled
gap> 67/6 - 1/6;
11    # the result is an integer ```

`q ^ i`

The powering operator `^` returns the i-th power of the rational q. i must be an integer. If the exponent i is zero, `q^i` is defined as 1; if i is positive, `q^i` is defined as the i-fold product `q*q*..*q`; finally, if i is negative, `q^i` is defined as `(1/q)^-i`. In this case q must of course be nonzero.

```    gap> (2/3) ^ 3;
8/27
gap> (-17/13) ^ -1;
-13/17    # note how the sign switched
gap> (1/2) ^ -2;
4 ```

GAP 3.4.4
April 1997