From Applicative To Environmental Bisimulation Vasileios - - PowerPoint PPT Presentation

from applicative to environmental bisimulation
SMART_READER_LITE
LIVE PREVIEW

From Applicative To Environmental Bisimulation Vasileios - - PowerPoint PPT Presentation

From Applicative To Environmental Bisimulation Vasileios Koutavas Trinity College Dublin Joint work with Paul B. Levy and Eijiro Sumii QMUL Program Equivalence


slide-1
SLIDE 1

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Research ¡supported ¡in ¡part ¡by ¡SFI ¡projects ¡ ¡13/RC/2094 ¡& ¡06/IN.1/1898 ¡ ¡

From ¡Applicative ¡To ¡ ¡ Environmental ¡Bisimulation

Vasileios ¡Koutavas ¡ Trinity ¡College ¡Dublin ¡ Joint ¡work ¡with ¡Paul ¡B. ¡Levy ¡and ¡Eijiro ¡Sumii ¡

QMUL ¡Program ¡Equivalence ¡Workshop, ¡April ¡2016 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡based ¡on ¡[MFPS’11]

slide-2
SLIDE 2 // Project AthensCinemas // Â.ÊïõôáâÜò, Ã.ÐáðáìÜñêïò, Ä.Âõôéíéþôçò // Éïýíéïò 2000 // DOMRepresentation.java // Äçìéïõñãåß Ýíá áíôéêåßìåíï áðü XML êåßìåíï, êáé äéáèÝôåé // ìåèüäïõò ðïõ åðéóôñÝöïõí XML êåßìåíï áíÜëïãá ìå ôï query ðïõ Ý÷åé æçôçèåß import com.ibm.xml.parsers.*; import org.w3c.dom.*; import java.io.*; import org.xml.sax.*; import java.lang.*; import java.util.*; public class DOMRepresentation { private Document doc = null; private HttpEncodingParser encoder = null; // See HTTPEncodingParser.java public DOMRepresentation(BufferedReader is, HttpEncodingParser ServletEncoder) { try { DOMParser ps = new DOMParser(); ps.parse(new InputSource(is)); doc = ps.getDocument(); encoder = ServletEncoder; } catch(Exception e) { System.out.println("Error in constructor DOMRepresentation: "); System.out.println(e.getMessage()); } } } public String getAreaList() //ÅðéóôñÝöåé Ýíá XML String ìå üëåò ôéò ðåñéï÷Ýò ðïõ êáëýðôåé ç âÜóç ìáò { String str =""; NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0;i<AreaList.getLength() ;i++) { Element OneArea = (Element)AreaList.item(i); str += "<element>\r\n<name>" + OneArea.getAttribute("value").trim() + "</name>\r\n</element>\r\n"; } return str; } public String getCinemasByArea(String theArea) // ÅðéóôñÝöåé XML String ìå üëá ôá óéíåìÜ ìéáò ðåñéï÷Þò { String ret = ""; Element OneArea = null; theArea = theArea.trim(); NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0; i<AreaList.getLength(); i++) { OneArea = (Element)AreaList.item(i); if (theArea.equals(OneArea.getAttribute("value").trim())) break; //area found, exit for-loop } NodeList CinemaList = OneArea.getElementsByTagName("cinema"); for (int j=0;j<CinemaList.getLength() ;j++) { Element OneCinema = (Element)CinemaList.item(j); NodeList OneCinemaNameList = OneCinema.getElementsByTagName("name"); Element theName = (Element)OneCinemaNameList.item(0); String theNameText = getLeafText(theName) ; ret += "<element>\r\n<name>" + theNameText + "</name>\r\n</element>\r\n"; } return ret; } class Cell extends Object { private Object g1, g2; private int cnt; Cell() { g1 = null; g2 = null; cnt = 0; } public void set(Object b) { cnt = cnt + 1; if ((cnt % 2) == 0) g1 = b; else g2 = b; } public Object get() { if ((cnt % 2) == 0) return g1; else return g2; } }} public String getCinemaInfo(String theCinema) // ÅðéóôñÝöåé ðëçñïöïñßåò ãéá Ýíá óõãêåêñéìÝíï óéíåìÜ { String ret = ""; theCinema = theCinema.trim() ; Element OneCinema = null ; String nametext = null ; NodeList CinemaList = doc.getElementsByTagName("cinema") ; for (int i=0 ; i<CinemaList.getLength() ; i++ ) { OneCinema =(Element) CinemaList.item(i) ; NodeList NameList = OneCinema.getElementsByTagName("name") ; Element theName = (Element) NameList.item(0) ; nametext = getLeafText(theName) ; if (nametext.equals(theCinema)) break ; //theCinema found } ret = "<cinema>\r\n"; ret += "<name>" + nametext + "</name>\r\n" ; NodeList addr = OneCinema.getElementsByTagName("address") ; ret += "<address>" + getLeafText((Element)addr.item(0)) + "</address>\r\n" ; NodeList tick = OneCinema.getElementsByTagName("tickprice") ; ret += "<tickprice>" + getLeafText((Element)tick.item(0)) + "</tickprice>\r\n" ; NodeList cinemainfos = OneCinema.getElementsByTagName("movie"); for (int k=0; k<cinemainfos.getLength() ; k++) { ret += "<movie>\r\n"; Element inf =(Element) cinemainfos.item(k) ; NodeList title = inf.getElementsByTagName("title") ; String titleText = getLeafText((Element)title.item(0)); ret += "<title>" + titleText + "</title>\r\n" ; ret += "<title-param>" + encoder.EncodeString(titleText) + "</title-param>\r\n" ; NodeList ctg = inf.getElementsByTagName("category") ; ret += "<category>" + getLeafText((Element)ctg.item(0)) + "</category>\r\n" ; NodeList story = inf.getElementsByTagName("story") ; ret += "<story>" + getLeafText((Element)story.item(0)) + "</story>\r\n" ; NodeList actors = inf.getElementsByTagName("actors"); ret += "<actors>" + getLeafText((Element)actors.item(0)) + "</actors>\r\n" ; NodeList hour = inf.getElementsByTagName("hour") ; for (int l=0; l<hour.getLength() ; l++ ) ret += "<hour>" + getLeafText((Element)hour.item(l)) + "</hour>\r\n" ; NodeList room = inf.getElementsByTagName("room") ; ret += "<room>" + getLeafText((Element)room.item(0)) + "</room>\r\n" ; ret += "</movie>\r\n"; } ret += "</cinema>\r\n"; return ret; } // Project AthensCinemas // Â.ÊïõôáâÜò, Ã.ÐáðáìÜñêïò, Ä.Âõôéíéþôçò // Éïýíéïò 2000 // DOMRepresentation.java // Äçìéïõñãåß Ýíá áíôéêåßìåíï áðü XML êåßìåíï, êáé äéáèÝôåé // ìåèüäïõò ðïõ åðéóôñÝöïõí XML êåßìåíï áíÜëïãá ìå ôï query ðïõ Ý÷åé æçôçèåß import com.ibm.xml.parsers.*; import org.w3c.dom.*; import java.io.*; import org.xml.sax.*; import java.lang.*; import java.util.*; public class DOMRepresentation { private Document doc = null; private HttpEncodingParser encoder = null; // See HTTPEncodingParser.java public DOMRepresentation(BufferedReader is, HttpEncodingParser ServletEncoder) { try { DOMParser ps = new DOMParser(); ps.parse(new InputSource(is)); doc = ps.getDocument(); encoder = ServletEncoder; } catch(Exception e) { System.out.println("Error in constructor DOMRepresentation: "); System.out.println(e.getMessage()); } } } public String getAreaList() //ÅðéóôñÝöåé Ýíá XML String ìå üëåò ôéò ðåñéï÷Ýò ðïõ êáëýðôåé ç âÜóç ìáò { String str =""; NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0;i<AreaList.getLength() ;i++) { Element OneArea = (Element)AreaList.item(i); str += "<element>\r\n<name>" + OneArea.getAttribute("value").trim() + "</name>\r\n</element>\r\n"; } return str; } public String getCinemasByArea(String theArea) // ÅðéóôñÝöåé XML String ìå üëá ôá óéíåìÜ ìéáò ðåñéï÷Þò { String ret = ""; Element OneArea = null; theArea = theArea.trim(); NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0; i<AreaList.getLength(); i++) { OneArea = (Element)AreaList.item(i); if (theArea.equals(OneArea.getAttribute("value").trim())) break; //area found, exit for-loop } NodeList CinemaList = OneArea.getElementsByTagName("cinema"); for (int j=0;j<CinemaList.getLength() ;j++) { Element OneCinema = (Element)CinemaList.item(j); NodeList OneCinemaNameList = OneCinema.getElementsByTagName("name"); Element theName = (Element)OneCinemaNameList.item(0); String theNameText = getLeafText(theName) ; ret += "<element>\r\n<name>" + theNameText + "</name>\r\n</element>\r\n"; } return ret; } class Cell extends Object { private Object g1, g2; private int cnt; Cell() { g1 = null; g2 = null; cnt = 0; } public void set(Object b) { cnt = cnt + 1; if ((cnt % 2) == 0) g1 = b; else g2 = b; } public Object get() { if ((cnt % 2) == 0) return g1; else return g2; } }} public String getCinemaInfo(String theCinema) // ÅðéóôñÝöåé ðëçñïöïñßåò ãéá Ýíá óõãêåêñéìÝíï óéíåìÜ { String ret = ""; theCinema = theCinema.trim() ; Element OneCinema = null ; String nametext = null ; NodeList CinemaList = doc.getElementsByTagName("cinema") ; for (int i=0 ; i<CinemaList.getLength() ; i++ ) { OneCinema =(Element) CinemaList.item(i) ; NodeList NameList = OneCinema.getElementsByTagName("name") ; Element theName = (Element) NameList.item(0) ; nametext = getLeafText(theName) ; if (nametext.equals(theCinema)) break ; //theCinema found } ret = "<cinema>\r\n"; ret += "<name>" + nametext + "</name>\r\n" ; NodeList addr = OneCinema.getElementsByTagName("address") ; ret += "<address>" + getLeafText((Element)addr.item(0)) + "</address>\r\n" ; NodeList tick = OneCinema.getElementsByTagName("tickprice") ; ret += "<tickprice>" + getLeafText((Element)tick.item(0)) + "</tickprice>\r\n" ; NodeList cinemainfos = OneCinema.getElementsByTagName("movie"); for (int k=0; k<cinemainfos.getLength() ; k++) { ret += "<movie>\r\n"; Element inf =(Element) cinemainfos.item(k) ; NodeList title = inf.getElementsByTagName("title") ; String titleText = getLeafText((Element)title.item(0)); ret += "<title>" + titleText + "</title>\r\n" ; ret += "<title-param>" + encoder.EncodeString(titleText) + "</title-param>\r\n" ; NodeList ctg = inf.getElementsByTagName("category") ; ret += "<category>" + getLeafText((Element)ctg.item(0)) + "</category>\r\n" ; NodeList story = inf.getElementsByTagName("story") ; ret += "<story>" + getLeafText((Element)story.item(0)) + "</story>\r\n" ; NodeList actors = inf.getElementsByTagName("actors"); ret += "<actors>" + getLeafText((Element)actors.item(0)) + "</actors>\r\n" ; NodeList hour = inf.getElementsByTagName("hour") ; for (int l=0; l<hour.getLength() ; l++ ) ret += "<hour>" + getLeafText((Element)hour.item(l)) + "</hour>\r\n" ; NodeList room = inf.getElementsByTagName("room") ; ret += "<room>" + getLeafText((Element)room.item(0)) + "</room>\r\n" ; ret += "</movie>\r\n"; } ret += "</cinema>\r\n"; return ret; } // Project AthensCinemas // Â.ÊïõôáâÜò, Ã.ÐáðáìÜñêïò, Ä.Âõôéíéþôçò // Éïýíéïò 2000 // DOMRepresentation.java // Äçìéïõñãåß Ýíá áíôéêåßìåíï áðü XML êåßìåíï, êáé äéáèÝôåé // ìåèüäïõò ðïõ åðéóôñÝöïõí XML êåßìåíï áíÜëïãá ìå ôï query ðïõ Ý÷åé æçôçèåß import com.ibm.xml.parsers.*; import org.w3c.dom.*; import java.io.*; import org.xml.sax.*; import java.lang.*; import java.util.*; public class DOMRepresentation { private Document doc = null; private HttpEncodingParser encoder = null; // See HTTPEncodingParser.java public DOMRepresentation(BufferedReader is, HttpEncodingParser ServletEncoder) { try { DOMParser ps = new DOMParser(); ps.parse(new InputSource(is)); doc = ps.getDocument(); encoder = ServletEncoder; } catch(Exception e) { System.out.println("Error in constructor DOMRepresentation: "); System.out.println(e.getMessage()); } } } public String getAreaList() //ÅðéóôñÝöåé Ýíá XML String ìå üëåò ôéò ðåñéï÷Ýò ðïõ êáëýðôåé ç âÜóç ìáò { String str =""; NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0;i<AreaList.getLength() ;i++) { Element OneArea = (Element)AreaList.item(i); str += "<element>\r\n<name>" + OneArea.getAttribute("value").trim() + "</name>\r\n</element>\r\n"; } return str; } public String getCinemasByArea(String theArea) // ÅðéóôñÝöåé XML String ìå üëá ôá óéíåìÜ ìéáò ðåñéï÷Þò { String ret = ""; Element OneArea = null; theArea = theArea.trim(); NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0; i<AreaList.getLength(); i++) { OneArea = (Element)AreaList.item(i); if (theArea.equals(OneArea.getAttribute("value").trim())) break; //area found, exit for-loop } NodeList CinemaList = OneArea.getElementsByTagName("cinema"); for (int j=0;j<CinemaList.getLength() ;j++) { Element OneCinema = (Element)CinemaList.item(j); NodeList OneCinemaNameList = OneCinema.getElementsByTagName("name"); Element theName = (Element)OneCinemaNameList.item(0); String theNameText = getLeafText(theName) ; ret += "<element>\r\n<name>" + theNameText + "</name>\r\n</element>\r\n"; } return ret; } class Cell extends Object { private Object g; Cell() { g = null; } public void set(Object b) { g = b; } public Object get() { return g; } } public String getCinemaInfo(String theCinema) // ÅðéóôñÝöåé ðëçñïöïñßåò ãéá Ýíá óõãêåêñéìÝíï óéíåìÜ { String ret = ""; theCinema = theCinema.trim() ; Element OneCinema = null ; String nametext = null ; NodeList CinemaList = doc.getElementsByTagName("cinema") ; for (int i=0 ; i<CinemaList.getLength() ; i++ ) { OneCinema =(Element) CinemaList.item(i) ; NodeList NameList = OneCinema.getElementsByTagName("name") ; Element theName = (Element) NameList.item(0) ; nametext = getLeafText(theName) ; if (nametext.equals(theCinema)) break ; //theCinema found } ret = "<cinema>\r\n"; ret += "<name>" + nametext + "</name>\r\n" ; NodeList addr = OneCinema.getElementsByTagName("address") ; ret += "<address>" + getLeafText((Element)addr.item(0)) + "</address>\r\n" ; NodeList tick = OneCinema.getElementsByTagName("tickprice") ; ret += "<tickprice>" + getLeafText((Element)tick.item(0)) + "</tickprice>\r\n" ; NodeList cinemainfos = OneCinema.getElementsByTagName("movie"); for (int k=0; k<cinemainfos.getLength() ; k++) { ret += "<movie>\r\n"; Element inf =(Element) cinemainfos.item(k) ; NodeList title = inf.getElementsByTagName("title") ; String titleText = getLeafText((Element)title.item(0)); ret += "<title>" + titleText + "</title>\r\n" ; ret += "<title-param>" + encoder.EncodeString(titleText) + "</title-param>\r\n" ; NodeList ctg = inf.getElementsByTagName("category") ; ret += "<category>" + getLeafText((Element)ctg.item(0)) + "</category>\r\n" ; NodeList story = inf.getElementsByTagName("story") ; ret += "<story>" + getLeafText((Element)story.item(0)) + "</story>\r\n" ; NodeList actors = inf.getElementsByTagName("actors"); ret += "<actors>" + getLeafText((Element)actors.item(0)) + "</actors>\r\n" ; NodeList hour = inf.getElementsByTagName("hour") ; for (int l=0; l<hour.getLength() ; l++ ) ret += "<hour>" + getLeafText((Element)hour.item(l)) + "</hour>\r\n" ; NodeList room = inf.getElementsByTagName("room") ; ret += "<room>" + getLeafText((Element)room.item(0)) + "</room>\r\n" ; ret += "</movie>\r\n"; } ret += "</cinema>\r\n"; return ret; } // Project AthensCinemas // Â.ÊïõôáâÜò, Ã.ÐáðáìÜñêïò, Ä.Âõôéíéþôçò // Éïýíéïò 2000 // DOMRepresentation.java // Äçìéïõñãåß Ýíá áíôéêåßìåíï áðü XML êåßìåíï, êáé äéáèÝôåé // ìåèüäïõò ðïõ åðéóôñÝöïõí XML êåßìåíï áíÜëïãá ìå ôï query ðïõ Ý÷åé æçôçèåß import com.ibm.xml.parsers.*; import org.w3c.dom.*; import java.io.*; import org.xml.sax.*; import java.lang.*; import java.util.*; public class DOMRepresentation { private Document doc = null; private HttpEncodingParser encoder = null; // See HTTPEncodingParser.java public DOMRepresentation(BufferedReader is, HttpEncodingParser ServletEncoder) { try { DOMParser ps = new DOMParser(); ps.parse(new InputSource(is)); doc = ps.getDocument(); encoder = ServletEncoder; } catch(Exception e) { System.out.println("Error in constructor DOMRepresentation: "); System.out.println(e.getMessage()); } } } public String getAreaList() //ÅðéóôñÝöåé Ýíá XML String ìå üëåò ôéò ðåñéï÷Ýò ðïõ êáëýðôåé ç âÜóç ìáò { String str =""; NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0;i<AreaList.getLength() ;i++) { Element OneArea = (Element)AreaList.item(i); str += "<element>\r\n<name>" + OneArea.getAttribute("value").trim() + "</name>\r\n</element>\r\n"; } return str; } public String getCinemasByArea(String theArea) // ÅðéóôñÝöåé XML String ìå üëá ôá óéíåìÜ ìéáò ðåñéï÷Þò { String ret = ""; Element OneArea = null; theArea = theArea.trim(); NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0; i<AreaList.getLength(); i++) { OneArea = (Element)AreaList.item(i); if (theArea.equals(OneArea.getAttribute("value").trim())) break; //area found, exit for-loop } NodeList CinemaList = OneArea.getElementsByTagName("cinema"); for (int j=0;j<CinemaList.getLength() ;j++) { Element OneCinema = (Element)CinemaList.item(j); NodeList OneCinemaNameList = OneCinema.getElementsByTagName("name"); Element theName = (Element)OneCinemaNameList.item(0); String theNameText = getLeafText(theName) ; ret += "<element>\r\n<name>" + theNameText + "</name>\r\n</element>\r\n"; } return ret; } class Cell extends Object { private Object g; Cell() { g = null; } public void set(Object b) { g = b; } public Object get() { return g; } } public String getCinemaInfo(String theCinema) // ÅðéóôñÝöåé ðëçñïöïñßåò ãéá Ýíá óõãêåêñéìÝíï óéíåìÜ { String ret = ""; theCinema = theCinema.trim() ; Element OneCinema = null ; String nametext = null ; NodeList CinemaList = doc.getElementsByTagName("cinema") ; for (int i=0 ; i<CinemaList.getLength() ; i++ ) { OneCinema =(Element) CinemaList.item(i) ; NodeList NameList = OneCinema.getElementsByTagName("name") ; Element theName = (Element) NameList.item(0) ; nametext = getLeafText(theName) ; if (nametext.equals(theCinema)) break ; //theCinema found } ret = "<cinema>\r\n"; ret += "<name>" + nametext + "</name>\r\n" ; NodeList addr = OneCinema.getElementsByTagName("address") ; ret += "<address>" + getLeafText((Element)addr.item(0)) + "</address>\r\n" ; NodeList tick = OneCinema.getElementsByTagName("tickprice") ; ret += "<tickprice>" + getLeafText((Element)tick.item(0)) + "</tickprice>\r\n" ; NodeList cinemainfos = OneCinema.getElementsByTagName("movie"); for (int k=0; k<cinemainfos.getLength() ; k++) { ret += "<movie>\r\n"; Element inf =(Element) cinemainfos.item(k) ; NodeList title = inf.getElementsByTagName("title") ; String titleText = getLeafText((Element)title.item(0)); ret += "<title>" + titleText + "</title>\r\n" ; ret += "<title-param>" + encoder.EncodeString(titleText) + "</title-param>\r\n" ; NodeList ctg = inf.getElementsByTagName("category") ; ret += "<category>" + getLeafText((Element)ctg.item(0)) + "</category>\r\n" ; NodeList story = inf.getElementsByTagName("story") ; ret += "<story>" + getLeafText((Element)story.item(0)) + "</story>\r\n" ; NodeList actors = inf.getElementsByTagName("actors"); ret += "<actors>" + getLeafText((Element)actors.item(0)) + "</actors>\r\n" ; NodeList hour = inf.getElementsByTagName("hour") ; for (int l=0; l<hour.getLength() ; l++ ) ret += "<hour>" + getLeafText((Element)hour.item(l)) + "</hour>\r\n" ; NodeList room = inf.getElementsByTagName("room") ; ret += "<room>" + getLeafText((Element)room.item(0)) + "</room>\r\n" ; ret += "</movie>\r\n"; } ret += "</cinema>\r\n"; return ret; } // Project AthensCinemas // Â.ÊïõôáâÜò, Ã.ÐáðáìÜñêïò, Ä.Âõôéíéþôçò // Éïýíéïò 2000 // DOMRepresentation.java // Äçìéïõñãåß Ýíá áíôéêåßìåíï áðü XML êåßìåíï, êáé äéáèÝôåé // ìåèüäïõò ðïõ åðéóôñÝöïõí XML êåßìåíï áíÜëïãá ìå ôï query ðïõ Ý÷åé æçôçèåß import com.ibm.xml.parsers.*; import org.w3c.dom.*; import java.io.*; import org.xml.sax.*; import java.lang.*; import java.util.*; public class DOMRepresentation { private Document doc = null; private HttpEncodingParser encoder = null; // See HTTPEncodingParser.java public DOMRepresentation(BufferedReader is, HttpEncodingParser ServletEncoder) { try { DOMParser ps = new DOMParser(); ps.parse(new InputSource(is)); doc = ps.getDocument(); encoder = ServletEncoder; } catch(Exception e) { System.out.println("Error in constructor DOMRepresentation: "); System.out.println(e.getMessage()); } } } public String getAreaList() //ÅðéóôñÝöåé Ýíá XML String ìå üëåò ôéò ðåñéï÷Ýò ðïõ êáëýðôåé ç âÜóç ìáò { String str =""; NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0;i<AreaList.getLength() ;i++) { Element OneArea = (Element)AreaList.item(i); str += "<element>\r\n<name>" + OneArea.getAttribute("value").trim() + "</name>\r\n</element>\r\n"; } return str; } public String getCinemasByArea(String theArea) // ÅðéóôñÝöåé XML String ìå üëá ôá óéíåìÜ ìéáò ðåñéï÷Þò { String ret = ""; Element OneArea = null; theArea = theArea.trim(); NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0; i<AreaList.getLength(); i++) { OneArea = (Element)AreaList.item(i); if (theArea.equals(OneArea.getAttribute("value").trim())) break; //area found, exit for-loop } NodeList CinemaList = OneArea.getElementsByTagName("cinema"); for (int j=0;j<CinemaList.getLength() ;j++) { Element OneCinema = (Element)CinemaList.item(j); NodeList OneCinemaNameList = OneCinema.getElementsByTagName("name"); Element theName = (Element)OneCinemaNameList.item(0); String theNameText = getLeafText(theName) ; ret += "<element>\r\n<name>" + theNameText + "</name>\r\n</element>\r\n"; } return ret; } class Cell extends Object { private Object g1, g2; private int cnt; Cell() { g1 = null; g2 = null; cnt = 0; } public void set(Object b) { cnt = cnt + 1; if ((cnt % 2) == 0) g1 = b; else g2 = b; } public Object get() { if ((cnt % 2) == 0) return g1; else return g2; } }} public String getCinemaInfo(String theCinema) // ÅðéóôñÝöåé ðëçñïöïñßåò ãéá Ýíá óõãêåêñéìÝíï óéíåìÜ { String ret = ""; theCinema = theCinema.trim() ; Element OneCinema = null ; String nametext = null ; NodeList CinemaList = doc.getElementsByTagName("cinema") ; for (int i=0 ; i<CinemaList.getLength() ; i++ ) { OneCinema =(Element) CinemaList.item(i) ; NodeList NameList = OneCinema.getElementsByTagName("name") ; Element theName = (Element) NameList.item(0) ; nametext = getLeafText(theName) ; if (nametext.equals(theCinema)) break ; //theCinema found } ret = "<cinema>\r\n"; ret += "<name>" + nametext + "</name>\r\n" ; NodeList addr = OneCinema.getElementsByTagName("address") ; ret += "<address>" + getLeafText((Element)addr.item(0)) + "</address>\r\n" ; NodeList tick = OneCinema.getElementsByTagName("tickprice") ; ret += "<tickprice>" + getLeafText((Element)tick.item(0)) + "</tickprice>\r\n" ; NodeList cinemainfos = OneCinema.getElementsByTagName("movie"); for (int k=0; k<cinemainfos.getLength() ; k++) { ret += "<movie>\r\n"; Element inf =(Element) cinemainfos.item(k) ; NodeList title = inf.getElementsByTagName("title") ; String titleText = getLeafText((Element)title.item(0)); ret += "<title>" + titleText + "</title>\r\n" ; ret += "<title-param>" + encoder.EncodeString(titleText) + "</title-param>\r\n" ; NodeList ctg = inf.getElementsByTagName("category") ; ret += "<category>" + getLeafText((Element)ctg.item(0)) + "</category>\r\n" ; NodeList story = inf.getElementsByTagName("story") ; ret += "<story>" + getLeafText((Element)story.item(0)) + "</story>\r\n" ; NodeList actors = inf.getElementsByTagName("actors"); ret += "<actors>" + getLeafText((Element)actors.item(0)) + "</actors>\r\n" ; NodeList hour = inf.getElementsByTagName("hour") ; for (int l=0; l<hour.getLength() ; l++ ) ret += "<hour>" + getLeafText((Element)hour.item(l)) + "</hour>\r\n" ; NodeList room = inf.getElementsByTagName("room") ; ret += "<room>" + getLeafText((Element)room.item(0)) + "</room>\r\n" ; ret += "</movie>\r\n"; } ret += "</cinema>\r\n"; return ret; }

