Google Releases Logic Programming Language
Written by Kay Ewbank   
Wednesday, 14 April 2021

Google has announced a new open source logic programming language. Logica is a successor to Google's existing logic language, Yedalog, and is a Datalog-like programming language.

Datalog is a logical query language that fits somewhere between Prolog and the formal relational algebra that underpins SQL. It can be thought of either an unusually powerful query language or a carefully limited logic programming language. Datalog was created to give database theorists a way to use logic programming, particularly via recursive queries.

logica

Yedalog extended Datalog to be more practical, adding support for concepts such as nested records. Yedalog lets programmers mix data-parallel pipelines and computation in a single language.

The new language, Logica, compiles to SQL and runs on Google BigQuery. Logica compiles the logic program into a SQL expression, so it can be executed on BigQuery, Google's advanced SQL engine. Logica also includes experimental support for PostgreSQL and SQLite. The Google team says it is more concise and

"supports the clean and reusable abstraction mechanisms that SQL lacks. It supports modules and imports, it can be used from an interactive Python notebook and it even makes testing your queries natural and easy."

The big advantage Logica offers over SQL is its support for abstraction. While SQL supports views and functions for saving and reusing subsets of logic, they are limited and vary between SQL implementations. The Google team says:

"This inherent resistance to decomposition of logic into bite-sized pieces is what leads into the contrived, lengthy queries, the copy-pasted chunks of code and, eventually, unmaintainable, unstructured (note the irony) SQL codebases."

Logic programming languages use the syntax of mathematical propositional logic rather than natural English language, and Logica extends classical Logic programming syntax further, most notably with aggregation, hence the name, which stands for

Logica = Logic + Aggregation.

While SQL operates with relations that equate to sets of rows. the equivalent in logic programming is a predicate. This still defines a set of rows, but is a logical condition that describes the rows of a relation. A sample of code to find prime numbers less than 30 would be:

# Define natural numbers from 1 to 29.
N(x) :- x in Range(30);
# Define primes.
Prime(prime: x) :-
  N(x),
  x > 1,
  ~(
    N(y),
    y > 1,
    y != x,
    Mod(x, y) == 0
  );

The developers say Logica brings readability and good engineering practices to database queries, making them easier to read. Logica also makes it possible to define and re-use subqueries and functions.

logica

More Information

Logica Website

Related Articles

Database The Prolog Way

Google Extends BigQuery For Multi-Cloud Analytics

BigQuery Updated and Repriced

Google BigQuery Updated

BigQuery Now Open to All

Google BigQuery Service

Towards Objects and Functions - Computer Languages In The 1980s

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Kafka Replaces Zookeeper With Quorum
22/04/2021

Apache Kafka has been updated to version 2.8, with improvements including early access version of KIP-500, which allows you to run Kafka brokers without Apache ZooKeeper, instead depending on an inter [ ... ]



Visual Basic 16.9 Support In .NET 5
10/05/2021

Visual Basic support in .NET 5 has been updated, and Visual Basic 16.9 is now supported, along with the ability to use Windows Forms. Microsoft is still firm in its stance that the Visual Basic   [ ... ]


More News

square

 



 

Comments




or email your comment to: comments@i-programmer.info