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


It Matters What Language AI Thinks In
23/10/2024

We are currently polarized in how we think about Large Language Models. Some say that they are just overgrown autocompletes and some say that they have captured some aspects of intelligence. How well  [ ... ]



Kotlin Ktor Improves Client-Server Support
04/11/2024

Kotlin Ktor 3 is now available with better performance and improvements including support for server-sent events and CSRF (Cross-Site Request Forgery) protection.


More News

espbook

 

Comments




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