Two Versions of Progr Fragment

Version 2

// Project AthensCinemas // Â.ÊïõôáâÜò, Ã.ÐáðáìÜñêïò, Ä.Âõôéíéþôçò // Éïýíéïò 2000 // DOMRepresentation.java // Äçìéïõñãåß Ýíá áíôéêåßìåíï áðü XML êåßìåíï, êáé äéáèÝôåé // ìåèüäïõò ðïõ åðéóôñÝöïõí XML êåßìåíï áíÜëïãá ìå ôï query ðïõ Ý÷åé æçôçèåß import com.ibm.xml.parsers.*; import org.w3c.dom.*; import java.io.*; import org.xml.sax.*; import java.lang.*; import java.util.*; public class DOMRepresentation { private Document doc = null; private HttpEncodingParser encoder = null; // See HTTPEncodingParser.java public DOMRepresentation(BufferedReader is, HttpEncodingParser ServletEncoder) { try { DOMParser ps = new DOMParser(); ps.parse(new InputSource(is)); doc = ps.getDocument(); encoder = ServletEncoder; } catch(Exception e) { System.out.println("Error in constructor DOMRepresentation: "); System.out.println(e.getMessage()); } } } public String getAreaList() //ÅðéóôñÝöåé Ýíá XML String ìå üëåò ôéò ðåñéï÷Ýò ðïõ êáëýðôåé ç âÜóç ìáò { String str =""; NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0;i<AreaList.getLength() ;i++) { Element OneArea = (Element)AreaList.item(i); str += "<element>\r\n<name>" + OneArea.getAttribute("value").trim() + "</name>\r\n</element>\r\n"; } return str; } public String getCinemasByArea(String theArea) // ÅðéóôñÝöåé XML String ìå üëá ôá óéíåìÜ ìéáò ðåñéï÷Þò { String ret = ""; Element OneArea = null; theArea = theArea.trim(); NodeList AreaList = doc.getElementsByTagName("area"); for (int i=0; i<AreaList.getLength(); i++) { OneArea = (Element)AreaList.item(i); if (theArea.equals(OneArea.getAttribute("value").trim())) break; //area found, exit for-loop } NodeList CinemaList = OneArea.getElementsByTagName("cinema"); for (int j=0;j<CinemaList.getLength() ;j++) { Element OneCinema = (Element)CinemaList.item(j); NodeList OneCinemaNameList = OneCinema.getElementsByTagName("name"); Element theName = (Element)OneCinemaNameList.item(0); String theNameText = getLeafText(theName) ; ret += "<element>\r\n<name>" + theNameText + "</name>\r\n</element>\r\n"; } return ret; } class Cell extends Object { private Object g; Cell() { g = null; } public void set(Object b) { g = b; } public Object get() { return g; } } public String getCinemaInfo(String theCinema) // ÅðéóôñÝöåé ðëçñïöïñßåò ãéá Ýíá óõãêåêñéìÝíï óéíåìÜ { String ret = ""; theCinema = theCinema.trim() ; Element OneCinema = null ; String nametext = null ; NodeList CinemaList = doc.getElementsByTagName("cinema") ; for (int i=0 ; i<CinemaList.getLength() ; i++ ) { OneCinema =(Element) CinemaList.item(i) ; NodeList NameList = OneCinema.getElementsByTagName("name") ; Element theName = (Element) NameList.item(0) ; nametext = getLeafText(theName) ; if (nametext.equals(theCinema)) break ; //theCinema found } ret = "<cinema>\r\n"; ret += "<name>" + nametext + "</name>\r\n" ; NodeList addr = OneCinema.getElementsByTagName("address") ; ret += "<address>" + getLeafText((Element)addr.item(0)) + "</address>\r\n" ; NodeList tick = OneCinema.getElementsByTagName("tickprice") ; ret += "<tickprice>" + getLeafText((Element)tick.item(0)) + "</tickprice>\r\n" ; NodeList cinemainfos = OneCinema.getElementsByTagName("movie"); for (int k=0; k<cinemainfos.getLength() ; k++) { ret += "<movie>\r\n"; Element inf =(Element) cinemainfos.item(k) ; NodeList title = inf.getElementsByTagName("title") ; String titleText = getLeafText((Element)title.item(0)); ret += "<title>" + titleText + "</title>\r\n" ; ret += "<title-param>" + encoder.EncodeString(titleText) + "</title-param>\r\n" ; NodeList ctg = inf.getElementsByTagName("category") ; ret += "<category>" + getLeafText((Element)ctg.item(0)) + "</category>\r\n" ; NodeList story = inf.getElementsByTagName("story") ; ret += "<story>" + getLeafText((Element)story.item(0)) + "</story>\r\n" ; NodeList actors = inf.getElementsByTagName("actors"); ret += "<actors>" + getLeafText((Element)actors.item(0)) + "</actors>\r\n" ; NodeList hour = inf.getElementsByTagName("hour") ; for (int l=0; l<hour.getLength() ; l++ ) ret += "<hour>" + getLeafText((Element)hour.item(l)) + "</hour>\r\n" ; NodeList room = inf.getElementsByTagName("room") ; ret += "<room>" + getLeafText((Element)room.item(0)) + "</room>\r\n" ; ret += "</movie>\r\n"; } ret += "</cinema>\r\n"; return ret; }

