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. For this task, you have access to sub-specifications. Please feel free to use them.

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 and Sub-specifications

Please hover over different parts of the implementation to see the corresponding sub-specifications.


def f(i1):
  def aux1(i2):
    return g1(i1, i2+1)
  return list(map(aux1, range(len(i1)))) f([9, 2, 7, 1]) = [1, 2, 7, 9]


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))) g1([9, 2, 7, 1], 1) = 1
g1([9, 2, 7, 1], 2) = 2
g1([9, 2, 7, 1], 3) = 7
g1([9, 2, 7, 1], 4) = 9


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] g2([9, 2, 7, 1]) = 9
g2([2, 7, 1]) = 7
g2([2, 1]) = 2
g2([1]) = 1