def integrate_rectangle(function, xmin, xmax, intervals):
    """ Integrate by using the rectangle rule."""
    dx = (xmax - xmin) / intervals
    total = 0

    # Perform the integration.
    x = xmin
    for interval in range(intervals):
        # Add the area in the rectangle for this slice.
        total += dx * function(x)

        # Move to the next slice.
        x += dx

    return total