Version 1 ...

C1 C2 C3 C1 C2 C3

... Is the behaviour preserved for any possible pair of programs? Contextual Equivalence

slide-3
SLIDE 3

Contextual Equivalence [Morris ‘60s]

For all program contexts C: If then and vice-versa

3

e ≡ e’ C[e] 42 ...

slide-4
SLIDE 4

Contextual Equivalence [Morris ‘60s]

For all program contexts C: If then and vice-versa

4

e ≡ e’ C[e] 42 ... C[e’] 42 ...

slide-5
SLIDE 5

Contextual Equivalence [Morris ‘60s]

For all program contexts C: If then and vice-versa

5

e ≡ e’ C[e] 42 ... C[e’] 42 ...

slide-6
SLIDE 6

Contextual Equivalence [Morris ‘60s]

For all program contexts C: If then and vice-versa

6

e ≡ e’ C[e] 42 ... C[e’] 42 ...

42 is unimportant

slide-7
SLIDE 7

Contextual Equivalence [Morris ‘60s]

For all program contexts C: If then and vice-versa

7

e ≡ e’ C[e] 42 ... C[e’] 42 ...

how can we prove anything equivalent?

slide-8
SLIDE 8

Theories of equivalence

We develop methods to prove contextual equivalence without the “forall C” Instead: describe the interactions of an expression with its environment Depends on

