Sixth Task

Our sixth 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 two lists of integers as input and produces a list of integers as output. They specify the function f as follows :

Specification


f([10, 11, 8], [1, 7, 5]) = [9, 4, 3]

The user intends to synthesize a program f which subtracts two lists of integers. 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.


import functools
import operator

def f(i1, i2):
  return g1(i1, operator.sub, i2) f([10, 11, 8], [1, 7, 5]) = [9, 4, 3]


def g1(i1, i2, i3):
  def aux1(i4):
    return i2(g2(i4, i1), g2(i4, i3))
  return list(map(aux1, range(g3(i1)))) g1([10, 11, 8], operator.sub, [1, 7, 5]) = [9, 4, 3]


def g2(i1, i2):
  def aux2(i3, i4):
    return i3[1:]
  return functools.reduce(aux2, range(i1), i2)[0] g2(0, [10, 11, 8]) - g2(0, [1, 7, 5]) = 9
g2(1, [10, 11, 8]) - g2(1, [1, 7, 5]) = 4
g2(2, [10, 11, 8]) - g2(2, [1, 7, 5]) = 3


def g3(i1):
  def aux3(i2, i3):
    return i2+1
  return functools.reduce(aux3, i1, 0) g3([10, 11, 8]) = 3