;-------------------------------------------------------------------- ; RSC-REPOSITORY ART/97 ;-------------------------------------------------------------------- ; Copyright@1996 by F. Luis Neves ; ; Author(s): FLN (F. Luis Neves) ; Revisions: 25.Fev.97 Rev: 22 Mar, 1997 ; Rev: 24 Mar, 1997 ; Rev: 3 Jan, 1998 (Final revisions) ; ;-------------------------------------------------------------------- ; ; ; Comments: Automatic Reification Tool (SETS) ; ( load "get.met" ) ;--------------------- ( load "ret.met" ) ;--------------------- ( load "set.met" ) ;--------------------- ; ; Total reification: with all rules available ; ; rfSHOWBEST(x)); ; rfSHOWREIF(x)); ( def _ops ( plus _ops ( makeff ( ( quote rfSTART ) ( quote ( ( ( X ) ( INT ) ( INT ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfSTART lambda ( x t n ) ( if ( is X x ) ( progn ( gpSETTINGS ( P 9 50 0 25 60 10 false 1 true 1 39 ) ) ( gpSHOWSETTINGS ) ( rrINIT ) ( gpSTART ) ( rfEVAL x t ) ( princ "> Best(" 0 "): " ( rfBESTVAL ) "\n> thinking..." ) ( foreach i ( inseg n ) ( rfSELECT ) ( gpCROSSOVER ) ( gpMUTATION ) ( rfEVAL x t ) ( princ " best (" i "): " ( rfBESTVAL ) "\n> thinking..." ) ) ( rfSHOWRESULT x ) ) ( strcat "ERROR (precondition violated) in function " "rfSTART" ) ) ) ;--------------------- ; ; Partial reification: only with rules applied to finite functions ; ;STATE progn(gpSETTINGS(P(5,20,0,25,60,0,false,1,true,1,39)), ; rfSHOWBEST(x)); ; rfSHOWREIF(x)); ( def _ops ( plus _ops ( makeff ( ( quote rfPSTART ) ( quote ( ( ( X ) ( INT ) ( INT ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfPSTART lambda ( x t n ) ( if ( is X x ) ( progn ( gpSETTINGS ( P 10 50 3 50 60 1 false 2 true 2 39 ) ) ( gpSHOWSETTINGS ) ( rrINIT ) ( gpPSTART ( makeset 24 26 28 29 30 31 33 34 35 36 37 38 39 ) ) ( rfEVAL x t ) ( princ "> Best(" 0 "): " ( rfBESTVAL ) "%\n> thinking..." ) ( foreach i ( inseg n ) ( rfSELECT ) ( gpCROSSOVER ) ( gpMUTATION ) ( rfEVAL x t ) ( princ " best (" i "): " ( rfBESTVAL ) "%\n> thinking..." ) ) ( rfSHOWRESULT x ) ) ( strcat "ERROR (precondition violated) in function " "rfPSTART" ) ) ) ;--------------------- ;STATE progn(gpSETTINGS(P(15,30,0,25,60,1,false,3,true,1,39)), ;STATE progn(gpSETTINGS(P(15,50,0,50,60,1,false,2,true,1,39)), ;STATE progn(gpSETTINGS(P(5,50,3,50,60,10,false,2,true,1,39)), ; rfSHOWBEST(x)); ; rfSHOWREIF(x)); ( def _ops ( plus _ops ( makeff ( ( quote rfPSTARTBAMS ) ( quote ( ( ( X ) ( INT ) ( INT ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfPSTARTBAMS lambda ( x t n ) ( if ( is X x ) ( progn ( gpSETTINGS ( P 10 50 3 50 60 1 false 2 true 2 39 ) ) ( gpSHOWSETTINGS ) ( rrINIT ) ( gpPSTART ( makeset 1 4 12 13 24 25 26 28 29 30 31 33 34 35 36 37 38 39 ) ) ( rfEVAL x t ) ( princ "> Best(" 0 "): " ( rfBESTVAL ) "%\n> thinking..." ) ( foreach i ( inseg n ) ( gpSELECT ) ( gpCROSSOVER ) ( gpMUTATION ) ( rfEVAL x t ) ( princ " best (" i "): " ( rfBESTVAL ) "%\n> thinking..." ) ) ( rfSHOWRESULT x ) ) ( strcat "ERROR (precondition violated) in function " "rfPSTARTBAMS" ) ) ) ;--------------------- ;STATE progn(gpSETTINGS(P(25,30,0,25,60,0,false,1,true,1,39)), ;STATE progn(gpSETTINGS(P(15,50,0,25,60,1,false,2,true,1,39)), ; rfSHOWBEST(x)); ; rfSHOWREIF(x)); ( def _ops ( plus _ops ( makeff ( ( quote rfPSTARTPPD ) ( quote ( ( ( X ) ( INT ) ( INT ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfPSTARTPPD lambda ( x t n ) ( if ( is X x ) ( progn ( gpSETTINGS ( P 10 50 3 50 60 1 false 2 true 2 39 ) ) ( gpSHOWSETTINGS ) ( rrINIT ) ( gpPSTART ( makeset 1 4 12 13 24 25 26 28 29 30 31 33 34 35 36 37 38 39 ) ) ( rfEVAL x t ) ( princ "> Best(" 0 "): " ( rfBESTVAL ) "%\n> thinking..." ) ( foreach i ( inseg n ) ( gpSELECT ) ( gpCROSSOVER ) ( gpMUTATION ) ( rfEVAL x t ) ( princ " best (" i "): " ( rfBESTVAL ) "%\n> thinking..." ) ) ( rfSHOWRESULT x ) ) ( strcat "ERROR (precondition violated) in function " "rfPSTARTPPD" ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfSELECT ) ( quote ( ( ) NIL ) ) ) ) ) ) ;--------------------- ( def rfSELECT lambda ( ) ( let ( ( p ( roleta G ( rfBEST ) ) ) ) ( if ( lt ( card ( dom p ) ) ( card ( dom G ) ) ) ( def G ( _fullsel_ p G ) ) ( def G p ) ) ) ) ;--------------------- ( def _fullsel_ lambda ( p s ) ( if ( geq ( card ( dom p ) ) ( card ( dom s ) ) ) p ( let ( ( x ( rchoice ( dom s ) ) ) ( k ( choice ( difference ( dom s ) ( dom p ) ) ) ) ) ( _fullsel_ ( plus p ( makeff ( k ( ap s x ) ) ) ) s ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfBEST ) ( quote ( ( ) ( FF I R ) ) ) ) ) ) ) ;--------------------- ( def rfBEST lambda ( ) ( ff1 ( list k ( ap G k ) ) ( from k ( dom G ) ( equal ( gpSEL k 2 ) ( rfBESTVAL ) ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfBESTVAL ) ( quote ( ( ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def rfBESTVAL lambda ( ) ( if ( not ( gpEMPTY ) ) ( reduce 0 max ( set ( gpSEL x 2 ) ( from x ( dom G ) ) ) ) ( strcat "ERROR (precondition violated) in function " "rfBESTVAL" ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfBESTOFALL ) ( quote ( ( ) ( FF I R ) ) ) ) ) ) ) ;--------------------- ( def rfBESTOFALL lambda ( ) ( ff1 ( list k ( ap G k ) ) ( from k ( dom G ) ( and ( equal ( gpSEL k 2 ) ( rfBESTVAL ) ) ( equal ( gpSEL k 3 ) ( reduce ( CS GV ) min ( set ( gpSEL x 3 ) ( from x ( dom G ) ) ) ) ) ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfPOPRULES ) ( quote ( ( ) ( SET INT ) ) ) ) ) ) ) ;--------------------- ( def rfPOPRULES lambda ( ) ( elems ( CONC ( seq ( B1 ( ap G x ) ) ( from x ( dom G ) ) ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfSHOWBEST ) ( quote ( ( ( X ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfSHOWBEST lambda ( x ) ( let ( ( b ( rfBESTOFALL ) ) ( k ( choice ( dom b ) ) ) ) ( xPrint ( ApplyFirstMatch x ( B1 ( ap b k ) ) ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfPREPARE ) ( quote ( ( ( STR ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfPREPARE lambda ( s ) ( def x ( SETS2BSETS ( ap ( FLATSETS s M ) s ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfSHOWREIF ) ( quote ( ( ( X ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfSHOWREIF lambda ( x ) ( let ( ( b ( rfBEST ) ) ( k ( choice ( dom b ) ) ) ( c ( B1 ( ap b k ) ) ) ) ( if ( equal ( GR GV ) 2 ) ( _showreif_ x ( CONC c ) ) ( _showreif_ x c ) ) ) ) ;--------------------- ; else let (h = head(c), t = tail(c), r = FirstMatchInv(x,h)) ( def _showreif_ lambda ( x c ) ( if ( equal c ( makeseq ) ) "" ( let ( ( h ( head c ) ) ( t ( tail c ) ) ( r ( FirstMatch x h ) ) ( i ( xAbsMatch ( rrGetAbs h ) x ( rrGetPat h ) ) ) ( j ( xRepMatch ( rrGetRep h ) x ( rrGetPat h ) ) ) ) ( if ( is X r ) ( progn ( if ( nequal x r ) ( princ "\n> applying " h "... " ( xString r ) "\n> abs = " ( xAbs2Str ( xAbsFun i ) ) "\n> rep = " ( xAbs2Str ( xRepFun j ) ) ) ) ( _showreif_ r t ) ) ( progn ( princ "\n> applying " h "... " ( xString ( E r ) ) "\n> ... invariant: " ( I r ) ) ( _showreif_ ( E r ) t ) ) ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfSAVEREIF ) ( quote ( ( ( X ) ( STR ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfSAVEREIF lambda ( x f ) ( let ( ( b ( rfBEST ) ) ( k ( choice ( dom b ) ) ) ( c ( B1 ( ap b k ) ) ) ) ( progn ( def fp ( fopen "_" "w" ) ) ( if ( equal ( GR GV ) 2 ) ( _savereif_ x ( CONC c ) ) ( _savereif_ x c ) ) ( sh ( strcat "mv _ " f ) ) ) ) ) ;--------------------- ; else let (h = head(c), t = tail(c), r = FirstMatchInv(x,h)) ( def _savereif_ lambda ( x c ) ( if ( equal c ( makeseq ) ) "" ( let ( ( h ( head c ) ) ( t ( tail c ) ) ( r ( FirstMatch x h ) ) ( i ( xAbsMatch ( rrGetAbs h ) x ( rrGetPat h ) ) ) ( j ( xRepMatch ( rrGetRep h ) x ( rrGetPat h ) ) ) ) ( progn ( if ( nequal x r ) ( progn ( fprint "_" "a" ( makeseq "\n\n> applying " h "... " ) ) ( fprint "_" "a" ( xString r ) ) ( fprint "_" "a" ( makeseq "\n\n> abs = " ) ) ( fprint "_" "a" ( xAbs2Str ( xAbsFun i ) ) ) ( fprint "_" "a" ( makeseq "\n> rep = " ) ) ( fprint "_" "a" ( xAbs2Str ( xRepFun j ) ) ) ) ) ( _savereif_ r t ) ) ) ) ) ;--------------------- ( def _ops ( plus _ops ( makeff ( ( quote rfTEXREIF ) ( quote ( ( ( X ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfTEXREIF lambda ( x ) ( let ( ( b ( rfBEST ) ) ( k ( choice ( dom b ) ) ) ( c ( B1 ( ap b k ) ) ) ) ( progn ( def fp ( fopen "_" "w" ) ) ( fprint "_" "a" ( makeseq "\\documentstyle{article}\n" ) ) ( fprint "_" "a" ( makeseq "\\begin{document}\n" ) ) ( fprint "_" "a" ( makeseq "\\section*{Data Reification}\n" ) ) ( fprint "_" "a" ( makeseq "\\footnotesize{\n" ) ) ( fprint "_" "a" ( makeseq "\n\\begin{eqnarray*}\n" ) ) ( fprint "_" "a" ( makeseq " & & " ) ) ( fprint "_" "a" ( SETS2TEX ( xSets x ) ) ) ( fprint "_" "a" ( makeseq "\\\\\n" ) ) ( fprint "_" "a" ( makeseq "\\\\" ) ) ( if ( equal ( GR GV ) 2 ) ( _texreif_ x ( CONC c ) ) ( _texreif_ x c ) ) ( fprint "_" "a" ( makeseq "\n\\end{eqnarray*}\n" ) ) ( fprint "_" "a" ( makeseq "}\n\\end{document}\n" ) ) ( sh "mv _ _reif_.tex" ) ) ) ) ;--------------------- ;,fclose(fp)); ; else let (h = head(c), t = tail(c), r = FirstMatchInv(x,h)) ; fprint("_","a",SETS2TEX(xSets(x))), ( def _texreif_ lambda ( x c ) ( if ( equal c ( makeseq ) ) "" ( let ( ( h ( head c ) ) ( t ( tail c ) ) ( r ( FirstMatch x h ) ) ( i ( xAbsMatch ( rrGetAbs h ) x ( rrGetPat h ) ) ) ( j ( xRepMatch ( rrGetRep h ) x ( rrGetPat h ) ) ) ) ( if ( nequal x r ) ( progn ( fprint "_" "a" ( makeseq "\n" ) ) ( fprint "_" "a" ( makeseq " & \\unlhd_{" h "} & " ) ) ( fprint "_" "a" ( SETS2TEX ( xSets r ) ) ) ( fprint "_" "a" ( makeseq "\\\\" ) ) ( fprint "_" "a" ( makeseq "\n & & > abs = " ) ) ( fprint "_" "a" ( xAbs2TeX ( xAbsFun i ) ) ) ( fprint "_" "a" ( makeseq "\\\\" ) ) ( fprint "_" "a" ( makeseq "\n & & > rep = " ) ) ( fprint "_" "a" ( xAbs2TeX ( xRepFun j ) ) ) ( fprint "_" "a" ( makeseq "\\\\" ) ) ( fprint "_" "a" ( makeseq "\n" ) ) ( fprint "_" "a" ( makeseq "\\\\" ) ) ( _texreif_ r t ) ) ( _texreif_ r t ) ) ) ) ) ;--------------------- ; in xString(erApplyFinalRule(ApplyFirstMatch(x,c))); ( def _ops ( plus _ops ( makeff ( ( quote rfSHOWRESULT ) ( quote ( ( ( X ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfSHOWRESULT lambda ( x ) ( let ( ( b ( rfBEST ) ) ( k ( choice ( dom b ) ) ) ( c ( B1 ( ap b k ) ) ) ) ( if ( equal ( GR GV ) 2 ) ( xString ( ApplyFirstMatch x ( CONC c ) ) ) ( xString ( ApplyFirstMatch x c ) ) ) ) ) ;--------------------- ; ; Evaluation function (t = evaluation type) ; t = 1 => ER_MODEL ; t = 2 => ER_MODELSIZE ; t = 3 => FF_MODEL ; t = 4 => FF_MODELSIZE ; t = 5 => RSC_MODEL ; t = 6 => RSC_MODELSIZE ; ( def _ops ( plus _ops ( makeff ( ( quote rfEVAL ) ( quote ( ( ( X ) ( INT ) ) NIL ) ) ) ) ) ) ;--------------------- ( def rfEVAL lambda ( x t ) ( def G ( rcprob ( _reify_ x t G ) ) ) ) ;--------------------- ( def _reify_ lambda ( e t s ) ( if ( equal s ( makeff ) ) ( makeff ) ( let ( ( x ( choice ( dom s ) ) ) ( cx ( gpSEL x 1 ) ) ( rx ( if ( equal ( GR GV ) 2 ) ( CONC cx ) cx ) ) ( fx ( rfEVALSETS ( ApplyFirstMatch e rx ) t ) ) ( sx ( gpSEL x 3 ) ) ) ( plus ( makeff ( x ( R cx fx sx 0 0 ) ) ) ( _reify_ e t ( ds s ( makeset x ) ) ) ) ) ) ) ;--------------------- ; ; Evaluates models in SETS (t = evaluation type) ; t = 1 => ER_MODEL ; t = 2 => ER_MODELSIZE ; t = 3 => FF_MODEL ; t = 4 => FF_MODELSIZE ; t = 5 => RSC_MODEL ; t = 6 => RSC_MODELSIZE ; ; t == 3 -> -1.*RSC_EVAL(x)) ( def _ops ( plus _ops ( makeff ( ( quote rfEVALSETS ) ( quote ( ( ( X ) ( INT ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def rfEVALSETS lambda ( x t ) ( cond ( ( equal t 1 ) ( ER_EVAL x ) ) ( ( equal t 2 ) ( ER_EVALSIZE x ) ) ( ( equal t 3 ) ( FF_EVAL x ) ) ( ( equal t 4 ) ( FF_EVALSIZE x ) ) ( ( equal t 5 ) ( RSC_EVAL x ) ) ( ( equal t 6 ) ( RSC_EVALSIZE x ) ) ( true ( RSC_EVAL x ) ) ) ) ;--------------------- ; ; Relational Model Evaluation function (ER_EVAL: X -> [0..10]) ; ( def _ops ( plus _ops ( makeff ( ( quote ER_EVAL ) ( quote ( ( ( X ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def ER_EVAL lambda ( x ) ( erDegreeMatch ( erApplyMetaMatch x ) ) ) ;--------------------- ; ; Relational Model Evaluation function (ER_EVALSIZE: X -> [0..10]) ; (size is important) ; ( def _ops ( plus _ops ( makeff ( ( quote ER_EVALSIZE ) ( quote ( ( ( X ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def ER_EVALSIZE lambda ( x ) ( let ( ( r ( erApplyMetaMatch x ) ) ) ( div ( pdiv ( erDegreeMatch r ) ( xComplex r ) ) 100 ) ) ) ;--------------------- ; ; Relational Model Evaluation function (FF_EVAL: X -> [0..10]) ; ( def _ops ( plus _ops ( makeff ( ( quote FF_EVAL ) ( quote ( ( ( X ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def FF_EVAL lambda ( x ) ( ffDegreeMatch ( ffApplyMetaMatch x ) ) ) ;--------------------- ; ; Relational Model Evaluation function (FF_EVALSIZE: X -> [0..10]) ; (size is important) ; ( def _ops ( plus _ops ( makeff ( ( quote FF_EVALSIZE ) ( quote ( ( ( X ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def FF_EVALSIZE lambda ( x ) ( let ( ( r ( ffApplyMetaMatch x ) ) ) ( div ( pdiv ( ffDegreeMatch r ) ( xComplex r ) ) 100 ) ) ) ;--------------------- ; ; Reusable Software Component Evaluation function (RSC_EVAL: X -> [0..10]) ; ( def _ops ( plus _ops ( makeff ( ( quote RSC_EVAL ) ( quote ( ( ( X ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def RSC_EVAL lambda ( x ) ( rscDegreeMatch ( ffApplyMetaMatch ( erApplyMetaMatch x ) ) ) ) ;--------------------- ; ; Reusable Software Component Evaluation function (RSC_EVAL: X -> [0..10]) ; (size is important) ; ( def _ops ( plus _ops ( makeff ( ( quote RSC_EVALSIZE ) ( quote ( ( ( X ) ) ( INT ) ) ) ) ) ) ) ;--------------------- ( def RSC_EVALSIZE lambda ( x ) ( let ( ( r ( ffApplyMetaMatch ( erApplyMetaMatch x ) ) ) ) ( div ( pdiv ( rscDegreeMatch r ) ( xComplex r ) ) 100 ) ) ) ;--------------------- ;-------------------------------------------------------------------- ; Test models ; ;Doc <- O("*",O("*",'H,'F),O("^",O("+",'Title,O("+",'Section,'Paragraph)),3)); ;DecTree <- O("*",'K,O("->",'K,O("*",'What,O("->",'Answer,'K)))); ;DecTree4 <- O("*",'K ,O("*",O("^",2,O("*",'K,'What)),O("^",2,O("*",O("*",'K,'Answer),'K)))); ;Entity <- O("*",O("->",O("+",'C,'E),'N),O("*",O("->",'C,'N),O("->",'E,O("->",O("+",'C,'E),'N)))); ;Entity2 <- O("*",O("->",O("*",'C,'E),'Q),O("*",O("->",'C,O("*",'A,O("*",'C,'Q))),O("->",'E,O("*",'D,'Q)))); ;;rule36 <- O("->",'A,O("*",'D,O("->",'B,'C)));