Language features Abstraction mechanisms

8

slide-9
SLIDE 9

Theories of equivalence

Prevailing techniques

Bisimulations Game semantics Logical relations Trace semantics CIU Theorems Denotational semantics ...

9

slide-10
SLIDE 10

Some history of bisimulations

Concurrency [Park’81,Milner’89, Sangiorgi’92,...]

CCS, π-calculus

Programming languages

Applicative bisimulation [Abramsky’90, Gordon & Rees’96] λ-calculus, object calculi Environmental Bisimulation [Sumii & Pierce‘04’05, Koutavas & Wand’06, Sangiorgi et al. ’07 …] Polymorphism, encryption, state update, Java,… Open Bisim [Sangiorgi’94,Lassen & Levy ’07, Jagadeesan et al. ’07]

10

slide-11
SLIDE 11

Bisimulation Theories of Equivalence

Applicative Bisimulation (A.B.) [Abramsky’90]

+ Simple defjnition ∓Soundness is a deep result, shown by [Howe’96] − Works only for pure languages (recursion, nondeterminism, I/O)

Environmental Bisimulation (E.B.) [Sumii-Pierce’04]

− Complicated defjnition ∓Soundness is rather trivial: a convenient way of organizing the

concept of contextual equivalence

+ Works for a wide range of languages (store, names, exceptions,

polymorphism, concurrency)

