Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Poster
1. •Why the name “Picat”?
Pattern-matching, Intuitive, Constraints, Actors, Tabling
•Core logic programming concepts
Logic variables (arrays and maps are terms)
Implicit pattern-matching and explicit unification
Explicit non-determinism
•Language constructs for scripting and modeling
Functions, loops, and list comprehensions
•Modules for combinatorial search
The cp, sat, and mip modules for CSPs
The planner module for planning
Niche Applications
Scripting and Modeling
•Constraint solving and optimization
•Planning
•NLP
•Knowledge engineering
•Complex data processing
•Web services
…
Background
Logic programming languages entered the scene of computer
science in the early 1970s as the answer to the need for paradigms
capable of representing and reasoning about different kinds of
knowledge.
In the early 1980s, results from unification theory and the
implementation of the Warren Abstract Machine improved the
efficiency of the Prolog implementations. Afterwards, researchers in
the US and in Europe offered effective frameworks and
implementation to enable the parametric extension of the Prolog
language into a constraint-based framework.
However, logic programming and constraint logic programming
continued to fall short of expectations for knowledge representation
and reasoning. It took researchers almost 10 years to understand how
to effectively embed semantics in a Prolog-style language, leading to
the development of answer set programming (ASP). In parallel with
the evolution of ASP, the notion of tabling was introduced, and was
implemented in Prolog systems, which allows the systems to be used
for supporting dynamic programming-style optimizations.
Picat is the culminating event of these developments. The language
is as declarative as Prolog, but it is more convenient than Prolog in
many aspects. It supports the encoding of problems by using
constraints, and it enables the search for solutions through the use of
constraint and SAT solvers. Picat also provides the use of tabling,
which, in particular, allows the encoding of planning problems in a
programming style.
ApplicationsApplications
SummarySummary
The Picat Language and its Application to Games and AI Problems
Neng-Fa Zhou, Jonathan Fruhman, Jie Mei
Computer and Information Science, Brooklyn College, CUNY
ResourcesResources
Path-finding
Logistics Planning
Puzzles
User’s Guide
http://picat-lang.org/download/picat_guide.pdf
Picat Book
http://www.springer.com/us/book/9783319258812
Håkan Kjellerstrand’s Picat Page
http://www.hakank.org/picat/
Examples
http://picat-lang.org/download/exs.pi
Modules
http://picat-lang.org/modules.html
Google News Group
https://groups.google.com/forum/#!forum/picat-lang
Picat integrates several programming paradigms, including logic
programming, imperative programming, functional programming,
scripting, dynamic programming with tabling, and constraint
programming.
This section compares Picat with Prolog as a logic programming
language, Haskell as a functional programming language, and
Python as a scripting language.
Picat vs. Prolog
Like in Prolog, logic variables in Picat are value holders. A logic
variable can be bound to any term, including another logic
variable. Logic variables are single-assignment, meaning that once
a variable is bound to a value, the variable takes the identity of the
value, and the variable cannot be bound again, unless the value is a
variable or contains variables.
Unlike Prolog, Picat uses pattern-matching, rather than unification,
to select applicable rules for a call. Pattern-matching is a simpler
operation than unification. Pattern-matching rules in Picat are fully
indexed, while Prolog clauses are typically indexed on one
argument. Therefore, Picat can be more scalable than Prolog.
In Prolog, every clause is implicitly backtrackable, and the cut
operator can be utilized to control backtracking. In contrast,
backtrackable rules in Picat must be explicitly denoted.
Picat vs. Haskell
Like Haskell, Picat supports function definitions with pattern-
matching rules. Haskell and Picat, as two declarative programming
languages, discourage the use of side effects in describing
computations.
A major difference between Haskell and Picat is that Haskell is a
statically-typed language, while Picat is a dynamically-typed
language. In Haskell, every variable has a known type at compile
time, while in Picat, a variable is typeless until it is bound to a
value. Although static typing allows the Haskell compiler to detect
type errors and to optimize code generation by automatically
inferring types, Picat is more flexible than Haskell.
Picat vs. Python
Both Python and Picat are dynamically-typed and interpreted
languages that emphasize flexibility and brevity of description
more than the efficiency of programs.
Python is an imperative language, and many of its built-ins have
side effects. Side effects can make code less manageable. In
addition, lists in Picat are linked lists, while lists in Python are
dynamic arrays. Picat supports constant-time access of array
elements, but Picat's arrays are not dynamic.
•Picat is a hybrid of LP, FP, and scripting
Picat provides many tools for modeling and solving combinatorial
search problems
•Picat borrows many features from other languages
Prolog (in particular B-Prolog), Haskell, Scala, Mercury,
Erlang, Python, Ruby, C-family (C++, Java, C#), OCaml,…
•The latest version is available at picat-lang.org
•Supported modules
basic, io, sys, math, os, cp, sat, mip, and util
•More modules will be added
What Is Picat?What Is Picat? ComparisonsComparisons
FundingFunding
NSF CCF1018006 and CCF1618046
CUNY Software Institute
PSC CUNY
ExamplesExamples
import cp.
queens(N) =>
Qs=new_array(N),
Qs :: 1..N,
foreach (I in 1..N-1, J in I+1..N)
Qs[I] #!= Qs[J],
abs(Qs[I]-Qs[J]) #!= J-I
end,
solve([ff],Qs),
writeln(Qs).
table(+,+,-,min)
sp(X,Y,Path,W) ?=>
Path=[(X,Y)],
edge(X,Y,W).
sp(X,Y,Path,W) =>
Path=[(X,Z)|PathR],
edge(X,Z,W1),
sp(Z,Y,PathR,W2),
W=W1+W2.