Fourth Task

Our fourth task will be in the context of programming-by-example, a popular application of program synthesis. For this task, you will not have access to sub-specifications.


In addition, we reproduce the definitions of strat and substr as used in SMT-LIB :

1- string strat(string s, int i) : Singleton string containing a character at given position or empty string when position is out of range. The leftmost position is 0.

2- string substr(string s, int i, int n) : It evaluates to the longest substring of s of length at most n starting at position i. It evaluates to the empty string if n is negative or i is not in the interval [0,l-1] where l is the length of s.

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

Specification


f("Ducati100")="Ducati"f("Honda125")="Honda"
f("Ducati125")="Ducati"f("Honda250")="Honda"
f("Ducati250")="Ducati"f("Honda550")="Honda"

In response, two different synthesizers produced the following two different implementations :

First Implementation


f(x)= substr(x, 0, 5)+strat(substr(x, 5, 4), 0)


Second Implementation


f(x)= substr(x, 0, len(substr(x, 4, 5)))+strat(x, len(substr(x, 4, 5)))


Question 2

Unfortunately, there is a bug in one of the implementations. Which implementation is buggy?

Question 3

Where is the bug?

  • First implementation
  • Second implementation