generated from gciatto/presentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2p-kt-talk.tex
6027 lines (5052 loc) · 235 KB
/
2p-kt-talk.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% !TeX spellcheck = en_GB
%
% \documentclass[handout]{beamer}
\documentclass[presentation]{beamer}
\mode<presentation>{\usetheme{AMSCesenaPurpleAndGold}}
\setbeamertemplate{bibliography item}{\insertbiblabel}
\setbeamersize{description width=0.57cm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{2p-kt-talk}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title[\twopkt]{
\twopkt{}: A Kotlin Multi-Platform ecosystem for Symbolic AI
}
%
% \subtitle{Extended Abstract}
%
% same authors order of the presented paper
\author[Ciatto, Rizzato]{
\emph{Giovanni Ciatto}$^{1}$ % empth the presenting author
\and
Lorenzo Rizzato$^{2}$
}
%
\institute[UniBo]{
$^{1}$ Dipartimento di Informatica -- Scienza e Ingegneria (DISI)
\\
\textsc{Alma Mater Studiorum} -- Università di Bologna
\\
\texttt{
giovanni.ciatto@unibo.it % emph the presenting author's email
}
\and
$^{2}$ \texttt{lorenzo.rizzato@studio.unibo.it}
}
%
\date[May 2021]{
May 2021
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AtBeginSection[]{
\begin{frame}<beamer>[shrink,noframenumbering]\frametitle{Next in Line\ldots}
\mbox{~}
\tableofcontents[sectionstyle=show/shaded,subsectionstyle=hide,subsubsectionstyle=hide]
\mbox{~}
\end{frame}
}
\AtBeginSubsection[]{
\begin{frame}<beamer>[shrink,noframenumbering]\frametitle{Focus on\ldots}
\mbox{~}
\tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded,subsubsectionstyle=hide]%[currentsection,currentsubsection,sectionstyle=shaded,subsectionstyle=shaded,subsubsectionstyle=hide]
\mbox{~}
\end{frame}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\\\\\\\\\\\\\\\\\\\\\
\frame{\titlepage}
%\\\\\\\\\\\\\\\\\\\\\
\begin{frame}{\tuprolog{} vs \twopkt{}}
\begin{block}{\tuprolog{} in the \textbf{past}}
\begin{itemize}
\item Malleable Java-based Prolog interpreter
\item Java library for Prolog-Java interoperability
\end{itemize}
\end{block}
\begin{block}{\tuprolog{} \textbf{nowadays}}
\begin{itemize}
\item An open, multi-platform, multi-paradigm ecosystem for LP
\item \twopkt{} as the main, Kotlin-based implementation
%
\begin{itemize}
\item currently targetting both JVM and JS
\item involving both GUI and CLI executables
\item[$\rightarrow$] providing a rich library for LP
\end{itemize}
\item Where each LP aspect is made individually available for re-use
\end{itemize}
\end{block}
\end{frame}
\begin{frame}{Useful Links}
\begin{block}{\tuprolog{} project homepage}
\centering
\url{http://tuprolog.unibo.it}
\end{block}
\smallskip
\begin{alertblock}{\tuprolog{} GitHub repository \hfill \textbf{(please support us with your star =)}}
\centering
\url{https://github.com/tuProlog/2p-kt}
\end{alertblock}
% %
% \begin{itemize}
% \item star us if you like this project, it's important!
% \end{itemize}
\smallskip
\begin{exampleblock}{Other useful links}
\begin{itemize}
\item \url{https://github.com/tuProlog}
%
\begin{itemize}
\item GitHub organization containing all \tuprolog{}-related software projects
\end{itemize}
\item \url{https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin}
%
\begin{itemize}
\item GitLab repository where the actual development occurs
\end{itemize}
\item \url{https://pika-lab.gitlab.io/tuprolog/2p-in-kotlin}
%
\begin{itemize}
\item documentation of \twopkt{}
\end{itemize}
\end{itemize}
\end{exampleblock}
\end{frame}
\begin{frame}<beamer>[shrink,noframenumbering]\frametitle{Outline}
\mbox{~}
\tableofcontents
\mbox{~}
\end{frame}
\section{Historical Perspective}
\subsection{Prolog History}
\begin{frame}{Implementations of Prolog -- Chronological Perspective}
\input{fig-timeline.tex}
\end{frame}
\begin{frame}{Implementations of Prolog -- Family Tree}
\input{fig-familytree.tex}
\end{frame}
\begin{frame}[allowframebreaks]{Implementations of Prolog -- Features (from \ccite{Korner2020HistoryFuturePrologTPLP})}
\input{tab-features.tex}
\end{frame}
\subsection{\tuprolog{} History}
\begin{frame}[allowframebreaks]{\tuprolog{} History}
\begin{block}{The original idea}
\begin{itemize}
\item light-weight Prolog system for \alert{distributed} applications \ccite{tuprolog-padl01}
\item intentionally designed around a \alert{minimal core}
\item \emph{configurable} by loading/unloading \alert{libraries} of predicates
\item native support for \alert{multi-paradigm programming} \ccite{tuprolog-scp57}
%
\begin{itemize}
\item bi-directional integration among OOP and Prolog
\end{itemize}
\end{itemize}
\end{block}
\framebreak
\begin{itemize}
\item first release lightweight Prolog solver written in Java \ccite{tuprolog-padl01}
\begin{itemize}
\item OOP-interoperable
\item state-machine-based \ccite{weblp-ia5}
\end{itemize}
\bigskip
\item foundation of many research projects
\begin{description}
\item[TuCSoN / ReSpecT] coordination model for Internet applications based on network-aware and mobile agents \ccite{tucson-jaamas2} by means of reactions to communication events \ccite{respect-scp41}
\item[MoK] self-organising knowledge-oriented model based on biochemical tuple space \ccite{mok-idc2012}
\item[LPaaS] micro-intelligence vision (lightweight logic solvers running on most devices) for IoT and Cloud/Edge computing \ccite{lpaas-tplp18}
\item[TuSoW] bringing tuple-based coordination at the edge \ccite{tusow-icccn2019}
\item[Arg2P] defeasible reasoning and argumentation tool \ccite{arg2p-cilc2020}
\end{description}
\end{itemize}
\framebreak
\begin{block}{Why a complete re-write}
\begin{itemize}
\item Need to support LP in general, not only Prolog
%
\begin{itemize}
\item re-design made \twopkt{} an \alert{ecosystem} for LP
\item widening the scope w.r.t. Prolog
\end{itemize}
\item Need to get rid of a lot of legacy-code
%
\begin{itemize}
\item accumulated as the code base stepped through many persons
\item sub-optimal design choices due to limitations of early Java
\item lack of fine-grained test units made the codebase hard to maintain
\item lack of module \& package segregation
\item lack of automated dependency management
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
\section{Motivation}
\begin{frame}{Why \twopkt{}}
\begin{itemize}
\item Building an open an extensible ecosystem\ldots
\vfill
\item \ldots supporting \alert{multiple logics} (e.g. FOL, DL, TL, BDI, etc)
%
\begin{itemize}
\item via as many \alert{inference rules} as possible (e.g. deduction, abduction, induction)
%
\begin{itemize}
\item implemented, in turn, via multiple \alert{resolution strategies} (e.g. SLDNF, IFF, Probabilistic, etc.)
\end{itemize}
\end{itemize}
\vfill
\item Making each aspect of LP individually usable \emph{per se}
\vfill
\item Reaching widest possible platform support
\vfill
\item Blending LP with OOP and FP
\vfill
\item Bridging symbolic and sub-symbolic AI
\end{itemize}
\end{frame}
\begin{frame}{Which features of LP}
\begin{enumerate}
\item Knowledge representation: \alert{terms}, and \alert{clauses}
\vfill
\item \alert{Unification}, based on \cite{MartelliMontanari1982} but possibly customisable
\vfill
\item Clauses \alert{indexing} and in-memory \alert{storage} facilities for \alert{knowledge bases}
\vfill
\item Prolog-like syntax \alert{parsing} \& \alert{formatting}
\vfill
\item \alert{Serialization} / \alert{deserialization} of terms, clauses, and knowledge bases
\vfill
\item Generic \alert{resolution} API, possibly customisable via \alert{pluggable features}
\vfill
\item \alert{SLD NF} (Prolog-like) resolution strategy \cite{Robinson65SLD,Clark77}
\vfill
\item Support for other resolution strategies
\vfill
\item Common \alert{UI} facilities
\vfill
\item[\vdots]
\end{enumerate}
\end{frame}
\begin{frame}{Why Kotlin}
\begin{itemize}
\item Multi-platform support:
%
\begin{itemize}
\item JVM (Win + Linux + Mac)
\item JS (Web, both browser and server side)
\item Android
\item Native?
\item iOS?
\end{itemize}
\vfill
\item Good platform-specific interoperability
%
\begin{itemize}
\item Kotlin libraries can easily be exploited in bare Java projects
\item Kotlin libraries can be exploited in bare JavaScript projects
\end{itemize}
\vfill
\item Clean and practical framework and tool-kit available
\end{itemize}
\end{frame}
\section{Overview of the Project}
\begin{frame}[allowframebreaks]{Project Map}
\begin{itemize}
\item \twopkt{} is an ecosystem of \alert{modules}
%
\begin{itemize}
\item denoted by Gradle's notation: \module{moduleName}
\end{itemize}
\medskip
\item Modules are \alert{loosely-coupled}, yet incrementally inter-dependent
%
\begin{itemize}
\item[$\rightarrow$] \alert{onion-like} architectural design
\end{itemize}
\medskip
\item Modules are compilation and \alert{deployment units}
%
\begin{itemize}
\item 1 module $\leftrightarrow$ 1 jar, on the JVM
\end{itemize}
\medskip
\item Using a module as a dependency $\implies$ importing \alert{all} its dependencies
\end{itemize}
\framebreak
\begin{center}
\includegraphics[width=\linewidth]{img/project-map.pdf}
\end{center}
\framebreak
\begin{description}
\item[\module{core}] provides \alert{knowledge representations} facilities \& common features
%
\begin{itemize}\small
\item[eg] terms, clauses, substitutions, operators, term formatting, basic exceptions, etc.
\end{itemize}
\medskip
\item[\module{unify}] provides support for \alert{logic unification}
%
\begin{itemize}\small
\item[eg] customisable notion of unificator based on \cite{MartelliMontanari1982}
\end{itemize}
\medskip
\item[\module{theory}] provides support in-memory \alert{storage \& indexing} of clauses
%
\begin{itemize}\small
\item[eg] mutable/immutable and ordered/unordered \alert{collections of clauses} + \alert{logic theories}
\end{itemize}
\medskip
\item[\module{solve}] provides generic support for \alert{resolution-related} stuff
%
\begin{itemize}\small
\item[!] agnostic w.r.t. inference procedures \& resolution strategy
\item[eg] solvers, solutions, libraries, errors, flags, channels, etc.
\end{itemize}
\framebreak
\item[\module{solve-*}] provide specific implementation for inference procedures \& \alert{resolution} strategy
%
\begin{description}\small
\item[\module{solve-classic}] SLD NF (Prolog-like) resolution \cite{Robinson65SLD,Clark77} based on Piancastelli's state machine \cite{tuprolog-sac08} (\alert{Prolog ISO \cite{prologISO-pt1} Compliant})
\item[\module{solve-streams}] SLD NF (Prolog-like) resolution \cite{Robinson65SLD,Clark77} based on Enrico Siboni's master thesis and on \cite{Carlsson84}
\end{description}
\medskip
\item[\module{parser-*}] supports \alert{parsing} of terms and clauses in Prolog syntax
%
\begin{description}\small
\item[\module{parser-core}] supports parsing terms
\item[\module{parser-theory}] supports parsing knowledge bases and streams of clauses
\item[\module{parser-jvm/js}] platform-specific implementations, based on ANTLR \cite{Parr2013} \hint{(not to be used directly!)}
\end{description}
\framebreak
\item[\module{serialization-*}] support \alert{(de)serialization} of terms, clauses, knowledge bases in \alert{YAML/JSON}
%
\begin{description}\small
\item[\module{serialization-core}] (de)serialization of terms and clauses
\item[\module{serialization-theory}] (de)serialization of knowledge bases and theories
\end{description}
\medskip
\item[\module{dsl-*}] incrementally support the Kotlin-based DSL for LP described in~\cite{kotlinDSl4PrologWoa2020}, aimed at blending LP, FP, and OOP
%
\begin{description}\small
\item[\module{dsl-core}] basic DSL for building terms/clauses in Kotlin
\item[\module{dsl-unify}] extension of the DSL including \module{unify} facilities
\item[\module{dsl-theory}] extension of the DSL including \module{theory} facilities
\item[\module{dsl-solve}] extension of the DSL including \module{solve} facilities
\end{description}
\framebreak
\item[\module{repl}] command-line interface for Prolog
\medskip
\item[\module{ide}] JavaFX-based GUI for Prolog (customisable)
\medskip
\item[\module{io-lib}] Prolog ISO compliant Prolog library for I/O
\medskip
\item[\module{oop-lib}] Prolog library for OOP interoperability
%
\begin{itemize}\small
\item essentially, lets Kotlin's and Java's OOP facilities be exploited from LP
\item only JVM is currently supported, due to limitations in Kotlin's reflection API
\end{itemize}
\end{description}
\end{frame}
\section{Knowledge Representation: the \module{core} Module}
\begin{frame}[allowframebreaks]{Main Abstractions from the \module{core} Module}
\begin{block}{Terms and Clauses}\center\itshape\small
Immutable data structures for terms and clauses in-memory representation \& manipulation
\end{block}
\begin{block}{Substitutions}\center\itshape\small
Immutable data structures representing variables assignments, applicable to terms/clauses
\end{block}
\begin{block}{Operators and Operators Sets}\center\itshape\small
Immutable data structures for representing logic operators and their esembles
\end{block}
\framebreak
\begin{block}{Formatters}\center\itshape\small
Functional objects aimed at converting terms/clauses into strings of customisable format
\end{block}
\begin{block}{Visitors}\center\itshape\small
Functional objects aimed at easing type-dependent algorithms writing
\end{block}
\begin{block}{Exceptions}\center\itshape\small
Base exception types extensively exploited in all whole \twopkt{} project
\end{block}
\end{frame}
\subsection{The \kt{Term} Hierarchy}
\subsubsection{Main Sorts of \kt{Term}s and \kt{Clause}s}
\begin{frame}[allowframebreaks]{Term Hierarchy}
\begin{center}
\includegraphics[width=.75\linewidth]{img/terms-nofields.pdf}
\end{center}
\begin{block}{Common Conventions}
\begin{itemize}
\item Only interfaces are publicly available, no classes
\item Immutable design: all terms are immutable data structures
\item The hierarchy is a DAG, not a tree
\item Terms are totally ordered, as the are \kt{Comparable} among each others
\item We call ``term'' any object which (indirectly) implements \kt{Term}
%
\begin{itemize}
\item[!] there including clauses, i.e. instances of \kt{Clause}
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[allowframebreaks]{The \kt{Term} type}
\begin{block}{The \kt{Term} type}\centering
Base type for all terms
\end{block}
%
\begin{center}
\includegraphics[width=0.5\linewidth]{img/term.pdf}
\end{center}
%
\framebreak
%
\begin{description}
\item[\kt{is\meta{SubType}: Boolean}] checks whether the current term is an instance of \kt{\meta{SubType}} or not
\item[\kt{as\meta{SubType}(): \meta{SubType}}] casts the current term to \kt{\meta{SubType}} or returns null if not possible
\item[\kt{castTo\meta{SubType}(): \meta{SubType}}] casts the current term to \kt{\meta{SubType}} or throws an exception if not possible
\item[\kt{freshCopy(): Term}] returns a deep copy of the current term where all \kt{Var}iables have been refreshed
\item[\kt{apply(Substitution): Term}] applies the provided \kt{Substitution} to the current \kt{Term} or throws a \kt{SubstitutionApplicationException} in case a failed \kt{Substitution} has been provided
\item[\kt{equals(Term, Boolean): Boolean}] checks whether the provided \kt{Term} is deeply equal to the current one, letting the caller choose whether to compare variables by simple or by complete name
\item[\kt{equals(Any?): Boolean}] checks whether the provides object is a \kt{Term} is deeply equal to the current one, comparing variables by complete names
\item[\kt{structurallyEquals(Term): Boolean}] checks whether the provided \kt{Term} is deeply equal to the current one, in such a way that all variables are considered equal
\item[\kt{accept<T>(TermVisitor<T>): T}] returns the object produced by letting the provided \kt{TermVisitor} visit the current \kt{Term}
\item[\kt{compareTo(Term): Int}] compares the current \kt{Term} with the provided one, according to the total ordering on \kt{Term}s
\item[\kt{toString(): String}] returns a representation of the current \kt{Term} for debugging purposes
\item[\kt{variables: Sequence<Var>}] returns the (possibly empty) sequence of variables contained in the current \kt{Term}
%
\begin{itemize}\small
\item[!] duplicates are \emph{not} removed
\end{itemize}
\item[\kt{isGround: Boolean}] returns \kt{true} if the current \kt{Term} contains no \kt{Var}iable
\end{description}
\framebreak
\ktSnippet{snippets/TermUsage.kt}
\end{frame}
\begin{frame}[allowframebreaks]{Main Sorts of \kt{Term}s}
\begin{block}{The \kt{Constant} type is a sub-type of \kt{Term}}\centering
Base type for all constant terms (namely, strings and numbers)
\end{block}
%
\begin{center}
\includegraphics[width=0.4\linewidth]{img/constant.pdf}
\end{center}
%
\begin{description}
\item[\kt{value: Any}] returns the value of this \kt{Constant}
\end{description}
\begin{alertblock}{About \kt{Constant}s}
\begin{itemize}
\item \kt{Constant}s are inherently \alert{ground}
\item Their \kt{isGround} property always return \kt{true}
\item Their \kt{variables} property always return an empty sequence
\end{itemize}
\end{alertblock}
\framebreak
\begin{block}{The \kt{Numeric} type is a sub-type of \kt{Constant}}\centering
Base type for all numeric terms (namely, reals and integers)
\end{block}
%
\begin{center}
\includegraphics[width=0.8\linewidth]{img/numeric.pdf}
\end{center}
%
\framebreak
%
\begin{description}
\item[\kt{intValue: BigInteger}] returns the integer value of the current number
%
\begin{itemize}
\item \kt{BigInteger}s can then be converted into \kt{Int}, \kt{Short}, etc.
\item unlimited amount of digits $\rightarrow$ no overflow, no max value
\end{itemize}
\item[\kt{decimalValue: BigDecimal}] returns the decimal value of the current number
%
\begin{itemize}
\item \kt{BigDecimal}s can then be converted into \kt{Double} or \kt{Float}
\item i.e. a real number with arbitrary precision
\end{itemize}
\end{description}
\framebreak
\begin{block}{The \kt{Integer} type is a sub-type of \kt{Numeric}}\centering
Type for all terms representing an integer number
\end{block}
%
\begin{description}
\item[\kt{value: BigInteger}] returns \kt{this.intValue}
%
\begin{itemize}
\item \kt{BigInteger}s can then be converted into \kt{Int}, \kt{Short}, etc.
\item unlimited amount of digits $\rightarrow$ no overflow, no max value
\end{itemize}
\end{description}
\ktSnippet{snippets/IntUsage.kt}
\framebreak
\begin{block}{The \kt{Real} type is a sub-type of \kt{Numeric}}\centering
Type for all terms representing a real number
\end{block}
%
\begin{description}
\item[\kt{value: BigDecimal}] returns \kt{this.decimalValue}
%
\begin{itemize}
\item \kt{BigDecimal}s can then be converted into \kt{Double} or \kt{Float}
\item i.e. a real number with arbitrary precision
\end{itemize}
\end{description}
\ktSnippet{snippets/RealUsage.kt}
\framebreak
\begin{block}{The \kt{Struct} type is a sub-type of \kt{Term}}\centering
Type for all terms of the form \kt{$f$($t_1$, \ldots, $t_N$)}, i.e. composed by a \alert{funtor} string $f$ and $N$ terms $t_1, \ldots, t_N$ called \alert{arguments}, where $N \geq 0$ is called \alert{arity}
\end{block}
%
\begin{center}
\includegraphics[width=0.6\linewidth]{img/struct.pdf}
\end{center}
%
\framebreak
%
\begin{description}
\item[\kt{functor: String}] returns $f$
\item[\kt{arity: Int}] returns $N$
\item[\kt{args: Array<Term>}] returns an array containing $t_1, \ldots, t_N$
\item[\kt{argsList: List<Term>}] returns a list containing $t_1, \ldots, t_N$
\item[\kt{argsSequence: Sequence<Term>}] returns a sequence containing $t_1, \ldots, t_N$
\item[\kt{isFunctorWellFormed: Boolean}] returns true if the following condition hold for $f$
%
\begin{enumerate}\small
\item it begins with a lower case letter
\item it only contains letters (either lower or upper case), digits, or underscores
\end{enumerate}
\item[\kt{toString(): String}] returns $f$ iff $N = 0$, otherwise a string of the form
%
\begin{center}
\kt{$f$($t_1$.toString(), \ldots, $t_N$.toString())}
\end{center}
%
\begin{itemize}\small
\item in both cases, $f$ is wrapped within single quotes iff \kt{isFunctorWellFormed} is false
\end{itemize}
\item[\kt{equals(Any?): Boolean}] compares this \kt{Struct}ure with the provided object, returning true if the latter is a \kt{Struct}ure having the same functor, arity, and arguments (which are recursively compared via \kt{equals(Any?)})
\item[\kt{hashCode(): Int}] computes an hash code value for this \kt{Struct}ure which is coherent w.r.t. \kt{equals(Any?)}
\item[\kt{equals(Term,Boolean): Boolean}] compares this \kt{Struct}ure with the provided object, returning true if the latter is a \kt{Struct}ure having the same functor, arity, and arguments (which are recursively compared via \kt{equals(Term,Boolean)})
\item[\kt{structurallyEquals(Term): Boolean}] compares this \kt{Struct}ure with the provided object, returning true if the latter is a \kt{Struct}ure having the same functor, arity, and arguments (which are recursively compared via \kt{structurallyEquals(Term)})
\item[\kt{indicator: Indicator}] returns the indicator corresponding to the current \kt{Struct}
%
\begin{itemize}\small
\item i.e. the \kt{Struct}ure of the form \pl{'/'($f$, $N$)}
\end{itemize}
\item[\kt{get(Int): Term}] returns an argument of the current \kt{Struct} given its index
\item[\kt{getArgAt(Int): Term}] an alias for \kt{get(Int)}
\item[\kt{addFirst(Term): Term}] returns a novel \kt{Struct} of the form \pl{$f$($t^*$, $t_1$, \ldots, $t_N$)}, where $t^*$ is the \kt{Term} provided as argument
\item[\kt{addLast(Term): Term}] returns a novel \kt{Struct} of the form \pl{$f$($t_1$, \ldots, $t_N$, $t^*$)}, where $t^*$ is the \kt{Term} provided as argument
\item[\kt{append(Term): Term}] an alias for \kt{addLast(Term)}
\item[\kt{insertAt(Int,Term): Term}] returns a novel \kt{Struct} of the form \pl{$f$($t_1$, \ldots, $t_{i-1}$, $t^*$, $t_{i+1}$, \ldots, $t_N$)}, where $t^*$ is the \kt{Term} provided as argument
\item[\kt{setFunctor(String): Term}] returns a novel \kt{Struct} of the form \pl{$f^*$($t_1$, \ldots, $t_N$)}, where $f^*$ is the functor \kt{String} provided as argument
\end{description}
\framebreak
\ktSnippet[\tiny]{snippets/StructUsage.kt}
\framebreak
\begin{block}{The \kt{Atom} type is a sub-type of both \kt{Struct} and \kt{Constant}}\centering
Type for all constant 0-ary structures (i.e., with no arguments), representing strings
\end{block}
%
\begin{center}
\includegraphics[width=0.6\linewidth]{img/atom.pdf}
\end{center}
%
\framebreak
%
\begin{description}
\item[\kt{value: String}] returns \kt{this.functor}
\item[\kt{arity: Int}] must return 0
\item[\kt{args: Array<Term>}] must return the empty array
\item[\kt{argsList: List<Term>}] must return the empty list
\item[\kt{argsSequence: Sequence<Term>}] must return the empty sequence
\end{description}
\framebreak
\ktSnippet{snippets/AtomUsage.kt}
\framebreak
\begin{block}{The \kt{Var} type is a sub-type of \kt{Term}}\centering
Type for all variable terms, representing \alert{named} placeholders for other terms.
\end{block}
%
\begin{center}
\includegraphics[width=0.5\linewidth]{img/var.pdf}
\end{center}
%
\framebreak
%
\begin{alertblock}{About \kt{Var}iable names}
\begin{itemize}
\item Variables are identified by \alert{complete name}
\item Variables' complete names are \kt{String}s of the form
%
\begin{center}
\pl{$Name$\_$Identifier$}
\end{center}
where
%
\begin{description}
\item[$Name$] is the variable's \alert{simple} name
\item[$Identifier$] is the variable's \alert{identifier}, i.e. an im\-ple\-men\-ta\-tion-spe\-ci\-fic string aimed at distinguishing \kt{Var}iables having the same simple name
\end{description}
\item Variables whose simple name is \pl{'\_'} are called \alert{anonymous}
\end{itemize}
\end{alertblock}
%
\begin{description}
\item[\kt{name: String}] returns $Name$
\item[\kt{completeName: String}] returns \pl{$Name$\_$Identifier$}
\item[\kt{id: String}] returns $Identifier$
\item[\kt{isAnonymous: Boolean}] returns true iff \pl{$Name$ = '\_'}
\item[\kt{toString(): Boolean}] returns this \kt{this.completeName}
\item[\kt{equals(Any?): Boolean}] compares this \kt{Var}iable with the provided object, returning true if the latter is a \kt{Var}iable having the same complete name
\item[\kt{equals(Term,Boolean): Boolean}] compares this \kt{Var}iable with the provided object, returning true if the latter is a \kt{Var}iable having the same complete (resp. simple) name, assuming that the provided \kt{Boolean} is true (resp. false)
\item[\kt{structurallyEquals(Term): Boolean}] compares this \kt{Var}iable with the provided object, returning true if the latter is a \kt{Var}iable
\end{description}
\ktSnippet{snippets/VarUsage.kt}
\framebreak
\begin{block}{The \kt{Indicator} type is a sub-type of \kt{Struct}}
\begin{center}
Type for all binary structures of the form
%
\begin{center}
\pl{'/'($f$, $n$)}
\end{center}
where $f,n$ are arbitrary terms. If $f$ is an atom and $n$ is a non-negative integer, then the indicator is considered \emph{well formed}
\end{center}
\end{block}
%
\begin{center}
\includegraphics[width=0.7\linewidth]{img/indicator.pdf}
\end{center}
%
\framebreak
%
\begin{description}
\item[\kt{nameTerm: Term}] returns $f$, shortcut for \kt{get(0)}
\item[\kt{indicatedName: String?}] if $f$ is an atom, returns \kt{$f$.value}, otherwise \kt{null}
\item[\kt{arityTerm: Term}] returns $n$, shortcut for \kt{get(1)}
\item[\kt{indicatedArity: Int?}] if $n$ is a non-negative integer, returns \kt{$n$.intValue.toInt()}, otherwise \kt{null}
\item[\kt{isWellFormed: Boolean}] returns \kt{true} if the indicator is well formed
\item[\kt{functor: String}] must return \kt{"/"}
\item[\kt{arity: String}] must return 2
\end{description}
\ktSnippet{snippets/IndicatorUsage.kt}
\framebreak
\begin{block}{The \kt{Truth} type is a sub-type of \kt{Atom}}
\begin{center}
Type for special atoms representing either tautology or contradiction.
It has only three admissible values: \pl{true} (tautology), \pl{false}, and \pl{fail} (contradictions).
\end{center}
\end{block}
%
\begin{center}
\includegraphics[width=0.9\linewidth]{img/truth.pdf}
\end{center}
%
\begin{description}
\item[\kt{isTrue: Boolean}] returns \kt{true} if the atom is a tautology
\item[\kt{isFail: Boolean}] returns \kt{true} if the atom is a contradiction
\end{description}
\framebreak
\ktSnippet[\tiny]{snippets/TruthUsage.kt}
\end{frame}
\begin{frame}[allowframebreaks]{Collections}
\begin{exampleblock}{How to fold items with structures}
\begin{itemize}
\item Suppose you want to collect terms $t_1, \ldots, t_N$\ldots
\item \ldots using binary structures whose functor is $f$
\item Two folding strategies: with or without a termination term $T$
%
\begin{itemize}
\item explicit termination: \pl{$f$($t_1$, $f$($t_2$, \ldots $f$($t_N$, $T$) \ldots ))}
\item implicit termination: \pl{$f$($t_1$, $f$($t_2$, \ldots $f$($t_{N-1}$, $t_N$) \ldots ))}
\end{itemize}
\item A particular collection is therefore determined by:
%
\begin{itemize}
\item the particular choice of $f$
\item the particular folding strategy adopted
\item the particular termination term $T$, if any
\end{itemize}
\end{itemize}
\end{exampleblock}
%
\framebreak
%
\begin{block}{The \kt{Collection} type is a sub-type of \kt{Struct}}\centering
Base type for all right-recursive structures aimed at containing an unlimited amount of terms.
\end{block}
%
\begin{center}
\includegraphics[width=.8\linewidth]{img/collection.pdf}
\end{center}
%
\framebreak
%
\begin{description}
\item[\kt{unfoldedSequence: Sequence<Term>}] in general, returns a sequence containing the terms $t_1, \ldots, t_N$, plus $T$ in case of explicit folding strategy
\item[\kt{unfoldedList: List<Term>}] in general, returns a list containing the terms $t_1, \ldots, t_N$, plus $T$ in case of explicit folding strategy
\item[\kt{unfoldedArray: Array<Term>}] in general, returns an array containing the terms $t_1, \ldots, t_N$, plus $T$ in case of explicit folding strategy
\item[\kt{size: Int}] in general, returns $N$
\item[\kt{toSequence(): Sequence<Term>}] in general, returns a sequence containing the terms $t_1, \ldots, t_N$
\item[\kt{toList(): List<Term>}] in general, returns a list containing the terms $t_1, \ldots, t_N$
\item[\kt{toArray(): Array<Term>}] in general, returns an array containing the terms $t_1, \ldots, t_N$
\item[\kt{unfold(): Sequence<Term>}] in general, returns a sequence containing the terms \pl{$f$($t1$, $f$($t_2$, \ldots))}, \pl{$f$($t_2$, \ldots)}, \pl{\ldots}, plus $T$ in case of explicit folding strategy, or \pl{$f$($t_{N-1}$, $t_N$)} otherwise
\end{description}
\framebreak
\begin{block}{The \kt{List} type is a sub-type of \kt{Collection}}
\begin{center}
Base type for logic lists, i.e. collections using \pl{'.'} as functor and \pl{'[]'} as the termination term.
%
So all lists are terms of the form
\begin{center}
\pl{'.'($t_1$, '.'($t_2$, \ldots '.'($t_N$, $T$)\ldots))}.
\end{center}
%
A list is considered well formed iff $T \equiv \pl{[]}$.
\end{center}
\end{block}
%
\begin{center}
\includegraphics[width=0.9\linewidth]{img/list.pdf}
\end{center}
%
\begin{alertblock}{About logic lists}
\begin{itemize}
\item There are two sub-types of \kt{List}:
%
\begin{itemize}
\item \alert{\kt{Cons}}, capturing all terms of the form \pl{'.'($h$, $t$)} where both $h$ and $t$ are terms of any sort
\item \alert{\kt{EmptyList}}, which has only one value, namely the atom \pl{'[]'}
\end{itemize}
\item Logic lists are represented as strings using the following notation:
%
\begin{center}
\pl{[$t_1$, $t_2$, \ldots $t_n$ | $T$]}
\end{center}
%
\begin{itemize}
\item where `\pl{| $T$}' may be omitted in case $T \equiv \pl{[]}$
\end{itemize}
\end{itemize}
\end{alertblock}
%
\begin{description}
\item[\kt{isWellFormed: Boolean}] returns \kt{true} if the list is well formed
\item[\kt{last: Term}] returns $T$
\item[\kt{isCons: Boolean}] returns \kt{true} if the list is not empty
\item[\kt{isEmptyList: Boolean}] returns \kt{true} if the list is empty
\item[\kt{unfoldedSequence: Sequence<Term>}] returns a sequence containing the terms $t_1, \ldots, t_N, \pl{[]}$
\item[\kt{unfoldedList: List<Term>}] returns a list containing the terms $t_1, \ldots, t_N, \pl{[]}$
\item[\kt{unfoldedArray: Array<Term>}] returns an array containing the terms $t_1, \ldots, t_N, \pl{[]}$
\item[\kt{size: Int}] returns $N$ if the list is well formed, or $N+1$ otherwise
\item[\kt{toSequence(): Sequence<Term>}] returns a sequence containing the terms $t_1, \ldots, t_N$, plus $T$ iff $T \not\equiv \pl{[]}$
\item[\kt{toList(): List<Term>}] returns a list containing the terms $t_1, \ldots, t_N$, plus $T$ iff $T \not\equiv \pl{[]}$
\item[\kt{toArray(): Array<Term>}] returns an array containing the terms $t_1, \ldots, t_N$, plus $T$ iff $T \not\equiv \pl{[]}$
\item[\kt{unfold(): Sequence<Term>}] returns a sequence containing the terms \pl{'.'($t1$, '.'($t_2$, \ldots))}, \pl{'.'($t_2$, \ldots)}, \pl{\ldots}, $T$
\end{description}
\ktSnippet[\tiny]{snippets/ListUsage.kt}
\framebreak
\begin{block}{The \kt{Tuple} type is a sub-type of \kt{Collection}}
\begin{center}
Base type for logic conjunctions, i.e. collections using \pl{','} as functor and an implicit termination strategy.
%
So all tuples are terms of the form
\begin{center}
\pl{','($t_1$, ','($t_2$, \ldots ','($t_{N-1}$, $t_N$)\ldots))}.
\end{center}
%
Notice that tuples always contain at least 2 terms.
\end{center}
\end{block}
%
\begin{center}
\includegraphics[width=0.9\linewidth]{img/tuple.pdf}
\end{center}
%
\begin{alertblock}{About logic tuples}
\begin{itemize}
\item Logic tuples are represented as strings using the following notation:
%
\begin{center}
\pl{($t_1$, $t_2$, \ldots $t_n$)}
\end{center}
\end{itemize}
\end{alertblock}
%
\begin{description}
\item[\kt{unfoldedSequence: Sequence<Term>}] returns a sequence containing the terms $t_1, \ldots, t_N$
\item[\kt{unfoldedList: List<Term>}] returns a list containing the terms $t_1, \ldots, t_N$
\item[\kt{unfoldedArray: Array<Term>}] returns an array containing the terms $t_1, \ldots, t_N$
\item[\kt{size: Int}] returns $N$
\item[\kt{toSequence(): Sequence<Term>}] returns \kt{this.unfoldedSequence}
\item[\kt{toList(): List<Term>}] returns \kt{this.unfoldedList}
\item[\kt{toArray(): Array<Term>}] returns \kt{this.unfoldedArray}
\item[\kt{unfold(): Sequence<Term>}] returns a sequence containing the terms \pl{','($t1$, ','($t_2$, \ldots))}, \pl{','($t_2$, \ldots)}, \pl{\ldots}, \pl{','($t_{N-1}$, $t_N$)}
\end{description}
\framebreak
\ktSnippet{snippets/TupleUsage.kt}
\framebreak
\begin{block}{The \kt{Set} type is a sub-type of \kt{Collection}}
\begin{center}
Base type for logic sets, i.e. a particular sort of collection using \pl{\{\}} as functor, which may either be empty or contain a single term---which may possibly be a tuple.
\end{center}
\end{block}
%
\begin{center}
\includegraphics[width=0.9\linewidth]{img/set.pdf}
\end{center}
%
\begin{alertblock}{About logic sets}
\begin{itemize}
\item There are two sub-types of \kt{Set}:
%
\begin{itemize}
\item \alert{\kt{Set}}, capturing all terms of the form \pl{'\{\}'($x$)} where $x$ is a term of any sort
\item \alert{\kt{EmptySet}}, which has only one value, namely the atom \pl{'\{\}'}
\end{itemize}
\item Logic sets are represented as strings using the following notations:
%
\begin{itemize}
\item \pl{\{\}} in case of empty set
\item \pl{\{$t_1$, \ldots $t_N$\}} in case $x$ $\equiv$ \pl{($t_1$, \ldots, $t_N$)}, i.e. if $x$ is a tuple
\item \pl{\{$x$\}} otherwise
\end{itemize}
\end{itemize}
\end{alertblock}
%
\begin{description}
\item[\kt{unfoldedSequence: Sequence<Term>}] returns a sequence containing the terms $t_1, \ldots, t_N$ if $x$ is a tuple, just $x$ otherwise, or nothing if the set is empty
\item[\kt{unfoldedList: List<Term>}] returns a list containing the terms $t_1, \ldots, t_N$ if $x$ is a tuple, just $x$ otherwise, or nothing if the set is empty
\item[\kt{unfoldedArray: Array<Term>}] returns an array containing the terms $t_1, \ldots, t_N$ if $x$ is a tuple, just $x$ otherwise, or nothing if the set is empty
\item[\kt{size: Int}] returns $N$ if $x$ is a tuple, 1 otherwise, or 0 if the set is empty
\item[\kt{toSequence(): Sequence<Term>}] returns \kt{this.unfoldedSequence}
\item[\kt{toList(): List<Term>}] returns \kt{this.unfoldedList}
\item[\kt{toArray(): Array<Term>}] returns \kt{this.unfoldedArray}
\end{description}
\ktSnippet{snippets/SetUsage.kt}
\end{frame}
\begin{frame}[allowframebreaks]{Clauses}
\begin{block}{The \kt{Clause} type is a sub-type of \kt{Struct}}\centering
Base type for all structures aimed at representing Horn clauses.
They all use \pl{':-'} as functor and carry either 1 or 2 arguments, named \emph{head} and \emph{body}.
\end{block}
%
\begin{center}
\includegraphics[width=0.95\linewidth]{img/clause.pdf}
\end{center}
\framebreak
\begin{alertblock}{About clauses}
\begin{itemize}
\item There are three sub-types of \kt{Clause}:
%
\begin{itemize}
\item \alert{\kt{Rule}}, capturing all structures of the form \pl{':-'($h$, $b$)} where $h$ is a \kt{Struct}ure and $b$ is a term of any sort
%
\begin{itemize}
\item \alert{\kt{Fact}}, capturing all rules of the form \pl{':-'($h$, true)}, where $b$ $\equiv$ \pl{true}
\end{itemize}
\item \alert{\kt{Directives}}, capturing all structures of the form \pl{':-'($b$)} where $b$ is a term of any sort
\end{itemize}
\item Logic clauses are represented as strings using the following notations:
%
\begin{itemize}
\item \pl{$h$ :- $b_1$, \ldots, $b_N$.} in case of rules where $b$ $\equiv$ \pl{($b_1$, \ldots, $b_N$)}
\item \pl{$h$ :- $b$.} in case of rules
\item \pl{$h$.} in case of facts
\item \pl{:- $b_1$, \ldots, $b_N$.} in case of directives where $b$ $\equiv$ \pl{($b_1$, \ldots, $b_N$)}
\item \pl{:- $b$.} in case of directives