11

slide-12
SLIDE 12

A functional language

slide-13
SLIDE 13

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

13

slide-14
SLIDE 14

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

e.g. (λx. x) (λx. x x)

14

slide-15
SLIDE 15

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

Operational Semantics:

e → e’

e.g. (λx. x) (λx. x x)

15

slide-16
SLIDE 16

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

Operational Semantics:

e → e’

e.g. (λx. x) 3 (λx. x x)

16

slide-17
SLIDE 17

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

Operational Semantics:

e → e’

e.g. (λx. x) 3 → 3 (λx. x x)

17

slide-18
SLIDE 18

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

Operational Semantics:

e → e’

e.g. (λx. x) 3 → 3 (λx. x x) (λy. y y)

18

slide-19
SLIDE 19

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

Operational Semantics:

e → e’

e.g. (λx. x) 3 → 3 (λx. x x) (λy. y y) → (λy. y y) (λy. y y) →...

19

slide-20
SLIDE 20

The Lambda Calculus

Syntax:

Functions: λx. e Application: (e e’)

Operational Semantics:

e → e’

e.g. (λx. x) 3 → 3 (λx. x x) (λy. y y) → (λy. y y) (λy. y y)

20

+ tuples, numbers, ...

slide-21
SLIDE 21

The Bisimulation Game

