├── README.md ├── contrib ├── FQLPP_Examples │ ├── SelectFromCTDBIntroductoryTalk.fqlpp │ └── surjectiveFK_chased.fqlpp └── FQL_Examples │ ├── CompositionUsingDeltaSigmaPi.fql │ ├── Cosimplicial.fql │ ├── CounitExample.fql │ ├── Dihedral.fql │ ├── FullSigmaAttributeClash.fql │ ├── FunWithNumbers.fql │ ├── GatesSchemaB.fql │ ├── GraphDatabases.fpql │ ├── KernelAndImage.fql │ ├── KernelPair.fql │ ├── MatchingExamples.fql │ ├── PathsAgain.fql │ ├── ReflPaths.fql │ ├── RelationImage.fql │ ├── RyansEDs.fql │ ├── SelectFromCTDBIntroductoryTalk.fql │ ├── SetFullSubcategory.fql │ ├── Simplex2Cat.fql │ ├── SimplexCategory.fql │ ├── SimpsonsETC.fql │ ├── Some_groups.fql │ ├── StateMachine.fql │ ├── TGD.fql │ ├── cyclicGroups.fql │ ├── databaseDictionary.fql │ ├── forceInjective.fql │ ├── imageFactorization.fql │ ├── paths.fql │ ├── paths3.fql │ ├── provenance.fql │ ├── pushoutExperiment.fql │ ├── retract.fql │ ├── strength.fql │ └── weirdPattern.fql ├── doc ├── fqlmanual │ ├── composition.png │ ├── deltaI.png │ ├── deltaJ.png │ ├── elements.png │ ├── initial.png │ ├── instance.png │ ├── mapping.png │ ├── observe.png │ ├── people.png │ ├── piI.png │ ├── piJ.png │ ├── schema.png │ ├── sigmaI.png │ ├── sigmaJ.png │ └── tutorial.tex ├── fqlppmanual │ ├── composition.png │ ├── deltaI.png │ ├── deltaJ.png │ ├── elements.png │ ├── initial.png │ ├── instance.png │ ├── mapping.png │ ├── observe.png │ ├── people.png │ ├── piI.png │ ├── piJ.png │ ├── schema.png │ ├── sigmaI.png │ ├── sigmaJ.png │ └── tutorial.tex └── oplmanual │ ├── group1.png │ ├── group2.png │ ├── group3.png │ ├── initial.png │ ├── instance.png │ ├── instance1.png │ ├── instance2.png │ ├── ml.png │ ├── nested1.png │ ├── nested2.png │ ├── team.png │ ├── teamtext.png │ ├── theory.png │ └── tutorial.tex ├── finance ├── Client │ └── client.csv ├── ClientHoldPos │ ├── client.csv │ ├── toClient.csv │ └── toHoldPos.csv ├── HoldPos │ ├── client.csv │ ├── holding.csv │ └── position.csv ├── Portfolio │ ├── portfolio.csv │ └── strategy.csv ├── PortfolioRef │ ├── strategy.csv │ ├── toPortfolio.csv │ └── toRef.csv ├── Ref │ ├── asset.csv │ ├── country.csv │ ├── currency.csv │ └── strategy.csv ├── RefTrans │ ├── asset.csv │ ├── currency.csv │ ├── toRefasset.csv │ ├── toRefcurrency.csv │ ├── toTransasset.csv │ └── toTranscurrency.csv └── Trans │ ├── asset.csv │ ├── currency.csv │ └── transaction.csv ├── fpqlparse ├── fql.jar ├── lib ├── autocomplete-3.0.0.jar ├── commons-collections4-4.2.jar ├── guava-23.4-jre.jar ├── h2-1.4.196.jar ├── javax.json-1.1.2.jar ├── javax.json-api-1.1.2.jar ├── jparsec-3.0.jar ├── jung-algorithms-2.1.1.jar ├── jung-api-2.1.1.jar ├── jung-graph-impl-2.1.1.jar ├── jung-visualization-2.1.1.jar ├── rstaui-3.0.0.jar └── rsyntaxtextarea-3.0.2.jar ├── oplparse ├── resources ├── examples │ ├── fpql │ │ ├── All Syntax.fpql │ │ ├── Coapply.fpql │ │ ├── Coprod.fpql │ │ ├── Cyclic.fpql │ │ ├── Delta.fpql │ │ ├── Disjunctive.fpql │ │ ├── Employees.fpql │ │ ├── EpiMono Factor.fpql │ │ ├── Flower.fpql │ │ ├── Inconsistent.fpql │ │ ├── Integration.fpql │ │ ├── Monad.fpql │ │ ├── NIST Data.fpql │ │ ├── NIST Full.fpql │ │ ├── NIST IsA.fpql │ │ ├── Nat.fpql │ │ ├── Olog.fpql │ │ ├── Pi.fpql │ │ ├── Prod.fpql │ │ ├── Relationalize.fpql │ │ ├── Reorder Joins.fpql │ │ ├── Reverse.fpql │ │ ├── SELECT CTDB.fpql │ │ ├── SOED.fpql │ │ ├── Sigma.fpql │ │ ├── Tableaux.fpql │ │ ├── Uber Bad.fpql │ │ └── Uber.fpql │ ├── fql │ │ ├── All Syntax.fql │ │ ├── Category.fql │ │ ├── Characteristic Fn.fql │ │ ├── Co-products.fql │ │ ├── Connected Components.fql │ │ ├── Cyclic.fql │ │ ├── Delta.fql │ │ ├── Dihedral 2.fql │ │ ├── EDs to FQL.fql │ │ ├── Employees.fql │ │ ├── Enums (User types).fql │ │ ├── Exponentials 2.fql │ │ ├── Exponentials.fql │ │ ├── External.fql │ │ ├── FOIL.fql │ │ ├── Full Sigma 2.fql │ │ ├── Full Sigma.fql │ │ ├── Function Operations.fql │ │ ├── Gene Ontology.fql │ │ ├── Image.fql │ │ ├── Infinite Employees.fql │ │ ├── Isomorphism.fql │ │ ├── NIST continued.fql │ │ ├── NIST.fql │ │ ├── People.fql │ │ ├── Pi.fql │ │ ├── Products.fql │ │ ├── Prop.fql │ │ ├── Query Composition.fql │ │ ├── Relationalize.fql │ │ ├── SQL to FQL.fql │ │ ├── Schema Matching 2.fql │ │ ├── Schema Matching.fql │ │ ├── Sigma.fql │ │ ├── Sub Schema.fql │ │ ├── Surjective Pi.fql │ │ ├── Transforms.fql │ │ ├── Transforms2.fql │ │ ├── Triangle.fql │ │ ├── Weird.fql │ │ └── Written Macro.fql │ ├── fqlpp │ │ ├── All Syntax.fqlpp │ │ ├── Ben.fqlpp │ │ ├── Categories.fqlpp │ │ ├── Co-Products.fqlpp │ │ ├── Delta.fqlpp │ │ ├── Employees.fqlpp │ │ ├── Exponentials.fqlpp │ │ ├── Integration.fqlpp │ │ ├── Monads.fqlpp │ │ ├── NIST.fqlpp │ │ ├── Pi.fqlpp │ │ ├── Products.fqlpp │ │ ├── Prop.fqlpp │ │ ├── SELECT CTDB.fqlpp │ │ ├── Sets.fqlpp │ │ └── Sigma.fqlpp │ └── opl │ │ ├── Aggregation.opl │ │ ├── Chase.opl │ │ ├── Delta.opl │ │ ├── Disjunctive.opl │ │ ├── Employees.opl │ │ ├── Flower.opl │ │ ├── Grouping.opl │ │ ├── Horn.opl │ │ ├── Integration 2.opl │ │ ├── Integration.opl │ │ ├── JS.opl │ │ ├── Java Double.opl │ │ ├── KB.opl │ │ ├── Matrix.opl │ │ ├── Mod4.opl │ │ ├── Nested 2.opl │ │ ├── Nested.opl │ │ ├── Outer Join.opl │ │ ├── Paper.opl │ │ ├── Pivot.opl │ │ ├── Sigma.opl │ │ ├── Std Lib.opl │ │ ├── Team Pics.opl │ │ ├── Ty Emp.opl │ │ ├── Ty Test.opl │ │ ├── Uber.opl │ │ ├── Unfailing.opl │ │ └── Union.opl └── help.txt └── src └── main └── java └── catdata ├── AlphanumComparator.java ├── Chc.java ├── ClassUtil.java ├── Environment.java ├── IntRef.java ├── LineException.java ├── Pair.java ├── ParseException.java ├── Prog.java ├── Program.java ├── Quad.java ├── Ref.java ├── RuntimeInterruptedException.java ├── Triple.java ├── Unit.java ├── Util.java ├── fpql ├── EnrichViewer.java ├── FpqlTokenMaker.java ├── XChaser.java ├── XChecker.java ├── XCodeEditor.java ├── XCtx.java ├── XDisplay.java ├── XDriver.java ├── XEasikToFQL.java ├── XEnvironment.java ├── XExp.java ├── XJsonToFQL.java ├── XKind.java ├── XMapping.java ├── XNeo4jToFQL.java ├── XObject.java ├── XOps.java ├── XOptions.java ├── XParser.java ├── XPoly.java ├── XProd.java ├── XProgram.java ├── XRaToFpql.java ├── XSqlToFql.java └── XString.java ├── fql ├── Chase.java ├── FQLException.java ├── Fn.java ├── FqlOptions.java ├── FqlUtil.java ├── JDBCBridge.java ├── RaToFql.java ├── RingToFql.java ├── SqlToFql.java ├── cat │ ├── Arr.java │ ├── CommaCat.java │ ├── FDM.java │ ├── FinCat.java │ ├── FinFunctor.java │ ├── FinTrans.java │ ├── Inst.java │ ├── LeftKan.java │ ├── LeftKanCat.java │ ├── LeftKanSigma.java │ ├── SemQuery.java │ ├── SetFunTrans.java │ └── Value.java ├── decl │ ├── Attribute.java │ ├── Driver.java │ ├── Edge.java │ ├── Eq.java │ ├── FQLProgram.java │ ├── FqlEnvironment.java │ ├── FullQuery.java │ ├── FullQueryExp.java │ ├── FullQueryExpChecker.java │ ├── InstChecker.java │ ├── InstExp.java │ ├── InstOps.java │ ├── Instance.java │ ├── InstanceEditor.java │ ├── MapExp.java │ ├── MapExpChecker.java │ ├── Mapping.java │ ├── MyTableRowSorter.java │ ├── Node.java │ ├── Path.java │ ├── PrintNiceMapExpVisitor.java │ ├── Query.java │ ├── QueryChecker.java │ ├── QueryExp.java │ ├── SigExp.java │ ├── SigExpChecker.java │ ├── SigOps.java │ ├── Signature.java │ ├── ToFullQueryExp.java │ ├── ToFullQueryVisitor.java │ ├── TransChecker.java │ ├── TransExp.java │ ├── Transform.java │ ├── TransformEditor.java │ ├── Type.java │ └── Unresolver.java ├── gui │ ├── CategoryOfElements.java │ ├── FqlCodeEditor.java │ └── FqlDisplay.java ├── parse │ ├── BadSyntax.java │ ├── FQLParser.java │ ├── FqlTokenMaker.java │ ├── FqlTokenizer.java │ ├── KeywordParser.java │ ├── LongStringParser.java │ ├── ParserUtils.java │ ├── Partial.java │ ├── PathParser.java │ ├── PrettyPrinter.java │ ├── QuotedParser.java │ ├── RyanParser.java │ ├── StringParser.java │ └── Tokens.java └── sql │ ├── CopyFlower.java │ ├── CreateTable.java │ ├── DropTable.java │ ├── ED.java │ ├── EmbeddedDependency.java │ ├── ExpPSM.java │ ├── Flower.java │ ├── FullSigma.java │ ├── FullSigmaCounit.java │ ├── FullSigmaTrans.java │ ├── InsertEmptyKeygen.java │ ├── InsertKeygen.java │ ├── InsertSQL.java │ ├── InsertSQL2.java │ ├── InsertValues.java │ ├── PSM.java │ ├── PSMAnd.java │ ├── PSMBool.java │ ├── PSMChi.java │ ├── PSMCurry.java │ ├── PSMEval.java │ ├── PSMGen.java │ ├── PSMInterp.java │ ├── PSMIso.java │ ├── PSMNot.java │ ├── PSMStep.java │ ├── PSMUnChi.java │ ├── PropPSM.java │ ├── Relationalizer.java │ ├── SQL.java │ ├── SimpleCreateTable.java │ ├── SquishFlower.java │ └── Union.java ├── fqlpp ├── Ben.java ├── CatExp.java ├── CatOps.java ├── FQLPPCodeEditor.java ├── FQLPPDriver.java ├── FQLPPEnvironment.java ├── FQLPPProgram.java ├── FUNCTION.java ├── FnExp.java ├── FqlPPTokenMaker.java ├── FqlppDisplay.java ├── FqlppOptions.java ├── FunctorExp.java ├── KBViewer.java ├── PPParser.java ├── PreProcessor.java ├── SetExp.java ├── SetOps.java ├── ThueSlow.java ├── TransExp.java └── cat │ ├── Adjunction.java │ ├── Category.java │ ├── CoMonad.java │ ├── Comma.java │ ├── FDM.java │ ├── FPInst.java │ ├── FPTransform.java │ ├── FinCat.java │ ├── FinSet.java │ ├── FiniteCategory.java │ ├── Flower.java │ ├── FunCat.java │ ├── Functor.java │ ├── Groth.java │ ├── Inst.java │ ├── Instance.java │ ├── LeftKan.java │ ├── LeftKanSigma.java │ ├── Mapping.java │ ├── Monad.java │ ├── Pi.java │ ├── Sig.java │ ├── Signature.java │ ├── SubInstances.java │ ├── Subobjects.java │ └── Transform.java ├── graph ├── DAG.java ├── DMG.java ├── PreOrder.java └── UnionFind.java ├── ide ├── ButtonTabComponent.java ├── CodeEditor.java ├── CodeTextPanel.java ├── DefunctGlobalOptions.java ├── Disp.java ├── Example.java ├── Examples.java ├── GUI.java ├── GuiUtil.java ├── IDE.java ├── IdeOptions.java ├── JFontChooser.java ├── Language.java ├── ListOutline.java ├── MyTableRowSorter.java ├── Options.java ├── Outline.java ├── ProgressMonitorWrapper.java └── Split.java ├── opl ├── CfgToOpl.java ├── JSWrapper.java ├── Operad.java ├── OplAggExample.java ├── OplChase.java ├── OplCodeEditor.java ├── OplCtx.java ├── OplDisplay.java ├── OplDoubleExample.java ├── OplDriver.java ├── OplExp.java ├── OplImage.java ├── OplInACan.java ├── OplKB.java ├── OplObject.java ├── OplOps.java ├── OplOptions.java ├── OplOuterExample.java ├── OplParser.java ├── OplQuery.java ├── OplStdLib.java ├── OplString.java ├── OplTerm.java ├── OplToKB.java └── OplTokenMaker.java └── provers ├── DPKB.java ├── KBExp.java ├── KBExpFactory.java ├── KBExpFactoryOldImpl.java ├── KBFO.java ├── KBHorn.java ├── KBOptions.java ├── KBOrders.java ├── KBTheory.java ├── KBUnifier.java ├── LPOUKB.java └── ThueSlow.java /contrib/FQLPP_Examples/SelectFromCTDBIntroductoryTalk.fqlpp: -------------------------------------------------------------------------------- 1 | //The query from http://categoricaldata.net/fql/introSlides.pdf#page=45 2 | //It's best to go to options and choose "Pi ID creation strategy" to be "Summary as ID". 3 | 4 | category C = { 5 | objects 6 | RL3, //numbers less than 3. 7 | R, //numbers 8 | Book, 9 | Isbn_num, 10 | String; 11 | arrows 12 | i:RL3->R, 13 | price:Book->R, 14 | title:Book->String, 15 | isbn:Book->Isbn_num; 16 | equations; 17 | } 18 | 19 | functor I = { 20 | objects 21 | RL3->{1,2}, 22 | R->{1,2,3,4,5}, 23 | Book->{1,2,3}, 24 | Isbn_num->{1,2,3,249,258,4597}, 25 | String->{"a","b","GoneWind","Catch22","CatTheory"}; 26 | arrows 27 | att->{(1,1),(2,2),(3,3),(4,4),(5,5)}, 28 | title->{(1,"GoneWind"),(2,"Catch22"), (3,"CatTheory")}, 29 | isbn->{(1,258),(2,4597),(3,249)}, //Note the last digit of the ISBN is the number of letters in the title. 30 | i->{(1,1),(2,2)}, 31 | price->{(1,4),(2,3),(3,1)}; 32 | } : C->Set 33 | 34 | //Note that there is exactly one book whose price is less than 3. 35 | 36 | category D = { 37 | objects 38 | RL3, 39 | R, 40 | W, 41 | Book, 42 | Isbn_num, 43 | String; 44 | arrows 45 | title:Book->String, 46 | isbn:Book->Isbn_num, 47 | f:W->RL3, 48 | g:W->Book, 49 | i:RL3->R, 50 | price:Book->R; 51 | equations 52 | W.f.i=W.g.price; 53 | } 54 | 55 | functor F = { 56 | objects 57 | RL3->RL3, 58 | R->R, 59 | Book->Book, 60 | Isbn_num->Isbn_num, 61 | String->String; 62 | arrows 63 | i->RL3.i, 64 | price->Book.price, 65 | title->Book.title, 66 | isbn->Book.isbn; 67 | } : C -> D 68 | 69 | 70 | functor pi_F_I = apply pi F on object I 71 | 72 | category E = { 73 | objects W, String, Isbn_num; 74 | arrows title:W->String, isbn:W->Isbn_num; 75 | equations; 76 | } 77 | 78 | functor G = { 79 | objects W->W, String->String, Isbn_num->Isbn_num; 80 | arrows title->W.g.title, isbn->W.g.isbn; 81 | } : E -> D 82 | 83 | functor Select = apply delta G on object pi_F_I 84 | -------------------------------------------------------------------------------- /contrib/FQLPP_Examples/surjectiveFK_chased.fqlpp: -------------------------------------------------------------------------------- 1 | //chasing surjective foreign key 2 | 3 | category C = { 4 | objects a,b,c; 5 | arrows f:a->b,g:a->c; 6 | equations; 7 | } 8 | 9 | functor I = { 10 | objects a->{1,2,3},b->{4,5,6},c->{7,8,9}; 11 | arrows f->{(1,4),(2,4),(3,5)}, g->{(1,7),(2,8),(3,9)}; 12 | } : C -> Set 13 | 14 | category D = { 15 | objects a,b,bb,c; 16 | arrows f:a->b, jj:b->bb, g:a->c; 17 | equations; 18 | } 19 | 20 | functor F = { 21 | objects a->a, b->b,bb->b,c->c; 22 | arrows f->a.f, jj->b, g->a.g; 23 | } : D -> C 24 | 25 | functor d_F_I = apply delta F on object I 26 | 27 | category E = { 28 | objects a,b,bb,a1,b1,c; 29 | arrows f:a->b, jj:b1->bb, i:a->a1,j:b->b1,f1:a1->b1,g:a->c; 30 | equations a.f.j=a.i.f1; 31 | } 32 | 33 | functor G = { 34 | objects a->a, b->b, bb->bb, c->c; 35 | arrows f->a.f, jj->b.j.jj, g->a.g; 36 | } : D -> E 37 | 38 | functor p_G_d_F_I=apply pi G on object d_F_I 39 | 40 | functor H = { 41 | objects a->a, b->b,bb->b,a1->a,b1->b,c->c; 42 | arrows f->a.f, jj->b,i->a,j->b,f1->a.f,g->a.g; 43 | } : E -> C 44 | 45 | functor chased=apply sigma H on object p_G_d_F_I -------------------------------------------------------------------------------- /contrib/FQL_Examples/CompositionUsingDeltaSigmaPi.fql: -------------------------------------------------------------------------------- 1 | /* Here we show that all three data migration functors (delta, pi, SIGMA) 2 | * can be used to compute composition of functions. 3 | * It's good to TURN OBSERVABLES ON. 4 | */ 5 | 6 | schema TwoMaps = { 7 | nodes A,B,C; 8 | attributes attA:A->int,attC:C->int; 9 | arrows sq:A->B,inc:B->C; 10 | equations; 11 | } 12 | 13 | instance I = { 14 | nodes 15 | A->{a,b,c,d}, 16 | B->{m,n,o,p,q}, 17 | C->{v,w,x,y,z}; 18 | attributes 19 | attA->{(a,"-1"),(b,0),(c,1),(d,2)}, 20 | attC->{(v,1),(w,2),(x,3),(y,4),(z,5)}; 21 | arrows 22 | sq->{(a,n),(b,m),(c,n),(d,q)},//square map \x.x^2 23 | inc->{(m,v),(n,w),(o,x),(p,y),(q,z)}//inc map \x.x+1 24 | ; 25 | } : TwoMaps 26 | 27 | schema OneMap = { 28 | nodes A,C; 29 | attributes attA:A->int,attC:C->int; 30 | arrows sqinc:A->C; 31 | equations; 32 | } 33 | 34 | mapping ForDelta = { 35 | nodes A->A,C->C; 36 | attributes attA->attA,attC->attC; 37 | arrows sqinc->A.sq.inc; 38 | } : OneMap -> TwoMaps 39 | 40 | instance ComposeUsingDelta = delta ForDelta I 41 | 42 | mapping ForSIGMA = { 43 | nodes A->A,B->C, C->C; 44 | attributes attA->attA,attC->attC; 45 | arrows sq->A.sqinc,inc->C; 46 | } : TwoMaps -> OneMap 47 | 48 | instance ComposeUsingSigma = SIGMA ForSIGMA I 49 | 50 | mapping ForPi = { 51 | nodes A->A,B->A, C->C; 52 | attributes attA->attA,attC->attC; 53 | arrows sq->A,inc->A.sqinc; 54 | } : TwoMaps -> OneMap 55 | 56 | instance ComposeUsingPi = pi ForPi I -------------------------------------------------------------------------------- /contrib/FQL_Examples/Cosimplicial.fql: -------------------------------------------------------------------------------- 1 | schema Cosimplicial2 = { 2 | nodes 3 | S0, 4 | S01, 5 | S012 6 | ; 7 | attributes; 8 | arrows 9 | Up0, 10 | Up1, 11 | Down00, 12 | Up01, 13 | Up02, 14 | Up12, 15 | Down001, 16 | Down011 17 | ; 18 | equations 19 | ; 20 | } 21 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/CounitExample.fql: -------------------------------------------------------------------------------- 1 | schema One = { 2 | nodes a; 3 | attributes attx:a->string,atty:a->string,attz:a->string; 4 | arrows; 5 | equations; 6 | } 7 | 8 | schema Join = { 9 | nodes x,y,z; 10 | attributes attx:x->string,atty:y->string,attz:z->string; 11 | arrows f:x->z, g:y->z; 12 | equations; 13 | } 14 | 15 | mapping ex = { 16 | nodes x->a, y->a, z->a; 17 | attributes attx->attx, atty->atty, attz->attz; 18 | arrows f->a, g->a; 19 | } : Join -> One 20 | 21 | instance I = { 22 | nodes x->{1,2,3},y->{4,5,6,7},z->{ev,od}; 23 | attributes x->{(1,1),(2,2),(3,3)},y->{(4,4),(5,5),(6,6),(7,7)},z->{(ev,even),(od,odd)}; 24 | arrows f->{(1,od),(2,ev),(3,od)},g->{(4,ev),(5,od),(6,ev),(7,od)}; 25 | } : Join 26 | 27 | instance J = pi ex I 28 | 29 | instance K = delta ex I -------------------------------------------------------------------------------- /contrib/FQL_Examples/Dihedral.fql: -------------------------------------------------------------------------------- 1 | /* Dihedral group Dih(n): (according to http://en.wikipedia.org/wiki/Dihedral_group) 2 | * D_n=< r,s | r^n=1, s^2=1, s^{-1}rs=r^{-1} > 3 | */ 4 | 5 | 6 | 7 | 8 | /* should have 4 elements */ 9 | schema Dihedral2 = { 10 | r: G -> G, s: G -> G; 11 | G.r.r = G, 12 | G.s.s = G, 13 | G.s.r.s=G.r 14 | } 15 | /* should have 8 elements */ 16 | schema Dihedral4 = { 17 | r: G -> G, s: G -> G ; 18 | G.r.r.r.r = G, 19 | G.s.s = G, 20 | G.s.r.s=G.r.r.r 21 | } 22 | 23 | mapping F:Dihedral2->Dihedral4 = { 24 | G->G; 25 | s->G.s, 26 | r->G.r.r 27 | } 28 | 29 | instance I:Dihedral2 = { 30 | G={(0,0),(1,1),(-1,-1)}, 31 | r={(0,0),(1,-1),(-1,1)}, 32 | s={(0,0),(1,1),(-1,-1)} 33 | } 34 | 35 | instance J:Dihedral2 = { 36 | G={(1,1),(-1,-1)}, 37 | r={(1,-1),(-1,1)}, 38 | s={(1,1),(-1,-1)} 39 | } 40 | 41 | instance K:Dihedral2 = { 42 | G={(0,0)}, 43 | r={(0,0)}, 44 | s={(0,0)} 45 | } 46 | 47 | /* 48 | *instance Pi_FI:Dihedral4 = pi F I 49 | */ 50 | 51 | /* 52 | * instance Pi_FJ:Dihedral4 = pi F J 53 | */ 54 | instance Pi_FJ:Dihedral4 = pi F J 55 | 56 | 57 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/FullSigmaAttributeClash.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes a,v; 3 | attributes vatt:v->string; 4 | arrows s:a->v, t:a->v; 5 | equations; 6 | } 7 | 8 | instance I = { 9 | nodes 10 | a -> {2, 1}, 11 | v -> {b, a2, a1}; 12 | attributes 13 | vatt -> {(b, bob), (a2, alice), (a1, alice)}; 14 | arrows 15 | t -> {(2, a1), (1, b)}, 16 | s -> {(2, a2), (1, a2)}; 17 | } : C 18 | 19 | instance I2 = { 20 | nodes 21 | a -> {1}, 22 | v -> {b, a2, a1}; 23 | attributes 24 | vatt -> {(b, bob), (a2, alice), (a1, alice)}; 25 | arrows 26 | t -> {(1, a1)}, 27 | s -> {(1, a2)}; 28 | } : C 29 | 30 | schema D = { 31 | nodes v; 32 | attributes vatt:v->string; 33 | arrows; 34 | equations; 35 | } 36 | 37 | mapping F = { 38 | nodes a->v,v->v; 39 | attributes vatt->vatt; 40 | arrows s->v, t->v; 41 | } : C -> D 42 | 43 | //instance J = SIGMA F I 44 | instance J2 = SIGMA F I2 -------------------------------------------------------------------------------- /contrib/FQL_Examples/GatesSchemaB.fql: -------------------------------------------------------------------------------- 1 | schema Bbig = { 2 | nodes 3 | patient, 4 | BPl, 5 | BPr, 6 | Wts, 7 | Wtb; 8 | attributes 9 | valbpl:BPl->int, 10 | valbpr:BPr->int, 11 | valwts:Wts->int, 12 | valwtb:Wtb->int, 13 | name:patient->string 14 | ; 15 | arrows 16 | bplpat:BPl->patient, 17 | bprpat:BPr->patient, 18 | wtspat:Wts->patient, 19 | wtbpat:Wtb->patient; 20 | equations; 21 | } 22 | 23 | instance I = { 24 | nodes 25 | patient->{p,j}, 26 | BPl->{p,j}, 27 | BPr->{p}, 28 | Wts->{j}, 29 | Wtb->{}; 30 | attributes 31 | valbpl->{(p,130),(j,115)}, 32 | valbpr->{(p,125)}, 33 | valwts->{(j,130)}, 34 | valwtb->{}, 35 | name->{(p,Peter),(j,Jane)} 36 | ; 37 | arrows 38 | bplpat->{(p,p),(j,j)}, 39 | bprpat->{(p,p)}, 40 | wtspat->{(j,j)}, 41 | wtbpat->{}; 42 | 43 | } : Bbig 44 | 45 | schema B = { 46 | nodes Obs,Pat; 47 | attributes val:Obs->int,name:Pat->string; 48 | arrows ObsPat:Obs->Pat; 49 | equations; 50 | } 51 | 52 | mapping F = { 53 | nodes 54 | patient->Pat, 55 | BPl->Obs, 56 | BPr->Obs, 57 | Wts->Obs, 58 | Wtb->Obs; 59 | attributes 60 | valbpl->val, 61 | valbpr->val, 62 | valwts->val, 63 | valwtb->val, 64 | name->name 65 | ; 66 | arrows 67 | bplpat->Obs.ObsPat, 68 | bprpat->Obs.ObsPat, 69 | wtspat->Obs.ObsPat, 70 | wtbpat->Obs.ObsPat; 71 | } : Bbig -> B 72 | 73 | instance J=sigma F I 74 | 75 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/GraphDatabases.fpql: -------------------------------------------------------------------------------- 1 | dom : type 2 | string : type 3 | 61 Mary: dom 4 | mother person woman age name : string 5 | 6 | G = schema { 7 | nodes Arrow, Node, NodeProperty; 8 | edges 9 | labA: Arrow->string, 10 | labN: Node ->string, 11 | Pname: NodeProperty -> string, 12 | val: NodeProperty-> dom, 13 | src: Arrow->Node, 14 | tgt: Arrow->Node, 15 | isOn: NodeProperty->Node 16 | ; 17 | equations; 18 | } 19 | 20 | //I changed this a little bit, so that mother: person -> woman, rather than mother:person->person 21 | 22 | I = instance { 23 | variables e : Arrow , n m w: Node, a b c d: NodeProperty; 24 | equations 25 | e.src=n, e.tgt=w, e.labA=mother, 26 | n.labN=person, m.labN=person, w.labN=woman, 27 | a.isOn=n, a.Pname=age, a.val=61, 28 | b.isOn=w, b.Pname=name, 29 | c.isOn=n, c.Pname=name, c.val=b.val, 30 | d.isOn=m, d.Pname=name, d.val=Mary; 31 | } 32 | : G 33 | 34 | FQL_Schema_for_I = schema { 35 | nodes nmperson, wwoman; 36 | edges 37 | emother: nmperson->wwoman, 38 | aage: nmperson->dom, bname:wwoman->dom, cname:nmperson->dom 39 | ; 40 | equations; 41 | } 42 | 43 | FQL_Instance_for_I = instance { 44 | variables n m : nmperson, w: wwoman; 45 | equations n.emother = w, n.aage=61, w.bname=n.cname, m.cname=Mary; 46 | } 47 | : FQL_Schema_for_I -------------------------------------------------------------------------------- /contrib/FQL_Examples/KernelPair.fql: -------------------------------------------------------------------------------- 1 | schema Arrow = { 2 | nodes a,b; 3 | attributes; 4 | arrows f:a->b; 5 | equations; 6 | } 7 | 8 | instance I = { 9 | nodes a->{i11,i21,i22,i23},b->{j0,j1,j2}; 10 | attributes; 11 | arrows f->{(i11,j1),(i21,j2),(i22,j2),(i23,j2)}; 12 | } : Arrow 13 | 14 | schema C = { 15 | nodes a1,a2,b; 16 | attributes; 17 | arrows f1:a1->b, f2:a2->b,g:a1->a2,h:a2->a1; 18 | equations a1.g.h=a1,a2.h.g=a2; 19 | } 20 | 21 | mapping C2Arr = { 22 | nodes a1->a, a2->a, b->b; 23 | attributes; 24 | arrows f1->a.f, f2->a.f, g->a,h->a; 25 | } : C -> Arrow 26 | 27 | instance J=delta C2Arr I 28 | 29 | schema D = { 30 | nodes NW,NE,SW,SE; 31 | attributes; 32 | arrows n:NW->NE,w:NW->SW,e:NE->SE,s:SW->SE,g:NE->SW,h:SW->NE; 33 | equations NW.n.e=NW.w.s, NE.g.h=NE, SW.h.g=SW; 34 | } 35 | 36 | mapping C2D = { 37 | nodes a1->NE,a2->SW,b->SE; 38 | attributes; 39 | arrows f1->NE.e,f2->SW.s, g->NE.g,h->SW.h; 40 | } : C -> D 41 | 42 | instance K=pi C2D J 43 | 44 | 45 | schema E = { 46 | nodes a,b1,b2; 47 | attributes; 48 | arrows f1:a->b1,f2:a->b2,g:b1->b2,h:b2->b1; 49 | equations b1.g.h=b1,b2.h.g=b2; 50 | } 51 | 52 | mapping E2D = { 53 | nodes a->NW,b1->NE,b2->SW; 54 | attributes; 55 | arrows f1->NW.n,f2->NW.w,g->NE.g, h->SW.h; 56 | } : E -> D 57 | 58 | instance L=delta E2D K 59 | 60 | schema Parallel = { 61 | nodes a,b; 62 | attributes; 63 | arrows f1:a->b,f2:a->b; 64 | equations; 65 | } 66 | 67 | mapping E2Par = { 68 | nodes a->a,b1->b,b2->b; 69 | attributes; 70 | arrows f1->a.f1,f2->a.f2, g->b,h->b; 71 | } : E -> Parallel 72 | 73 | instance M=pi E2Par L 74 | 75 | mapping F=unit{} Parallel 76 | 77 | instance N=SIGMA F M 78 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/ReflPaths.fql: -------------------------------------------------------------------------------- 1 | schema Path1 = { //This is the graph-indexing schema 2 | nodes A1,A0; 3 | attributes att1:A1->string,att0:A0->string; 4 | arrows src1:A1->A0, tgt1:A1->A0; 5 | equations; 6 | } 7 | 8 | 9 | instance G1 = { 10 | nodes A0->{a,b,c}, A1->{f,g}; 11 | attributes att0->{(a,a),(b,b),(c,c)},att1->{(f,f),(g,g)}; 12 | arrows src1->{(f,a),(g,b)},tgt1->{(f,b),(g,c)}; 13 | } : Path1 14 | 15 | schema ReflPath1 = { 16 | nodes A1,A0; 17 | attributes att1:A1->string,att0:A0->string; 18 | arrows src1:A1->A0, tgt1:A1->A0, refl0:A0->A1; 19 | equations A0.refl0.src1=A0,A0.refl0.tgt1=A0; 20 | } 21 | 22 | mapping Reflizer1 = { 23 | nodes A0->A0, A1->A1; 24 | attributes att0->att0,att1->att1; 25 | arrows src1->A1.src1, tgt1->A1.tgt1; 26 | } : Path1 -> ReflPath1 27 | 28 | instance Refl_G1=SIGMA Reflizer1 G1 29 | 30 | schema Refl1Path2 = { 31 | nodes A2,A1,A0; 32 | attributes att1:A1->string,att0:A0->string; 33 | arrows 34 | src2:A2->A1, 35 | tgt2:A2->A1, 36 | src1:A1->A0, 37 | tgt1:A1->A0, 38 | refl0:A0->A1; 39 | equations 40 | A2.src2.tgt1=A2.tgt2.src1, 41 | A0.refl0.src1=A0,A0.refl0.tgt1=A0; 42 | } 43 | 44 | mapping UpTo2 = { 45 | nodes A0->A0,A1->A1; 46 | attributes att1->att1,att0->att0; 47 | arrows 48 | src1->A1.src1, 49 | tgt1->A1.tgt1, 50 | refl0->A0.refl0; 51 | } : ReflPath1 -> Refl1Path2 52 | 53 | instance U2R_G1=pi UpTo2 Refl_G1 54 | 55 | schema Refl2Path2 = { 56 | nodes A2,A1,A0; 57 | attributes att1:A1->string,att0:A0->string; 58 | arrows 59 | src2:A2->A1, 60 | tgt2:A2->A1, 61 | src1:A1->A0, 62 | tgt1:A1->A0, 63 | refl0:A0->A1, 64 | refl1:A1->A2; 65 | equations 66 | A2.src2.tgt1=A2.tgt2.src1, 67 | A0.refl0.src1=A0,A0.refl0.tgt1=A0, 68 | A1.refl1.src2=A1,A1.refl1.tgt2=A1; 69 | } 70 | 71 | mapping Reflizer2 = { 72 | nodes A0->A0, A1->A1,A2->A2; 73 | attributes att0->att0,att1->att1; 74 | arrows 75 | src1->A1.src1, 76 | tgt1->A1.tgt1, 77 | refl0->A0.refl0, 78 | src2->A2.src2, 79 | tgt2->A2.tgt2; 80 | } : Refl1Path2 -> Refl2Path2 81 | 82 | //instance R2_U2_R_G1 = SIGMA Reflizer2 U2R_G1 83 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/SelectFromCTDBIntroductoryTalk.fql: -------------------------------------------------------------------------------- 1 | //The query from http://categoricaldata.net/fql/introSlides.pdf#page=45 2 | //This is a mix of using attributes and not. Later versions of FQL will be able to use constants in SELECT statements. 3 | 4 | category C = { 5 | objects 6 | RL3, //numbers less than 3. 7 | R, //numbers 8 | Book, 9 | Isbn_num, 10 | String; 11 | arrows 12 | i:RL3->R, 13 | price:Book->R, 14 | title:Book->String, 15 | isbn:Book->Isbn_num; 16 | equations; 17 | } 18 | 19 | functor I = { 20 | objects 21 | RL3->{1,2}, 22 | R->{1,2,3,4,5}, 23 | Book->{1,2,3}, 24 | Isbn_num->{1,2,3,249,258,4597}, 25 | String->{"a","b","GoneWind","Catch22","CatTheory"}; 26 | arrows 27 | att->{(1,1),(2,2),(3,3),(4,4),(5,5)}, 28 | title->{(1,"GoneWind"),(2,"Catch22"), (3,"CatTheory")}, 29 | isbn->{(1,258),(2,4597),(3,249)}, //Note the last digit of the ISBN is the number of letters in the title. 30 | i->{(1,1),(2,2)}, 31 | price->{(1,4),(2,3),(3,1)}; 32 | } : C->Set 33 | 34 | //Note that there is exactly one book whose price is less than 3. 35 | 36 | category D = { 37 | objects 38 | RL3, 39 | R, 40 | W, 41 | Book, 42 | Isbn_num, 43 | String; 44 | arrows 45 | title:Book->String, 46 | isbn:Book->Isbn_num, 47 | f:W->RL3, 48 | g:W->Book, 49 | i:RL3->R, 50 | price:Book->R; 51 | equations 52 | W.f.i=W.g.price; 53 | } 54 | 55 | functor F = { 56 | objects 57 | RL3->RL3, 58 | R->R, 59 | Book->Book, 60 | Isbn_num->Isbn_num, 61 | String->String; 62 | arrows 63 | i->RL3.i, 64 | price->Book.price, 65 | title->Book.title, 66 | isbn->Book.isbn; 67 | } : C -> D 68 | 69 | 70 | functor pi_F_I = apply pi F on object I 71 | 72 | category E = { 73 | objects W, String, Isbn_num; 74 | arrows title:W->String, isbn:W->Isbn_num; 75 | equations; 76 | } 77 | 78 | functor G = { 79 | objects W->W, String->String, Isbn_num->Isbn_num; 80 | arrows title->W.g.title, isbn->W.g.isbn; 81 | } : E -> D 82 | 83 | functor Select = apply delta G on object pi_F_I -------------------------------------------------------------------------------- /contrib/FQL_Examples/SetFullSubcategory.fql: -------------------------------------------------------------------------------- 1 | schema upto2 = { 2 | nodes 3 | a0, 4 | a1, 5 | a2; 6 | attributes; 7 | arrows 8 | f01:a0->a1, 9 | f12_1:a1->a2, 10 | f21:a2->a1, 11 | f22_21:a2->a2; 12 | equations 13 | a0.f01.f12_1.f22_21=a0.f01.f12_1, 14 | a1.f12_1.f21=a1, 15 | a2.f22_21.f22_21=a2, 16 | a2.f22_21.f21=a2.f21 17 | ; 18 | } 19 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/Simplex2Cat.fql: -------------------------------------------------------------------------------- 1 | schema D0 = { 2 | nodes a0; 3 | attributes; 4 | arrows; 5 | equations; 6 | } 7 | 8 | schema D1 = { 9 | nodes a0, a1; 10 | attributes; 11 | arrows af : a0 -> a1; 12 | equations; 13 | } 14 | 15 | schema D2 = { 16 | nodes b0, b1, b2; 17 | attributes; 18 | arrows bf1 : b0 -> b1, bf2 : b1 -> b2; 19 | equations; 20 | } 21 | 22 | schema D3 = { 23 | nodes b0, b1, b2, b3; 24 | attributes; 25 | arrows bf1 : b0 -> b1, bf2 : b1 -> b2, bf3: b2->b3; 26 | equations; 27 | } 28 | 29 | 30 | 31 | schema H0_0=(D0^D0) 32 | schema H0_1=(D0^D1) 33 | schema H0_2=(D0^D2) 34 | schema H0_3=(D0^D3) 35 | 36 | schema H1_0=(D1^D0) 37 | schema H1_1=(D1^D1) 38 | schema H1_2=(D1^D2) 39 | schema H1_3=(D1^D3) 40 | 41 | schema H2_0=(D2^D0) 42 | schema H2_1=(D2^D1) 43 | schema H2_2=(D2^D2) 44 | schema H2_3=(D2^D3) 45 | 46 | schema H3_0=(D3^D0) 47 | schema H3_1=(D3^D1) 48 | schema H3_2=(D3^D2) 49 | //schema H3_3=(D3^D3) -------------------------------------------------------------------------------- /contrib/FQL_Examples/SimplexCategory.fql: -------------------------------------------------------------------------------- 1 | schema SimplexCategory = { 2 | nodes 3 | s1, 4 | s12, 5 | s123 6 | ; 7 | attributes; 8 | arrows 9 | //s1->s1 10 | f11_1:s1->s1, 11 | //s1->s2 12 | f12_1:s1->s2, 13 | f12_2:s1->s2, 14 | //s1->s3 15 | f13_1:s1->s3, 16 | f13_2:s1->s3, 17 | f13_3:s1->s3, 18 | //s2->s1 19 | f21_11:s2->s1, 20 | //s2->s2 21 | f22_11:s2->s2, 22 | f22_12:s2->s2, 23 | f22_22:s2->s2, 24 | //s2->s3 25 | f23_11:s2->s3, 26 | f23_12:s2->s3, 27 | f23_13:s2->s3, 28 | f23_22:s2->s3, 29 | f23_23:s2->s3, 30 | f23_33:s2->s3, 31 | //s3->s1 32 | f31_111:s3->s1, 33 | //s3->s2 34 | f32_111:s3->s2, 35 | f32_112:s3->s2, 36 | f32_122:s3->s2, 37 | f32_222:s3->s2, 38 | //s3->s3 39 | f33_111:s3->s3 40 | f33_112:s3->s3 41 | f33_113:s3->s3 42 | f33_122:s3->s3 43 | f33_123:s3->s3 44 | f33_133:s3->s3 45 | f33_222:s3->s3 46 | f33_223:s3->s3 47 | f33_233:s3->s3 48 | f33_333:s3->s3 49 | ; 50 | equations; 51 | } 52 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/StateMachine.fql: -------------------------------------------------------------------------------- 1 | schema StateMachineABC = { 2 | nodes 3 | states; 4 | attributes 5 | output:states->string; 6 | arrows 7 | A:states->states, 8 | B:states->states, 9 | C:states->states; 10 | equations 11 | states.A.B=states.B.A, 12 | states.A.C=states.C.A, 13 | states.B.C=states.C.B, 14 | states.A.A=states.A, 15 | states.B.B=states.B, 16 | states.C.C=states.C 17 | ; 18 | } 19 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/TGD.fql: -------------------------------------------------------------------------------- 1 | //I want the TGD forall x,y R(x,y) => exists z S(y,z). 2 | 3 | schema X = { 4 | nodes r,s,x,y,z; 5 | attributes; 6 | arrows rx:r->x,ry:r->y, sy:s->y, sz:s->z; 7 | equations; 8 | } 9 | 10 | instance I = { 11 | nodes r->{1,2}, s->{1,2}, x->{x1,x2},y->{y1,y2,y3},z->{z1,z3}; 12 | attributes; 13 | arrows 14 | rx->{(1,x1),(2,x2)}, 15 | ry->{(1,y1),(2,y2)}, 16 | sy->{(1,y1),(2,y3)}, 17 | sz->{(1,z1),(2,z3)} 18 | ; 19 | } : X 20 | 21 | schema X1 = { 22 | nodes rs,r,s,x,y,z; 23 | attributes; 24 | arrows rsr:rs->r,rss:rs->s,rx:r->x,ry:r->y, sy:s->y, sz:s->z; 25 | equations rs.rsr.ry=rs.rss.sy; 26 | } 27 | 28 | mapping F1 = { 29 | nodes r->r, s->s,x->x,y->y,z->z; 30 | attributes; 31 | arrows rx->r.rx, ry->r.ry, sy->s.sy, sz->s.sz; 32 | } : X -> X1 33 | 34 | instance I1 = pi F1 I 35 | 36 | schema X2 = { 37 | nodes r,s,x,y,z; 38 | attributes; 39 | arrows rs:r->s, rx:r->x,ry:r->y, sy:s->y, sz:s->z; 40 | equations r.rs.sy=r.ry; 41 | } 42 | 43 | mapping F2 = { 44 | nodes rs->r,r->r,s->s,x->x,y->y,z->z; 45 | attributes; 46 | arrows rsr->r, rss->r.rs,rx->r.rx,ry->r.ry,sy->s.sy,sz->s.sz; 47 | } : X1 -> X2 48 | 49 | instance I2 = SIGMA F2 I1 50 | 51 | mapping G = { 52 | nodes r->r,s->s,x->x,y->y,z->z; 53 | attributes; 54 | arrows rx->r.rx, ry->r.ry, sy->s.sy, sz->s.sz; 55 | } : X -> X2 56 | 57 | instance J = delta G I2 -------------------------------------------------------------------------------- /contrib/FQL_Examples/cyclicGroups.fql: -------------------------------------------------------------------------------- 1 | /* Dihedral group Dih(n): (according to http://en.wikipedia.org/wiki/Dihedral_group) 2 | * D_n=< r,s | r^n=1, s^2=1, s^{-1}rs=r^{-1} > 3 | */ 4 | 5 | 6 | 7 | 8 | /* should have 4 elements */ 9 | schema Z2 = { 10 | r: G -> G; 11 | G.r.r = G 12 | } 13 | /* should have 8 elements */ 14 | schema Z4 = { 15 | r: G -> G; 16 | G.r.r.r.r = G 17 | } 18 | 19 | mapping F:Z2->Z4 = { 20 | G->G; 21 | r->G.r.r 22 | } 23 | 24 | instance I:Z2 = { 25 | G={(0,0),(1,1),(-1,-1)}, 26 | r={(0,0),(1,-1),(-1,1)} 27 | } 28 | 29 | instance J:Z2 = { 30 | G={(1,1),(-1,-1)}, 31 | r={(1,-1),(-1,1)} 32 | } 33 | 34 | instance K:Z2 = { 35 | G={(0,0)}, 36 | r={(0,0)} 37 | } 38 | 39 | /* 40 | *instance Pi_FI:Dihedral4 = pi F I 41 | */ 42 | 43 | /* 44 | * instance Pi_FJ:Dihedral4 = pi F J 45 | */ 46 | instance Pi_FK:Z4 = pi F K 47 | 48 | 49 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/forceInjective.fql: -------------------------------------------------------------------------------- 1 | //I'm wondering what happens when I take a non-injective function and force it to be an injective map 2 | //using a left pushforward to the retract schema. 3 | 4 | schema C = { 5 | nodes E,B; 6 | attributes 7 | //ASWRITTEN 8 | ; 9 | arrows s:B->E; 10 | equations; 11 | } 12 | 13 | instance I1 = { 14 | nodes E->{11,21,22,31,32,33}, B->{1,2,3}; 15 | attributes 16 | //ASWRITTEN 17 | ; 18 | arrows s->{(1,11),(2,21),(3,31)}; 19 | } : C 20 | 21 | instance I2 = { 22 | nodes E->{11,21,22,31,32,33}, B->{1,2,311,312}; 23 | attributes 24 | //ASWRITTEN 25 | ; 26 | arrows s->{(1,11),(2,21),(311,31),(312,31)}; 27 | } : C 28 | 29 | schema D = { 30 | nodes E,B; 31 | attributes 32 | //ASWRITTEN 33 | ; 34 | arrows s:B->E, p:E->B; 35 | equations B.s.p=B; 36 | } 37 | 38 | mapping F = { 39 | nodes E->E, B->B; 40 | attributes 41 | //B_att->B_att, E_att->E_att 42 | ; 43 | arrows s->B.s; 44 | } : C -> D 45 | 46 | instance J1=SIGMA F I1 47 | instance J2=SIGMA F I2 48 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/imageFactorization.fql: -------------------------------------------------------------------------------- 1 | /* This file starts with a function f:x->y 2 | * and factors it as a surjection, x->im, followed by an injection im->y. 3 | * This is done using data migration queries delta,pi,SIGMA. 4 | * The function f is encoded as an A-instance J:A->Set. 5 | */ 6 | 7 | schema A = { 8 | nodes x,y; 9 | attributes; 10 | arrows f:x->y; 11 | equations; 12 | } 13 | 14 | schema B = { 15 | nodes a,b,c,d; 16 | attributes; 17 | arrows f:a->b,g:a->c,h:b->d,i:c->d; 18 | equations;//? 19 | } 20 | 21 | schema C = { 22 | nodes a,b,c,d,e; 23 | attributes; 24 | arrows f:a->b,g:a->c,h:b->d,i:c->d, ff:e->b,gg:e->c; 25 | equations e.ff.h=e.gg.i; 26 | } 27 | 28 | schema D = { 29 | nodes v,w,x,y; 30 | attributes; 31 | arrows f:v->w,ff:v->w,g:w->x,h:x->y; 32 | equations v.f.g=v.ff.g; 33 | } 34 | 35 | schema E = { 36 | nodes x,im,y; 37 | attributes; 38 | arrows f:x->im, g:im->y; 39 | equations; 40 | } 41 | 42 | mapping F = { 43 | nodes a->x,b->x,c->x,d->y; 44 | attributes; 45 | arrows f->x,g->x,h->x.f,i->x.f; 46 | } : B -> A 47 | 48 | mapping G = { 49 | nodes a->a,b->b,c->c,d->d; 50 | attributes ; 51 | arrows f->a.f,g->a.g,h->b.h,i->c.i; 52 | } : B -> C 53 | 54 | mapping H = { 55 | nodes e->v,a->w,b->w,c->w,d->y; 56 | attributes; 57 | arrows f->w,g->w,h->w.g.h,i->w.g.h,ff->v.f,gg->v.ff; 58 | } : C -> D 59 | 60 | mapping I = { 61 | nodes x->w,im->x,y->y; 62 | attributes; 63 | arrows f->w.g, g->x.h; 64 | } : E -> D 65 | 66 | 67 | instance J = { 68 | nodes x->{1,2,3,4,5,6},y->{1,2,3,4}; 69 | attributes; 70 | arrows f->{(1,1),(2,1),(3,1),(4,2),(5,2),(6,3)}; 71 | } : A 72 | 73 | instance J2=delta F J 74 | 75 | instance J3=pi G J2 76 | 77 | instance J4=SIGMA H J3 78 | 79 | instance ImageFactorization=delta I J4 80 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/provenance.fql: -------------------------------------------------------------------------------- 1 | schema W1 = { 2 | nodes 3 | P, a1, a2, a3; 4 | attributes prov:P->string, att1:a1->string,att2:a2->string,att3:a3->string; 5 | arrows p1:P->a1,p2:P->a2,p3:P->a3; 6 | equations; 7 | } 8 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/pushoutExperiment.fql: -------------------------------------------------------------------------------- 1 | schema Arrow = { 2 | nodes A,B; 3 | attributes;// Aatt:A->string,Batt:B->string; 4 | arrows f:A->B; 5 | equations; 6 | } 7 | 8 | schema D2 = { 9 | nodes A,B; 10 | attributes;// Aatt:A->string,Batt:B->string; 11 | arrows; 12 | equations; 13 | } 14 | 15 | schema D1 = { 16 | nodes X; 17 | attributes;// Xatt:X->string; 18 | arrows; 19 | equations; 20 | } 21 | 22 | schema Loop = { 23 | nodes X; 24 | attributes;// Xatt:X->string; 25 | arrows f:X->X; 26 | equations X.f.f.f.f=X.f.f.f.f.f; 27 | } 28 | 29 | mapping D2Arrow = { 30 | nodes A->A,B->B; 31 | attributes;// Aatt->Aatt,Batt->Batt; 32 | arrows; 33 | } : D2 -> Arrow 34 | 35 | mapping ArrowLoop = { 36 | nodes A->X,B->X; 37 | attributes ; 38 | arrows f->X.f; 39 | } : Arrow -> Loop 40 | 41 | instance P = { 42 | nodes A->{1,2,3,4},B->{1,2,3,4}; 43 | attributes; 44 | arrows f->{(1,2),(2,4),(3,2),(4,4)}; 45 | } : Arrow 46 | 47 | instance P2 = pi ArrowLoop P 48 | -------------------------------------------------------------------------------- /contrib/FQL_Examples/retract.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes E, D; 3 | attributes EName:E->string,DName:D->string; 4 | arrows Works:E->D, Secr:D->E; 5 | equations D.Secr.Works=D; 6 | } 7 | 8 | schema C0 = { 9 | nodes E,D; 10 | attributes EName:E->string,DName:D->string; 11 | arrows; 12 | equations; 13 | } 14 | 15 | instance I = { 16 | nodes E->{a,b,c},D->{l,m}; 17 | attributes EName->{(a,amy),(b,bob),(c,carl)},DName->{(l,ling),(m,math)}; 18 | arrows ; 19 | } : C0 20 | 21 | mapping ii = { 22 | nodes E->E,D->D; 23 | attributes EName->EName,DName->DName; 24 | arrows; 25 | } : C0 -> C 26 | 27 | instance J= pi ii I -------------------------------------------------------------------------------- /contrib/FQL_Examples/strength.fql: -------------------------------------------------------------------------------- 1 | schema AxPB = { 2 | nodes a,b,Pb,Pbp,axPb; 3 | attributes atta:a->string,attb:b->string; 4 | arrows pi1:axPb->a,pi2:axPb->Pb,el:Pbp->b,set:Pbp->Pb; 5 | equations; 6 | } 7 | 8 | instance I = { 9 | nodes 10 | a->{1,2}, 11 | b->{a,b,c}, 12 | Pb->{e,a,b,c,ab,ac,bc,abc}, 13 | Pbp->{a,b,c,aba,abb,aca,acc,bcb,bcc,abca,abcb,abcc}, 14 | axPb->{e1,e2,a1,a2,b1,b2,c1,c2,ab1,ab2,ac1,ac2,bc1,bc2,abc1,abc2}; 15 | attributes 16 | atta->{(1,1),(2,2)}, 17 | attb->{(a,a),(b,b),(c,c)}; 18 | arrows 19 | pi1->{(e1,1),(e2,2),(a1,1),(a2,2),(b1,1),(b2,2),(c1,1),(c2,2),(ab1,1),(ab2,2),(ac1,1),(ac2,2),(bc1,1),(bc2,2),(abc1,1),(abc2,2)}, 20 | pi2->{(e1,e),(e2,e),(a1,a),(a2,a),(b1,b),(b2,b),(c1,c),(c2,c),(ab1,ab),(ab2,ab),(ac1,ac),(ac2,ac),(bc1,bc),(bc2,bc),(abc1,abc),(abc2,abc)}, 21 | el->{(a,a),(b,b),(c,c),(aba,a),(abb,b),(aca,a),(acc,c),(bcb,b),(bcc,c),(abca,a),(abcb,b),(abcc,c)}, 22 | set->{(a,a),(b,b),(c,c),(aba,ab),(abb,ab),(aca,ac),(acc,ac),(bcb,bc),(bcc,bc),(abca,abc),(abcb,abc),(abcc,abc)}; 23 | } : AxPB 24 | 25 | schema C = { 26 | nodes a,b,Pb,axPb,Pbp,axPbp,axb; 27 | attributes atta:a->string,attb:b->string; 28 | arrows 29 | pi1:axPb->a, 30 | pi2:axPb->Pb, 31 | el:Pbp->b, 32 | set:Pbp->Pb, 33 | q1:axPbp->axPb, 34 | q2:axPbp->Pbp, 35 | r1:axb->a, 36 | r2:axb->b, 37 | link:axPbp->axb; 38 | equations 39 | axPbp.q1.pi2=axPbp.q2.set, 40 | axPbp.q1.pi1=axPbp.link.r1, 41 | axPbp.q2.el=axPbp.link.r2; 42 | } 43 | 44 | mapping F = {//an inclusion 45 | nodes 46 | a->a, 47 | b->b, 48 | Pb->Pb, 49 | Pbp->Pbp, 50 | axPb->axPb; 51 | attributes atta->atta,attb->attb; 52 | arrows 53 | pi1->axPb.pi1, 54 | pi2->axPb.pi2, 55 | el->Pbp.el, 56 | set->Pbp.set; 57 | } : AxPB -> C 58 | 59 | instance I2=pi F I 60 | 61 | schema PAxB = { 62 | nodes a,b,axb,Paxbp,Paxb; 63 | attributes atta:a->string,attb:b->string; 64 | arrows pi1:axb->a,pi2:axb->b,el:Paxbp->axb,set:Paxbp->Paxb; 65 | equations; 66 | } 67 | 68 | mapping G = { 69 | nodes a->a,b->b,axb->axb,Paxbp->axPbp,Paxb->axPb; 70 | attributes atta->atta,attb->attb; 71 | arrows pi1->axb.r1,pi2->axb.r2,el->axPbp.link,set->axPbp.q1; 72 | } : PAxB -> C 73 | 74 | instance I3=delta G I2 -------------------------------------------------------------------------------- /contrib/FQL_Examples/weirdPattern.fql: -------------------------------------------------------------------------------- 1 | dd -------------------------------------------------------------------------------- /doc/fqlmanual/composition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/composition.png -------------------------------------------------------------------------------- /doc/fqlmanual/deltaI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/deltaI.png -------------------------------------------------------------------------------- /doc/fqlmanual/deltaJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/deltaJ.png -------------------------------------------------------------------------------- /doc/fqlmanual/elements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/elements.png -------------------------------------------------------------------------------- /doc/fqlmanual/initial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/initial.png -------------------------------------------------------------------------------- /doc/fqlmanual/instance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/instance.png -------------------------------------------------------------------------------- /doc/fqlmanual/mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/mapping.png -------------------------------------------------------------------------------- /doc/fqlmanual/observe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/observe.png -------------------------------------------------------------------------------- /doc/fqlmanual/people.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/people.png -------------------------------------------------------------------------------- /doc/fqlmanual/piI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/piI.png -------------------------------------------------------------------------------- /doc/fqlmanual/piJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/piJ.png -------------------------------------------------------------------------------- /doc/fqlmanual/schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/schema.png -------------------------------------------------------------------------------- /doc/fqlmanual/sigmaI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/sigmaI.png -------------------------------------------------------------------------------- /doc/fqlmanual/sigmaJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlmanual/sigmaJ.png -------------------------------------------------------------------------------- /doc/fqlppmanual/composition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/composition.png -------------------------------------------------------------------------------- /doc/fqlppmanual/deltaI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/deltaI.png -------------------------------------------------------------------------------- /doc/fqlppmanual/deltaJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/deltaJ.png -------------------------------------------------------------------------------- /doc/fqlppmanual/elements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/elements.png -------------------------------------------------------------------------------- /doc/fqlppmanual/initial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/initial.png -------------------------------------------------------------------------------- /doc/fqlppmanual/instance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/instance.png -------------------------------------------------------------------------------- /doc/fqlppmanual/mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/mapping.png -------------------------------------------------------------------------------- /doc/fqlppmanual/observe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/observe.png -------------------------------------------------------------------------------- /doc/fqlppmanual/people.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/people.png -------------------------------------------------------------------------------- /doc/fqlppmanual/piI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/piI.png -------------------------------------------------------------------------------- /doc/fqlppmanual/piJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/piJ.png -------------------------------------------------------------------------------- /doc/fqlppmanual/schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/schema.png -------------------------------------------------------------------------------- /doc/fqlppmanual/sigmaI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/sigmaI.png -------------------------------------------------------------------------------- /doc/fqlppmanual/sigmaJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/fqlppmanual/sigmaJ.png -------------------------------------------------------------------------------- /doc/oplmanual/group1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/group1.png -------------------------------------------------------------------------------- /doc/oplmanual/group2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/group2.png -------------------------------------------------------------------------------- /doc/oplmanual/group3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/group3.png -------------------------------------------------------------------------------- /doc/oplmanual/initial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/initial.png -------------------------------------------------------------------------------- /doc/oplmanual/instance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/instance.png -------------------------------------------------------------------------------- /doc/oplmanual/instance1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/instance1.png -------------------------------------------------------------------------------- /doc/oplmanual/instance2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/instance2.png -------------------------------------------------------------------------------- /doc/oplmanual/ml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/ml.png -------------------------------------------------------------------------------- /doc/oplmanual/nested1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/nested1.png -------------------------------------------------------------------------------- /doc/oplmanual/nested2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/nested2.png -------------------------------------------------------------------------------- /doc/oplmanual/team.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/team.png -------------------------------------------------------------------------------- /doc/oplmanual/teamtext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/teamtext.png -------------------------------------------------------------------------------- /doc/oplmanual/theory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/doc/oplmanual/theory.png -------------------------------------------------------------------------------- /finance/Client/client.csv: -------------------------------------------------------------------------------- 1 | id,client_id,client_name,client_description 2 | cc1,1,Tom,Tom Client 3 | cc2,2,Dick,Dick Client 4 | cc3,3,Harry,Harry Client -------------------------------------------------------------------------------- /finance/ClientHoldPos/client.csv: -------------------------------------------------------------------------------- 1 | id,client_id,client_name,client_description 2 | tom,1,Tom,Tom Client 3 | dick,2,Dick,Dick Client 4 | -------------------------------------------------------------------------------- /finance/ClientHoldPos/toClient.csv: -------------------------------------------------------------------------------- 1 | tom,cc1 2 | dick,cc2 3 | -------------------------------------------------------------------------------- /finance/ClientHoldPos/toHoldPos.csv: -------------------------------------------------------------------------------- 1 | tom,hpc1 2 | dick,hpc2 3 | -------------------------------------------------------------------------------- /finance/HoldPos/client.csv: -------------------------------------------------------------------------------- 1 | id,client_no,client_nm,client_desc 2 | hpc1,1,Tom,Tom Client 3 | hpc2,2,Dick,Dick Client -------------------------------------------------------------------------------- /finance/HoldPos/holding.csv: -------------------------------------------------------------------------------- 1 | id,holding_id,holding_client_no,holding_portfolio_id,holding_asset_id,holding_quantity,holding_purchase_date,holding_purchase_price,holding_currency_code,holding_begin_date,holding_end_date,holding_client 2 | hph1,1,1,1,1,200,1/1/11,5.51,EUR,1/1/11,6/1/11,hpc1 3 | hph2,2,1,1,1,100,1/1/11,5.51,EUR,6/1/11,,hpc1 4 | hph3,3,2,3,3,150,9/1/13,2.5,USD,9/1/13,3/1/14,hpc2 5 | hph4,4,2,3,5,200,2/1/13,1.6,JPY,2/1/13,7/1/13,hpc2 6 | hph5,5,2,3,5,100,2/1/13,1.6,JPY,7/1/13,NULL,hpc2 7 | -------------------------------------------------------------------------------- /finance/HoldPos/position.csv: -------------------------------------------------------------------------------- 1 | id,position_id,position_client_no,position_asset_id,position_quantity,position_current_value,position_current_value_currency_id,position_cost_basis,position_cost_basis_currency_code,position_client,position_current_value_currency_code 2 | hpp1,1,1,1,100,550,2,551,EUR,hpc1,EUR 3 | hpp2,2,2,5,100,170,3,160,JPY,hpc2,JPY -------------------------------------------------------------------------------- /finance/Portfolio/portfolio.csv: -------------------------------------------------------------------------------- 1 | id,portfolio_id,portfolio_name,portfolio_description,portfolio_client_id,portfolio_strategy_id,portfolio_strategy,portfolio_parent_portfolio,portfolio_parent_portfolio_id 2 | pp1,1,Port1,Portfolio1,1,2,ps2,pp1,1 3 | pp2,2,Port2,Portfolio2,2,2,ps2,pp2,2 4 | pp3,3,Port3,Portfolio3,2,1,ps1,pp2,2 -------------------------------------------------------------------------------- /finance/Portfolio/strategy.csv: -------------------------------------------------------------------------------- 1 | id,strategy_id,strategy_name,strategy_description 2 | ps1,1,Strat1,Strategy1 3 | ps3,3,Strat3,Strategy3 4 | ps2,2,Strat2,Strategy2 -------------------------------------------------------------------------------- /finance/PortfolioRef/strategy.csv: -------------------------------------------------------------------------------- 1 | id,strategy_id,strategy_name,strategy_description 2 | strat1,1,Strat1,Strategy1 3 | strat3,3,Strat3,Strategy3 4 | -------------------------------------------------------------------------------- /finance/PortfolioRef/toPortfolio.csv: -------------------------------------------------------------------------------- 1 | strat1,ps1 2 | strat3,ps3 -------------------------------------------------------------------------------- /finance/PortfolioRef/toRef.csv: -------------------------------------------------------------------------------- 1 | strat1,rs1 2 | strat3,rs3 3 | -------------------------------------------------------------------------------- /finance/Ref/asset.csv: -------------------------------------------------------------------------------- 1 | id,asset_id,asset_name,asset_description,asset_strategy_id,asset_strategy 2 | ra1,1,A1,Asset1,1,rs1 3 | ra2,2,A2,Asset2,3,rs3 4 | ra3,3,A3,Asset3,2,rs2 5 | ra4,4,A4,Asset4,4,rs4 6 | ra5,5,A5,Asset5,5,rs5 7 | ra6,6,A6,Asset6,4,rs4 8 | ra7,7,A7,Asset7,4,rs4 9 | ra8,8,A8,Asset8,5,rs5 10 | ra9,9,A9,Asset9,3,rs3 11 | ra10,10,A10,Asset10,1,rs1 -------------------------------------------------------------------------------- /finance/Ref/country.csv: -------------------------------------------------------------------------------- 1 | id,country_id,country_code,country_name 2 | rcty1,1,AU,Australia 3 | rcty2,2,CH,Switzerland 4 | rcty3,3,CN,China 5 | rcty4,4,EU,European Union 6 | rcty5,5,JP,Japan 7 | rcty6,6,US,United States of America -------------------------------------------------------------------------------- /finance/Ref/currency.csv: -------------------------------------------------------------------------------- 1 | id,currency_id,currency_code,currency_name,currency_country_id,currency_country 2 | rcur1,1,USD,US Dollar,6,rcty6 3 | rcur2,2,EUR,Euro,4,rcty4 4 | rcur3,3,JPY,Japanese Yen,5,rcty5 -------------------------------------------------------------------------------- /finance/Ref/strategy.csv: -------------------------------------------------------------------------------- 1 | id,strategy_id,strategy_name,strategy_description 2 | rs1,1,Strat1,Strategy1 3 | rs2,2,Strat2,Strategy2 4 | rs3,3,Strat3,Strategy3 5 | rs4,4,Strat4,Strategy4 6 | rs5,5,Strat5,Strategy5 -------------------------------------------------------------------------------- /finance/RefTrans/asset.csv: -------------------------------------------------------------------------------- 1 | id,asset_id,asset_name,asset_description 2 | one,1,A1,Asset1 3 | three,3,A3,Asset3 4 | five,5,A5,Asset5 5 | seven,7,A7,Asset7 6 | nine,9,A9,Asset9 -------------------------------------------------------------------------------- /finance/RefTrans/currency.csv: -------------------------------------------------------------------------------- 1 | id,currency_id,currency_code,currency_name 2 | usd,1,USD,US Dollar 3 | eur,2,EUR,Euro 4 | jpy,3,JPY,Japanese Yen -------------------------------------------------------------------------------- /finance/RefTrans/toRefasset.csv: -------------------------------------------------------------------------------- 1 | one,ra1 2 | three,ra3 3 | five,ra5 4 | seven,ra7 5 | nine,ra9 -------------------------------------------------------------------------------- /finance/RefTrans/toRefcurrency.csv: -------------------------------------------------------------------------------- 1 | usd,rcur1 2 | eur,rcur2 3 | jpy,rcur3 -------------------------------------------------------------------------------- /finance/RefTrans/toTransasset.csv: -------------------------------------------------------------------------------- 1 | one,ta1 2 | three,ta3 3 | five,ta5 4 | seven,ta7 5 | nine,ta9 -------------------------------------------------------------------------------- /finance/RefTrans/toTranscurrency.csv: -------------------------------------------------------------------------------- 1 | usd,tc1 2 | eur,tc2 3 | jpy,tc3 -------------------------------------------------------------------------------- /finance/Trans/asset.csv: -------------------------------------------------------------------------------- 1 | id,asset_id,asset_name,asset_description 2 | ta1,1,A1,Asset1 3 | ta3,3,A3,Asset3 4 | ta5,5,A5,Asset5 5 | ta7,7,A7,Asset7 6 | ta9,9,A9,Asset9 -------------------------------------------------------------------------------- /finance/Trans/currency.csv: -------------------------------------------------------------------------------- 1 | id,currency_id,currency_code,currency_name 2 | tc1,1,USD,US Dollar 3 | tc2,2,EUR,Euro 4 | tc3,3,JPY,Japanese Yen -------------------------------------------------------------------------------- /finance/Trans/transaction.csv: -------------------------------------------------------------------------------- 1 | id,transaction_id,transaction_date,transaction_asset_id,transaction_portfolio_id,transaction_buy_sell_ind,transaction_quantity,transaction_price,transaction_currency_id,transaction_asset,transaction_currency 2 | tt1,1,1/1/2011,1,1,B,200,5.5100,2,ta1,tc2 3 | tt2,2,6/1/2011,1,1,S,100,5.5000,2,ta1,tc2 4 | tt3,3,9/1/2013,3,2,B,150,2.5000,1,ta3,tc1 5 | tt4,4,3/1/2014,3,2,S,150,3.5000,1,ta3,tc1 6 | tt5,5,2/1/2013,5,3,B,200,1.6000,3,ta5,tc3 7 | tt6,6,7/1/2013,5,3,S,100,1.5000,3,ta5,tc3 -------------------------------------------------------------------------------- /fql.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/fql.jar -------------------------------------------------------------------------------- /lib/autocomplete-3.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/autocomplete-3.0.0.jar -------------------------------------------------------------------------------- /lib/commons-collections4-4.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/commons-collections4-4.2.jar -------------------------------------------------------------------------------- /lib/guava-23.4-jre.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/guava-23.4-jre.jar -------------------------------------------------------------------------------- /lib/h2-1.4.196.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/h2-1.4.196.jar -------------------------------------------------------------------------------- /lib/javax.json-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/javax.json-1.1.2.jar -------------------------------------------------------------------------------- /lib/javax.json-api-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/javax.json-api-1.1.2.jar -------------------------------------------------------------------------------- /lib/jparsec-3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/jparsec-3.0.jar -------------------------------------------------------------------------------- /lib/jung-algorithms-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/jung-algorithms-2.1.1.jar -------------------------------------------------------------------------------- /lib/jung-api-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/jung-api-2.1.1.jar -------------------------------------------------------------------------------- /lib/jung-graph-impl-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/jung-graph-impl-2.1.1.jar -------------------------------------------------------------------------------- /lib/jung-visualization-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/jung-visualization-2.1.1.jar -------------------------------------------------------------------------------- /lib/rstaui-3.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/rstaui-3.0.0.jar -------------------------------------------------------------------------------- /lib/rsyntaxtextarea-3.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/lib/rsyntaxtextarea-3.0.2.jar -------------------------------------------------------------------------------- /resources/examples/fpql/Coapply.fpql: -------------------------------------------------------------------------------- 1 | dom : type 2 | 1 2 3 : dom 3 | 4 | S = schema { 5 | nodes S1, S2; 6 | edges a:S1->dom, b:S1->dom, c:S2->dom, d:S2->dom, e:S2->dom; 7 | equations; 8 | } 9 | 10 | T = schema { 11 | nodes T; 12 | edges x:T->dom; 13 | equations; 14 | } 15 | 16 | Q = polynomial { 17 | q = {for v:S1, u:S2; where v.b=u.c; attributes x=v.b; edges;} : T 18 | } : S -> T 19 | 20 | J = instance { 21 | variables j1 j2 j3 j4 : T; 22 | equations j1.x=1, j2.x=2, j3.x=3; 23 | } : T 24 | 25 | I = coapply Q J 26 | 27 | /////////////////////////////////////////////////////// 28 | /* 29 | Suppose S := T1(a,b) and T2(c,d,e) 30 | Suppose T := T(x) 31 | 32 | Suppose Q := 33 | SELECT b 34 | FROM T1(a,b) and T2(c,d,e) 35 | WHERE b=c 36 | 37 | Suppose J(1), J(2), J(3), J(y) [variables y, constants 1,2,3] 38 | 39 | Then frozen_Q = T1(a,b), T2(c,d,e), b=c [variables b, constants a c d e] 40 | 41 | Then coeval_Q(J) = chase [ 42 | //additional EDs in S, T would go here 43 | _ => exists a c d e, T1(a,b), T2(c,d,e), b=c, b=1 44 | _ => exists a c d e, T1(a,b), T2(c,d,e), b=c, b=2 45 | _ => exists a c d e, T1(a,b), T2(c,d,e), b=c, b=3 46 | _ => exists a c d e, T1(a,b), T2(c,d,e), b=c, b=y 47 | ] 48 | the above is obtained by "running" frozen_Q on J. it is also an 49 | instance 50 | { 51 | T1 (a, 1), T2 (1, d, e), 52 | T1 (a, 2), T2 (2, d, e), 53 | T1 (a, 3), T2 (3, d, e), 54 | T1 (a, y), T2 (y, d, e) 55 | } 56 | 57 | If eval_Q(I) = {2, 3, x}, the possible homomorphisms J => eval_Q(I) are 58 | 59 | h1 := y |-> 2 60 | h2 := y |-> 3 61 | h3 := y |-> x 62 | 63 | Each of these is also a homomorphism coeval_Q(J) => I; i.e., is the same thing as a valuation in I for coeval_Q(J)'s variables. 64 | */ 65 | -------------------------------------------------------------------------------- /resources/examples/fpql/Coprod.fpql: -------------------------------------------------------------------------------- 1 | S = schema { 2 | nodes A, B; 3 | edges f : A -> B; 4 | equations; 5 | } 6 | 7 | I = instance { 8 | variables v1:A, v2:A, v3:B; 9 | equations v1.f=v3, v2.f=v3; 10 | } : S 11 | 12 | J = instance { 13 | variables a:A,b:A,c:A, d:B,e:B; 14 | equations a.f=d, b.f=e, c.f=e; 15 | } : S 16 | 17 | A = (I + J) 18 | 19 | k = inl I J 20 | 21 | l = inr I J 22 | 23 | m = case k l //is id 24 | 25 | N = void S 26 | 27 | O = ff J 28 | -------------------------------------------------------------------------------- /resources/examples/fpql/Cyclic.fpql: -------------------------------------------------------------------------------- 1 | CM53 = schema { 2 | nodes M; 3 | edges arr : M -> M; 4 | equations M.arr.arr.arr.arr.arr = M.arr.arr; 5 | } 6 | 7 | CM33 = schema { 8 | nodes J; 9 | edges a : J -> J; 10 | equations J.a.a.a = J; 11 | } 12 | 13 | F = mapping { 14 | nodes M -> J; 15 | edges arr -> J.a; 16 | } : CM53 -> CM33 17 | -------------------------------------------------------------------------------- /resources/examples/fpql/Delta.fpql: -------------------------------------------------------------------------------- 1 | string int : type 2 | 3 | Bob Sue Alice Smith Jones xxx c115234 c112988 c198887 : string 4 | c100 c250 c300 c0 : int 5 | 6 | C = schema { 7 | nodes 8 | T1, T2; 9 | edges 10 | t1_ssn : T1 -> string, 11 | t1_first : T1 -> string, 12 | t1_last : T1 -> string, 13 | t2_first : T2 -> string, 14 | t2_last : T2 -> string, 15 | t2_salary : T2 -> int; 16 | equations; 17 | } 18 | 19 | D = schema { 20 | nodes 21 | T; 22 | edges 23 | ssn0 : T -> string, 24 | first0 : T -> string, 25 | last0 : T -> string, 26 | salary0 : T -> int; 27 | equations; 28 | } 29 | 30 | F = mapping { 31 | nodes 32 | T1 -> T, 33 | T2 -> T; 34 | edges 35 | t1_ssn -> T.ssn0, 36 | t1_first -> T.first0, 37 | t2_first -> T.first0, 38 | t1_last -> T.last0, 39 | t2_last -> T.last0, 40 | t2_salary -> T.salary0; 41 | } : C -> D 42 | 43 | J = instance { 44 | variables 45 | XF667 XF891 XF221 : T; 46 | equations 47 | XF667.ssn0 = c115234, XF891.ssn0 = c112988, XF221.ssn0 = c198887, 48 | XF667.first0 = Bob, XF891.first0 = Sue, XF221.first0 = Alice, 49 | XF667.last0 = Smith, XF891.last0 = Smith, XF221.last0 = Jones, 50 | XF667.salary0 = c250, XF891.salary0 = c300, XF221.salary0 = c100; 51 | } : D 52 | 53 | df = delta F J 54 | 55 | J0 = instance { 56 | variables 57 | zXF667 zXF891 zXF221 v : T; 58 | equations 59 | zXF667.ssn0 = c115234, zXF891.ssn0 = c112988, zXF221.ssn0 = c198887, v.ssn0 = xxx, 60 | zXF667.first0 = Bob, zXF891.first0 = Sue, zXF221.first0 = Alice, v.first0 = xxx, 61 | zXF667.last0 = Smith, zXF891.last0 = Smith, zXF221.last0 = Jones, v.last0 = xxx, 62 | zXF667.salary0 = c250, zXF891.salary0 = c300, zXF221.salary0 = c100, v.salary0 = c0; 63 | } : D 64 | 65 | trans = homomorphism { 66 | variables 67 | XF667 -> zXF667, XF891 -> zXF891, XF221 -> zXF221; 68 | } : J -> J0 69 | 70 | trans0 = delta F trans 71 | -------------------------------------------------------------------------------- /resources/examples/fpql/Disjunctive.fpql: -------------------------------------------------------------------------------- 1 | 2 | color : type 3 | red green blue : color 4 | 5 | S = schema { 6 | nodes 7 | E; 8 | edges 9 | att : E -> color; 10 | equations; 11 | } 12 | 13 | T = schema { 14 | nodes 15 | R, RB, RG; 16 | edges 17 | r_rb : R -> RB, 18 | r_rg : R -> RG, 19 | r_att : R -> color; 20 | equations 21 | r_att = "!_R".red; //if changed to say blue, error occurs in Q 22 | } 23 | 24 | Q = polynomial { 25 | R_Q = {for e:E; 26 | where e.att = red ; 27 | attributes r_att=e.att; 28 | edges r_rb = {e1=e} : RB_Q_1, 29 | r_rg = {e3=e} : RG_Q_1;} : R, 30 | 31 | RB_Q_1 = {for e1:E; 32 | where e1.att = red ; 33 | attributes; edges;} : RB, 34 | 35 | RB_Q_2 = {for e2:E; 36 | where e2.att = blue ; 37 | attributes; edges;} : RB, 38 | 39 | RG_Q_1 = {for e3:E; 40 | where e3.att = red ; 41 | attributes; edges;} : RG, 42 | 43 | RG_Q_2 = {for e4:E; 44 | where e4.att = green ; 45 | attributes; edges;} : RG 46 | 47 | } : S -> T 48 | 49 | I = instance { 50 | variables 51 | r1 r2 g1 g2 b1 b2 : E; 52 | equations 53 | r1.att = red, 54 | r2.att = red, 55 | g1.att = green, 56 | g2.att = green, 57 | b1.att = blue, 58 | b2.att = blue; 59 | } : S 60 | 61 | J = apply Q I 62 | 63 | -------------------------------------------------------------------------------- /resources/examples/fpql/Employees.fpql: -------------------------------------------------------------------------------- 1 | dom : type 2 | Al Akin Bob Bo Carl Cork Math Cs : dom 3 | 4 | S = schema { 5 | nodes 6 | Employee, Department; 7 | edges 8 | first : Employee -> dom, 9 | last : Employee -> dom, 10 | name : Department -> dom, 11 | manager : Employee -> Employee, 12 | worksIn : Employee -> Department, 13 | secretary : Department -> Employee; 14 | equations 15 | Employee.manager.worksIn = Employee.worksIn, 16 | Department.secretary.worksIn = Department, 17 | Employee.manager.manager = Employee.manager; 18 | } 19 | 20 | I = instance { 21 | variables a b c : Employee, m s : Department; 22 | equations a.first = Al, a.last = Akin, 23 | b.first = Bob, b.last = Bo, 24 | c.first = Carl, c.last = Cork, 25 | m.name = Math, s.name = Cs, 26 | a.worksIn = m, b.worksIn = m, c.worksIn = s, 27 | s.secretary=c, m.secretary=b; 28 | } : S 29 | 30 | ////////////////////////////////////////////// 31 | 32 | String : type 33 | Int : type 34 | 35 | one : Int 36 | two : Int 37 | foo : String 38 | 39 | //length : String -> Int 40 | print : Int -> String 41 | //succ : Int -> Int 42 | reverse : String -> String 43 | 44 | eq1 : reverse.reverse = String 45 | 46 | X = schema { 47 | nodes n; 48 | edges f : n -> n, g : n -> String, h : n -> Int; 49 | equations n.f.f = f, f.g = f.g.reverse; 50 | } 51 | -------------------------------------------------------------------------------- /resources/examples/fpql/EpiMono Factor.fpql: -------------------------------------------------------------------------------- 1 | //This FPQL program finds the image of any function, i.e., the epi-mono factorization. 2 | 3 | //Schema A is where you put your function (as an instance). 4 | 5 | A = schema { 6 | nodes c, x; 7 | edges f:c->x; 8 | equations; 9 | } 10 | 11 | //Schemas B and C are just auxilliary schemas to perform our calculation. 12 | 13 | B = schema { 14 | nodes c1,c2,c,x; 15 | edges f1:c1->x, f2:c2->x, f:c->x, g1:c1->c, g2:c2->c; 16 | equations f1=g1.f, f2=g2.f; 17 | } 18 | 19 | C = schema { 20 | nodes k,c1,c2,c,x; 21 | edges 22 | f1:c1->x, f2:c2->x, f:c->x, g1:c1->c, g2:c2->c, 23 | h1:k->c1, h2:k->c2 24 | ; 25 | equations f1=g1.f, f2=g2.f, h1.f1=h2.f2; 26 | } 27 | 28 | //Schema D is where the result will show up. 29 | 30 | D = schema { 31 | nodes k,c,image,x; 32 | edges h1:k->c, h2:k->c, quotient:c->image,f:image->x; 33 | equations h1.quotient=h2.quotient; 34 | } 35 | 36 | F = mapping { 37 | nodes c1->c,c2->c,c->c,x->x; 38 | edges f1->f, f2->f, f->f, g1->c,g2->c; 39 | } 40 | : B -> A 41 | 42 | G= mapping { 43 | nodes c1->c1,c2->c2,c->c,x->x; 44 | edges f1->f1, f2->f2,f->f, g1->g1,g2->g2; 45 | } 46 | : B -> C 47 | 48 | H= mapping { 49 | nodes k->k, c1->c, c2->c,c->c,x->x; 50 | edges f1->quotient.f, f2->quotient.f,f->quotient.f, g1->c,g2->c,h1->h1,h2->h2; 51 | } 52 | : C -> D 53 | 54 | //Any function can go here: 55 | 56 | func = instance { 57 | variables x11 x12 x13 x21 x22:c, y1 y2 y3:x; 58 | equations x11.f=y1, x12.f=y1,x13.f=y1,x21.f=y1,x22.f=y2; 59 | } 60 | : A 61 | 62 | setup = delta F func 63 | 64 | pullback = pi G setup 65 | 66 | //the following instance is the result of our epi-mono factorization. 67 | //k contains the kernel, and the functions c->image->x is the epi-mono factorization of f. 68 | 69 | epimono = sigma H pullback 70 | -------------------------------------------------------------------------------- /resources/examples/fpql/Inconsistent.fpql: -------------------------------------------------------------------------------- 1 | 2 | Int : type 3 | 4 | one : Int 5 | two : Int 6 | 7 | //eq1 : one = two 8 | 9 | X = schema { 10 | nodes; 11 | edges; 12 | equations; 13 | } 14 | 15 | I = instance { 16 | variables x : Int, y : Int; 17 | equations x = one, y = two, x = y; 18 | } : X 19 | -------------------------------------------------------------------------------- /resources/examples/fpql/Monad.fpql: -------------------------------------------------------------------------------- 1 | Graph = schema { 2 | nodes arrow,vertex; 3 | edges src:arrow->vertex,tgt:arrow->vertex; 4 | equations; 5 | } 6 | 7 | //has 4 connected components 8 | G = instance { 9 | variables 10 | a b c d e : arrow, 11 | t u v w x y z : vertex; 12 | equations 13 | a.src = t, b.src = t, c.src = x, d.src = y, e.src = z, 14 | a.tgt = u, b.tgt = v, c.tgt = x, d.tgt = z, e.tgt = y; 15 | } : Graph 16 | 17 | Terminal = schema { 18 | nodes X; 19 | edges; 20 | equations; 21 | } 22 | 23 | F = mapping { 24 | nodes arrow->X, vertex->X; 25 | edges src->X, tgt->X; 26 | } : Graph -> Terminal 27 | 28 | //has 4 rows 29 | Components = sigma F G 30 | 31 | //puts 4 rows into vertex, 4 rows into arrow, corresponding to the connected components 32 | I = delta F Components 33 | 34 | //gives the transform from the original graph to the connected components 35 | t = return sigma delta F G 36 | 37 | u = coreturn sigma delta F Components 38 | -------------------------------------------------------------------------------- /resources/examples/fpql/Nat.fpql: -------------------------------------------------------------------------------- 1 | /* 2 | * Nat(X) := 1+X 3 | * Nat(f) := 1+f 4 | * Nat := lfix X. Nat(X) 5 | * 6 | * in : 1 + Nat -> Nat 7 | * out: Nat -> 1 + Nat 8 | * in o out = id 9 | * out o id = id 10 | * 11 | * fold(f) : Nat -> Y for f : 1+Y -> Y 12 | * in o fold(f) = Nat(fold(f)) o f 13 | */ 14 | S = schema { 15 | nodes One 16 | ,Nat 17 | ,Nat_mod_2 18 | ,One_Plus_Nat 19 | ,One_Plus_Nat_mod_2 20 | ; 21 | edges zero : One -> Nat_mod_2 22 | ,succ : Nat_mod_2 -> Nat_mod_2 23 | ,in : One_Plus_Nat -> Nat 24 | ,out : Nat -> One_Plus_Nat 25 | ,inj1 : Nat -> One_Plus_Nat 26 | ,inj2 : One -> One_Plus_Nat 27 | ,inj3 : Nat_mod_2 -> One_Plus_Nat_mod_2 28 | ,inj4 : One -> One_Plus_Nat_mod_2 29 | ,f : One_Plus_Nat_mod_2 -> Nat_mod_2 30 | ,fold_f : Nat -> Nat_mod_2 31 | ,Natfold_f : One_Plus_Nat -> One_Plus_Nat_mod_2 32 | ; 33 | equations succ . succ = Nat_mod_2 34 | ,in . out = One_Plus_Nat 35 | ,out . in = Nat 36 | ,inj4 . f = zero 37 | ,inj3 . f = succ 38 | ,inj1 . Natfold_f = fold_f . inj3 39 | ,inj2 . Natfold_f = inj4 40 | ,in . fold_f = Natfold_f . f 41 | ; //missing equations about coproducts and terminal objects 42 | } 43 | 44 | I = instance { 45 | variables; 46 | equations; 47 | } : S 48 | 49 | // One.inj2.in.fold_f ----> zero 50 | // One.inj2.in.inj1.in.fold_f ----> zero.succ 51 | // One.inj2.in.inj1.in.inj1.in.fold_f ---> zero 52 | -------------------------------------------------------------------------------- /resources/examples/fpql/Olog.fpql: -------------------------------------------------------------------------------- 1 | S = schema { 2 | nodes "arginine", "an electrically-charged side chain", "a side chain", 3 | "an amino acid found in dairy", "an amino acid", "an amine group", 4 | "a carboxylic acid"; 5 | edges "is " : "arginine" -> "an amino acid found in dairy", 6 | "is" : "an amino acid found in dairy" -> "an amino acid", 7 | "is " : "arginine" -> "an amino acid", 8 | "has" : "arginine" -> "an electrically-charged side chain", 9 | "has " : "an amino acid" -> "a side chain", 10 | "is " : "an electrically-charged side chain" -> "a side chain", 11 | "has " : "an amino acid" -> "a carboxylic acid", 12 | "has " : "an amino acid" -> "an amine group"; 13 | equations 14 | "is "."is" = "is ", "has"."is " = "is "."has "; 15 | } 16 | -------------------------------------------------------------------------------- /resources/examples/fpql/Pi.fpql: -------------------------------------------------------------------------------- 1 | string : type 2 | Ryan Wisnesky David Spivak Harvard MIT Leslie : string 3 | 4 | C = schema { 5 | nodes 6 | c1, 7 | c2; 8 | edges 9 | att1 : c1 -> string, 10 | att2 : c1 -> string, 11 | att3 : c2 -> string; 12 | equations; 13 | } 14 | 15 | I = instance { 16 | variables 17 | v11 v12 : c1, 18 | v21 v22 v23 : c2; 19 | equations 20 | v11.att1 = David, v12.att1 = Ryan, 21 | v11.att2 = Spivak, v12.att2 = Wisnesky, 22 | v21.att3 = MIT, v22.att3 = Harvard, v23.att3 = Leslie; 23 | } : C 24 | 25 | D = schema { 26 | nodes 27 | d; 28 | edges 29 | a1 : d -> string, 30 | a2 : d -> string, 31 | a3 : d -> string; 32 | equations; 33 | } 34 | 35 | F = mapping { 36 | nodes 37 | c1 -> d, 38 | c2 -> d; 39 | edges 40 | att1 -> d.a1, 41 | att2 -> d.a2, 42 | att3 -> d.a3; 43 | } : C -> D 44 | 45 | J = pi F I 46 | 47 | 48 | I0 = instance { 49 | variables 50 | u11:c1, 51 | u21 u22:c2; 52 | equations 53 | u11.att1 = David, 54 | u11.att2 = Spivak, 55 | u21.att3 = MIT, u22.att3 = Harvard; 56 | } : C 57 | 58 | t = homomorphism { 59 | variables u11 -> v11, u21 -> v21, u22 -> v22; 60 | } : I0 -> I 61 | 62 | tx = pi F t 63 | 64 | XXX = instance { 65 | variables a b c : d; 66 | equations 67 | a.a1 = Harvard, b.a1 = Harvard, c.a1 = Harvard, 68 | a.a2 = MIT, b.a2 = MIT, c.a2 = MIT, 69 | a.a3 = Leslie, b.a3 = Leslie, c.a3 = Leslie; 70 | } : D 71 | 72 | ret = return delta pi F XXX 73 | 74 | coret = coreturn delta pi F I 75 | -------------------------------------------------------------------------------- /resources/examples/fpql/Prod.fpql: -------------------------------------------------------------------------------- 1 | string : type 2 | common : string 3 | baz : string 4 | 5 | S = schema { 6 | nodes A, B; 7 | edges att : A -> string, f : A -> B; 8 | equations; 9 | } 10 | 11 | I = instance { 12 | variables v1:A, v2:A, v3:B; 13 | equations v1.att = common, v2.att=common, 14 | v1.f = v3, v2.f = v3; 15 | } : S 16 | 17 | J = instance { 18 | variables a:A, b:A, c:A, d:B, e:B; 19 | equations a.att = common, b.att = common, c.att = baz, 20 | a.f = d, b.f = e, c.f = e; 21 | } : S 22 | 23 | IJ = (I * J) 24 | 25 | K = fst I J 26 | 27 | L = snd I J 28 | 29 | M = pair K L //is id 30 | 31 | N = unit S 32 | 33 | O = tt J -------------------------------------------------------------------------------- /resources/examples/fpql/Relationalize.fpql: -------------------------------------------------------------------------------- 1 | string : type 2 | c1 c2 c3 c4 c5 c6 c7 : string 3 | 4 | C = schema { 5 | nodes A; 6 | edges att:A->string, f:A->A; 7 | equations A.f.f.f.f=A.f.f; 8 | } 9 | 10 | I = instance { 11 | variables x1 x2 x3 x4 x5 x6 x7 : A; 12 | equations x1.att=c1,x2.att=c2,x3.att=c3,x4.att=c1,x5.att=c5,x6.att=c3,x7.att=c5, 13 | x1.f=x2,x2.f=x3,x3.f=x5,x4.f=x2,x5.f=x3,x6.f=x7,x7.f=x6; 14 | } : C 15 | 16 | RelI = relationalize I 17 | -------------------------------------------------------------------------------- /resources/examples/fpql/Reorder Joins.fpql: -------------------------------------------------------------------------------- 1 | adom : type 2 | c1 c2 c3 c4 c5 c6 c7 c8 : adom 3 | 4 | S = schema { 5 | nodes N; 6 | edges f : N -> adom; 7 | equations; 8 | } 9 | 10 | I = instance { 11 | variables v1 v2 v3 v4 v5 v6 v7 v8 : N; 12 | equations v1.f = c1, v2.f = c2, v3.f = c3, v4.f = c4, v5.f = c5, v6.f = c6, v7.f = c7, v8.f = c8; 13 | } : S 14 | 15 | //requires FROM clause reordering to compute 16 | Q = flower { 17 | select n.f as nf; 18 | from N as n1, N as n2, N as n3, N as n4, N as n5, N as n6, N as n7, N as n; 19 | where n1.f = n.f, n2.f = n.f, n3.f = n.f, n4.f = n.f, n5.f = n.f, n6.f = n.f, n7.f = n.f; 20 | } I 21 | -------------------------------------------------------------------------------- /resources/examples/fpql/Reverse.fpql: -------------------------------------------------------------------------------- 1 | string : type 2 | nat : type 3 | 4 | length : string -> nat 5 | reverse : string -> string 6 | 7 | C = schema { 8 | nodes X; 9 | edges att1 : X -> string, att2 : X -> nat; 10 | equations X.att1.length = X.att2; 11 | } 12 | 13 | F = mapping { 14 | nodes X -> X; 15 | edges att1 -> X.att1.reverse.reverse, att2 -> X.att2; 16 | } : C -> C 17 | 18 | //eq1 : reverse.reverse = string 19 | -------------------------------------------------------------------------------- /resources/examples/fpql/SELECT CTDB.fpql: -------------------------------------------------------------------------------- 1 | String : type 2 | a b GoneWind Catch22 CatTheory : String 3 | 4 | Isbn_num : type 5 | isbn1 isbn2 isbn3 isbn249 isbn258 isbn4597 : Isbn_num 6 | 7 | R : type 8 | zero : R 9 | succ : R -> R 10 | eq0 : succ.succ.succ.succ.succ = succ //otherwise, pi doesn't terminate 11 | 12 | RL3 : type 13 | one two : RL3 14 | 15 | i : RL3 -> R 16 | eq1 : one.i = zero.succ 17 | eq2 : two.i = zero.succ.succ 18 | 19 | C = schema { 20 | nodes 21 | Book; 22 | edges 23 | price:Book->R, 24 | title:Book->String, 25 | isbn:Book->Isbn_num; 26 | equations; 27 | } 28 | 29 | //Note the last digit of the ISBN is the number of letters in the title. 30 | I = instance { 31 | variables 32 | book1 book2 book3:Book; 33 | equations 34 | book1.title = GoneWind, book2.title=Catch22, book3.title=CatTheory, 35 | book1.isbn = isbn258, book2.isbn = isbn4597, book3.isbn = isbn249, 36 | book1.price = zero.succ.succ.succ.succ, book2.price = zero.succ.succ.succ, book3.price = zero.succ; 37 | } : C 38 | 39 | //Note that there is exactly one book whose price is less than 3. 40 | D = schema { 41 | nodes 42 | W, 43 | Book; 44 | edges 45 | title:Book->String, 46 | isbn:Book->Isbn_num, 47 | f:W->RL3, 48 | g:W->Book, 49 | price:Book->R; 50 | equations 51 | W.f.i=W.g.price; 52 | } 53 | 54 | F = mapping { 55 | nodes 56 | Book->Book; 57 | edges 58 | price->Book.price, 59 | title->Book.title, 60 | isbn->Book.isbn; 61 | } : C -> D 62 | 63 | 64 | pi_F_I = pi F I 65 | 66 | 67 | E = schema { 68 | nodes W; 69 | edges title:W->String, isbn:W->Isbn_num; 70 | equations; 71 | } 72 | 73 | G = mapping { 74 | nodes W->W; 75 | edges title->W.g.title, isbn->W.g.isbn; 76 | } : E -> D 77 | 78 | Select = delta G pi_F_I 79 | -------------------------------------------------------------------------------- /resources/examples/fpql/Sigma.fpql: -------------------------------------------------------------------------------- 1 | String : type 2 | 3 | gecko frog human cow horse dolphin fish : String 4 | 5 | C = schema { 6 | nodes 7 | Amphibian, 8 | LandAnimal, 9 | WaterAnimal; 10 | edges 11 | attA: Amphibian -> String, 12 | attL: LandAnimal -> String, 13 | attW: WaterAnimal -> String, 14 | IsAL: Amphibian -> LandAnimal, 15 | IsAW: Amphibian -> WaterAnimal; 16 | equations; 17 | } 18 | 19 | I = instance { 20 | variables 21 | a1 a2: Amphibian, 22 | l1 l2 l3 l4 l5: LandAnimal, 23 | w1 w2 w3 w4: WaterAnimal; 24 | equations 25 | a1.attA = gecko, a2.attA = frog, 26 | l1.attL = gecko, l2.attL = frog, l3.attL = human, l4.attL = cow, l5.attL = horse, 27 | w1.attW = fish, w2.attW = gecko, w3.attW = frog, w4.attW = dolphin, 28 | a1.IsAL = l1, a2.IsAL = l2, 29 | a1.IsAW = w2, a2.IsAW = w3; 30 | } : C 31 | 32 | 33 | D = schema { 34 | nodes 35 | yAmphibian, 36 | yLandAnimal, 37 | yWaterAnimal, 38 | yAnimal; 39 | edges 40 | yattA:yAmphibian->String, 41 | yattL:yLandAnimal->String, 42 | yattW:yWaterAnimal->String, 43 | yIsAL:yAmphibian->yLandAnimal, 44 | yIsAW:yAmphibian->yWaterAnimal, 45 | yIsALL:yLandAnimal->yAnimal, 46 | yIsAWW:yWaterAnimal->yAnimal; 47 | equations 48 | yAmphibian.yIsAL.yIsALL=yAmphibian.yIsAW.yIsAWW; 49 | } 50 | 51 | F = mapping { 52 | nodes 53 | Amphibian->yAmphibian, 54 | LandAnimal->yLandAnimal, 55 | WaterAnimal->yWaterAnimal; 56 | edges 57 | attA -> yAmphibian.yattA, 58 | attL -> yLandAnimal.yattL, 59 | attW -> yWaterAnimal.yattW, 60 | IsAL -> yAmphibian.yIsAL, 61 | IsAW -> yAmphibian.yIsAW; 62 | } : C -> D 63 | 64 | J = sigma F I 65 | 66 | I0 = instance { 67 | variables 68 | xa1: Amphibian, 69 | xl1 xl2 xl3 xl4: LandAnimal, 70 | xw1 xw2 xw3: WaterAnimal; 71 | equations 72 | xa1.attA = gecko, 73 | xl1.attL = gecko, xl2.attL = frog, xl3.attL = human, xl4.attL = cow, 74 | xw1.attW = fish, xw2.attW = gecko, xw3.attW = frog, 75 | xa1.IsAL = xl1, 76 | xa1.IsAW = xw2; 77 | } : C 78 | 79 | t = homomorphism { 80 | variables 81 | xa1 -> a1, xl1 -> l1, xl2 -> l2, xl3 -> l3, xl4 -> l4, xw1 -> w1, xw2 -> w2, xw3 -> w3; 82 | } : I0 -> I 83 | 84 | t0 = sigma F t 85 | -------------------------------------------------------------------------------- /resources/examples/fpql/Tableaux.fpql: -------------------------------------------------------------------------------- 1 | adom:type 2 | 1 2 3 4 5 6:adom 3 | 4 | S = schema { 5 | nodes A, B; 6 | edges f : A -> B, A_att : A -> adom, B_att : B -> adom; 7 | equations; 8 | } 9 | 10 | I = instance { 11 | variables a1 a2 a3 : A, b1 b2 b3 : B; 12 | equations a1.f = b1, a2.f = b1, a3.f = b1, 13 | a1.A_att=1, a2.A_att=2, a3.A_att=3, 14 | b1.B_att=4, b2.B_att=5, b3.B_att=6; 15 | } : S 16 | 17 | //we will do this flower by hand 18 | //J = flower { 19 | // select a.A_att as p, b.B_att as q; 20 | // from A as a, B as b; 21 | // where; 22 | //} I 23 | 24 | //schema for from clause 25 | S2 = schema { 26 | nodes A, B, Q; 27 | edges f : A -> B, A_att : A -> adom, B_att : B -> adom, a:Q->A, b:Q->B; 28 | equations; 29 | } 30 | 31 | M2 = mapping { 32 | nodes A->A, B->B; 33 | edges f->f, A_att->A_att, B_att->B_att; 34 | } : S -> S2 35 | 36 | J2 = pi M2 I //from part 37 | 38 | S3 = schema { //schema for select part 39 | nodes Q; 40 | edges p:Q->adom, q:Q->adom; 41 | equations; 42 | } 43 | 44 | M3 = mapping { 45 | nodes Q->Q; 46 | edges p->a.A_att, q->b.B_att; 47 | } : S3 -> S2 48 | 49 | //final result 50 | J3 = delta M3 J2 51 | 52 | //////////////////// 53 | 54 | Patrick1 = instance { 55 | variables var : Q; 56 | equations; 57 | } : S3 58 | 59 | Patrick2 = delta M2 sigma M3 Patrick1 //on S 60 | 61 | //This is the "canonical" or "frozen" instance for a non-relational conjunctive query! 62 | -------------------------------------------------------------------------------- /resources/examples/fpql/Uber Bad.fpql: -------------------------------------------------------------------------------- 1 | S = schema { 2 | nodes A; 3 | edges; 4 | equations; 5 | } 6 | 7 | T = schema { 8 | nodes A, B; 9 | edges f : A -> B, g : A -> B; 10 | equations f = g; 11 | } 12 | 13 | I = instance { 14 | variables a1 a2:A; 15 | equations; 16 | } : S 17 | 18 | Q = polynomial { 19 | q1 = {for v1:A, v2:A; where; attributes; edges f = {v=v1}:q2, g = {v=v2}:q2 ;} : A, 20 | q2 = {for v :A; where; attributes; edges; } : B 21 | } : S -> T 22 | -------------------------------------------------------------------------------- /resources/examples/fql/Characteristic Fn.fql: -------------------------------------------------------------------------------- 1 | //our schema S has one node, so an instance on S will just be a set. 2 | schema S = { 3 | nodes n; 4 | attributes; 5 | arrows; 6 | equations; 7 | } 8 | 9 | //the set {true, false}. 10 | //For sets, any 2-element set is a sub-object classifier. 11 | instance P = prop S // has n -> {true, false} . 12 | 13 | //the set { tt }. 14 | //For sets, any 1-element set is a terminal instance 15 | instance terminal = unit S // has n -> { tt } . 16 | 17 | //truth values are transforms terminal -> P 18 | transform tru = P.true terminal // maps tt -> true 19 | transform fals = P.false terminal // maps tt -> false 20 | 21 | //the set {1,2,3,4} 22 | instance J = { 23 | nodes n -> {1,2,3,4}; 24 | attributes; 25 | arrows; 26 | } : S 27 | 28 | //the set {a,b,c} 29 | instance I = { 30 | nodes n -> {a,b,c}; 31 | attributes; 32 | arrows; 33 | } : S 34 | 35 | //the injective function a -> 1, b -> 2, c -> 3 36 | transform f = { 37 | nodes n -> {(a,1),(b,2),(c,3)}; 38 | } : I -> J 39 | 40 | //the characteristic function J -> prop 41 | //maps 1 -> true, 2 -> true, 3 -> true, 4 -> false 42 | transform char_f = P.char f 43 | 44 | //these two transforms I -> prop are equal 45 | //they map a -> true, b -> true, c -> true 46 | transform rhs = (terminal.unit I then tru) 47 | transform lhs = (f then char_f) -------------------------------------------------------------------------------- /resources/examples/fql/Co-products.fql: -------------------------------------------------------------------------------- 1 | schema S = { 2 | nodes a, b; 3 | attributes att : a -> string; 4 | arrows f : a -> b; 5 | equations; 6 | } 7 | 8 | instance I = { 9 | nodes a -> {1,2}, b -> {3}; 10 | attributes att -> {(1,one),(2,two)}; 11 | arrows f -> {(1,3),(2,3)}; 12 | } : S 13 | 14 | instance J = { 15 | nodes a -> {a,b,c}, b -> {d,e}; 16 | attributes att -> {(a,foo),(b,bar),(c,baz)}; 17 | arrows f -> {(a,d),(b,e),(c,e)}; 18 | } : S 19 | 20 | instance A = (I + J) 21 | 22 | transform K = A.inl 23 | 24 | transform L = A.inr 25 | 26 | transform M = A.(K + L) //is id 27 | 28 | instance N = void S 29 | 30 | transform O = N.void J 31 | 32 | schema C = { nodes a, b; attributes att : a -> string; arrows f : a -> b, g : a -> a; equations a.g = a; } 33 | 34 | schema D = { nodes a; attributes att : a -> string; arrows ; equations ; } 35 | 36 | schema E = (C + D) 37 | 38 | mapping f = inl C D 39 | 40 | mapping g = inr C D 41 | 42 | mapping h = (f + g) // this is actually the identity! 43 | 44 | schema X = void 45 | 46 | schema Y = ((C + (C + C)) + void) 47 | 48 | mapping q = void C -------------------------------------------------------------------------------- /resources/examples/fql/Connected Components.fql: -------------------------------------------------------------------------------- 1 | schema Graph = { 2 | nodes arrow,vertex; 3 | attributes; 4 | arrows src:arrow->vertex,tgt:arrow->vertex; 5 | equations; 6 | } 7 | 8 | //has 4 connected components 9 | instance G = { 10 | nodes arrow->{a,b,c,d,e}, vertex->{t,u,v,w,x,y,z}; 11 | attributes; 12 | arrows 13 | src->{(a,t),(b,t),(c,x),(d,y),(e,z)}, 14 | tgt->{(a,u),(b,v),(c,x),(d,z),(e,y)}; 15 | } : Graph 16 | 17 | schema Terminal = { 18 | nodes X; 19 | attributes; 20 | arrows; 21 | equations; 22 | } 23 | 24 | mapping F = { 25 | nodes arrow->X, vertex->X; 26 | attributes; 27 | arrows src->X, tgt->X; 28 | } : Graph -> Terminal 29 | 30 | //has 4 rows 31 | instance Components=SIGMA F G 32 | 33 | //puts 4 rows into vertex, 4 rows into arrow, corresponding to the connected components 34 | instance I = delta F Components 35 | 36 | //gives the transform from the original graph to the connected components 37 | transform t = I.return 38 | 39 | //has 1 row 40 | instance Loops=pi F G 41 | 42 | //puts 1 row into vertex, 1 row into arrow, corresponding to the single loop. 43 | instance J = delta F Loops 44 | 45 | //gives the transform including the subgraph of instances into the original graph. 46 | transform u = J.coreturn -------------------------------------------------------------------------------- /resources/examples/fql/Cyclic.fql: -------------------------------------------------------------------------------- 1 | schema CM53 = { 2 | nodes M; 3 | attributes; 4 | arrows arr : M -> M; 5 | equations M.arr.arr.arr.arr.arr = M.arr.arr; 6 | } 7 | 8 | schema CM33 = { 9 | nodes J; 10 | attributes; 11 | arrows a : J -> J; 12 | equations J.a.a.a = J; 13 | } 14 | 15 | mapping F = { 16 | nodes M -> J; 17 | attributes; 18 | arrows arr -> J.a; 19 | } : CM53 -> CM33 20 | 21 | instance A53 = { 22 | nodes M -> { mm1,mm2,mmm,m }; 23 | attributes; 24 | arrows arr -> { (mm1,mm2), (mm2,m), (mmm,m),(m,m) }; 25 | } : CM53 26 | 27 | instance A33 = { 28 | nodes J -> { m1, m2 , m3 }; 29 | attributes; 30 | arrows a -> { (m1,m2), (m2,m3), (m3,m1) }; 31 | } : CM33 32 | 33 | instance Inst2 = pi F A53 34 | -------------------------------------------------------------------------------- /resources/examples/fql/Delta.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes 3 | T1, 4 | T2; 5 | attributes 6 | t1_ssn : T1 -> string, 7 | t1_first : T1 -> string, 8 | t1_last : T1 -> string, 9 | t2_first : T2 -> string, 10 | t2_last : T2 -> string, 11 | t2_salary : T2 -> int; 12 | arrows; 13 | equations; 14 | } 15 | 16 | schema D = { 17 | nodes 18 | T; 19 | attributes 20 | ssn0 : T -> string, 21 | first0 : T -> string, 22 | last0 : T -> string, 23 | salary0 : T -> int; 24 | arrows; 25 | equations; 26 | } 27 | 28 | mapping F = { 29 | nodes 30 | T1 -> T, 31 | T2 -> T; 32 | attributes 33 | t1_ssn -> ssn0, 34 | t1_first -> first0, 35 | t2_first -> first0, 36 | t1_last -> last0, 37 | t2_last -> last0, 38 | t2_salary -> salary0; 39 | arrows; 40 | } : C -> D 41 | 42 | instance J = { 43 | nodes 44 | T -> { XF667,XF891,XF221 } ; 45 | attributes 46 | ssn0 -> { (XF667, "115-234"),(XF891,"112-988"),(XF221,"198-887") }, 47 | first0 -> { (XF667,Bob),(XF891,Sue),(XF221,Alice) }, 48 | last0 -> { (XF667,Smith),(XF891,Smith),(XF221,Jones) }, 49 | salary0 -> { (XF667,250),(XF891,300),(XF221,100) }; 50 | arrows; 51 | } : D 52 | 53 | instance I = delta F J 54 | 55 | instance J0 = { 56 | nodes 57 | T -> { XF667,XF891,XF221, xxx } ; 58 | attributes 59 | ssn0 -> { (XF667, "115-234"),(XF891,"112-988"),(XF221,"198-887"), (xxx,"xxx") }, 60 | first0 -> { (XF667,Bob),(XF891,Sue),(XF221,Alice),(xxx, "xxx" )}, 61 | last0 -> { (XF667,Smith),(XF891,Smith),(XF221,Jones), (xxx, "xxx") }, 62 | salary0 -> { (XF667,250),(XF891,300),(XF221,100), (xxx, 0) }; 63 | arrows; 64 | } : D 65 | 66 | transform trans = { 67 | nodes T -> {(XF667,XF667),(XF891,XF891),(XF221,XF221)}; 68 | } : J -> J0 69 | 70 | instance I0 = delta F J0 71 | 72 | transform trans0 = delta I I0 trans -------------------------------------------------------------------------------- /resources/examples/fql/Dihedral 2.fql: -------------------------------------------------------------------------------- 1 | // should have 4 elements. 2 | schema Dihedral2 = { 3 | nodes G; 4 | attributes; 5 | arrows 6 | r: G -> G, 7 | s: G -> G; 8 | equations 9 | G.r.r = G, 10 | G.s.s = G, 11 | G.s.r.s = G.r; 12 | } 13 | 14 | //alternative presentation 15 | schema Dihedral2x = { 16 | nodes G; 17 | attributes; 18 | arrows 19 | r: G -> G, 20 | R0: G -> G, 21 | s: G -> G, 22 | S0: G -> G; 23 | equations 24 | G.r.R0 = G, 25 | G.R0.r = G, 26 | G.s.S0 = G, 27 | G.S0.s = G, 28 | G.r.r = G, 29 | G.s.s = G, 30 | G.S0.r.s = G.R0; 31 | } -------------------------------------------------------------------------------- /resources/examples/fql/Employees.fql: -------------------------------------------------------------------------------- 1 | schema S = { 2 | nodes 3 | Employee, Department; 4 | attributes 5 | name : Department -> string, 6 | first : Employee -> string, 7 | last : Employee -> string; 8 | arrows 9 | manager : Employee -> Employee, 10 | worksIn : Employee -> Department, 11 | secretary : Department -> Employee; 12 | equations 13 | Employee.manager.worksIn = Employee.worksIn, 14 | Department.secretary.worksIn = Department, 15 | Employee.manager.manager = Employee.manager; 16 | } 17 | 18 | instance I = { 19 | nodes 20 | Employee -> { 101, 102, 103 }, 21 | Department -> { q10, x02 }; 22 | attributes 23 | first -> { (101, Alan), (102, Camille), (103, Andrey) }, 24 | last -> { (101, Turing), (102, Jordan), (103, Markov) }, 25 | name -> { (q10, AppliedMath), (x02, PureMath) }; 26 | arrows 27 | manager -> { (101, 103), (102, 102), (103, 103) }, 28 | worksIn -> { (101, q10), (102, x02), (103, q10) }, 29 | secretary -> { (q10, 101), (x02, 102) }; 30 | } : S 31 | -------------------------------------------------------------------------------- /resources/examples/fql/Enums (User types).fql: -------------------------------------------------------------------------------- 1 | enum color = { red, green, blue } 2 | 3 | enum quark = { "top", "bottom", "up", "down", "charm", "strange" } 4 | 5 | schema S = { 6 | nodes S_node; 7 | attributes S_att : S_node -> color; 8 | arrows; 9 | equations; 10 | } 11 | 12 | schema T = { 13 | nodes T_node; 14 | attributes T_att : T_node -> quark; 15 | arrows; 16 | equations; 17 | } 18 | 19 | instance I = { 20 | nodes S_node -> {0,1}; 21 | attributes S_att -> {(0,red),(1,blue)}; 22 | arrows; 23 | } : S 24 | 25 | /* bad 26 | mapping F = { 27 | nodes S_node -> T_node; 28 | attributes S_att -> T_att; 29 | arrows; 30 | } : S -> T 31 | */ 32 | 33 | //good 34 | mapping F = { 35 | nodes S_node -> S_node; 36 | attributes S_att -> S_att; 37 | arrows; 38 | } : S -> S -------------------------------------------------------------------------------- /resources/examples/fql/Exponentials 2.fql: -------------------------------------------------------------------------------- 1 | schema D0 = { 2 | nodes a0; 3 | attributes; 4 | arrows; 5 | equations; 6 | } 7 | 8 | schema D1 = { 9 | nodes a0, a1; 10 | attributes; 11 | arrows af : a0 -> a1; 12 | equations; 13 | } 14 | 15 | schema D2 = { 16 | nodes b0, b1, b2; 17 | attributes; 18 | arrows bf1 : b0 -> b1, bf2 : b1 -> b2; 19 | equations; 20 | } 21 | 22 | schema D3 = { 23 | nodes b0, b1, b2, b3; 24 | attributes; 25 | arrows bf1 : b0 -> b1, bf2 : b1 -> b2, bf3: b2->b3; 26 | equations; 27 | } 28 | 29 | 30 | 31 | schema H0_0=(D0^D0) 32 | schema H0_1=(D0^D1) 33 | schema H0_2=(D0^D2) 34 | schema H0_3=(D0^D3) 35 | 36 | schema H1_0=(D1^D0) 37 | schema H1_1=(D1^D1) 38 | schema H1_2=(D1^D2) 39 | schema H1_3=(D1^D3) 40 | 41 | schema H2_0=(D2^D0) 42 | schema H2_1=(D2^D1) 43 | schema H2_2=(D2^D2) 44 | schema H2_3=(D2^D3) 45 | 46 | 47 | schema H3_0=(D3^D0) 48 | schema H3_1=(D3^D1) 49 | schema H3_2=(D3^D2) 50 | //schema H3_3=(D3^D3) 51 | 52 | 53 | schema Loop43 = { 54 | nodes a; 55 | attributes; 56 | arrows f:a->a; 57 | equations a.f.f.f.f=a.f.f.f; 58 | } 59 | 60 | schema Loop32 = { 61 | nodes a; 62 | attributes; 63 | arrows f:a->a; 64 | equations a.f.f.f=a.f.f; 65 | } 66 | 67 | schema term = { 68 | nodes a; 69 | attributes; 70 | arrows; 71 | equations; 72 | } 73 | 74 | schema Y=(Loop32^term) 75 | schema X=(Loop43^Loop32) -------------------------------------------------------------------------------- /resources/examples/fql/Exponentials.fql: -------------------------------------------------------------------------------- 1 | schema A = { 2 | nodes a1, a2; 3 | attributes; 4 | arrows af : a1 -> a2; 5 | equations; 6 | } 7 | 8 | schema B = { 9 | nodes b1, b2, b3; 10 | attributes; 11 | arrows bf1 : b1 -> b2, bf2 : b2 -> b3; 12 | equations; 13 | } 14 | 15 | schema S = (A^B) 16 | 17 | mapping eta = curry eval A B // (= id) 18 | 19 | mapping F = unit {} (A*B) //can use any F for beta, we choose this one 20 | 21 | mapping beta = ( ((fst A B then curry F) * (snd A B then id B)) then eval unit {} B ) // (= F) 22 | 23 | // exponentials of instances below ///////////////////////////////////// 24 | 25 | enum dom = {foo, bar, baz} 26 | 27 | schema C = { 28 | nodes a, b; 29 | attributes att : a -> dom; 30 | arrows f : a -> b; 31 | equations; 32 | } 33 | 34 | instance I = { 35 | nodes a -> {1,2,3}, b -> {4,5}; 36 | attributes att -> {(1,foo),(2,bar),(3,baz)}; 37 | arrows f -> {(1,4),(2,5),(3,5)}; 38 | } : C 39 | 40 | instance J = { 41 | nodes a -> {1,2}, b -> {4}; 42 | attributes att -> {(1,foo),(2,baz)}; 43 | arrows f -> {(1,4),(2,4)}; 44 | } : C 45 | 46 | instance K = (J^I) 47 | 48 | instance M = (K*I) 49 | 50 | transform trans = M.eval 51 | 52 | transform idx = K.curry trans //eta 53 | 54 | // beta below here 55 | instance one = unit C 56 | instance ab = (I * J) 57 | instance oneB = (one ^ J) 58 | instance oneBB = (oneB * J) 59 | 60 | transform G = one.unit ab 61 | 62 | transform curryF = oneB.curry G 63 | 64 | transform tr = (oneBB.( (ab.fst then curryF) * ab.snd) then oneBB.eval) //beta (= G) -------------------------------------------------------------------------------- /resources/examples/fql/External.fql: -------------------------------------------------------------------------------- 1 | //The keyword 'external' can be used to suppress CREATE TABLE statements 2 | //in the generated SQL output. Hence, the generated output can be run 3 | //on pre-existing database intances. 4 | 5 | schema C = { nodes T; attributes; arrows; equations; } 6 | 7 | // generates CREATE TABLE I_T(c1 VARCHAR(128), c0 VARCHAR(128)); 8 | instance I = { nodes T -> {}; attributes; arrows; } : C 9 | 10 | // copies given extblname into J 11 | instance J = external C extblname 12 | 13 | // external (and only external) instances can have external transforms 14 | transform K = external J J exttransname 15 | 16 | drop I //drops tables for I -------------------------------------------------------------------------------- /resources/examples/fql/FOIL.fql: -------------------------------------------------------------------------------- 1 | schema Begin = { 2 | nodes a, b, c, d; 3 | attributes 4 | atta:a->string, 5 | attb:b->string, 6 | attc:c->string, 7 | attd:d->string; 8 | arrows; 9 | equations; 10 | } 11 | 12 | schema Added = { 13 | nodes aPLUSb, cPLUSd; 14 | attributes 15 | attab:aPLUSb->string, 16 | attcd:cPLUSd->string; 17 | arrows; 18 | equations; 19 | } 20 | 21 | schema Multiplied = { 22 | nodes aPLUSbTIMEScPLUSd; 23 | attributes 24 | attab : aPLUSbTIMEScPLUSd -> string, 25 | attcd : aPLUSbTIMEScPLUSd -> string; 26 | arrows; 27 | equations; 28 | } 29 | 30 | mapping F = { 31 | nodes 32 | a->aPLUSb, 33 | b->aPLUSb, 34 | c->cPLUSd, 35 | d->cPLUSd; 36 | attributes 37 | atta->attab, 38 | attb->attab, 39 | attc->attcd, 40 | attd->attcd; 41 | arrows; 42 | }:Begin->Added 43 | 44 | mapping G = { 45 | nodes 46 | aPLUSb->aPLUSbTIMEScPLUSd, 47 | cPLUSd->aPLUSbTIMEScPLUSd; 48 | attributes 49 | attab->attab, 50 | attcd->attcd; 51 | arrows; 52 | }:Added->Multiplied 53 | 54 | /* Below, put any number of elements into a,b,c,d. 55 | * The output should have (a+b)*(c+d) many elements 56 | */ 57 | 58 | instance I = { 59 | nodes 60 | a -> {1}, 61 | b -> {1,2}, 62 | c -> {1,2}, 63 | d -> {1,2,3}; 64 | attributes 65 | atta -> {(1,a1)}, 66 | attb -> {(1,b1),(2,b2)}, 67 | attc -> {(1,c1),(2,c2)}, 68 | attd -> {(1,d1),(2,d2),(3,d3)}; 69 | arrows; 70 | }: Begin 71 | 72 | /*(1+2)*(2+3)=15*/ 73 | 74 | instance J = sigma F I 75 | instance K =pi G J -------------------------------------------------------------------------------- /resources/examples/fql/Full Sigma 2.fql: -------------------------------------------------------------------------------- 1 | schema T = { 2 | nodes s; 3 | attributes; 4 | arrows; 5 | equations; 6 | } 7 | 8 | instance I = { 9 | nodes s->{1,2}; 10 | attributes; 11 | arrows; 12 | } : T 13 | 14 | schema Loop = { 15 | nodes s; 16 | attributes; 17 | arrows f:s->s; 18 | equations s.f.f.f.f.f=s.f.f.f; 19 | } 20 | 21 | instance J = { 22 | nodes s->{1,2,3,4,5,6,7}; 23 | attributes; 24 | arrows f->{(1,2),(2,3),(3,4),(4,3),(5,2), (6,7),(7,6)}; 25 | } : Loop 26 | 27 | mapping F = { 28 | nodes s->s; 29 | attributes; 30 | arrows; 31 | } : T -> Loop 32 | 33 | mapping G = { 34 | nodes s->s; 35 | attributes; 36 | arrows f->s; 37 | } : Loop -> T 38 | 39 | instance Sigma_FI = SIGMA F I 40 | 41 | instance Sigma_GJ = SIGMA G J -------------------------------------------------------------------------------- /resources/examples/fql/Image.fql: -------------------------------------------------------------------------------- 1 | /* 2 | * Let A and B be sets and F : A -> B a function. 3 | * 4 | * The pre-image of F is a function P(B) -> P(A) defined by 5 | * J -> { a | F(a) in J } 6 | * 7 | * The direct-image of F is a function P(A) -> P(B) defined by 8 | * I -> { b | b = F(x), for some x in I } 9 | * 10 | * The dual-image of F is a function P(A) -> P(B) defined by 11 | * I -> { b | b = F(x), for all x in I } 12 | */ 13 | 14 | /* 15 | * We can encode a set {e1,e2,...,eN} as a schema with nodes e1,e2,...,eN. 16 | * A function from set A to set B is encoded as a mapping from A to B. 17 | * A subset of {e1,e2,...,eN} is encoded as an instance, where each node has either 0 or 1 elements. 18 | * 19 | * Under this encoding, 20 | * delta is pre-image, 21 | * sigma is direct-image, 22 | * pi is dual-image. 23 | */ 24 | 25 | // Example 26 | 27 | // {m1, m2, n} 28 | schema A = { 29 | nodes m1, m2, n; 30 | attributes; 31 | arrows; 32 | equations; 33 | } 34 | 35 | // {m, n, o} 36 | schema B = { 37 | nodes m, n, o; 38 | attributes; 39 | arrows; 40 | equations; 41 | } 42 | 43 | // m1 -> m, m2 -> m, n -> n 44 | mapping F = { 45 | nodes m1 -> m, m2 -> m, n -> n; 46 | attributes; 47 | arrows; 48 | } : A -> B 49 | 50 | // {m1, n} 51 | instance I = { 52 | nodes m1 -> { present }, m2 -> { }, n -> { present } ; 53 | attributes; 54 | arrows; 55 | } : A 56 | 57 | // {m, n} 58 | instance temp1 = sigma F I 59 | instance direct_imFI = relationalize temp1 60 | 61 | // {n, o} 62 | instance temp2 = pi F I 63 | instance dual_imFI = relationalize temp2 64 | 65 | // {m, o} 66 | instance J = { 67 | nodes m -> { present }, n -> { }, o -> { present }; 68 | attributes; 69 | arrows; 70 | } : B 71 | 72 | // {m1, m2} 73 | instance temp3 = delta F J 74 | instance pre_imFJ = relationalize temp3 75 | 76 | /* 77 | Written in terms of adjunctions, we have 78 | 79 | image(I) subseteq J 80 | ---------------------- 81 | I subseteq preimage(J) 82 | 83 | preimage(J) subseteq I 84 | ---------------------- 85 | J subseteq dualimage(I) 86 | */ -------------------------------------------------------------------------------- /resources/examples/fql/Infinite Employees.fql: -------------------------------------------------------------------------------- 1 | /* This is an example of an infinite schema. To compile it, 2 | - check 'allow infinte schemas' in the options menu 3 | - set 'maximum category iterations' to a low value like 400 4 | */ 5 | schema S = { 6 | nodes 7 | Employee, Department, FirstName, LastName, DepartmentName; 8 | attributes; 9 | arrows 10 | manager : Employee -> Employee, 11 | worksIn : Employee -> Department, 12 | secretary : Department -> Employee, 13 | name : Department -> DepartmentName, 14 | first : Employee -> FirstName, 15 | last : Employee -> LastName; 16 | equations 17 | Employee.manager.worksIn = Employee.worksIn, 18 | Department.secretary.worksIn = Department; 19 | } 20 | 21 | instance I = { 22 | nodes 23 | FirstName -> { Alan, Alice, Andrey, Camille, David }, 24 | LastName -> { Arden, Hoover, Jordan, Markov, Turing }, 25 | DepartmentName -> { AppliedMath, Biology, PureMath }, 26 | Employee -> { 101, 102, 103 }, 27 | Department -> { q10, x02 }; 28 | attributes; 29 | arrows 30 | first -> { (101, Alan), (102, Camille), (103, Andrey) }, 31 | last -> { (101, Turing),(102, Jordan), (103, Markov) }, 32 | manager -> { (101, 103), (102, 102), (103, 103) }, 33 | worksIn -> { (101, q10), (102, x02), (103, q10) }, 34 | name -> { (q10, AppliedMath), (x02, PureMath) }, 35 | secretary -> { (q10, 101), (x02, 102) }; 36 | } : S 37 | 38 | 39 | //delta and SIGMA migrations on infinite schemas are possible 40 | mapping F = id S 41 | instance J = delta F I 42 | instance K = SIGMA F I 43 | -------------------------------------------------------------------------------- /resources/examples/fql/Isomorphism.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes A, B; 3 | attributes; 4 | arrows f : A -> B , g : B -> A; 5 | equations A.f.g = A, B.g.f = B; 6 | } 7 | 8 | instance I = { 9 | nodes A -> {1,2}, B -> {a,b}; 10 | attributes; 11 | arrows f -> {(1,a),(2,b)}, g -> {(a,1),(b,2)}; 12 | } : C 13 | -------------------------------------------------------------------------------- /resources/examples/fql/Pi.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes 3 | c1, 4 | c2; 5 | attributes 6 | att1 : c1 -> string, 7 | att2 : c1 -> string, 8 | att3 : c2 -> string; 9 | arrows; 10 | equations; 11 | } 12 | 13 | instance I = { 14 | nodes 15 | c1 -> { 1,2 }, 16 | c2 -> { 1,2,3 }; 17 | attributes 18 | att1 -> { (1,David), (2,Ryan) }, 19 | att2 -> { (1,Spivak), (2,Wisnesky) }, 20 | att3 -> { (1,MIT), (2,Harvard),(3,Leslie) }; 21 | arrows; 22 | } : C 23 | 24 | schema D = { 25 | nodes 26 | d; 27 | attributes 28 | a1 : d -> string, 29 | a2 : d -> string, 30 | a3 : d -> string; 31 | arrows; 32 | equations; 33 | } 34 | 35 | mapping F = { 36 | nodes 37 | c1 -> d, 38 | c2 -> d; 39 | attributes 40 | att1 -> a1, 41 | att2 -> a2, 42 | att3 -> a3; 43 | arrows; 44 | } : C -> D 45 | 46 | instance J = pi F I 47 | 48 | instance K = delta F J 49 | 50 | transform monad_counit = K.coreturn 51 | 52 | instance L = pi F K 53 | 54 | transform monad_unit = L.return 55 | 56 | instance I0 = { 57 | nodes 58 | c1 -> { 1 }, 59 | c2 -> { 1,2 }; 60 | attributes 61 | att1 -> { (1,David) }, 62 | att2 -> { (1,Spivak) }, 63 | att3 -> { (1,MIT), (2,Harvard) }; 64 | arrows; 65 | } : C 66 | 67 | transform t = { 68 | nodes c1 -> {(1,1)}, c2 -> {(1,1),(2,2)} ; 69 | } : I0 -> I 70 | 71 | instance J0 = pi F I0 72 | 73 | transform t0 = pi J0 J t -------------------------------------------------------------------------------- /resources/examples/fql/Products.fql: -------------------------------------------------------------------------------- 1 | schema S = { 2 | nodes a, b; 3 | attributes att : a -> string; 4 | arrows f : a -> b; 5 | equations; 6 | } 7 | 8 | instance I = { 9 | nodes a -> {1,2}, b -> {3}; 10 | attributes att -> {(1,common),(2,common)}; 11 | arrows f -> {(1,3),(2,3)}; 12 | } : S 13 | 14 | instance J = { 15 | nodes a -> {a,b,c}, b -> {d,e}; 16 | attributes att -> {(a,common),(b,common),(c,baz)}; 17 | arrows f -> {(a,d),(b,e),(c,e)}; 18 | } : S 19 | 20 | instance A = (I * J) 21 | 22 | transform K = A.fst 23 | 24 | transform L = A.snd 25 | 26 | transform M = A.(K * L) //is id 27 | 28 | schema X = { 29 | nodes a; 30 | attributes; 31 | arrows; 32 | equations; 33 | } 34 | 35 | instance N = unit X 36 | 37 | transform O = N.unit N 38 | 39 | enum color = {r,g,b} 40 | enum num = {1,2} 41 | 42 | schema C = { 43 | nodes a,b,c; 44 | attributes attb:b->color, attc:c->num; 45 | arrows f:a->b, g:a->c; 46 | equations; 47 | } 48 | 49 | instance II = unit C 50 | 51 | instance JJ = { 52 | nodes a -> {1,2,3}, b -> {1,2}, c -> {1,3}; 53 | attributes attb -> {(1,r),(2,g)}, attc -> {(1,1),(3,2)}; 54 | arrows f -> {(1,1),(2,1),(3,2)}, g -> {(1,1),(2,1),(3,3)}; 55 | } : C 56 | 57 | transform KK = II.unit JJ 58 | 59 | schema SS = { 60 | nodes a, b, c; 61 | attributes att:a->string; 62 | arrows f:a->b, g:b->c, h:a->c; 63 | equations a.h = a.f.g; 64 | } 65 | 66 | schema TT = { 67 | nodes x, y; 68 | attributes att:x->string; 69 | arrows u:x->y, z:x->y; 70 | equations x.u = x.z; 71 | } 72 | 73 | mapping F = { 74 | nodes x -> a, y -> c; 75 | attributes att->att; 76 | arrows u -> a.f.g, z->a.f.g; 77 | } : TT -> SS 78 | 79 | schema AA = (SS * TT) 80 | 81 | mapping p1 = fst SS TT 82 | mapping p2 = snd SS TT 83 | 84 | mapping p = (p1*p2) //is identity 85 | 86 | schema XX = unit {string} 87 | mapping H = unit {string} TT -------------------------------------------------------------------------------- /resources/examples/fql/Query Composition.fql: -------------------------------------------------------------------------------- 1 | //requires parallel or hybrid left-kan 2 | schema S = { nodes s ; attributes satt : s -> string; arrows; equations; } 3 | schema T = { nodes t1,t2 ; attributes t1att : t1 -> string; arrows; equations; } 4 | schema B = { nodes b1,b2; attributes b1att : b1 -> string,b2att : b2 -> string; arrows; equations; } 5 | schema A = { nodes a1,a2,a3,a4; attributes a1att : a1 -> string,a2att : a2 -> string; arrows; equations; } 6 | 7 | mapping sm = { nodes b1 -> s, b2 -> s; attributes b1att -> satt,b2att -> satt; arrows; } : B -> S 8 | mapping fm = { nodes b1 -> a1, b2 -> a2 ; attributes b1att -> a1att,b2att -> a2att; arrows; } : B -> A 9 | mapping tm = { nodes a1 -> t1, a2 -> t1, a3 -> t2,a4->t2 ; attributes a1att -> t1att,a2att->t1att; arrows; } : A -> T 10 | 11 | query q1 = delta sm pi fm sigma tm 12 | 13 | instance I = { 14 | nodes s->{1,2,3}; 15 | attributes satt->{(1,one),(2,two),(3,three)}; 16 | arrows; 17 | } : S 18 | 19 | instance q1I =eval q1 I 20 | 21 | schema D = { nodes d1,d2,d3 ; attributes d1att : d1 -> string; arrows; equations; } 22 | schema C = { nodes c1,c2 ; attributes c1att : c1 -> string; arrows; equations; } 23 | schema U = { nodes u1,u2 ; attributes u1att : u1 -> string; arrows; equations;} 24 | 25 | mapping um = { nodes d1 -> t1, d2 -> t1 , d3->t2; attributes d1att -> t1att; arrows;} : D -> T 26 | 27 | mapping gm = { nodes d1 -> c1, d2 -> c2,d3->c2 ; attributes d1att -> c1att; arrows;} : D -> C 28 | 29 | mapping vm = { nodes c1 -> u1,c2->u2 ; attributes c1att -> u1att; arrows; } : C -> U 30 | 31 | query q2 = delta um pi gm sigma vm 32 | query q = (q1 then q2) 33 | 34 | /* 35 | * The following two queries should be equal when applied to I. 36 | * The first q2q1I is manual composition of q1 and q2. 37 | * The second qI is formulaic composition. 38 | */ 39 | 40 | instance q2q1I=eval q2 q1I 41 | instance qI= eval q I -------------------------------------------------------------------------------- /resources/examples/fql/Relationalize.fql: -------------------------------------------------------------------------------- 1 | 2 | schema C={nodes A;attributes att:A->string;arrows f:A->A;equations A.f.f.f.f=A.f.f;} 3 | 4 | instance I ={ 5 | nodes A->{1,2,3,4,5,6,7}; 6 | attributes att->{(1,1),(2,2),(3,3),(4,1),(5,5),(6,3),(7,5)}; 7 | arrows f->{(1,2),(2,3),(3,5),(4,2),(5,3),(6,7),(7,6)}; 8 | } : C 9 | 10 | instance RelI=relationalize I 11 | 12 | transform trans = RelI.relationalize 13 | 14 | instance J ={ 15 | nodes A->{1,2,3,4,5}; 16 | attributes att->{(1,1),(2,2),(3,3),(4,1),(5,5)}; 17 | arrows f->{(1,2),(2,3),(3,5),(4,2),(5,3)}; 18 | } : C 19 | 20 | instance RelJ=relationalize J 21 | 22 | transform t = { 23 | nodes A -> {(1,1),(2,2),(3,3),(4,4),(5,5)}; 24 | } : J -> I 25 | 26 | transform h = relationalize RelJ RelI t -------------------------------------------------------------------------------- /resources/examples/fql/Schema Matching.fql: -------------------------------------------------------------------------------- 1 | schema C ={ 2 | nodes 3 | Amphibian, 4 | LandAnimal, 5 | WaterAnimal; 6 | attributes 7 | attA : Amphibian -> string, 8 | attL:LandAnimal-> string, 9 | attW:WaterAnimal->string; 10 | arrows 11 | IsAL:Amphibian->LandAnimal, 12 | IsAW:Amphibian->WaterAnimal; 13 | equations; 14 | } 15 | 16 | schema D ={ 17 | nodes 18 | Amphibian, 19 | LandAnimal, 20 | WaterAnimal, 21 | Animal; 22 | attributes 23 | attA : Amphibian -> string, 24 | attL:LandAnimal-> string, 25 | attW:WaterAnimal->string; 26 | arrows 27 | IsAL:Amphibian->LandAnimal, 28 | IsAW:Amphibian->WaterAnimal, 29 | IsALL:LandAnimal->Animal, 30 | IsAWW:WaterAnimal->Animal; 31 | equations 32 | Amphibian.IsAL.IsALL=Amphibian.IsAW.IsAWW; 33 | } 34 | 35 | instance I = { 36 | nodes 37 | Amphibian->{1,2}, 38 | LandAnimal->{1,2,3,4,5}, 39 | WaterAnimal->{1,2,3,4}; 40 | attributes 41 | attA -> {(1,gecko),(2, frog)}, 42 | attL ->{(1,gecko),(2,frog),(3,human),(4,cow),(5,horse)}, 43 | attW -> {(1,fish),(2,gecko),(3,frog),(4,dolphin)}; 44 | arrows 45 | IsAL->{(1,1),(2,2)}, 46 | IsAW->{(1,2),(2,3)}; 47 | } : C 48 | 49 | 50 | 51 | QUERY q1 = match {(attA, attA),(attL, attL), (attW, attW)} C D "delta sigma forward" 52 | QUERY q2 = match {(attA, attA),(attL, attL), (attW, attW)} C D "delta pi forward" 53 | QUERY q3 = match {(attA, attA),(attL, attL), (attW, attW)} C D "delta sigma backward" 54 | QUERY q4 = match {(attA, attA),(attL, attL), (attW, attW)} C D "delta pi backward" 55 | 56 | //instance out1 = EVAL q1 I // - I has wrong type 57 | //instance out2 = EVAL q2 I // - I has wrong type 58 | instance out3 = EVAL q3 I // SIGMA fails if it can't create nulls 59 | instance out4 = EVAL q4 I // has 40 rows -------------------------------------------------------------------------------- /resources/examples/fql/Sub Schema.fql: -------------------------------------------------------------------------------- 1 | schema ab = { 2 | nodes a, b; 3 | attributes atta : a -> string, attb : b -> string; 4 | arrows f : a -> b; 5 | equations; 6 | } 7 | 8 | schema c = { 9 | nodes c; 10 | attributes attc : c -> string; 11 | arrows ; 12 | equations; 13 | } 14 | 15 | schema abc = (ab union c) 16 | 17 | mapping F = subschema ab abc -------------------------------------------------------------------------------- /resources/examples/fql/Surjective Pi.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes a, b; 3 | attributes att1 : a -> string, att2 : b -> string; 4 | arrows; 5 | equations; 6 | } 7 | 8 | schema D = { 9 | nodes c; 10 | attributes att : c -> string; 11 | arrows; 12 | equations; 13 | } 14 | 15 | instance I = { 16 | nodes a -> {1,2,3}, b -> {1,2}; 17 | attributes att1 -> {(1,alpha), (2,beta), (3,gamma)}, att2 -> {(1,alpha),(2,dlta)}; 18 | arrows; 19 | } : C 20 | 21 | mapping F = { 22 | nodes a -> c, b -> c; 23 | attributes att1 -> att, att2 -> att; 24 | arrows; 25 | } : C -> D 26 | 27 | instance J = pi F I -------------------------------------------------------------------------------- /resources/examples/fql/Transforms.fql: -------------------------------------------------------------------------------- 1 | schema s = { 2 | nodes a, b; 3 | attributes att : a -> string; 4 | arrows f : b -> a; 5 | equations; 6 | } 7 | 8 | instance i = { 9 | nodes a -> {1,2,3}, b -> {4}; 10 | attributes att -> {(1,1),(2,2),(3,3)}; 11 | arrows f -> {(4,1)}; 12 | } : s 13 | 14 | instance j = { 15 | nodes a -> {a,b}, b -> {}; 16 | attributes att -> {(a,a),(b,b)}; 17 | arrows f -> {}; 18 | } : s 19 | 20 | transform g = id i 21 | 22 | instance ij0 = (i * j) 23 | 24 | transform ij0fst = ij0.fst 25 | 26 | transform ij0snd = ij0.snd 27 | 28 | transform ij00 = ij0.(ij0fst * ij0snd) 29 | 30 | instance ij = (i + j) 31 | 32 | transform ijinl = ij.inl 33 | 34 | transform ijinr = ij.inr 35 | 36 | transform ij0X = ij.(ijinl + ijinr) 37 | 38 | instance II = void s 39 | 40 | transform t1 = II.void j 41 | 42 | schema t = {nodes a; attributes; arrows; equations;} 43 | 44 | instance tx = unit t 45 | 46 | instance tj = {nodes a -> {a,b,c}; attributes; arrows;} : t 47 | 48 | transform JJ = tx.unit tj -------------------------------------------------------------------------------- /resources/examples/fql/Transforms2.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes A; 3 | attributes att:A->string; 4 | arrows f:A->A; 5 | equations A.f.f.f=A.f.f; 6 | } 7 | 8 | instance I = { 9 | nodes A->{1,2,3,4,5}; 10 | attributes att->{(1,common),(2,common),(3,common),(4,common),(5,common)}; 11 | arrows f->{(1,2),(2,3),(3,3),(4,2),(5,3)}; 12 | } : C 13 | 14 | instance J = { 15 | nodes A->{1,2,3}; 16 | attributes att->{(1,common),(2,common),(3,common)}; 17 | arrows f->{(1,2),(2,3),(3,3)}; 18 | } : C 19 | 20 | //transform BadTransform = { 21 | // nodes A->{(1,1),(2,2),(3,4)}; 22 | //} : J -> I 23 | 24 | transform GoodTransform1 = { 25 | nodes A->{(1,1),(2,2),(3,3)}; 26 | } : J -> I 27 | 28 | transform GoodTransform2 = { 29 | nodes A->{(1,1),(2,2),(3,3),(4,1),(5,2)}; 30 | } : I -> J -------------------------------------------------------------------------------- /resources/examples/fql/Triangle.fql: -------------------------------------------------------------------------------- 1 | schema C = { 2 | nodes 3 | A, B, C; 4 | attributes; 5 | arrows 6 | ax : A -> B, bx : B -> C, cx : C -> A; 7 | equations 8 | A.ax.bx.cx = A, 9 | B.bx.cx.ax = B, 10 | C.cx.ax.bx = C; 11 | } 12 | 13 | schema D = opposite C 14 | 15 | mapping F = id C 16 | mapping Fop = opposite F -------------------------------------------------------------------------------- /resources/examples/fql/Weird.fql: -------------------------------------------------------------------------------- 1 | schema Z2 = { 2 | nodes 3 | G; 4 | attributes 5 | att1: G->string; 6 | arrows 7 | r: G -> G; 8 | equations 9 | G.r.r = G; 10 | } 11 | 12 | schema Z4 = { 13 | nodes 14 | G; 15 | attributes 16 | attr1:G->string; 17 | arrows 18 | r: G -> G; 19 | equations 20 | G.r.r.r.r = G; 21 | } 22 | 23 | mapping F = { 24 | nodes 25 | G->G; 26 | attributes 27 | att1->attr1; 28 | arrows 29 | r->G.r.r; 30 | } : Z2 -> Z4 31 | 32 | 33 | instance I0 = { 34 | nodes 35 | G->{1,2}; 36 | attributes 37 | att1->{(1,1),(2,2)}; 38 | arrows 39 | r->{(1,2),(2,1)}; 40 | } : Z2 41 | instance Pi_FI0 = pi F I0 42 | 43 | 44 | instance I1 = { 45 | nodes 46 | G->{a0,1,2}; 47 | attributes 48 | att1->{(1,1),(2,2),(a0,a0)}; 49 | arrows 50 | r->{(a0,a0),(1,2),(2,1)}; 51 | } : Z2 52 | instance Pi_FI1 = pi F I1 53 | 54 | 55 | instance I2 = { 56 | nodes 57 | G->{a0,b0,1,2}; 58 | attributes 59 | att1->{(1,1),(2,2),(a0,a0),(b0,b0)}; 60 | arrows 61 | r->{(a0,a0),(b0,b0),(1,2),(2,1)}; 62 | } : Z2 63 | instance Pi_FI2 = pi F I2 64 | 65 | instance I3 = { 66 | nodes 67 | G->{a0,b0,c0,1,2}; 68 | attributes 69 | att1->{(1,1),(2,2),(a0,a0),(b0,b0),(c0,c0)}; 70 | arrows 71 | r->{(a0,a0),(b0,b0),(c0,c0),(1,2),(2,1)}; 72 | } : Z2 73 | instance Pi_FI3 = pi F I3 74 | 75 | instance I4 = { 76 | nodes 77 | G->{a0,b0,c0,d0,1,2}; 78 | attributes 79 | att1->{(1,1),(2,2),(a0,a0),(b0,b0),(c0,c0),(d0,d0)}; 80 | arrows 81 | r->{(a0,a0),(b0,b0),(c0,c0),(d0,d0),(1,2),(2,1)}; 82 | } : Z2 83 | instance Pi_FI4 = pi F I4 84 | -------------------------------------------------------------------------------- /resources/examples/fql/Written Macro.fql: -------------------------------------------------------------------------------- 1 | //Illustrates ASWRITTEN macro for automatically adding attributes to schemas and instances. 2 | 3 | schema C = { 4 | nodes A; 5 | attributes ASWRITTEN; 6 | arrows f:A->A; 7 | equations A.f.f.f.f.f.f=A.f; 8 | } 9 | 10 | instance I = { 11 | nodes A->{a,b,c,d,e}; 12 | attributes ASWRITTEN; 13 | arrows f->{(a,b),(b,c),(c,d),(d,e),(e,a)}; 14 | } : C -------------------------------------------------------------------------------- /resources/examples/fqlpp/All Syntax.fqlpp: -------------------------------------------------------------------------------- 1 | //Syntax for the FQL fragment of FQL++ 2 | 3 | category c1 = void 4 | category c2 = unit 5 | category c3 = (c2 + c2) 6 | category c4 = (c2 * c2) 7 | category c5 = (unit ^ void) 8 | category c6 = Set 9 | category C = {objects; arrows; equations;} 10 | category CC = union C C 11 | 12 | functor f1 = id unit 13 | functor f2 = (f1 ; f1) 14 | functor f4 = iso1 c4 c5 15 | functor f6 = iso2 c4 c5 16 | functor f7 = (fst c3 c3 * snd c3 c3) 17 | functor f8 = (inl c3 c3 + inr c3 c3) 18 | functor f9 = curry eval c3 c3 19 | functor f10 = {objects; arrows;} : C -> C //mapping 20 | functor f20 = {objects; arrows;} : C -> Set //instance 21 | functor f13 = (f20 ^ f20) 22 | functor f14 = delta f10 23 | functor f15 = sigma f10 24 | functor f16 = pi f10 25 | functor f17 = apply f14 on object f20 26 | functor f18 = prop C 27 | functor t21 = void C Set //need Set here 28 | functor t22 = unit C Set //need Set here 29 | functor f3 = ff unit 30 | functor f5 = tt unit 31 | 32 | category c6x = dom f1 33 | category c7x = cod f2 34 | 35 | transform t0 = {objects;} : (f20:C->Set) -> (f20:C->Set) //must have dom and cod of functors 36 | transform t1 = id f20 37 | transform t2 = (t1 ; t1) 38 | transform t3x= (inl f20 f20 + inr f20 f20) 39 | transform t4x= (fst f20 f20 * snd f20 f20) 40 | transform t5 = curry eval f20 f20 41 | transform t5x = tt f20 42 | transform t5y = ff f20 43 | transform t6 = apply f14 on arrow t1 44 | transform t7 = true C 45 | transform t8 = false C 46 | transform t9 = and C 47 | transform t7y= or C 48 | transform t7x= not C 49 | transform t8z= implies C 50 | transform t8x= return sigma delta f10 51 | transform t9x= coreturn sigma delta f10 52 | transform t10= return delta pi f10 53 | transform t11= coreturn delta pi f10 54 | transform t12= iso1 f20 f20 55 | transform t13= iso2 f20 f20 56 | 57 | functor f19x = dom t1 58 | functor t20x = cod t1 59 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/Ben.fqlpp: -------------------------------------------------------------------------------- 1 | /* 2 | Consider the diagram shape A <-- O --> B in Cat, 3 | where O is the terminal category (x), A and B are free arrows 4 | A = (a0--->a1) and B = (b0-->b1), 5 | the map O-->A picks out the target, a1, and the map O-->B picks out the source, b0. 6 | The colimit category has a "new path" (a0-->x-->b1) that neither A nor B "knew about". 7 | */ 8 | 9 | category O = { 10 | objects 11 | x; 12 | arrows; 13 | equations; 14 | } 15 | 16 | category A = { 17 | objects 18 | a0, a1; 19 | arrows 20 | f : a0 -> a1; 21 | equations; 22 | } 23 | 24 | category B = { 25 | objects 26 | b0, b1; 27 | arrows 28 | g : b0 -> b1; 29 | equations; 30 | } 31 | 32 | functor F = { 33 | objects 34 | x -> a1; 35 | arrows; 36 | } : O -> A 37 | 38 | functor G = { 39 | objects 40 | x -> b0; 41 | arrows; 42 | } : O -> B 43 | 44 | category span = { 45 | objects 46 | o, a, b; 47 | arrows 48 | f : o -> a, g : o -> b; 49 | equations; 50 | } 51 | 52 | functor colimFunctor = { 53 | objects 54 | o -> O, a -> A, b -> B; 55 | arrows 56 | f -> F, g -> G; 57 | } : span -> Cat 58 | 59 | category colimCat = colim colimFunctor 60 | 61 | /* colimCat should be 62 | category { 63 | objects 64 | a1, b1, a0; 65 | arrows 66 | f : a0 -> a1, 67 | g : a1 -> b1; 68 | equations; 69 | } 70 | */ 71 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/Co-Products.fqlpp: -------------------------------------------------------------------------------- 1 | /* Functors S to Set ****************************/ 2 | 3 | category S = { 4 | objects a, b; 5 | arrows f : a -> b; 6 | equations; 7 | } 8 | 9 | functor I = { 10 | objects a -> {1,2}, b -> {3}; 11 | arrows f -> {(1,3),(2,3)}; 12 | } : S -> Set 13 | 14 | functor J = { 15 | objects a -> {a,b,c}, b -> {d,e}; 16 | arrows f -> {(a,d),(b,e),(c,e)}; 17 | } : S -> Set 18 | 19 | functor A = (I + J) 20 | 21 | transform K = inl I J 22 | 23 | transform L = inr I J 24 | 25 | transform M = (K + L) //is id 26 | 27 | functor N = void S Set 28 | 29 | transform O = ff J 30 | 31 | /* Functors S to Cat ****************************/ 32 | 33 | functor N2 = void S Cat 34 | 35 | transform O2 = ff N2 36 | 37 | category C = { 38 | objects 39 | T1, 40 | T2, 41 | string, 42 | int; 43 | arrows 44 | t1_ssn : T1 -> string, 45 | t1_first : T1 -> string, 46 | t1_last : T1 -> string, 47 | t2_first : T2 -> string, 48 | t2_last : T2 -> string, 49 | t2_salary : T2 -> int; 50 | equations; 51 | } 52 | 53 | category D = { 54 | objects 55 | T, 56 | string, 57 | int; 58 | arrows 59 | ssn : T -> string, 60 | first : T -> string, 61 | last : T -> string, 62 | salary : T -> int; 63 | equations; 64 | } 65 | 66 | functor F = { 67 | objects 68 | T1 -> T, 69 | T2 -> T, 70 | string -> string, 71 | int -> int; 72 | arrows 73 | t1_ssn -> T.ssn, 74 | t1_first -> T.first, 75 | t2_first -> T.first, 76 | t1_last -> T.last, 77 | t2_last -> T.last, 78 | t2_salary -> T.salary; 79 | } : C -> D 80 | 81 | category X = { 82 | objects 83 | c, d; 84 | arrows 85 | f : c -> d; 86 | equations; 87 | } 88 | 89 | functor Y = { 90 | objects 91 | c -> C, 92 | d -> D; 93 | arrows 94 | f -> F; 95 | } : X -> Cat 96 | 97 | functor Z = { 98 | objects 99 | c -> C, 100 | d -> C; 101 | arrows 102 | f -> id C; 103 | } : X -> Cat 104 | 105 | functor YZ = (Y + Z) 106 | 107 | transform YZ_1 = inl Y Z 108 | 109 | transform YZ_2 = inr Y Z 110 | 111 | transform YZ_id = (YZ_1 + YZ_2) 112 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/Employees.fqlpp: -------------------------------------------------------------------------------- 1 | category S = { 2 | objects 3 | Employee, Department; 4 | arrows 5 | manager : Employee -> Employee, 6 | worksIn : Employee -> Department, 7 | secretary : Department -> Employee; 8 | equations 9 | Employee.manager.worksIn = Employee.worksIn, 10 | Department.secretary.worksIn = Department, 11 | Employee.manager.manager = Employee.manager; 12 | } 13 | 14 | functor I = { 15 | objects 16 | Employee -> { 101, 102, 103 }, 17 | Department -> { q10, x02 }; 18 | arrows 19 | manager -> { (101, 103), (102, 102), (103, 103) } : {101,102,103} -> {101,102,103}, 20 | worksIn -> { (101, q10), (102, x02), (103, q10) } : {101,102,103} -> {q10,x02}, 21 | secretary -> { (q10, 101), (x02, 102) } : {q10,x02} -> {101,102} ; 22 | } : S -> Set 23 | 24 | set emps = { 101, 102, 103 } 25 | set depts = { q10, x02 } 26 | function foo = { (101,(101,q10)),(102,(102,x02)),(103,(103,q10)) } : emps -> (emps * depts) 27 | 28 | functor J = { 29 | objects 30 | Employee -> emps, 31 | Department -> depts; 32 | arrows 33 | manager -> id emps, 34 | worksIn -> (foo ; snd emps depts), 35 | secretary -> { (q10, 101), (x02, 102) } : depts -> emps ; 36 | } : S -> Set 37 | 38 | functor K = pivot J 39 | category grothJ = dom K 40 | functor L = unpivot K 41 | transform JK = iso1 J L 42 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/Exponentials.fqlpp: -------------------------------------------------------------------------------- 1 | //Exponentials in C-Set 2 | 3 | category C = { 4 | objects a, b; 5 | arrows f : a -> b; 6 | equations; 7 | } 8 | 9 | functor I = { 10 | objects a -> {1,2,3}, b -> {4,5}; 11 | arrows f -> {(1,4),(2,5),(3,5)}; 12 | } : C -> Set 13 | 14 | functor J = { 15 | objects a -> {1,2}, b -> {4}; 16 | arrows f -> {(1,4),(2,4)}; 17 | } : C -> Set 18 | 19 | //eta says these two are equal 20 | functor K = (J^I) 21 | transform eta_lhs = curry eval J I 22 | transform eta_rhs = id K 23 | 24 | //beta says that for any G, G = tr 25 | functor IJ = (I * J) 26 | functor one= unit C Set 27 | transform G = tt IJ 28 | transform tr = (((fst I J ; curry G) * snd I J) ; eval unit C Set J) 29 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/Monads.fqlpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////// 2 | //functors Set -> Set 3 | 4 | functor Maybe = { 5 | objects 6 | X -> (unit + X); 7 | arrows 8 | f : A -> B -> (inl unit B + (f ; inr unit B)); 9 | } : Set -> Set 10 | 11 | set Maybe3 = apply Maybe on object 3 12 | set Maybe4 = apply Maybe on object 4 13 | 14 | function MaybeF = apply Maybe on arrow {(0,1),(1,2),(2,0),(3,0)} : 4 -> 3 15 | 16 | functor Double = { 17 | objects X->(X*X); 18 | arrows f:A->B -> ((fst A A; f)*(snd A A; f)); 19 | } : Set -> Set 20 | 21 | set dbl=apply Double on object {1,2,3} 22 | 23 | function f = apply Double on arrow id {1,2,3} 24 | 25 | transform ret = { 26 | objects 27 | X -> inr unit X; 28 | } : (id Set : Set -> Set) -> (Maybe : Set -> Set) 29 | 30 | transform join = { 31 | objects 32 | X -> (inl unit X + id (unit + X)); 33 | } : ((Maybe ; Maybe) : Set -> Set) -> (Maybe : Set -> Set) 34 | 35 | function ret1 = apply ret {1,2,3} 36 | set set1 = apply Maybe on object {1,2,3} 37 | set set2 = apply Maybe on object set1 38 | function joined = apply join set2 39 | 40 | category K = kleisli Maybe ret join 41 | 42 | //////// 43 | 44 | category C = { 45 | objects a,b,c; 46 | arrows f:a->b,g:b->c; 47 | equations; 48 | } 49 | 50 | functor M = { 51 | objects a->a, b->c,c->c; 52 | arrows f->a.f.g,g->c; 53 | } : C -> C 54 | 55 | transform eta = { 56 | objects a->a, b->b.g, c->c; 57 | } : (id C:C->C) -> (M: C->C) 58 | 59 | transform mu = { 60 | objects a->a, b->c, c->c; 61 | } : ((M;M):C->C) -> (M: C->C) 62 | 63 | category M_kleisli = kleisli M eta mu 64 | 65 | /////////// 66 | 67 | category D = { 68 | objects a,b,c; 69 | arrows f:a->b,g:b->c; 70 | equations; 71 | } 72 | 73 | functor T = { 74 | objects a->a, b->a,c->c; 75 | arrows f->a,g->a.f.g; 76 | } : D -> D 77 | 78 | transform epsilon = { 79 | objects a->a, b->a.f, c->c; 80 | } : (T: D->D) -> (id D:D->D) 81 | 82 | transform Delta = { 83 | objects a->a, b->a, c->c; 84 | } : (T:D->D) -> ((T;T): D->D) 85 | 86 | category CK = cokleisli T epsilon Delta 87 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/Pi.fqlpp: -------------------------------------------------------------------------------- 1 | category C = { 2 | objects 3 | c1, 4 | c2, 5 | string; 6 | arrows 7 | att1 : c1 -> string, 8 | att2 : c1 -> string, 9 | att3 : c2 -> string; 10 | equations; 11 | } 12 | 13 | functor I = { 14 | objects 15 | c1 -> { 1,2 }, 16 | c2 -> { 1,2,3 }, 17 | string->{ Ryan, Wisnesky, David, Spivak, Harvard, MIT, Leslie }; 18 | arrows 19 | att1 -> { (1,David), (2,Ryan) }, 20 | att2 -> { (1,Spivak), (2,Wisnesky) }, 21 | att3 -> { (1,MIT), (2,Harvard),(3,Leslie) }; 22 | } : C -> Set 23 | 24 | functor I0 = { 25 | objects 26 | c1 -> { x1 }, 27 | c2 -> { x1,x2 }, 28 | string->{ Davidx, Spivakx, MITx, Harvardx }; 29 | arrows 30 | att1 -> { (x1,Davidx) }, 31 | att2 -> { (x1,Spivakx) }, 32 | att3 -> { (x1,MITx), (x2,Harvardx) }; 33 | } : C -> Set 34 | 35 | transform t = { 36 | objects c1 -> {(x1,1)}, c2 -> {(x1,1),(x2,2)}, 37 | string -> {(Davidx,David),(Spivakx, Spivak),(MITx,MIT),(Harvardx,Harvard)} ; 38 | } : (I0:C->Set) -> (I:C->Set) 39 | 40 | category D = { 41 | objects 42 | d, 43 | string; 44 | arrows 45 | a1 : d -> string, 46 | a2 : d -> string, 47 | a3 : d -> string; 48 | equations; 49 | } 50 | 51 | functor F = { 52 | objects 53 | c1 -> d, 54 | c2 -> d, 55 | string -> string; 56 | arrows 57 | att1 -> d.a1, 58 | att2 -> d.a2, 59 | att3 -> d.a3; 60 | } : C -> D 61 | 62 | functor J = apply pi F on object I 63 | transform tx = apply pi F on arrow t 64 | 65 | functor XXX = { 66 | objects 67 | d -> {a,b,c}, 68 | string -> {foo,bar,baz}; 69 | arrows 70 | a1 -> {(a,foo),(b,foo),(c,foo)}, 71 | a2 ->{(a,bar),(b,bar),(c,bar)}, 72 | a3 ->{(a,baz),(b,baz),(c,baz)}; 73 | } : D -> Set 74 | 75 | transform coret = apply coreturn delta pi F on I 76 | transform ret = apply return delta pi F on XXX 77 | -------------------------------------------------------------------------------- /resources/examples/fqlpp/SELECT CTDB.fqlpp: -------------------------------------------------------------------------------- 1 | //The query from http://categoricaldata.net/fql/introSlides.pdf#page=45 2 | //It's best to go to options and choose "Pi ID creation strategy" to be "Summary as ID". 3 | 4 | category C = { 5 | objects 6 | RL3, //numbers less than 3. 7 | R, //numbers 8 | Book, 9 | Isbn_num, 10 | String; 11 | arrows 12 | i:RL3->R, 13 | price:Book->R, 14 | title:Book->String, 15 | isbn:Book->Isbn_num; 16 | equations; 17 | } 18 | 19 | functor I = { 20 | objects 21 | RL3->{1,2}, 22 | R->{1,2,3,4,5}, 23 | Book->{1,2,3}, 24 | Isbn_num->{1,2,3,249,258,4597}, 25 | String->{"a","b","GoneWind","Catch22","CatTheory"}; 26 | arrows 27 | title->{(1,"GoneWind"),(2,"Catch22"), (3,"CatTheory")}, 28 | isbn->{(1,258),(2,4597),(3,249)}, //Note the last digit of the ISBN is the number of letters in the title. 29 | i->{(1,1),(2,2)}, 30 | price->{(1,4),(2,3),(3,1)}; 31 | } : C->Set 32 | 33 | //Note that there is exactly one book whose price is less than 3. 34 | 35 | category D = { 36 | objects 37 | RL3, 38 | R, 39 | W, 40 | Book, 41 | Isbn_num, 42 | String; 43 | arrows 44 | title:Book->String, 45 | isbn:Book->Isbn_num, 46 | f:W->RL3, 47 | g:W->Book, 48 | i:RL3->R, 49 | price:Book->R; 50 | equations 51 | W.f.i=W.g.price; 52 | } 53 | 54 | functor F = { 55 | objects 56 | RL3->RL3, 57 | R->R, 58 | Book->Book, 59 | Isbn_num->Isbn_num, 60 | String->String; 61 | arrows 62 | i->RL3.i, 63 | price->Book.price, 64 | title->Book.title, 65 | isbn->Book.isbn; 66 | } : C -> D 67 | 68 | 69 | functor pi_F_I = apply pi F on object I 70 | 71 | category E = { 72 | objects W, String, Isbn_num; 73 | arrows title:W->String, isbn:W->Isbn_num; 74 | equations; 75 | } 76 | 77 | functor G = { 78 | objects W->W, String->String, Isbn_num->Isbn_num; 79 | arrows title->W.g.title, isbn->W.g.isbn; 80 | } : E -> D 81 | 82 | functor Select = apply delta G on object pi_F_I 83 | -------------------------------------------------------------------------------- /resources/examples/opl/Aggregation.opl: -------------------------------------------------------------------------------- 1 | preamble = pragma { 2 | options 3 | "opl_secret_agg" = "true"; 4 | } 5 | 6 | Ty = theory { 7 | sorts 8 | Double; 9 | symbols 10 | plus : Double,Double -> Double, 11 | zero, ten, one, fifty, two : Double; 12 | equations; 13 | } 14 | 15 | M = javascript { 16 | symbols 17 | "zero" -> "return 0", 18 | "ten" -> "return 10", 19 | "fifty" -> "return 50", 20 | "two" -> "return 2", 21 | "one" -> "return 1", 22 | "plus" -> "return (input[0] + input[1])"; 23 | } : Ty 24 | 25 | S = SCHEMA { 26 | entities 27 | Emp, Dept; 28 | edges; 29 | attributes 30 | salary : Emp -> Double, 31 | worksIn : Emp -> Dept; 32 | pathEqualities; 33 | obsEqualities; 34 | } : Ty 35 | 36 | T = SCHEMA { 37 | entities 38 | Dept; 39 | edges; 40 | attributes 41 | totalCost : Dept -> Double; 42 | pathEqualities; 43 | obsEqualities; 44 | } : Ty 45 | 46 | I0 = presentation { 47 | generators 48 | p1, p2, p3, p4 : Emp, 49 | d1, d2: Dept; 50 | equations 51 | p1.salary = ten, p2.salary = one, p3.salary = fifty, p4.salary = two, 52 | p1.worksIn = d1, p2.worksIn = d1, p3.worksIn = d2, p4.worksIn = d2; 53 | } : S 54 | I = instance S I0 M 55 | 56 | Q1 = query { 57 | Q = 58 | {for d:Dept; 59 | where ; 60 | return totalCost = agg zero plus { 61 | for p:Emp; 62 | where p.worksIn = d; 63 | return p.salary 64 | }; 65 | keys; } : Dept 66 | } : S -> T 67 | 68 | J = apply Q1 I 69 | -------------------------------------------------------------------------------- /resources/examples/opl/Disjunctive.opl: -------------------------------------------------------------------------------- 1 | 2 | color : type 3 | red green blue : color 4 | 5 | S = schema { 6 | nodes 7 | E; 8 | edges 9 | att : E -> color; 10 | equations; 11 | } 12 | 13 | T = schema { 14 | nodes 15 | R, RB, RG; 16 | edges 17 | r_rb : R -> RB, 18 | r_rg : R -> RG, 19 | r_att : R -> color; 20 | equations 21 | r_att = "!_R".red; //if changed to say blue, error occurs in Q 22 | } 23 | 24 | Q = polynomial { 25 | R_Q = {for e:E; 26 | where e.att = red ; 27 | attributes r_att=e.att; 28 | edges r_rb = {e1=e} : RB_Q_1, 29 | r_rg = {e3=e} : RG_Q_1;} : R, 30 | 31 | RB_Q_1 = {for e1:E; 32 | where e1.att = red ; 33 | attributes; edges;} : RB, 34 | 35 | RB_Q_2 = {for e2:E; 36 | where e2.att = blue ; 37 | attributes; edges;} : RB, 38 | 39 | RG_Q_1 = {for e3:E; 40 | where e3.att = red ; 41 | attributes; edges;} : RG, 42 | 43 | RG_Q_2 = {for e4:E; 44 | where e4.att = green ; 45 | attributes; edges;} : RG 46 | 47 | } : S -> T 48 | 49 | I = instance { 50 | variables 51 | r1 r2 g1 g2 b1 b2 : E; 52 | equations 53 | r1.att = red, 54 | r2.att = red, 55 | g1.att = green, 56 | g2.att = green, 57 | b1.att = blue, 58 | b2.att = blue; 59 | } : S 60 | 61 | J = apply Q I -------------------------------------------------------------------------------- /resources/examples/opl/Employees.opl: -------------------------------------------------------------------------------- 1 | S = theory { 2 | sorts 3 | Employee, Department, dom; 4 | symbols 5 | first,last: Employee -> dom, 6 | name : Department -> dom, 7 | manager : Employee -> Employee, 8 | worksIn : Employee -> Department, 9 | secretary : Department -> Employee; 10 | equations 11 | forall x. worksIn(manager(x)) = worksIn(x), 12 | forall x. worksIn(secretary(x)) = x, 13 | forall x. manager(manager(x)) = manager(x); 14 | } 15 | 16 | I = presentation { 17 | generators a, b, c : Employee, 18 | m, s : Department, 19 | Al, Akin, Bob, Bo, Carl, Cork, Math, Cs : dom; 20 | equations first(a) = Al, last(a) = Akin, 21 | first(b) = Bob, last(b) = Bo, 22 | first(c) = Carl, last(c) = Cork, 23 | name(m) = Math, name(s) = Cs, 24 | worksIn(a) = m, worksIn(b) = m, worksIn(c) = s, 25 | secretary(s) = c, secretary(m) = b; 26 | } : S 27 | 28 | J = saturate I 29 | K = unsaturate J 30 | L = saturate K 31 | 32 | C = schema { 33 | entities Employee, Department; 34 | } : S 35 | 36 | Q = query { 37 | qE = {for e:Employee; 38 | where; 39 | return first=first(e), last=last(e); 40 | keys manager = {e=manager(e)} : qE, worksIn = {d=worksIn(e)} : qD;} : Employee, 41 | qD = {for d:Department; 42 | where; 43 | return name=name(d); 44 | keys secretary = {e=secretary(d)} : qE;} : Department 45 | } : C -> C 46 | 47 | Q0 = id C 48 | -------------------------------------------------------------------------------- /resources/examples/opl/Flower.opl: -------------------------------------------------------------------------------- 1 | Mod4 = theory { 2 | sorts 3 | Nat; 4 | symbols 5 | O : Nat, 6 | S : Nat -> Nat, 7 | plus : Nat , Nat -> Nat; 8 | equations 9 | forall x. S(S(S(S(x)))) = x, 10 | forall x, y. plus(S(x),y) = S(plus(x,y)); 11 | } 12 | 13 | Four = model { 14 | sorts 15 | Nat -> {0,1,2,3}; 16 | symbols 17 | O -> { ((),0) }, 18 | S -> { ((0),1), ((1),2), ((2),3), ((3),0) }, 19 | plus -> { ((0,0), 0), ((0,1),1), ((0,2),2), ((0,3),3), 20 | ((1,0), 1), ((1,1),2), ((1,2),3), ((1,3),0), 21 | ((2,0), 2), ((2,1),3), ((2,2),0), ((2,3),1), 22 | ((3,0), 3), ((3,1),0), ((3,2),1), ((3,3),2) }; 23 | } : Mod4 24 | 25 | Two = model { 26 | sorts 27 | Nat -> {x0,x1}; 28 | symbols 29 | O -> { ((),x0) }, 30 | S -> { ((x0),x1), ((x1),x0) }, 31 | plus -> { ((x0,x0), x0), ((x0,x1),x1), 32 | ((x1,x0), x1), ((x1,x1),x0) }; 33 | } : Mod4 34 | 35 | h = transform { 36 | sorts 37 | Nat -> {(0,x0),(1,x1),(2,x0),(3,x1)}; 38 | } : Four -> Two 39 | 40 | Q = flower { 41 | select S(n1) as col1, S(n2) as col2; 42 | from Nat as n1, Nat as n2; 43 | where plus(n1,n2) = O(); 44 | } Four 45 | 46 | hQ = flower { 47 | select S(n1) as col1, S(n2) as col2; 48 | from Nat as n1, Nat as n2; 49 | where plus(n1,n2) = O(); 50 | } h 51 | -------------------------------------------------------------------------------- /resources/examples/opl/Horn.opl: -------------------------------------------------------------------------------- 1 | S1 = theory { 2 | sorts X, dom; 3 | symbols r1 : X -> dom, r2 : X -> dom; 4 | equations; 5 | } 6 | I1 = presentation { 7 | generators x1, x2 : X; 8 | equations r1(x1) = r1(x2); 9 | } : S1 10 | J1 = saturate I1 11 | 12 | ////////// 13 | 14 | S2 = theory { 15 | sorts X, dom; 16 | symbols r1 : X -> dom, r2 : X -> dom; 17 | equations; 18 | implications 19 | forall x1, x2. r1(x1) = r1(x2) -> r2(x1) = r2(x2); 20 | } 21 | I2 = presentation { 22 | generators x1, x2 : X; 23 | equations r1(x1) = r1(x2); 24 | } : S2 25 | J2 = saturate I2 26 | -------------------------------------------------------------------------------- /resources/examples/opl/JS.opl: -------------------------------------------------------------------------------- 1 | T = theory { 2 | sorts 3 | Int, String; 4 | symbols 5 | zero : Int, 6 | succ, pred : Int -> Int, 7 | length : String -> Int, 8 | reverse : String -> String, 9 | append : String, String -> String, 10 | print : Int -> String; 11 | equations 12 | forall x. pred(succ(x)) = x, 13 | forall x. succ(pred(x)) = x, 14 | forall x. length(x) = length(reverse(x)); 15 | } 16 | 17 | M = javascript { 18 | symbols 19 | _preamble -> "javax.swing.JOptionPane.showMessageDialog(null, \"hello\")", 20 | zero -> "return 0", 21 | succ -> "return (input[0] + 1)", 22 | pred -> "return (input[0] - 1)", 23 | length -> "return input[0].length", 24 | reverse -> "return input[0].split('').reverse().join('')", 25 | append -> "return input[0].concat(input[1])", 26 | print -> "return input[0].toString()"; 27 | } : T 28 | 29 | z = eval M zero() 30 | sz = eval M succ(zero()) 31 | ssz = eval M succ(succ(zero())) 32 | pssz = eval M pred(succ(succ(zero()))) 33 | 34 | test1 = eval M append(print(succ(zero())), print(zero())) 35 | rev_test1 = eval M reverse(append(print(succ(zero())), print(zero()))) 36 | len_test1 = eval M length(reverse(append(print(succ(zero())), print(zero())))) 37 | -------------------------------------------------------------------------------- /resources/examples/opl/Java Double.opl: -------------------------------------------------------------------------------- 1 | T = theory { 2 | sorts 3 | Double, Boolean; 4 | symbols 5 | tru : Boolean, 6 | plus : Double,Double -> Double, 7 | gt : Double,Double -> Boolean, 8 | pi, e, zero, one : Double; 9 | equations; 10 | } 11 | 12 | M = javascript { 13 | symbols 14 | "tru" -> "return true", 15 | "pi" -> "return 3.14", 16 | "e" -> "return 2.71", 17 | "zero" -> "return 0", 18 | "one" -> "return 1", 19 | "plus" -> "return (input[0] + input[1])", 20 | "gt" -> "return (input[0] > input[1])"; 21 | } : T 22 | 23 | S = SCHEMA { 24 | entities 25 | Person; 26 | edges; 27 | attributes 28 | age : Person -> Double; 29 | pathEqualities; 30 | obsEqualities; 31 | } : T 32 | 33 | I0 = presentation { 34 | generators 35 | p1, p2, p3, p4 : Person; 36 | equations 37 | p1.age = pi, p2.age = e, p3.age = zero, p4.age = one; 38 | } : S 39 | I = instance S I0 M 40 | 41 | 42 | Q1 = query { 43 | PersonQ = 44 | {for p:Person; 45 | where ; 46 | return age = plus(p.age, one); 47 | keys; } : Person 48 | } : S -> S 49 | 50 | J = apply Q1 I 51 | 52 | 53 | Q2 = query { 54 | PersonQ = 55 | {for p:Person; 56 | where gt(age(p), pi) = tru; 57 | return age = age(p); 58 | keys; } : Person 59 | } : S -> S 60 | 61 | K = apply Q2 J 62 | -------------------------------------------------------------------------------- /resources/examples/opl/KB.opl: -------------------------------------------------------------------------------- 1 | Group = theory { 2 | sorts 3 | S; 4 | symbols 5 | e : S, 6 | I : S -> S, 7 | o : S,S -> S; 8 | equations 9 | forall x. (e o x) = x, 10 | forall x. (I(x) o x) = e, 11 | forall x, y, z. ((x o y) o z) = (x o (y o z)); 12 | } 13 | AGroupPresentation = presentation { 14 | generators g : S; 15 | equations o(g, o(g, g)) = g; 16 | } : Group 17 | AGroup = saturate AGroupPresentation 18 | AGroupPresentationAgain = unsaturate AGroup 19 | AGroupAgain = saturate AGroupPresentationAgain 20 | 21 | TrivialGroup = model { 22 | sorts S -> {x}; 23 | symbols e -> { ((),x) }, 24 | I -> { ((x),x) }, 25 | o -> { ((x,x),x) }; 26 | } : Group 27 | 28 | LR = theory { 29 | sorts 30 | S; 31 | symbols 32 | e : S, 33 | I : S -> S, 34 | o : S,S -> S; 35 | equations 36 | forall x. o(e,x) = x, 37 | forall x. o(x,I(x)) = e, 38 | forall x, y, z. o(o(x,y),z)=o(x,o(y,z)); 39 | } 40 | 41 | RL = theory { 42 | sorts 43 | S; 44 | symbols 45 | e : S, 46 | I : S -> S, 47 | o : S,S -> S; 48 | equations 49 | forall x. o(x,e) = x, 50 | forall x. o(I(x),x) = e, 51 | forall x, y, z. o(o(x,y),z)=o(x,o(y,z)); 52 | } 53 | 54 | OddEvenMod4 = theory { 55 | sorts 56 | Odd, Even; 57 | symbols 58 | zero@0 : Even, 59 | one@1 : Odd, 60 | incO@2 : Odd -> Even, 61 | incE@3 : Even -> Odd; 62 | equations 63 | forall x. incE(incO(incE(incO(x)))) = x, 64 | forall x. incO(incE(incO(incE(x)))) = x; 65 | } 66 | 67 | Arith = theory { 68 | sorts 69 | N; 70 | symbols 71 | zero@1 : N, 72 | succ@2 : N -> N, 73 | plus@3 : N,N -> N, 74 | times@4 : N,N -> N; 75 | equations 76 | forall x. plus(zero, x) = x, 77 | forall x, y. plus(succ(x),y) = succ(plus(x,y)), 78 | forall x, y. times(succ(x),y) = plus(x,times(x,y)); 79 | } 80 | -------------------------------------------------------------------------------- /resources/examples/opl/Matrix.opl: -------------------------------------------------------------------------------- 1 | //algebraic theory for boxes of wiring diagram 2.27 2 | T = theory { 3 | sorts 4 | A, B, C; 5 | symbols 6 | X1 : A -> B, 7 | X2 : B -> C, 8 | a : A; 9 | equations; 10 | } 11 | 12 | //a functor T -> "Matrix"? . I got this from section 2.4 13 | Impl = javascript { 14 | symbols 15 | _preamble -> "java.lang.Class.forName('catdata.ide.Util'); 16 | var Util = Java.type('catdata.ide.Util');", 17 | _compose -> "return Util.multiply_many(input[0](), input[1]);", //comose is matrix multiply 18 | X1 -> "return Util.mat_conv2([[1,2],[3,0]])", 19 | X2 -> "return Util.mat_conv2([[2,2,0],[3,1,1]])", 20 | a -> "return Util.mat_conv2([[1,0],[0,1]])"; 21 | } : T 22 | 23 | //prints [[8, 4, 2], [6, 6, 0]] 24 | J = eval Impl X2(X1(a())) 25 | -------------------------------------------------------------------------------- /resources/examples/opl/Mod4.opl: -------------------------------------------------------------------------------- 1 | Mod4 = theory { 2 | sorts 3 | Nat; 4 | symbols 5 | zero : Nat, 6 | succ : Nat -> Nat; 7 | equations 8 | forall x. succ(succ(succ(succ(x)))) = x; 9 | } 10 | 11 | Four = model { 12 | sorts 13 | Nat -> {0,1,2,3}; 14 | symbols 15 | zero -> { ((),0) }, 16 | succ -> { ((0),1), ((1),2), ((2),3), ((3),0) }; 17 | } : Mod4 18 | 19 | Two = model { 20 | sorts 21 | Nat -> {t, f}; 22 | symbols 23 | zero -> { ((),t) }, 24 | succ -> { ((t),f), ((f),t) }; 25 | } : Mod4 26 | 27 | h = transform { 28 | sorts 29 | Nat -> {(0,t),(1,f),(2,t),(3,f)}; 30 | } : Four -> Two 31 | 32 | zero_nat = eval Four zero() 33 | one_nat = eval Four succ(zero()) 34 | two_nat = eval Four succ(succ(zero())) 35 | three_nat = eval Four succ(succ(succ(zero()))) 36 | 37 | zero_bool = eval Two zero() 38 | one_bool = eval Two succ(zero()) 39 | two_bool = eval Two succ(succ(zero())) 40 | three_bool = eval Two succ(succ(succ(zero()))) 41 | -------------------------------------------------------------------------------- /resources/examples/opl/Nested 2.opl: -------------------------------------------------------------------------------- 1 | Ax = theory { 2 | sorts A1, A2; 3 | symbols; 4 | equations; 5 | } 6 | 7 | Bx = theory { 8 | sorts B; 9 | symbols b : B; 10 | equations; 11 | } 12 | B = saturate Bx 13 | 14 | F = mapping { 15 | sorts A1 -> B, A2 -> B; 16 | symbols; 17 | } : Ax -> Bx 18 | 19 | S0 = theory { 20 | sorts 21 | M, T1, T2; 22 | symbols 23 | modelOf1@4 : M -> T1, 24 | modelOf2@3 : M -> T2, 25 | Q@2 : T2 -> T1, 26 | t2@1 : T2; 27 | equations 28 | forall m. modelOf1(m) = Q(modelOf2(m)); 29 | } 30 | 31 | S = schema { 32 | entities M; 33 | } : S0 34 | 35 | T = types S 36 | 37 | I0 = presentation { 38 | generators m : M; 39 | equations modelOf2(m)=t2; 40 | } : S0 41 | 42 | M = javascript { 43 | symbols 44 | Q -> "return F.delta(input[0])", 45 | t2 -> "return B"; 46 | } : T 47 | 48 | I = instance S I0 M 49 | -------------------------------------------------------------------------------- /resources/examples/opl/Nested.opl: -------------------------------------------------------------------------------- 1 | Ax = theory { 2 | sorts A1, A2; 3 | symbols a : A1 -> A2, a1 : A1, a2 : A2; 4 | equations; 5 | } 6 | A = saturate Ax 7 | 8 | Bx = theory { 9 | sorts B; 10 | symbols b : B -> B, b1 : B; 11 | equations forall x. b(x) = x; 12 | } 13 | B = saturate Bx 14 | 15 | S0 = theory { 16 | sorts 17 | M, Model, Int; 18 | symbols 19 | modelOf : M -> Model, 20 | size1 : M -> Int, 21 | size2 : Model -> Int, 22 | m1, m2 : Model; 23 | equations 24 | forall m. size1(m) = size2(modelOf(m)); 25 | } 26 | 27 | S = schema { 28 | entities M; 29 | } : S0 30 | 31 | T = types S 32 | 33 | I0 = presentation { 34 | generators mA, mB : M; 35 | equations modelOf(mA)=m1, modelOf(mB)=m2; 36 | } : S0 37 | 38 | M = javascript { 39 | symbols 40 | size2 -> "return input[0].size()", 41 | m1 -> "return A", 42 | m2 -> "return B"; 43 | } : T 44 | 45 | I = instance S I0 M 46 | -------------------------------------------------------------------------------- /resources/examples/opl/Pivot.opl: -------------------------------------------------------------------------------- 1 | Type = theory { 2 | sorts String, Nat; 3 | symbols 4 | Adam, Bill : String, 5 | Four : Nat; 6 | equations; 7 | } 8 | 9 | S = SCHEMA { 10 | entities 11 | Person, Home; 12 | edges 13 | livesIn : Person -> Home; 14 | attributes 15 | name : Person -> String, 16 | size : Home -> Nat; 17 | pathEqualities; 18 | obsEqualities; 19 | } : Type 20 | 21 | I = INSTANCE { 22 | generators 23 | p1, p2: Person, 24 | h: Home; 25 | equations 26 | p1.livesIn = h, p1.name = Adam, p2.name = Bill, 27 | p2.livesIn = h, h.size = Four; 28 | } : S 29 | 30 | J = pivot I 31 | -------------------------------------------------------------------------------- /resources/examples/opl/Std Lib.opl: -------------------------------------------------------------------------------- 1 | preamble = pragma { 2 | options 3 | "opl_prover_force_prec" = "true"; 4 | } 5 | 6 | //bools, computationally (note: not boolean algebra) 7 | Bool = theory { 8 | sorts 9 | Bool; 10 | symbols 11 | true, false : Bool, 12 | aand, or, implies : Bool, Bool -> Bool, 13 | not : Bool -> Bool; 14 | equations 15 | aand(true, true) = true, 16 | aand(true, false) = false, 17 | aand(false, true) = false, 18 | aand(false, false) = false, 19 | 20 | or(true, true) = true, 21 | or(true, false) = true, 22 | or(false, true) = true, 23 | or(false, false) = false, 24 | 25 | implies(true, true) = true, 26 | implies(true, false) = false, 27 | implies(false, true) = true, 28 | implies(false, false) = true, 29 | 30 | not(true) = false, 31 | not(false) = true; 32 | } 33 | 34 | //nats, computationally (note: not commutative ring) 35 | Nat = theory { 36 | sorts 37 | Nat; 38 | symbols 39 | plus : Nat, Nat -> Nat, 40 | zero : Nat, 41 | succ : Nat -> Nat; 42 | equations 43 | forall x. plus(zero, x) = x, 44 | forall x, y. plus(succ(x), y) = succ(plus(x,y)); 45 | } 46 | 47 | //strings, computationally (note: not free monoid) 48 | String = theory { 49 | sorts 50 | Char, String; 51 | symbols 52 | a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z : Char, 53 | "" : Char, String -> String, 54 | " " : String; 55 | equations; 56 | } 57 | 58 | StdLib = theory { 59 | imports 60 | Bool, Nat, String; 61 | sorts 62 | Void; 63 | symbols 64 | length : String -> Nat; 65 | equations 66 | length(" ") = zero, 67 | forall x, y. length(""(x, y)) = succ(length(y)); 68 | } 69 | -------------------------------------------------------------------------------- /resources/examples/opl/Team Pics.opl: -------------------------------------------------------------------------------- 1 | S0 = theory { 2 | sorts 3 | Person, Image, String; 4 | symbols 5 | cn, dn, rn, pn, jn : String, 6 | ci, di, ri, ji : Image, 7 | picture : Person -> Image, 8 | name : Person -> String; 9 | equations; 10 | } 11 | 12 | S = schema { 13 | entities Person; 14 | } : S0 15 | 16 | T = types S 17 | 18 | I0 = presentation { 19 | generators c, d, r, p, j : Person; 20 | equations picture(d) = di, picture(r) = ri, picture(j) = ji, picture(c) = ci, 21 | name(p) = pn, name(d) = dn, name(r) = rn, name(c) = cn, name(j) = jn; 22 | } : S0 23 | 24 | M = javascript { 25 | symbols 26 | _preamble -> "var image = Java.type('catdata.opl.OplImage');", 27 | ri -> "return new image('http://wisnesky.net/pic.jpg')", 28 | di -> "return new image('http://math.mit.edu/images/gallery/postdoc/spivak-david.jpg')", 29 | ci -> "return new image('http://math.mit.edu/images/gallery/postdoc/vasilakopoulou.png')", 30 | ji -> "return new image('http://www.joshuatan.com/wp-content/uploads/2014/11/cropped-IMG-0823.jpg')", 31 | rn -> "return 'Ryan'", 32 | dn -> "return 'David'", 33 | pn -> "return 'Patrick'", 34 | cn -> "return 'Christina'", 35 | jn -> "return 'Josh'" 36 | ; 37 | } : T 38 | 39 | I = instance S I0 M 40 | -------------------------------------------------------------------------------- /resources/examples/opl/Ty Test.opl: -------------------------------------------------------------------------------- 1 | S = theory { 2 | sorts 3 | Person, Nat; 4 | symbols 5 | parent@5 : Person -> Person, 6 | age@3 : Person -> Nat, 7 | zero@0 : Nat, 8 | infinity@1 : Nat, 9 | succ@2 : Nat -> Nat, 10 | plus@4 : Nat,Nat -> Nat; 11 | equations 12 | forall x. parent(x) = x, 13 | forall x. plus(zero,x) = x, 14 | forall x, y. plus(succ(x),y) = succ(plus(x,y)); 15 | } 16 | 17 | I = presentation { 18 | generators undef : Nat, 19 | bill, george, sue, william, alice : Person; 20 | equations bill = william, 21 | age(alice)=succ(zero), 22 | age(bill) = succ(infinity), 23 | // keep commented for testing age(george) = succ(infinity), 24 | age(sue)=succ(undef); 25 | } : S 26 | C = schema { 27 | entities Person; 28 | } : S 29 | 30 | Q = query { 31 | qP = {for pA:Person, pB:Person; 32 | where age(pA) = age(pB); 33 | return age=succ(age(pA)); 34 | keys parent={pA=pA, pB=pB} : qP;} : Person //use pA=pB and pB=pA to fail equality check 35 | } : C -> C 36 | 37 | I0 = instance C I none 38 | 39 | J0 = apply Q I0 40 | 41 | T = types C 42 | 43 | M = javascript { 44 | symbols zero -> "return 0", 45 | succ -> "return input[0]+1", 46 | plus -> "return input[0]+input[1]", 47 | infinity -> "return 0"; 48 | } : T 49 | 50 | I1 = instance C I M 51 | 52 | J1 = apply Q I1 53 | 54 | ////////////////////////////////////////////////////////////////////////////////////////////////// 55 | K = presentation { 56 | generators undef2:Nat, billy, george, sue, alice : Person; 57 | equations 58 | age(sue)=succ(succ(billy.age)), 59 | age(billy) = succ(infinity), 60 | age(alice)=succ(zero); 61 | } : S 62 | K0 = instance C K none 63 | 64 | h = transpres { 65 | sorts Nat -> {(undef,succ(billy.age))}, 66 | Person -> {(bill,billy), (george,george.parent), (sue,sue), (william,billy), (alice,alice)}; 67 | } : I0 -> K0 68 | 69 | oplquh0 = apply Q h 70 | -------------------------------------------------------------------------------- /resources/examples/opl/Unfailing.opl: -------------------------------------------------------------------------------- 1 | Entropic = theory { 2 | sorts 3 | S; 4 | symbols 5 | o : S,S -> S; 6 | equations 7 | forall x, y, z, w. o(o(x,y),o(z,w)) = o(o(x,z),o(y,w)), 8 | forall x, y. o(o(x,y),x) = x; 9 | } 10 | 11 | //will fail without semantic AC 12 | AC = theory { 13 | sorts 14 | S; 15 | symbols 16 | o : S,S -> S; 17 | equations 18 | forall x, y, z. o(o(x,y),z) = o(x,o(y,z)), 19 | forall x, y. o(x,y) = o(y,x), 20 | forall x, y, z. o(x,o(y,z)) = o(y,o(x,z)); 21 | } 22 | 23 | /*BooleanRing = theory { 24 | sorts 25 | S; 26 | symbols 27 | plus : S,S -> S, 28 | times : S,S -> S, 29 | zero : S, 30 | one : S; 31 | equations 32 | forall x, y, z. plus(plus(x,y),z) = plus(x,plus(y,z)), 33 | forall x, y, z. times(times(x,y),z) = times(x,times(y,z)), 34 | forall x, y. plus(x,y) = plus(y,x), 35 | forall x, y. times(x,y) = times(y,x), 36 | forall x, y, z. plus(x,plus(y,z)) = plus(y,plus(x,z)), 37 | forall x, y, z. times(x,times(y,z)) = times(y,times(x,z)), 38 | forall x, y, z. times(x,plus(y,z)) = plus(times(x,y),times(x,z)), 39 | forall x, y, z. times(plus(x,y),z) = plus(times(x,z),times(y,z)), 40 | forall x. plus(zero,x) = x, 41 | forall x. plus(x,zero) = x, 42 | forall x. times(one,x) = x, 43 | forall x. times(x,one) = x, 44 | forall x. times(zero,x) = zero, 45 | forall x. times(x,zero) = zero, 46 | forall x. plus(x,x) = zero, 47 | forall x. times(x,x) = x, 48 | forall x, y. plus(x,plus(x,y)) = y, 49 | forall x, y. times(x,times(x,y)) = times(x,y); 50 | }*/ 51 | -------------------------------------------------------------------------------- /resources/examples/opl/Union.opl: -------------------------------------------------------------------------------- 1 | Type = theory { 2 | sorts 3 | String; 4 | symbols 5 | ; 6 | equations; 7 | } 8 | 9 | A = SCHEMA { 10 | entities 11 | Person, Food, X; 12 | edges 13 | favorite1 : Person -> Food, 14 | favorite2 : Person -> Food; 15 | attributes 16 | foodname : Food -> String; 17 | pathEqualities 18 | forall x. x.favorite1 = x.favorite2; 19 | obsEqualities 20 | forall x. x.favorite1.foodname = x.favorite2.foodname; 21 | } : Type 22 | 23 | B = SCHEMA { 24 | entities 25 | Department, Employee, X; 26 | edges 27 | worksIn1 : Employee -> Department, 28 | worksIn2 : Employee -> Department; 29 | attributes 30 | deptname : Department -> String; 31 | pathEqualities 32 | forall x. x.worksIn1 = x.worksIn2; 33 | obsEqualities 34 | forall x. x.worksIn1.deptname = x.worksIn1.deptname; 35 | } : Type 36 | 37 | C = union Type {A B} 38 | 39 | 40 | I = INSTANCE { 41 | generators 42 | p1, p2 : Person, 43 | f1 : Food, 44 | x : X; 45 | equations 46 | p1.favorite1 = f1; 47 | } : A 48 | 49 | J = INSTANCE { 50 | generators 51 | d1, d2 : Person, 52 | e1 : Food, 53 | e : X; 54 | equations 55 | d1.favorite1 = e1; 56 | } : A 57 | 58 | K = union A {I J} 59 | -------------------------------------------------------------------------------- /resources/help.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CategoricalData/FQL/1ed8ab13de98e74ae3989c7475d1898efac133ae/resources/help.txt -------------------------------------------------------------------------------- /src/main/java/catdata/ClassUtil.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | public final class ClassUtil { 4 | /** 5 | * This method is used when an unchecked cast is appropriate. 6 | * This should be almost never. 7 | * 8 | * e.g. 9 | * final E e = ClassUtil.unchecked_cast(x); 10 | * ( ..., x -> ClassUtil.unchecked_cast(x), ... ) 11 | */ 12 | @SuppressWarnings("unchecked") 13 | public static T unchecked_cast(Object obj) { 14 | return (T)obj; 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/catdata/Environment.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | import java.util.Collections; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | //TODO aql replace with Ctx 9 | public class Environment { 10 | 11 | private final Map objs = Collections.synchronizedMap(new LinkedHashMap<>()); 12 | 13 | public Set keys() { 14 | return objs.keySet(); 15 | } 16 | 17 | 18 | 19 | public synchronized void put(String k, X v) { 20 | if (k == null || v == null) { 21 | throw new RuntimeException(); 22 | } 23 | if (objs.containsKey(k)) { 24 | throw new RuntimeException("Duplicate name: " + k); 25 | } 26 | objs.put(k, v); 27 | } 28 | 29 | public synchronized X get(String name) { 30 | X ret = objs.get(name); 31 | if (ret == null) { 32 | throw new RuntimeException("Unbound variable: " + name); 33 | } 34 | return ret; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/catdata/IntRef.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | public class IntRef { 4 | 5 | public int i; 6 | 7 | public IntRef(int i) { 8 | this.i = i; 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | return "?" + i; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /src/main/java/catdata/LineException.java: -------------------------------------------------------------------------------- 1 | 2 | package catdata; 3 | 4 | @SuppressWarnings("serial") 5 | public class LineException extends RuntimeException { 6 | 7 | public final String decl; 8 | public final String kind; 9 | private final String str ; 10 | 11 | public LineException(String string, String decl, String kind) { 12 | super(string == null ? "" : string); 13 | this.decl = decl == null ? "" : decl; 14 | this.kind = kind == null ? "" : kind; 15 | str = string == null ? "" : string; 16 | } 17 | 18 | @Override public boolean equals(Object o) { 19 | if (!(o instanceof LineException)) { 20 | return false; 21 | } 22 | // if (o == null) { 23 | // return false; 24 | //} //dead code, apparently 25 | LineException oe = (LineException) o; 26 | return (oe.decl.equals(decl) && oe.kind.equals(kind) && oe.str.equals(str)); 27 | } 28 | 29 | @Override public int hashCode() { 30 | return 0; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/catdata/Pair.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | 4 | 5 | /** 6 | * @author Ryan Wisnesky 7 | */ 8 | 9 | public class Pair /*Comparable>,*/ { 10 | 11 | public T1 first; //TODO aql make these final. Same for Triple 12 | public T2 second; 13 | 14 | public void setFirst(T1 x) { 15 | first = x; 16 | // hashCode2(); 17 | } 18 | public void setSecond(T2 x) { 19 | second = x; 20 | // hashCode2(); 21 | } 22 | 23 | public Pair(T1 value, T2 value2) { 24 | first = value; 25 | second = value2; 26 | //Util.assertNotNull(value, value2); 27 | // hashCode2(); 28 | } 29 | //private int hashCode = -1; 30 | 31 | @Override 32 | public String toString() { 33 | return "(" + first + ", " + second + ")"; 34 | 35 | } 36 | 37 | private int code = -1; 38 | @Override 39 | public synchronized int hashCode() { 40 | if (code != -1) { 41 | return code; 42 | } 43 | final int prime = 31; 44 | int result = 1; 45 | result = prime * result + ((first == null) ? 0 : first.hashCode()); 46 | result = prime * result + ((second == null) ? 0 : second.hashCode()); 47 | code = result; 48 | return result; 49 | } 50 | 51 | 52 | 53 | @Override 54 | public boolean equals(Object obj) { 55 | if (this == obj) 56 | return true; 57 | if (obj == null) 58 | return false; 59 | if (getClass() != obj.getClass()) 60 | return false; 61 | Pair other = (Pair) obj; 62 | return (first.equals(other.first) && second.equals(other.second)); 63 | } 64 | 65 | 66 | 67 | public Pair reverse() { 68 | return new Pair<>(second, first); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/catdata/ParseException.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | public class ParseException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 1L; 9 | public final int column; 10 | public final int line; 11 | 12 | public ParseException(int column, int line, Exception ex) { 13 | super(ex); 14 | this.column = column; 15 | this.line = line; 16 | } 17 | 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/catdata/Prog.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | import java.util.Collection; 4 | 5 | public interface Prog { 6 | 7 | Integer getLine(String s); 8 | 9 | Collection keySet(); 10 | 11 | @SuppressWarnings("unused") 12 | default String kind(String s) { 13 | return ""; 14 | } 15 | 16 | default long timeout() { 17 | return 30; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/catdata/Quad.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | /** 4 | * @author Ryan Wisnesky 5 | */ 6 | public class Quad { 7 | 8 | public final A first; 9 | public final B second; 10 | public final C third; 11 | public final D fourth; 12 | 13 | @Override 14 | public int hashCode() { 15 | int prime = 31; 16 | int result = 1; 17 | result = prime * result + ((first == null) ? 0 : first.hashCode()); 18 | result = prime * result + ((fourth == null) ? 0 : fourth.hashCode()); 19 | result = prime * result + ((second == null) ? 0 : second.hashCode()); 20 | result = prime * result + ((third == null) ? 0 : third.hashCode()); 21 | return result; 22 | } 23 | 24 | @Override 25 | public boolean equals(Object obj) { 26 | if (this == obj) 27 | return true; 28 | if (obj == null) 29 | return false; 30 | if (getClass() != obj.getClass()) 31 | return false; 32 | Quad other = (Quad) obj; 33 | if (first == null) { 34 | if (other.first != null) 35 | return false; 36 | } else if (!first.equals(other.first)) 37 | return false; 38 | if (fourth == null) { 39 | if (other.fourth != null) 40 | return false; 41 | } else if (!fourth.equals(other.fourth)) 42 | return false; 43 | if (second == null) { 44 | if (other.second != null) 45 | return false; 46 | } else if (!second.equals(other.second)) 47 | return false; 48 | if (third == null) { 49 | if (other.third != null) 50 | return false; 51 | } else if (!third.equals(other.third)) 52 | return false; 53 | return true; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "(" + first + ", " + second + ", " 59 | + third + ", " + fourth + ")"; 60 | } 61 | 62 | public Triple first3() { 63 | return new Triple<>(first, second, third); 64 | } 65 | 66 | public Quad(A first, B second, C third, D fourth) { 67 | this.first = first; 68 | this.second = second; 69 | this.third = third; 70 | this.fourth = fourth; 71 | } 72 | 73 | public Triple last3() { 74 | return new Triple<>(second, third, fourth); 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/catdata/Ref.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | public class Ref { 4 | 5 | public volatile X x; 6 | 7 | private volatile int var; //needed to make sure refs don't compare to equal just because their referents are equal. could have not used value eauality, but var aso useful for printing 8 | 9 | private static int count = 0; 10 | 11 | public Ref() { 12 | var = count++; 13 | } 14 | 15 | public synchronized boolean isSet() { 16 | return x != null; 17 | } 18 | 19 | public Ref(X x) { 20 | if (x == null) { 21 | throw new RuntimeException("Anomaly, please report"); 22 | } 23 | this.x = x; 24 | } 25 | 26 | public synchronized void set(X x) { 27 | if (x == null) { 28 | throw new RuntimeException("Anomaly, please report"); 29 | } 30 | if (this.x == null) { 31 | this.x = x; 32 | var = -1; 33 | } if (!this.x.equals(x)) { 34 | throw new RuntimeException("Reference already set to " + this.x + ", cannot set to " + x); 35 | } 36 | } 37 | 38 | public synchronized void set(Ref ref) { 39 | if (ref == null) { 40 | throw new RuntimeException("Anomaly, please report"); 41 | } 42 | if (ref.x != null) { 43 | set(ref.x); 44 | } else { 45 | count = ref.var; 46 | } 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return x == null ? "?" + var : x.toString(); 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | int prime = 31; 57 | int result = 1; 58 | result = prime * result + var; 59 | result = prime * result + ((x == null) ? 0 : x.hashCode()); 60 | return result; 61 | } 62 | 63 | @Override 64 | public boolean equals(Object obj) { 65 | if (this == obj) 66 | return true; 67 | if (obj == null) 68 | return false; 69 | if (getClass() != obj.getClass()) 70 | return false; 71 | Ref other = (Ref) obj; 72 | if (var != other.var) 73 | return false; 74 | if (x == null) { 75 | if (other.x != null) 76 | return false; 77 | } else if (!x.equals(other.x)) 78 | return false; 79 | return true; 80 | } 81 | 82 | 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/catdata/RuntimeInterruptedException.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | @SuppressWarnings("serial") 4 | public class RuntimeInterruptedException extends RuntimeException { 5 | 6 | private final Exception ex; 7 | 8 | public RuntimeInterruptedException(InterruptedException ie) { 9 | ex = ie; 10 | } 11 | 12 | public RuntimeInterruptedException(@SuppressWarnings("unused") ThreadDeath ie) { 13 | ex = new RuntimeException("Thread death"); 14 | } 15 | 16 | 17 | @Override 18 | public String toString() { 19 | return ex.toString(); 20 | } 21 | 22 | @Override 23 | public void printStackTrace() { } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/catdata/Unit.java: -------------------------------------------------------------------------------- 1 | package catdata; 2 | 3 | public class Unit { 4 | 5 | public static final Unit unit = new Unit(); 6 | 7 | public Unit() {} 8 | 9 | @Override 10 | public String toString() { 11 | return "()"; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object o) { 16 | return o.getClass() == Unit.class; 17 | } 18 | 19 | @Override 20 | public int hashCode() { 21 | return 0; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/catdata/fpql/XDriver.java: -------------------------------------------------------------------------------- 1 | package catdata.fpql; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | 7 | import catdata.LineException; 8 | import catdata.fpql.XExp.Flower; 9 | import catdata.ide.DefunctGlobalOptions; 10 | 11 | 12 | class XDriver { 13 | 14 | @SuppressWarnings({ "rawtypes" }) 15 | public static XEnvironment makeEnv(String str, XProgram init, String... toUpdate) { 16 | if (DefunctGlobalOptions.debug.fpql.x_typing) { 17 | init.doTypes(); 18 | } 19 | XEnvironment ret = new XEnvironment(init, str); 20 | Map extra = new HashMap<>(); 21 | 22 | int i = 0; 23 | for (String k : init.order) { 24 | XExp se = init.exps.get(k); 25 | try { 26 | XObject xxx = se.accept(init, new XOps(ret)); 27 | if (xxx == null) { 28 | throw new RuntimeException(); 29 | } 30 | if (se instanceof Flower) { 31 | Flower f = (Flower) se; 32 | if (ret.objs.containsKey(f.ty)) { 33 | throw new RuntimeException("Duplicate: " + f.ty); 34 | } 35 | XCtx c = (XCtx) xxx; 36 | if (f.ty != null) { 37 | ret.objs.put(f.ty, c.schema); 38 | extra.put(f.ty, i); 39 | } 40 | } 41 | if (ret.objs.containsKey(k)) { 42 | throw new RuntimeException("Duplicate: " + k); 43 | } 44 | ret.objs.put(k, xxx); 45 | if (toUpdate != null && toUpdate.length > 0) { 46 | toUpdate[0] = "Last Processed: " + k ; 47 | } 48 | i++; 49 | } catch (Throwable t) { 50 | t.printStackTrace(); 51 | throw new LineException(t.getLocalizedMessage(), k, ""); 52 | } 53 | } 54 | 55 | int j = 0; 56 | for (Entry e : extra.entrySet()) { 57 | init.order.add(e.getValue() + j, e.getKey()); 58 | j++; 59 | } 60 | 61 | //: add to order 62 | return ret; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/catdata/fpql/XObject.java: -------------------------------------------------------------------------------- 1 | package catdata.fpql; 2 | 3 | import javax.swing.JComponent; 4 | 5 | public interface XObject { 6 | 7 | String kind(); 8 | 9 | JComponent display(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/catdata/fpql/XString.java: -------------------------------------------------------------------------------- 1 | package catdata.fpql; 2 | 3 | import javax.swing.BorderFactory; 4 | import javax.swing.JComponent; 5 | 6 | import catdata.ide.CodeTextPanel; 7 | 8 | public class XString implements XObject { 9 | 10 | private final String title; 11 | private final String value; 12 | 13 | 14 | public XString(String title, String value) { 15 | this.title = title; 16 | this.value = value; 17 | } 18 | 19 | 20 | @Override 21 | public JComponent display() { 22 | return new CodeTextPanel(BorderFactory.createEtchedBorder(), title, value); 23 | } 24 | 25 | 26 | @Override 27 | public String kind() { 28 | return "black-box"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/FQLException.java: -------------------------------------------------------------------------------- 1 | package catdata.fql; 2 | 3 | @SuppressWarnings("serial") 4 | /* 5 | 6 | @author ryan 7 | * 8 | * Recoverable FQL exceptions (type errors, syntax errors, etc) 9 | */ 10 | public class FQLException extends Exception { 11 | 12 | public FQLException(String string) { 13 | super(string); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/Fn.java: -------------------------------------------------------------------------------- 1 | package catdata.fql; 2 | 3 | @FunctionalInterface 4 | public interface Fn { 5 | 6 | Y of(X x) ; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/cat/Arr.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.cat; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * @param 8 | * type of source and target objects 9 | * @param 10 | * type of the arrow data 11 | */ 12 | public class Arr { 13 | 14 | @Override 15 | public String toString() { 16 | return arr.toString(); 17 | } 18 | 19 | public String toString2() { 20 | return arr + " : " + src + " -> " + dst; 21 | } 22 | 23 | public Arrow arr; 24 | public Obj src; 25 | public Obj dst; 26 | 27 | public Arr(Arrow arr, Obj src, Obj dst) { 28 | if (arr == null) { 29 | throw new RuntimeException(); 30 | } 31 | this.arr = arr; 32 | this.src = src; 33 | this.dst = dst; 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | int prime = 31; 39 | int result = 1; 40 | result = prime * result + ((arr == null) ? 0 : arr.hashCode()); 41 | result = prime * result + ((dst == null) ? 0 : dst.hashCode()); 42 | result = prime * result + ((src == null) ? 0 : src.hashCode()); 43 | return result; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) 49 | return true; 50 | if (obj == null) 51 | return false; 52 | if (getClass() != obj.getClass()) 53 | return false; 54 | @SuppressWarnings("rawtypes") 55 | Arr other = (Arr) obj; 56 | if (arr == null) { 57 | if (other.arr != null) 58 | return false; 59 | } else if (!arr.equals(other.arr)) 60 | return false; 61 | if (dst == null) { 62 | if (other.dst != null) 63 | return false; 64 | } else if (!dst.equals(other.dst)) 65 | return false; 66 | if (src == null) { 67 | if (other.src != null) 68 | return false; 69 | } else if (!src.equals(other.src)) 70 | return false; 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/cat/FinTrans.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.cat; 2 | 3 | import java.util.Map; 4 | import java.util.Objects; 5 | 6 | import catdata.ide.DefunctGlobalOptions; 7 | 8 | /** 9 | * @author ryan Implementation of finite natural transformations. 10 | */ 11 | class FinTrans { 12 | 13 | private final Map> eta; 14 | private final FinFunctor F; 15 | private final FinFunctor G; 16 | 17 | /** 18 | * Construct a new natural transformation. Does not copy inputs. 19 | */ 20 | public FinTrans(Map> eta, 21 | FinFunctor F, 22 | FinFunctor G) { 23 | this.eta = eta; 24 | this.F = F; 25 | this.G = G; 26 | if (DefunctGlobalOptions.debug.fql.VALIDATE) { 27 | validate(); 28 | } 29 | } 30 | 31 | private Arr eta(Obj1 X) { 32 | return eta.get(X); 33 | } 34 | 35 | private void validate() { 36 | if (!Objects.equals(F.srcCat, G.srcCat)) { 37 | throw new RuntimeException("SrcCat FinTrans mismath " + F.srcCat 38 | + " and " + G.srcCat); 39 | } 40 | if (!Objects.equals(F.dstCat, G.dstCat)) { 41 | throw new RuntimeException("DstCat FinTrans mismath " + F.dstCat 42 | + " and " + G.dstCat); 43 | } 44 | for (Arr f : F.srcCat.arrows) { 45 | Arr lhs = F.dstCat.compose(F.applyA(f), eta(f.dst)); 46 | Arr rhs = F.dstCat.compose(eta(f.src), G.applyA(f)); 47 | if (!lhs.equals(rhs)) { 48 | throw new RuntimeException("Bad nat trans " + f + " in " + this); 49 | } 50 | } 51 | 52 | } 53 | 54 | @SuppressWarnings("static-method") 55 | public boolean equals() { 56 | throw new RuntimeException("Equality of FinTrans"); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "FinTrans [eta=\n" + eta + "]"; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/cat/SemQuery.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.cat; 2 | 3 | import catdata.fql.cat.FinFunctor; 4 | 5 | /** 6 | * 7 | * @author ryan 8 | * 9 | * A placeholder for semantic queries. 10 | */ 11 | public class SemQuery { 12 | 13 | public final FinFunctor project; 14 | public final FinFunctor join; 15 | public final FinFunctor union; 16 | 17 | public SemQuery(FinFunctor project, 18 | FinFunctor join, 19 | FinFunctor union) { 20 | this.project = project; 21 | this.join = join; 22 | this.union = union; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "SemQuery [project=" + project + ", join=" + join + ", union=" 28 | + union + "]"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/Attribute.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * Implentation of atomic attributes. 8 | */ 9 | @SuppressWarnings("hiding") 10 | public class Attribute implements Comparable> { 11 | 12 | public Attribute(String name, Node source, Type target) { 13 | this.name = name; 14 | this.source = source; 15 | this.target = target; 16 | } 17 | 18 | @Override 19 | public int hashCode() { 20 | int prime = 31; 21 | int result = 1; 22 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 23 | result = prime * result + ((source == null) ? 0 : source.hashCode()); 24 | result = prime * result + ((target == null) ? 0 : target.hashCode()); 25 | return result; 26 | } 27 | 28 | @SuppressWarnings("rawtypes") 29 | @Override 30 | public boolean equals(Object obj) { 31 | if (this == obj) 32 | return true; 33 | if (obj == null) 34 | return false; 35 | if (getClass() != obj.getClass()) 36 | return false; 37 | Attribute other = (Attribute) obj; 38 | if (name == null) { 39 | if (other.name != null) 40 | return false; 41 | } else if (!name.equals(other.name)) 42 | return false; 43 | if (source == null) { 44 | if (other.source != null) 45 | return false; 46 | } else if (!source.equals(other.source)) 47 | return false; 48 | if (target == null) { 49 | if (other.target != null) 50 | return false; 51 | } else if (!target.equals(other.target)) 52 | return false; 53 | return true; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return name; // + " : " + source + " -> " + target; 59 | } 60 | 61 | // public String toString() { 62 | // return name + " : " + source + " -> " + target; 63 | //} 64 | 65 | public final String name; 66 | public final Node source; 67 | public final Type target; 68 | @Override 69 | public int compareTo(Attribute o) { 70 | return name.compareTo(o.name); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/Edge.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | 4 | /** 5 | * 6 | * @author ryan 7 | * 8 | * Class for edges in a signature. 9 | */ 10 | public class Edge { 11 | 12 | @Override 13 | public String toString() { 14 | return name + " : " + source + " -> " + target; 15 | } 16 | 17 | public final String name; 18 | public final Node source; 19 | public final Node target; 20 | 21 | public Object morphism; 22 | 23 | public Edge(String name, Node source, Node target) { 24 | this.name = name; 25 | this.source = source; 26 | this.target = target; 27 | if (source == null || target == null || name == null) { 28 | throw new RuntimeException(); 29 | } 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | int prime = 31; 35 | int result = 1; 36 | result = prime * result + name.hashCode(); 37 | result = prime * result + source.hashCode(); 38 | result = prime * result + target.hashCode(); 39 | return result; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) 45 | return true; 46 | if (obj == null) 47 | return false; 48 | if (getClass() != obj.getClass()) 49 | return false; 50 | Edge other = (Edge) obj; 51 | return name.equals(other.name) && source.equals(other.source) && target.equals(other.target); 52 | } 53 | 54 | public String tojson() { 55 | String s = "{"; 56 | s += "\"source\" : " + source.tojson(); 57 | s += ", \"target\" : " + target.tojson(); 58 | s += ", \"label\" : \"" + name + "\"}"; 59 | return s; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/Eq.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | 4 | /** 5 | * 6 | * @author ryan 7 | * 8 | * Syntax for equality of paths. 9 | */ 10 | public class Eq { 11 | 12 | public final Path lhs; 13 | public final Path rhs; 14 | 15 | public Eq(Path lhs, Path rhs) { 16 | this.lhs = lhs; 17 | this.rhs = rhs; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return lhs + " = " + rhs; 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | int prime = 31; 28 | int result = 1; 29 | result = prime * result + ((lhs == null) ? 0 : lhs.hashCode()); 30 | result = prime * result + ((rhs == null) ? 0 : rhs.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | Eq other = (Eq) obj; 43 | if (lhs == null) { 44 | if (other.lhs != null) 45 | return false; 46 | } else if (!lhs.equals(other.lhs)) 47 | return false; 48 | if (rhs == null) { 49 | if (other.rhs != null) 50 | return false; 51 | } else if (!rhs.equals(other.rhs)) 52 | return false; 53 | return true; 54 | } 55 | 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/MyTableRowSorter.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | import java.util.Comparator; 4 | 5 | import javax.swing.table.TableModel; 6 | import javax.swing.table.TableRowSorter; 7 | 8 | /** 9 | * 10 | * @author ryan 11 | * 12 | * Helper class for row sorting. 13 | */ 14 | class MyTableRowSorter extends TableRowSorter { 15 | 16 | public MyTableRowSorter(TableModel model) { 17 | super(model); 18 | } 19 | 20 | @Override 21 | protected boolean useToString(int c) { 22 | return false; 23 | } 24 | 25 | @Override 26 | public Comparator getComparator(int c) { 27 | return (Object o1, Object o2) -> { 28 | try { 29 | Integer i1 = Integer.parseInt(o1.toString()); 30 | Integer i2 = Integer.parseInt(o2.toString()); 31 | return i1.compareTo(i2); 32 | } catch (Exception ex) { 33 | try { 34 | Double i1 = Double.parseDouble(o1.toString()); 35 | Double i2 = Double.parseDouble(o2.toString()); 36 | return i1.compareTo(i2); 37 | } catch (Exception ex2) { 38 | 39 | // if (o1 instanceof Integer && o2 instanceof Integer) { 40 | // return ((Integer)o1).compareTo((Integer)o2); 41 | // } 42 | return o1.toString().compareTo(o2.toString()); 43 | } } 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/Node.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | 4 | /** 5 | * 6 | * @author ryan 7 | * 8 | * Nodes in a signature. 9 | */ 10 | public class Node implements Comparable { 11 | 12 | @Override 13 | public String toString() { 14 | return string; 15 | } 16 | 17 | public String string; 18 | 19 | public Node(String string) { 20 | assert (string != null); 21 | this.string = string; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((string == null) ? 0 : string.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) 35 | return true; 36 | if (obj == null) 37 | return false; 38 | if (getClass() != obj.getClass()) 39 | return false; 40 | Node other = (Node) obj; 41 | if (string == null) { 42 | if (other.string != null) 43 | return false; 44 | } else if (!string.equals(other.string)) 45 | return false; 46 | return true; 47 | } 48 | 49 | public String tojson() { 50 | return "\"" + string + "\""; 51 | } 52 | 53 | @Override 54 | public int compareTo(Node o) { 55 | return string.compareTo(o.string); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/QueryChecker.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import catdata.Pair; 7 | import catdata.fql.decl.QueryExp.Comp; 8 | import catdata.fql.decl.QueryExp.Const; 9 | import catdata.fql.decl.QueryExp.QueryExpVisitor; 10 | import catdata.fql.decl.QueryExp.Var; 11 | 12 | public class QueryChecker implements 13 | QueryExpVisitor, FQLProgram> { 14 | 15 | private List seen = new LinkedList<>(); 16 | 17 | @Override 18 | public Pair visit(FQLProgram env, Const e) { 19 | Pair d = e.delta.type(env); 20 | Pair p = e.pi.type(env); 21 | Pair s = e.sigma.type(env); 22 | 23 | if (!d.first.equals(p.first)) { 24 | throw new RuntimeException("Mismatch: " + d.first + " and " 25 | + p.first); 26 | } 27 | if (!p.second.equals(s.first)) { 28 | throw new RuntimeException("Mismatch: " + p.second + " and " 29 | + s.first); 30 | } 31 | 32 | return new Pair<>(d.second, s.second); 33 | } 34 | 35 | @Override 36 | public Pair visit(FQLProgram env, Comp e) { 37 | List x = new LinkedList<>(seen); 38 | Pair lt = e.l.accept(env, this); 39 | seen = x; 40 | Pair rt = e.r.accept(env, this); 41 | seen = x; 42 | if (!lt.second.equals(rt.first)) { 43 | throw new RuntimeException("Mismatch: " + lt.second + " and " 44 | + rt.first); 45 | } 46 | return new Pair<>(lt.first, rt.second); 47 | } 48 | 49 | @Override 50 | public Pair visit(FQLProgram env, Var e) { 51 | if (seen.contains(e.v)) { 52 | throw new RuntimeException("Circular: " + e.v); 53 | } 54 | seen.add(e.v); 55 | QueryExp q = env.queries.get(e.v); 56 | if (q == null) { 57 | throw new RuntimeException("Unknown query: " + e.v); 58 | } 59 | return q.accept(env, this); 60 | } 61 | 62 | 63 | /* 64 | private boolean contains(List> attrs, 65 | String s) { 66 | for (Triple a : attrs) { 67 | if (a.first.equals(s)) { 68 | return true; 69 | } 70 | } 71 | return false; 72 | } */ 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/decl/ToFullQueryVisitor.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.decl; 2 | 3 | import catdata.fql.decl.FullQueryExp.Comp; 4 | import catdata.fql.decl.FullQueryExp.Delta; 5 | import catdata.fql.decl.FullQueryExp.FullQueryExpVisitor; 6 | import catdata.fql.decl.FullQueryExp.Match; 7 | import catdata.fql.decl.FullQueryExp.Pi; 8 | import catdata.fql.decl.FullQueryExp.Sigma; 9 | import catdata.fql.decl.FullQueryExp.Var; 10 | 11 | public class ToFullQueryVisitor implements 12 | FullQueryExpVisitor { 13 | 14 | @Override 15 | public FullQuery visit(FQLProgram env, Delta e) { 16 | return new FullQuery.Delta(e.f.toMap(env)); 17 | } 18 | 19 | @Override 20 | public FullQuery visit(FQLProgram env, Sigma e) { 21 | return new FullQuery.Sigma(e.f.toMap(env)); 22 | } 23 | 24 | @Override 25 | public FullQuery visit(FQLProgram env, Pi e) { 26 | return new FullQuery.Pi(e.f.toMap(env)); 27 | } 28 | 29 | @Override 30 | public FullQuery visit(FQLProgram env, Comp e) { 31 | return new FullQuery.Comp(e.l.accept(env, this), e.r.accept(env, this)); 32 | } 33 | 34 | @Override 35 | public FullQuery visit(FQLProgram env, Var e) { 36 | return env.full_queries.get(e.v).accept(env, this); 37 | } 38 | 39 | @Override 40 | public FullQuery visit(FQLProgram env, Match e) { 41 | throw new RuntimeException("Match encountered in to query " + e); 42 | } 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/BadSyntax.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * Exception for bad syntax 8 | */ 9 | public class BadSyntax extends Exception { 10 | 11 | private static final long serialVersionUID = 1L; 12 | 13 | private static Tokens furthest; 14 | 15 | @SuppressWarnings("unused") 16 | private BadSyntax() { 17 | } 18 | 19 | // keep static singleton of furthest match 20 | // add line numbers to tokens 21 | public BadSyntax(Tokens t, String s) { 22 | super(s); 23 | if (furthest == null) { 24 | furthest = t; 25 | } 26 | if (furthest.words().size() > t.words().size()) { 27 | furthest = t; 28 | } 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/KeywordParser.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | import catdata.Unit; 4 | 5 | /** 6 | * 7 | * @author ryan 8 | * 9 | * parses a keyword 10 | */ 11 | public class KeywordParser implements RyanParser { 12 | 13 | private final String word; 14 | 15 | public KeywordParser(String keyword) { 16 | word = keyword; 17 | } 18 | 19 | @Override 20 | public Partial parse(Tokens s) throws BadSyntax { 21 | if (s.head().equals(word)) { 22 | return new Partial<>(s.pop(), Unit.unit); 23 | } 24 | throw new BadSyntax(s, "Keyword " + word + " expected at " + s.head() 25 | + " " + s.peek(1) + " " + s.peek(2)); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/LongStringParser.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | 4 | /** 5 | * 6 | * @author ryan 7 | * 8 | * parses a potentially quoted string 9 | */ 10 | public class LongStringParser implements RyanParser { 11 | 12 | @Override 13 | public Partial parse(Tokens s) throws BadSyntax { 14 | try { 15 | return new QuotedParser().parse(s); 16 | } catch (Exception e) { } 17 | return new StringParser().parse(s); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/Partial.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * @param 8 | * the type of thing to parse 9 | * 10 | * Represents the intermediate parsing states return from parsing 11 | * combinators. 12 | */ 13 | public class Partial { 14 | public final Tokens tokens; 15 | 16 | public final T value; 17 | 18 | public Partial(Tokens t, T v) { 19 | tokens = t; 20 | value = v; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "Partial [tokens=" + tokens + "\n value=" + value + "]"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/PathParser.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | * @author ryan 8 | * 9 | * Parser for paths. 10 | */ 11 | public class PathParser implements RyanParser> { 12 | 13 | @Override 14 | public Partial> parse(Tokens s) throws BadSyntax { 15 | Partial> ret = ParserUtils.manySep(new StringParser(), 16 | new KeywordParser(".")).parse(s); 17 | if (ret.value.isEmpty()) { 18 | throw new BadSyntax(s, "Error - empty path at " + s); 19 | } 20 | 21 | return ret; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/PrettyPrinter.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | * @author ryan 8 | * 9 | * Some helper pretty printing methods 10 | */ 11 | public class PrettyPrinter { 12 | 13 | public static Object q(Object o) { 14 | if (o == null) { 15 | return "!!!NULL!!!"; 16 | } 17 | String s = o.toString(); 18 | if ((s.contains("\t") || s.contains("\n") || s.contains("\r") || s.contains(" ") || s.contains("-") || s.isEmpty()) && !s.contains("\"")) { 19 | return "\"" + s + "\""; 20 | } 21 | return s; 22 | } 23 | 24 | public static String sep0(String delim, List o) { 25 | if (o.isEmpty()) { 26 | return ""; 27 | } 28 | if (o.size() == 1) { 29 | return o.get(0); 30 | } 31 | String s = o.get(0); 32 | for (int i = 1; i < o.size(); i++) { 33 | s += delim + o.get(i); 34 | } 35 | return s; 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/QuotedParser.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * Parser for quoted strings. 8 | */ 9 | public class QuotedParser implements RyanParser { 10 | 11 | @Override 12 | public Partial parse(Tokens s) throws BadSyntax { 13 | return ParserUtils.outside(new KeywordParser("\""), new StringParser(), new KeywordParser("\"")).parse(s); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/RyanParser.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * @param 8 | * the type of thing to parse 9 | * 10 | * interface for parser combinators 11 | */ 12 | @FunctionalInterface 13 | public interface RyanParser { 14 | 15 | Partial parse(Tokens s) throws BadSyntax; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/StringParser.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | /** 4 | * 5 | * @author ryan 6 | * 7 | * Parser for strings. 8 | */ 9 | public class StringParser implements RyanParser { 10 | 11 | @Override 12 | public Partial parse(Tokens s) throws BadSyntax { 13 | String k = s.peek(0); 14 | if (!k.equals(";") && !k.equals("}")&& !k.equals(",")&& !k.equals("{")&& !k.equals(")") && !k.equals("=") && !k.equals("/") && !k.equals("\\")) { 15 | return new Partial<>(s.pop(), s.head()); 16 | } 17 | throw new BadSyntax(s, "Cannot parse string from " + s); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/parse/Tokens.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.parse; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | * @author ryan 8 | * 9 | * Interface for tokenizers. 10 | */ 11 | public interface Tokens { 12 | 13 | String toString2(); 14 | 15 | /** 16 | * @return a new Tokens without the head 17 | * @throws BadSyntax 18 | * is there is no head 19 | */ 20 | Tokens pop() throws BadSyntax; 21 | 22 | /** 23 | * Look ahead without popping 24 | * 25 | * @param n 26 | * how far ahead to look 27 | * @return the nth token, or null if there is none 28 | */ 29 | String peek(int n); 30 | 31 | /** 32 | * @return the current token 33 | * @throws BadSyntax 34 | * if there is none 35 | */ 36 | String head() throws BadSyntax; 37 | 38 | List words(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/CopyFlower.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | /** 7 | * 8 | * @author ryan 9 | * 10 | * A Select-from-where that just copies a table. 11 | */ 12 | public class CopyFlower extends Flower { 13 | 14 | private final String name; 15 | private final String c0; 16 | private final String c1; 17 | 18 | public CopyFlower(String name, String c0, String c1) { 19 | this.name = name; 20 | this.c0 = c0; 21 | this.c1 = c1; 22 | } 23 | 24 | @Override 25 | public String toPSM() { 26 | return "SELECT " + c0 + "," + c1 + " FROM " + name; 27 | } 28 | 29 | @Override 30 | public Set> eval(Map>> state) { 31 | return state.get(name); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/CreateTable.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | /** 10 | * 11 | * @author ryan 12 | * 13 | * Create table statements. 14 | */ 15 | public class CreateTable extends PSM { 16 | 17 | private final String name; 18 | private final Map attrs; 19 | 20 | public CreateTable(String name, Map attrs, boolean suppress) { 21 | this.name = name; 22 | this.attrs = attrs; 23 | this.suppress = suppress; 24 | for (String k : attrs.values()) { 25 | if (!(k.equals(PSM.VARCHAR()) || k.equals(PSM.INTEGER) || k.equals(PSM.FLOAT))) { 26 | throw new RuntimeException("bad attribute in " + this + " are " + attrs 27 | + " problematic: " + k); 28 | } 29 | } 30 | } 31 | 32 | private final boolean suppress; 33 | 34 | @Override 35 | public String toPSM() { 36 | if (suppress) { 37 | return ""; 38 | } 39 | String s = ""; 40 | List keys = new LinkedList<>(attrs.keySet()); 41 | 42 | for (int i = 0; i < keys.size(); i++) { 43 | if (i > 0) { 44 | s += ", "; 45 | } 46 | s += keys.get(i) + " " + attrs.get(keys.get(i)); 47 | } 48 | 49 | return "CREATE TABLE " + name + "(" + s + ")"; 50 | } 51 | 52 | @Override 53 | public void exec(PSMInterp interp, Map>> state) { 54 | if (state.get(name) != null) { 55 | throw new RuntimeException("table already exists: " + name + " in " + state); 56 | } 57 | state.put(name, new HashSet<>()); 58 | } 59 | 60 | @Override 61 | public String isSql() { 62 | return null; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/DropTable.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | /** 7 | * 8 | * @author ryan 9 | * 10 | * Drop table statements. 11 | */ 12 | public class DropTable extends PSM { 13 | 14 | private final String name; 15 | 16 | public DropTable(String name) { 17 | this.name = name; 18 | } 19 | 20 | @Override 21 | public String toPSM() { 22 | return "DROP TABLE " + name; 23 | } 24 | 25 | @Override 26 | public void exec(PSMInterp interp, Map>> state) { 27 | if (state.containsKey(name) && state.get(name) == null) { 28 | throw new RuntimeException("Table does not exist: " + name); 29 | } 30 | if (!state.containsKey(name)) { 31 | throw new RuntimeException("No table to drop: " + name); 32 | } 33 | state.remove(name); 34 | } 35 | 36 | @Override 37 | public String isSql() { 38 | return null; 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/InsertEmptyKeygen.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * 10 | * @author ryan 11 | * 12 | * The unit for keygen, since SQL doesn't allow empty select-from-wheres 13 | */ 14 | public class InsertEmptyKeygen extends InsertKeygen { 15 | 16 | public InsertEmptyKeygen(String name) { 17 | this.name = name; 18 | } 19 | 20 | @Override 21 | public String toPSM() { 22 | return "INSERT INTO " + name + " VALUES (@guid:=@guid+1)"; 23 | } 24 | 25 | @Override 26 | public void exec(PSMInterp interp, 27 | Map>> state) { 28 | if (!state.containsKey(name)) { 29 | throw new RuntimeException(toString()); 30 | } 31 | if (!state.get(name).isEmpty()) { 32 | throw new RuntimeException(toString()); 33 | } 34 | Set> ret = new HashSet<>(); 35 | Map m = new HashMap<>(); 36 | m.put("guid", Integer.toString(++interp.guid)); 37 | ret.add(m); 38 | 39 | state.put(name, ret); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/InsertSQL.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | /** 7 | * 8 | * @author ryan 9 | * 10 | * Insert the result of a SQL query into a table. 11 | */ 12 | public class InsertSQL extends PSM { 13 | 14 | private final String name; 15 | private final String c0; 16 | private final String c1; 17 | private final SQL sql; 18 | 19 | public InsertSQL(String name, SQL sql, String c0, String c1) { 20 | this.name = name; 21 | this.sql = sql; 22 | this.c0 = c0; 23 | this.c1 = c1; 24 | } 25 | 26 | @Override 27 | public String toPSM() { 28 | return "INSERT INTO " + name + "(" + c0 + "," + c1 + ") " + sql.toPSM(); 29 | } 30 | 31 | @Override 32 | public void exec(PSMInterp interp, Map>> state) { 33 | if (!state.containsKey(name)) { 34 | throw new RuntimeException("does not contain key " + name + "\n\n" + state + " sql was " + this); 35 | } 36 | if (!state.get(name).isEmpty()) { 37 | throw new RuntimeException(name + ": already " + state.get(name) + " in " + this); 38 | } 39 | state.put(name, sql.eval(state)); 40 | } 41 | 42 | @Override 43 | public String isSql() { 44 | return null; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/InsertSQL2.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | import catdata.fql.parse.PrettyPrinter; 8 | 9 | /** 10 | * 11 | * @author ryan 12 | * 13 | * Insert the result of a SQL query into a table. 14 | */ 15 | public class InsertSQL2 extends PSM { 16 | 17 | private final String name; 18 | private final SQL sql; 19 | private final List cols; 20 | 21 | public InsertSQL2(String name, SQL sql, List cols) { 22 | this.name = name; 23 | this.sql = sql; 24 | this.cols = cols; 25 | } 26 | 27 | @Override 28 | public String toPSM() { 29 | return "INSERT INTO " + name + "(" + PrettyPrinter.sep0(",", cols) + ") " + sql.toPSM(); 30 | } 31 | 32 | @Override 33 | public void exec(PSMInterp interp, Map>> state) { 34 | if (!state.containsKey(name)) { 35 | throw new RuntimeException("does not contain key " + name + "\n\n" + state + " sql was " + this); 36 | } 37 | if (!state.get(name).isEmpty()) { 38 | throw new RuntimeException(name + ": already " + state.get(name) + " in " + this); 39 | } 40 | state.put(name, sql.eval(state)); 41 | } 42 | 43 | @Override 44 | public String isSql() { 45 | return null; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/InsertValues.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | /** 8 | * 9 | * @author ryan 10 | * 11 | * Insert values syntax 12 | */ 13 | public class InsertValues extends PSM { 14 | 15 | private final String name; 16 | private final List attrs; 17 | private final Set> values; 18 | 19 | public InsertValues(String name, List attrs, 20 | Set> values) { 21 | this.name = name; 22 | this.attrs = attrs; 23 | this.values = values; 24 | if (values.isEmpty()) { 25 | throw new RuntimeException(); 26 | } 27 | } 28 | 29 | /* 30 | * INSERT INTO TABLE (column-a, [column-b, ...]) VALUES ('value-1a', 31 | * ['value-1b', ...]), ('value-2a', ['value-2b', ...]), 32 | */ 33 | @Override 34 | public String toPSM() { 35 | 36 | String attrsStr = ""; 37 | for (int i = 0; i < attrs.size(); i++) { 38 | if (i > 0) { 39 | attrsStr += ", "; 40 | } 41 | attrsStr += attrs.get(i); 42 | } 43 | 44 | String pre = "INSERT INTO " + name + "(" + attrsStr + ") VALUES "; 45 | 46 | String ret = ""; 47 | boolean b = false; 48 | for (Map row : values) { 49 | String rowStr = ""; 50 | for (int j = 0; j < attrs.size(); j++) { 51 | if (j > 0) { 52 | rowStr += ", "; 53 | } 54 | rowStr += "'" + row.get(attrs.get(j)) + "'"; 55 | } 56 | if (b) { 57 | ret += ","; 58 | } 59 | b = true; 60 | ret += " (" + rowStr + ") "; 61 | } 62 | 63 | return pre + ret.trim(); 64 | } 65 | 66 | @Override 67 | public void exec(PSMInterp interp, 68 | Map>> state) { 69 | if (!state.get(name).isEmpty()) { 70 | throw new RuntimeException("table not empty: " + name); 71 | } 72 | state.put(name, values); 73 | } 74 | 75 | @Override 76 | public String isSql() { 77 | return null; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/PSM.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | import catdata.ide.DefunctGlobalOptions; 7 | 8 | /** 9 | * 10 | * @author ryan 11 | * 12 | * Class for PSM, which raps SQL. 13 | */ 14 | public abstract class PSM { 15 | 16 | public abstract String isSql(); 17 | 18 | public static final String INTEGER = "INTEGER"; 19 | public static final String FLOAT = "FLOAT"; 20 | public static String VARCHAR() { 21 | return "VARCHAR(" + DefunctGlobalOptions.debug.fql.varlen + ")"; 22 | } 23 | 24 | public abstract void exec(PSMInterp interp, Map>> state); 25 | 26 | public abstract String toPSM(); 27 | 28 | @Override 29 | public String toString() { 30 | return toPSM(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/PSMIso.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | import catdata.Pair; 7 | import catdata.fql.decl.Transform; 8 | import catdata.fql.FQLException; 9 | import catdata.fql.cat.Inst; 10 | import catdata.fql.decl.Instance; 11 | import catdata.fql.decl.Signature; 12 | 13 | public class PSMIso extends PSM { 14 | 15 | private final boolean lToR; 16 | private final String l; 17 | private final String r; 18 | private final Signature sig; 19 | private final String pre; 20 | 21 | public PSMIso(boolean lToR, String pre, String l, String r, Signature sig) { 22 | this.lToR = lToR; 23 | this.l = l; 24 | this.r = r; 25 | this.sig = sig; 26 | this.pre = pre; 27 | } 28 | 29 | @Override 30 | public void exec(PSMInterp interp, 31 | Map>> state) { 32 | //throw new RuntimeException("Iso finder is not working right now"); 33 | try { 34 | Instance li = new Instance(sig, PSMGen.gather(l, sig, state)); 35 | Instance ri = new Instance(sig, PSMGen.gather(r, sig, state)); 36 | 37 | Pair k = Inst.iso(li, ri); 38 | if (k == null) { 39 | throw new RuntimeException("Cannot find iso between " + l + " and " + r); 40 | } 41 | 42 | if (lToR) { 43 | PSMGen.shred(pre, k.first, state); 44 | } else { 45 | PSMGen.shred(pre, k.second, state); 46 | } 47 | 48 | } catch (FQLException fe) { 49 | fe.printStackTrace(); 50 | throw new RuntimeException(fe.getMessage()); 51 | } 52 | 53 | } 54 | 55 | @Override 56 | public String toPSM() { 57 | throw new RuntimeException("Cannot generate SQL for iso."); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return lToR ? "iso1 " + l + " " + r : "iso2 " + l + " " + r; 63 | } 64 | 65 | @Override 66 | public String isSql() { 67 | return pre; 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/SQL.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | /** 7 | * 8 | * @author ryan 9 | * 10 | * SQL expressions 11 | */ 12 | public abstract class SQL { 13 | 14 | public abstract Set> eval( 15 | Map>> state); 16 | 17 | public abstract String toPSM(); 18 | 19 | @Override 20 | public String toString() { 21 | return toPSM(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/SimpleCreateTable.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.HashSet; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | /** 8 | * 9 | * @author ryan 10 | * 11 | * Simple create table statements. 12 | */ 13 | public class SimpleCreateTable extends PSM { 14 | 15 | private final String name; 16 | private final String attr; 17 | private final boolean suppress; 18 | 19 | public SimpleCreateTable(String name, String attr, boolean suppress) { 20 | this.name = name; 21 | this.attr = attr; 22 | this.suppress = suppress; 23 | if (!(attr.equals(PSM.VARCHAR()) || attr.equals(PSM.INTEGER) || attr.equals(PSM.FLOAT))) { 24 | throw new RuntimeException("bad attribute in " + this + ": " + attr); 25 | } 26 | 27 | } 28 | 29 | @Override 30 | public String toPSM() { 31 | if (suppress) { 32 | return ""; 33 | } 34 | 35 | return "CREATE TABLE " + name + "(c0 " + PSM.VARCHAR() 36 | + " PRIMARY KEY, c1 " + attr + ")"; 37 | } 38 | 39 | @Override 40 | public void exec(PSMInterp interp, 41 | Map>> state) { 42 | if (state.get(name) != null) { 43 | throw new RuntimeException("table already exists: " + name + " in " 44 | + state); 45 | } 46 | state.put(name, new HashSet<>()); 47 | } 48 | 49 | @Override 50 | public String isSql() { 51 | return null; 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/SquishFlower.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * 10 | * @author ryan 11 | * 12 | * Syntax for projecting out and doubling up a guid column 13 | */ 14 | public class SquishFlower extends Flower { 15 | 16 | private final String name; 17 | 18 | public SquishFlower(String name) { 19 | this.name = name; 20 | } 21 | 22 | @Override 23 | public String toPSM() { 24 | return "SELECT guid AS c0, guid as c1 FROM " + name; 25 | } 26 | 27 | @Override 28 | public Set> eval( 29 | Map>> state) { 30 | Set> v = state.get(name); 31 | 32 | Set> ret = new HashSet<>(); 33 | 34 | for (Map row : v) { 35 | Map newrow = new HashMap<>(); 36 | newrow.put("c0", row.get("guid")); 37 | newrow.put("c1", row.get("guid")); 38 | ret.add(newrow); 39 | } 40 | return ret; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/catdata/fql/sql/Union.java: -------------------------------------------------------------------------------- 1 | package catdata.fql.sql; 2 | 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * 10 | * @author ryan 11 | * 12 | * SQL Union 13 | */ 14 | public class Union extends SQL { 15 | 16 | private final List flowers; 17 | 18 | public Union(List flowers) { 19 | if (flowers.size() < 2) { 20 | throw new RuntimeException(); 21 | } 22 | this.flowers = flowers; 23 | } 24 | 25 | @Override 26 | public String toPSM() { 27 | String ret = ""; 28 | for (int i = 0; i < flowers.size(); i++) { 29 | if (i > 0) { 30 | ret += " UNION "; 31 | } 32 | ret += flowers.get(i); 33 | } 34 | 35 | return ret; 36 | } 37 | 38 | @Override 39 | public Set> eval( 40 | Map>> state) { 41 | Set> ret = new HashSet<>(); 42 | for (Flower f : flowers) { 43 | ret.addAll(f.eval(state)); 44 | } 45 | return ret; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/catdata/fqlpp/FQLPPEnvironment.java: -------------------------------------------------------------------------------- 1 | package catdata.fqlpp; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.ObjectInputStream; 6 | import java.io.Serializable; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | import catdata.fqlpp.cat.Category; 12 | import catdata.fqlpp.cat.Functor; 13 | import catdata.fqlpp.cat.Transform; 14 | import catdata.fqlpp.cat.FinSet.Fn; 15 | 16 | @SuppressWarnings("serial") 17 | public class FQLPPEnvironment implements Serializable { 18 | 19 | public final FQLPPProgram prog; 20 | private final String text; 21 | public final Map> sets; 22 | public final Map> fns; 23 | public final Map> cats; 24 | public final Map> ftrs; 25 | public final Map> trans; 26 | 27 | public FQLPPEnvironment(FQLPPEnvironment e) { 28 | this(e.prog, e.text, new HashMap<>(e.sets), new HashMap<>(e.fns), new HashMap<>(e.cats), new HashMap<>(e.ftrs), new HashMap<>(e.trans)); 29 | } 30 | 31 | public FQLPPEnvironment(FQLPPProgram prog, String text, Map> sets, Map> fns, 32 | Map> cats, Map> ftrs, 33 | Map> trans) { 34 | this.sets = sets; 35 | this.fns = fns; 36 | this.cats = cats; 37 | this.ftrs = ftrs; 38 | this.trans = trans; 39 | this.text = text; 40 | this.prog = prog; 41 | } 42 | 43 | public static FQLPPEnvironment load(File path) throws Exception { 44 | FileInputStream fileIn = new FileInputStream(path); 45 | ObjectInputStream in = new ObjectInputStream(fileIn); 46 | FQLPPEnvironment e = (FQLPPEnvironment) in.readObject(); 47 | in.close(); 48 | fileIn.close(); 49 | if (e == null) { 50 | throw new RuntimeException(); 51 | } 52 | return e; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/catdata/fqlpp/FUNCTION.java: -------------------------------------------------------------------------------- 1 | package catdata.fqlpp; 2 | 3 | import java.io.Serializable; 4 | import java.util.function.Function; 5 | 6 | @FunctionalInterface 7 | public interface FUNCTION extends Function, Serializable { 8 | 9 | default FUNCTION andThen(FUNCTION f) { 10 | return x -> f.apply(apply(x)); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/catdata/fqlpp/cat/Sig.java: -------------------------------------------------------------------------------- 1 | package catdata.fqlpp.cat; 2 | 3 | import java.util.Set; 4 | 5 | // turns out this is useless because signatures *always* denote categories 6 | @SuppressWarnings("serial") 7 | public class Sig extends Category, Mapping> { 8 | 9 | private Sig() { } 10 | 11 | @Override 12 | public boolean isInfinite() { 13 | return true; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "Sig"; 19 | } 20 | 21 | @Override 22 | public boolean isObject(Signature o) { 23 | return true; 24 | } 25 | 26 | @Override 27 | public boolean isArrow(Mapping a) { 28 | return true; 29 | } 30 | 31 | public static Sig Sig = new Sig(); 32 | 33 | //@Override 34 | //public boolean equals(Object o) { 35 | // return (o == this); 36 | //} 37 | 38 | @Override 39 | public Set> objects() { 40 | throw new RuntimeException("Cannot enumerate objects of Sig."); 41 | } 42 | 43 | @Override 44 | public Set> arrows() { 45 | throw new RuntimeException("Cannot enumerate arrows of Sig."); 46 | } 47 | 48 | @Override 49 | public Signature source(Mapping a) { 50 | return a.source; 51 | } 52 | 53 | @Override 54 | public Signature target(Mapping a) { 55 | return a.target; 56 | } 57 | 58 | @Override 59 | public Mapping identity(Signature o) { 60 | return Mapping.identity(o); 61 | } 62 | 63 | @SuppressWarnings({ "rawtypes", "unchecked" }) 64 | @Override 65 | public Mapping compose(Mapping a1, Mapping a2) { 66 | return Mapping.compose(a1, a2); 67 | } 68 | 69 | // ///// 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/catdata/fqlpp/cat/Subobjects.java: -------------------------------------------------------------------------------- 1 | package catdata.fqlpp.cat; 2 | 3 | public interface Subobjects { 4 | 5 | O prop(); 6 | 7 | A tru(); 8 | 9 | A fals(); 10 | 11 | A chr(A a); 12 | 13 | A kernel(A a); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/catdata/ide/Disp.java: -------------------------------------------------------------------------------- 1 | package catdata.ide; 2 | 3 | @FunctionalInterface 4 | public interface Disp { 5 | 6 | void close(); 7 | 8 | default Throwable exn() { 9 | return null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/catdata/ide/Example.java: -------------------------------------------------------------------------------- 1 | package catdata.ide; 2 | 3 | public abstract class Example implements Comparable { 4 | 5 | public abstract String getName(); 6 | 7 | public abstract String getText(); 8 | 9 | @SuppressWarnings("static-method") 10 | public Language lang() { 11 | return null; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | String pre = lang() == null ? "" : lang().prefix(); 17 | return (pre + " " + getName()).trim(); 18 | } 19 | 20 | @Override 21 | public int compareTo(Example e) { 22 | return toString().compareTo(e.toString()); 23 | } 24 | 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/catdata/ide/MyTableRowSorter.java: -------------------------------------------------------------------------------- 1 | package catdata.ide; 2 | 3 | import java.util.Comparator; 4 | 5 | import javax.swing.table.TableModel; 6 | import javax.swing.table.TableRowSorter; 7 | 8 | import catdata.AlphanumComparator; 9 | 10 | public class MyTableRowSorter extends TableRowSorter { 11 | 12 | public MyTableRowSorter(TableModel model) { 13 | super(model); 14 | } 15 | 16 | @Override 17 | protected boolean useToString(int c) { 18 | return false; 19 | } 20 | 21 | AlphanumComparator noc = new AlphanumComparator(); 22 | // NaturalOrderComparator noc = new NaturalOrderComparator(); 23 | 24 | @Override 25 | public Comparator getComparator(int c) { 26 | return (o1, o2) -> { 27 | if (o1 instanceof Integer && o2 instanceof Integer) { 28 | return ((Integer) o1).compareTo((Integer) o2); 29 | } 30 | return noc.compare(o1.toString(), o2.toString()); 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/catdata/ide/Options.java: -------------------------------------------------------------------------------- 1 | package catdata.ide; 2 | 3 | import java.awt.GridBagConstraints; 4 | import java.awt.GridBagLayout; 5 | import java.io.Serializable; 6 | import java.util.function.Function; 7 | 8 | import javax.swing.JComponent; 9 | import javax.swing.JPanel; 10 | import javax.swing.JTextField; 11 | 12 | import catdata.Pair; 13 | import catdata.Unit; 14 | 15 | public abstract class Options implements Serializable { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | public abstract String getName(); 20 | 21 | public abstract Pair> display(); 22 | 23 | public abstract int size(); 24 | 25 | protected static JPanel wrap(JTextField f) { 26 | GridBagConstraints c1 = new GridBagConstraints(); 27 | c1.weightx = 1.0; 28 | c1.fill = GridBagConstraints.HORIZONTAL; 29 | 30 | JPanel p1 = new JPanel(new GridBagLayout()); 31 | p1.add(f, c1); 32 | return p1; 33 | } 34 | 35 | public static int biggestSize = 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/catdata/ide/ProgressMonitorWrapper.java: -------------------------------------------------------------------------------- 1 | package catdata.ide; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | 6 | import javax.swing.ProgressMonitor; 7 | import javax.swing.SwingUtilities; 8 | import javax.swing.Timer; 9 | 10 | public class ProgressMonitorWrapper implements ActionListener { 11 | 12 | private final ProgressMonitor pbar; 13 | private int counter = 0; 14 | 15 | private final long start_time; 16 | private final Thread thread; 17 | private final Timer timer; 18 | 19 | public ProgressMonitorWrapper(String msg, Runnable task) { 20 | pbar = new ProgressMonitor(null, msg, "Elapsed: 0 secs", 0, 4); 21 | start_time = System.currentTimeMillis(); 22 | timer = new Timer(500, this); 23 | timer.start(); 24 | 25 | thread = new Thread(() -> { 26 | task.run(); 27 | timer.stop(); 28 | pbar.close(); 29 | }); 30 | thread.start(); 31 | } 32 | 33 | /* public static void main(String args[]) { 34 | Runnable r = () -> { 35 | for (;;) { } 36 | }; 37 | new ProgressMonitorWrapper("test", r); 38 | } */ 39 | 40 | @Override 41 | public void actionPerformed(ActionEvent e) { 42 | SwingUtilities.invokeLater(new Update()); 43 | } 44 | 45 | class Update implements Runnable { 46 | @Override 47 | @SuppressWarnings("deprecation") 48 | public void run() { 49 | if (pbar.isCanceled()) { 50 | try { 51 | thread.stop(); 52 | } catch (RuntimeException ex) { 53 | ex.printStackTrace(); 54 | } 55 | timer.stop(); 56 | return; 57 | } 58 | pbar.setProgress(counter % 4); 59 | pbar.setNote("Elapsed: " + ((double)(System.currentTimeMillis() - start_time) / ((double)1000) + " secs")); 60 | counter++; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/catdata/ide/Split.java: -------------------------------------------------------------------------------- 1 | package catdata.ide; 2 | 3 | import javax.swing.JSplitPane; 4 | 5 | @SuppressWarnings("serial") 6 | /* 7 | @author ryan 8 | * A split panel, but doesn't work well. 9 | */ 10 | public class Split extends JSplitPane { 11 | 12 | private final double bias; 13 | 14 | public Split(double bias, int split) { 15 | super(split); 16 | this.bias = bias; 17 | setDividerSize(2); 18 | } 19 | 20 | @Override 21 | public void setVisible(boolean b) { 22 | super.setVisible(b); 23 | setDividerLocation(bias); 24 | invalidate(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/catdata/opl/Operad.java: -------------------------------------------------------------------------------- 1 | package catdata.opl; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | public interface Operad { 7 | 8 | class Arrow { 9 | public final A a; 10 | public final List src; 11 | public final O dst; 12 | 13 | public Arrow(List src, O dst, A a) { 14 | this.a = a; 15 | this.src = src; 16 | this.dst = dst; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "Arrow [a=" + a + ", src=" + src + ", dst=" + dst + "]"; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | int prime = 31; 27 | int result = 1; 28 | result = prime * result + ((a == null) ? 0 : a.hashCode()); 29 | result = prime * result + ((dst == null) ? 0 : dst.hashCode()); 30 | result = prime * result + ((src == null) ? 0 : src.hashCode()); 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | Arrow other = (Arrow) obj; 43 | if (a == null) { 44 | if (other.a != null) 45 | return false; 46 | } else if (!a.equals(other.a)) 47 | return false; 48 | if (dst == null) { 49 | if (other.dst != null) 50 | return false; 51 | } else if (!dst.equals(other.dst)) 52 | return false; 53 | if (src == null) { 54 | if (other.src != null) 55 | return false; 56 | } else if (!src.equals(other.src)) 57 | return false; 58 | return true; 59 | } 60 | 61 | } 62 | 63 | Set objects(); 64 | 65 | Set> hom(List src, O dst); 66 | 67 | Arrow id(O o); 68 | 69 | Arrow comp(Arrow F, List> A); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/catdata/opl/OplImage.java: -------------------------------------------------------------------------------- 1 | package catdata.opl; 2 | 3 | import javax.swing.ImageIcon; 4 | import javax.swing.JComponent; 5 | import javax.swing.JLabel; 6 | import java.net.URL; 7 | 8 | public class OplImage implements OplObject { 9 | 10 | private String msg; 11 | private JLabel label; 12 | private String url; 13 | 14 | public OplImage(String url) { 15 | try { 16 | this.url = url; 17 | label = new JLabel(new ImageIcon(new URL(url))); 18 | } catch (Exception ex) { 19 | ex.printStackTrace(); 20 | msg = ex.getMessage(); 21 | } 22 | } 23 | 24 | @Override 25 | public JComponent display() { 26 | if (label != null) { 27 | return label; 28 | } 29 | return new JLabel(msg); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | if (msg != null) { 35 | return msg; 36 | } 37 | return url; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (!(o instanceof OplImage)) { 43 | return false; 44 | } 45 | OplImage other = (OplImage) o; 46 | boolean ret = (other.url.equals(url)); 47 | return ret; 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return 0; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/catdata/opl/OplInACan.java: -------------------------------------------------------------------------------- 1 | package catdata.opl; 2 | 3 | import catdata.Environment; 4 | import catdata.Program; 5 | import catdata.opl.OplExp.OplInst; 6 | 7 | class OplInACan { 8 | 9 | public static void main(String... args) { 10 | System.out.println(openCan(args[0])); 11 | } 12 | 13 | private static String openCan(String can) { 14 | try { 15 | Program program = OplParser.program(can); 16 | Environment result = OplDriver.makeEnv(null, program, 17 | null, null, null, null); 18 | String html = "Result\n\n"; 19 | for (String definition : program.order) { 20 | OplObject exp = result.get(definition); 21 | if (!(exp instanceof OplInst)) { //only show instances 22 | continue; 23 | } 24 | html += "

