├── 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.> {
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