Player & Opponent

21

f1..fn f’1..f’n

slide-22
SLIDE 22

The Bisimulation Game

22

f1..fn i, ui f’1..f’n

Player & Opponent fi ui →* w

slide-23
SLIDE 23

Player & Opponent

The Bisimulation Game

23

f1..fn i, ui w↝g1..gm f’1..f’n

fi ui →* w

slide-24
SLIDE 24

The Bisimulation Game

24

f1..fn i, ui w↝g1..gm f’1..f’n

Player & Opponent decompose w and collect all the functions

slide-25
SLIDE 25

The Bisimulation Game

Player & Opponent

25

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m

slide-26
SLIDE 26

The Bisimulation Game

Player & Opponent

26

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m

Same decomposition: w and w’ may differ only on functions

slide-27
SLIDE 27

The Bisimulation Game

Player & Opponent

27

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m j, uj v’↝h’1..h’k

slide-28
SLIDE 28

The Bisimulation Game

Player & Opponent

28

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m j, uj v↝h1..hk j, uj v’↝h’1..h’k

slide-29
SLIDE 29

Player & Opponent O wins: when exists a play where P cannot match move P wins: otherwise

29

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m j, uj v↝h1..hk j, uj v’↝h’1..h’k

The Bisimulation Game

slide-30
SLIDE 30

