<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def octaves(freq, fmin=20., fmax=2e4):
 """ Given a frequency and a frequency range, returns all frequencies in that range that is an integer number of octaves related to the given frequency. Parameters freq : Frequency, in any (linear) unit. fmin, fmax : Frequency range, in the same unit of ``freq``. Defaults to 20.0 and 20,000.0, respectively. Returns ------- A list of frequencies, in the same unit of ``freq`` and in ascending order. Examples -------- [27.5, 55.0, 110.0, 220.0, 440.0, 880.0, 1760.0, 3520.0, 7040.0, 14080.0] [3520.0, 7040.0, 14080.0] 2 [0.062689, 0.125379] [440.0, 880.0] """

  # Input validation
  if any(f <= 0 for f in (freq, fmin, fmax)):
    raise ValueError("Frequencies have to be positive")

  # If freq is out of range, avoid range extension
  while freq < fmin:
    freq *= 2
  while freq > fmax:
    freq /= 2
  if freq < fmin: # Gone back and forth
    return []

  # Finds the range for a valid input
  return list(it.takewhile(lambda x: x > fmin,
                           (freq * 2 ** harm for harm in it.count(0, -1))
                          ))[::-1] \
       + list(it.takewhile(lambda x: x < fmax,
                           (freq * 2 ** harm for harm in it.count(1))
                          ))