" + definition + " =\n

" + result.get(definition).toHtml() 25 | + "\n



\n"; 26 | } 27 | return html + "\n\n"; 28 | } catch (RuntimeException ex) { 29 | ex.printStackTrace(); 30 | return "ERROR " + ex.getMessage(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/catdata/opl/OplObject.java: -------------------------------------------------------------------------------- 1 | package catdata.opl; 2 | 3 | import javax.swing.JComponent; 4 | 5 | @FunctionalInterface 6 | public interface OplObject { 7 | 8 | JComponent display(); 9 | 10 | default String toHtml() { 11 | return toString().replace("\n", "
").replace("\t", " "); 12 | } 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/catdata/opl/OplString.java: -------------------------------------------------------------------------------- 1 | package catdata.opl; 2 | 3 | import javax.swing.BorderFactory; 4 | import javax.swing.JComponent; 5 | 6 | import catdata.ide.CodeTextPanel; 7 | 8 | public class OplString implements OplObject { 9 | private final String str; 10 | 11 | public OplString(String str) { 12 | this.str = str; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return OplTerm.strip(str); 18 | } 19 | 20 | @Override 21 | public JComponent display() { 22 | return new CodeTextPanel(BorderFactory.createEtchedBorder(), "", str); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/catdata/provers/DPKB.java: -------------------------------------------------------------------------------- 1 | package catdata.provers; 2 | 3 | import java.util.Map; 4 | 5 | public abstract class DPKB { 6 | 7 | public KBTheory kb; 8 | 9 | public DPKB(KBTheory kb) { 10 | this.kb = kb; 11 | } 12 | 13 | public abstract boolean eq(Map ctx, KBExp lhs, KBExp rhs); 14 | 15 | public abstract void add(C c, T t); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/catdata/provers/KBExpFactory.java: -------------------------------------------------------------------------------- 1 | package catdata.provers; 2 | 3 | import java.util.List; 4 | 5 | public interface KBExpFactory { 6 | 7 | public KBExp KBApp(C c, List> in); 8 | 9 | public KBExp KBVar(V v); 10 | 11 | public KBExp freshConst(T ty, int n); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/catdata/provers/KBHorn.java: -------------------------------------------------------------------------------- 1 | package catdata.provers; 2 | 3 | import java.util.Collections; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | public class KBHorn { 8 | 9 | public static final String _false = "_false"; 10 | public static final String _true = "_true"; 11 | public static final String _eq = "_eq"; 12 | public static final String _not = "_not"; 13 | public static final String _or = "_or"; 14 | public static final String[] reserved = new String[] { _false, _true, _eq, _not, _or }; 15 | 16 | private static KBExp falseAtom, trueAtom; 17 | 18 | public static KBExp fals() { 19 | if (falseAtom != null) { 20 | return falseAtom; 21 | } 22 | falseAtom = KBExpFactoryOldImpl.factory.KBApp(_false, Collections.emptyList()); 23 | return falseAtom; 24 | } 25 | 26 | public static KBExp tru() { 27 | if (trueAtom != null) { 28 | return trueAtom; 29 | } 30 | trueAtom = KBExpFactoryOldImpl.factory.KBApp(_true, Collections.emptyList()); 31 | return trueAtom; 32 | } 33 | 34 | public static KBExp not(KBExp e) { 35 | List l = new LinkedList<>(); 36 | l.add(e); 37 | return KBExpFactoryOldImpl.factory.KBApp(_not, l); 38 | } 39 | 40 | public static KBExp or(KBExp e1, KBExp e2) { 41 | List l = new LinkedList(); 42 | l.add(e1); 43 | l.add(e2); 44 | return KBExpFactoryOldImpl.factory.KBApp(_or, l); 45 | } 46 | 47 | public static KBExp eq(KBExp e1, KBExp e2) { 48 | List l = new LinkedList(); 49 | l.add(e1); 50 | l.add(e2); 51 | return KBExpFactoryOldImpl.factory.KBApp(_eq, l); 52 | } 53 | 54 | public static boolean isAtom(KBExp e) { 55 | 56 | if (e.isVar()) { 57 | return false; 58 | } 59 | if (e.equals(tru())) { 60 | return true; 61 | } 62 | if (e.equals(fals())) { 63 | return true; 64 | } 65 | KBExp app = e; 66 | return app.f().equals(_or) || app.f().equals(_not) || (app.f().equals(_eq)); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/catdata/provers/KBOptions.java: -------------------------------------------------------------------------------- 1 | package catdata.provers; 2 | 3 | public class KBOptions { 4 | 5 | public boolean filter_subsumed_by_self = true; 6 | public boolean unfailing = true; 7 | public boolean sort_cps = true; 8 | public boolean semantic_ac = true; 9 | public boolean compose = true; 10 | public boolean syntactic_ac = true; 11 | 12 | @Deprecated 13 | public boolean horn = false; 14 | 15 | @Deprecated 16 | public int iterations = 200000; 17 | 18 | @Deprecated 19 | public int red_its = 32; 20 | 21 | private KBOptions() { 22 | } 23 | 24 | public static final KBOptions defaultOptions = new KBOptions(); 25 | 26 | public KBOptions(boolean xunfailing, boolean xsort_cps, boolean xhorn, boolean xsemantic_ac, int xiterations, 27 | int xred_its, boolean xfilter_subsumed_by_self, /* boolean simplify, */boolean xcompose, 28 | boolean xsyntactic_ac) { 29 | unfailing = xunfailing; 30 | sort_cps = xsort_cps; 31 | horn = xhorn; 32 | semantic_ac = xsemantic_ac; 33 | iterations = xiterations; 34 | red_its = xred_its; 35 | filter_subsumed_by_self = xfilter_subsumed_by_self; 36 | // this.simplify = simplify; 37 | compose = xcompose; 38 | syntactic_ac = xsyntactic_ac; 39 | } 40 | 41 | } 42 | --------------------------------------------------------------------------------