Player & Opponent O wins: when exists a play where P cannot match move P wins: otherwise

30

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m j, uj v↝h1..hk j, uj v’↝h’1..h’k

The Bisimulation Game

Coinduction

slide-31
SLIDE 31

e.g.:

31

λx.(x, x) λx.(x x, x)

The Bisimulation Game

slide-32
SLIDE 32

e.g.:

32

λx.(x, x) 1, λy.y y (λy.y y, λy.y y) λx.(x x, x)

The Bisimulation Game

slide-33
SLIDE 33

e.g.:

33

λx.(x, x) 1, λy.y y (λy.y y, λy.y y) λx.(x x, x) 1, λy.y y

The Bisimulation Game

slide-34
SLIDE 34

This is Applicative Bisimulation

The arguments to fi, f’i are the same closed value They do not contain the f1 .. fn, f’1 .. f’n Functional extensionality It forgets the functions of previous stages

34

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m j, uj v↝h1..hk j, uj v’↝h’1..h’k

The Bisimulation Game

slide-35
SLIDE 35

Theorem [Howe’96]: for simple functional languages (λ- calculus) e, e’ are contextually equivalent iff e, e’ are applicative bisimilar

35

Applicative Bisimulation

slide-36
SLIDE 36

Useful: Bisimulation gives us a proof technique

  • 1. Construct R containing all the states of the bisimulation

game

  • 2. Prove that from each state to the next the player cannot get

stuck

36

Applicative Bisimulation

slide-37
SLIDE 37

Useful: Bisimulation gives us a proof technique

  • 1. Construct R containing all the states of the bisimulation

game

  • 2. Prove that from each state to the next the player cannot get

stuck

37

Applicative Bisimulation

f1..fn f’1..f’n R

slide-38
SLIDE 38

Useful: Bisimulation gives us a proof technique

  • 1. Construct R containing all the states of the bisimulation

game

  • 2. Prove that from each state to the next the player cannot get

stuck

38

Applicative Bisimulation

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m R R

slide-39
SLIDE 39

Useful: Bisimulation gives us a proof technique

  • 1. Construct R containing all the states of the bisimulation

game

  • 2. Prove that from each state to the next the player cannot get

stuck

39

Applicative Bisimulation

f1..fn i, ui w↝g1..gm f’1..f’n i, ui w’↝g’1..g’m R R

Does it scale to other languages?

[K,Levy,Sumii’11]

slide-40
SLIDE 40

A.B. for a Pure Language

Consider equivalence at type (1→1)→Bool

Functions are applicative bisimilar if they map closed values of type (1→1) to the same boolean (or divergence) This encodes the notion of extensionality of functions

Is A.B. a sound reasoning principle for

state? names? existential types? exceptions?

40

No, but what changes would it take to make it work?

slide-41
SLIDE 41

First Change: Generation

Consider contexts that generate fresh locations (or names, exceptions) used in arguments to functions

41

M, M’ : (Int→1)→1 M ≜ λf. f 1; f 2 M‘ ≜ λf. f 2; f 1 C ≜ new r:=1; [ ] (λx. r:=x); !r

slide-42
SLIDE 42

Second Change: Accumulation

Applicative bisimulation contexts apply functions

  • nce

With state: a function may give a different answer the second time it is called With names: a function may return a different name every time it is called With existential types: must allow to apply an old function of type α→Bool to a new value of type α With exceptions: the need is more subtle (see examples in [MFPS’11])

42

The bisimulation needs to accumulate functions as it goes along

slide-43
SLIDE 43

A.B. w/ Generation & Accumulation

Main question: whether applicative bisimulation + generation + accumulation is sound for various language features

NO for names NO for state NO for existential types NO for exceptions

43

slide-44
SLIDE 44

λ-calculus + bool store

slide-45
SLIDE 45

λ-Calculus + bool store

