MEMELANG

v03 · 01 Mar 2025 · Bri Holt · info@memelang.net

Introduction

Memelang is a notation for logically encoding and querying knowledge. The simple syntax enables complex relationships that were previously impractical in older query languages such as SQL, Prolog, GraphQL, Cypher, RDF, and CycL. View the web demo or the GitHub repo.

Syntax

Memelang traverses a knowledge graph using only three novel operators: ] indicates a node, [ indicates an edge, and - "inverses" an edge. Memelang also uses standard math operators such as =, !=, <=, >=, >, and <. The basic syntax states that some node A has some relation (edge) R to some other node B:

A[R]B=Q

For example, "Alice's uncle is Bob," where A=Alice and R=uncle, B=Bob, and Q=t (true). Memelang encodes this relation thusly:

Alice[uncle]Bob = t

The Q value may indicate true, false, or a quantity. Whenever the value is a quantity, the B must be a unit of that quantity. For example, "Alice's height is 1.6 meters" is encoded:

Alice[height]meter = 1.6

Relations may be chained. For example, we know that an uncle is a parent's brother:

Alice[parent[brother]Bob = t

Inverse Relations

Logically, for any true relation, there exists an inverse relation as well. The inverse relation is indicated by a minus sign:

A[R]B = B[-R]A

For the example above, Bob's "inverse uncle" is Alice. In English, inverse uncle could be "niece" or "nephew."

Alice[uncle]Bob = Bob[-uncle]Alice

Inverse relation chains are inverted and reversed:

Alice[parent[brother]Bob = Bob[-brother[-parent]Alice

Queries

An incomplete statement is interpreted as a search query where the missing field is a wildcard:

// A is wildcard
// returns everyone who has Bob as an uncle
[uncle]Bob

// B is wildcard
// returns everyone who is Alice's uncle
Alice[uncle]

// R is wildcard
// returns all relations between Alice and Bob
Alice[]Bob

// Both Bs are chained wildcards
// returns all grandchildren of Cindy
Cindy[child]child]

Note that an empty =Q is interpreted as the semi-wildcard !=f which returns any value except false.

To search for A values matching two statements, the space character is used as an AND operator. This query searches for people whose uncle is Bob and whose mother is Cindy:

[uncle]Bob [mother]Cindy

To search for A values that match at least one of multiple statements, the OR operator |n (where n is a whole number) is added to the end of the statements. All statements with the same n value are grouped into an OR clause. The query below searches for people whose uncle is Bob and whose mother is Dana or Cindy:

[uncle]Bob [mother]Dana=t|1 [mother]Cindy=t|1

Logic

Memelang encodes a logical statements with an >> implication operator. If the relation to the left of the implication operator is true, then the relation to the right is also true. For example, "if a person is at least 1 meter tall, then they may ride the rollercoaster" is encoded:

[height]meter >= 1.0 >> [rideRollercoaster]allow = t
Alice[height]meter = 1.6
// therefore
Alice[rideRollercoaster]allow = t

Logic may suggest a relation. For example, any kind of product should have a price in USD greater than or equal to one cent:

[kind]product = t >> [price]usd >= 0.01

Logic may also encode a relation chain. For example, an uncle is a parent's brother:

[uncle >> [parent[brother

Memelang in PostgreSQL

In the memesql3 implementation, statements are stored in a PostgreSQL database:

CREATE TABLE name (
 aid BIGINT,   /* A node ID */
 bid BIGINT,   /* ID representing the "type" of name */
 str DECIMAL   /* string like "Alice" */
);

CREATE TABLE meme (
 aid BIGINT,   /* A node ID */
 rid BIGINT,   /* Relation edge ID */
 bid BIGINT,   /* B node ID */
 qnt DECIMAL   /* NULL or floating point number like -2.7 */
);

Each row is interpreted to produce a meme in the form below. The case of qnt=NULL is interpreted as =t (true).

aid[rid]bid = qnt

License

Memelang is free for public use under the Memelicense. Patents pending. Copyright 2025 HOLTWORK LLC. Contact info@memelang.net.