Fifth Task

Our fifth task will be in the context of programming-by-example, a popular application of program synthesis. Feel free to consult with any resources.

Say the user wishes to synthesize a function f which accepts a list of integers as input and produces a list of integers as output. They specify the function f as follows :

Specification


f([9, 2, 7, 1]) = [1, 2, 7, 9]

The user intends to synthesize a program f which sorts the input list of integers in ascending order. In response, the synthesizer produces the following python code :

Implementation


def f(i1):
  def aux1(i2):
    return g1(i1, i2+1)
  return list(map(aux1, range(len(i1))))


def g1(i1, i2):
  def aux2(i3):
    def aux3(i4):
      return i3>i4
    return i2>len(list(filter(aux3, i1)))
  return g2(list(filter(aux2, i1)))


def g2(i1):
  def aux4(i2):
    def aux5(i3):
      return i2 < i3
    return len(list(filter(aux5, i1)))==0
  return list(filter(aux4, i1))[0]