T ::= 0 | A+A | 1 | AxA | A→A | X | recX. A V ::= ... M ::= ... | new ℓ:=b | !ℓ | ℓ:=b s ∈ Loc ⇀ Bool s, M ⇓ t, V

45

slide-46
SLIDE 46

Example

M, M’ : (1→1)→Bool M ≜ λg. g(); true M‘ ≜ new fmag:=true. F’ F‘ ≜ λg. if !fmag then fmag:=false; g(); fmag:=true; true else false

46

closed stateful arguments of type V : (1→1)

  • read global state & diverge
  • read/write global state & return ()
slide-47
SLIDE 47

Example

M, M’ : (1→1)→Bool M ≜ λg. g(); true M‘ ≜ new fmag:=true. F’ F‘ ≜ λg. if !fmag then fmag:=false; g(); fmag:=true; true else false

47

Applying the functions multiple times to closed (stateful) arguments will not distinguish them

slide-48
SLIDE 48

Example

M, M’ : (1→1)→Bool M ≜ λg. g(); true M‘ ≜ new fmag:=true. F’ F‘ ≜ λg. if !fmag then fmag:=false; g(); fmag:=true; true else false

48

distinguishing argument: V ≜ λ(). r := [ ] dummy distinguishing context: new r:=true; let f = [ ] in f V[f]; !r

slide-49
SLIDE 49

λ + Higher-Order Store

The same example is valid for languages that can store functions Similar examples for other languages

  • λ + names
  • λ + exceptions
  • λ + existential types (!)

49

slide-50
SLIDE 50

Example

50

M = λf:unit → unit. f(); return true M’= new fmag=true in V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

slide-51
SLIDE 51

Example

51

M = λf:unit → unit. f(); return true M’= new fmag=true. V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

let g = [ ] in new record = true in g (λz.record:= g (λy.y); return z); return record C =

slide-52
SLIDE 52

Example

52

M = λf:unit → unit. f(); return true M’= new fmag=true. V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

let g = [ ] in new record = true in g (λz.record:= g (λy.y); return z); return record C = “resourceful” argument

slide-53
SLIDE 53

Environmental Bisimulation

53

s; f1..fn i, (si, ui)[f1..fn/x1..xn] s,t; (w1..wk↝g1..gm), f1..fn s’; f’1..f’n i, (si, ui)[f’1..f’n/x1..xn] s’ ,t’; (w’1..w’k↝g’1..g’m), f’1..f’n

slide-54
SLIDE 54

Example

54

M = λf:unit → unit. f(); return true M’= new fmag=true. V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

slide-55
SLIDE 55

Example

55

M = λf:unit → unit. f(); return true M’= new fmag=true. V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

[]; M [fmag=true]; V’

slide-56
SLIDE 56

Example

56

M = λf:unit → unit. f(); return true M’= new fmag=true. V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

[]; M 1, s1, u1[M/g] []; (true,true↝ε), Μ [fmag=true]; V’ s1= [record=true] u1=λz.record:= g (λy.y); return z

slide-57
SLIDE 57

Example

57

M = λf:unit → unit. f(); return true M’= new fmag=true. V’ V’ = λf:unit → unit. if fmag then fmag:=false; f(); fmag:=true; return true else return false

[]; M 1, s1, u1[M/g] []; (true,true↝ε), Μ [fmag=true]; V’ 1, s1, u1[V’/g] [fmag=true]; false,true↝ s1= [record=true] u1=λz.record:= g (λy.y); return z

slide-58
SLIDE 58

So...

The obvious extension of A.B. with

Name generation Accumulation of functions

is not sufficient to achieve soundness in We need something more: “Resourceful” arguments

i.e. open arguments, closed with the related functions With this addition we get exactly Environmental Bisim.

58

λ + store (FO & HO) λ + names λ + exceptions λ + existential types

slide-59
SLIDE 59

One more thing...

slide-60
SLIDE 60

The obvious extension of A.B. with

Name generation Accumulation of functions

is not sufficient to achieve soundness in We need something more: “Resourceful” arguments

i.e. open arguments, closed with the related functions With this addition we get exactly E.B. λ + store (FO & HO) λ + names λ + exceptions λ + existential types

So...

60

UNSOUND! (see paper)

slide-61
SLIDE 61

The obvious extension of A.B. with

Name generation Accumulation of functions

is not sufficient to achieve soundness in We need something more: “Resourceful” arguments

i.e. open arguments, closed with the related functions With this addition we get exactly E.B. λ + store (FO & HO) λ + names λ + exceptions λ + existential types

So...

61

No single answer...

slide-62
SLIDE 62

A.B. + Acc. + Resourcefulness

Sound* for

Deterministic languages Countable nondeterminism + may testing Finite nondeterminism + must testing

Unsound for

Countable nondeterminism + must testing Finite nondeterminism + divergent-insensitive bisimilarity

62

* Have not proved this

slide-63
SLIDE 63

One Last Example

M, M’ : rec α. Nm→1+α M ≜ accepts an unbounded number of fresh names M‘ ≜ chooses k and accepts up to k fresh names

63

λ + names + countable nondeterminism + ≣must

n1 n2 n3 n4

M

n1 () n1 n2 n3

M’

n1 n2 () ()

slide-64
SLIDE 64

One Last Example

M, M’ : rec α. Nm→1+α M ≜ accepts an unbounded number of fresh names M‘ ≜ chooses k and accepts up to k fresh names

64

n1 n2 n3 n4

M + M’

n1 () n1 n2 n3

M’

n1 n2 () ()

Indistinguishable by contexts that pick (a fjnite number of) names only at the beginning

λ + names + countable nondeterminism + ≣must

slide-65
SLIDE 65

One Last Example

M, M’ : rec α. Nm→1+α M ≜ accepts an unbounded number of fresh names M‘ ≜ chooses k and accepts up to k fresh names

65

n1 n2 n3 n4

M + M’

n1 () n1 n2 n3

M’

n1 n2 () ()

distinguishing context: provides fresh names as long as the function accepts them λ + names + countable nondeterminism + ≣must

slide-66
SLIDE 66

Thanks!