Memelang 02
17 Oct 2024 · Bri Holt · info@memelang.net
Introduction
Memelang is a notation for efficiently encoding and querying complex knowledge. Memelang considers the smallest unit of knowledge a meme. A meme states some idea A
has some relation R
to some other idea B
. For example, "Alice's uncle is Bob," where A=Alice
and R=uncle
, and B=Bob
. Memelang encodes this relation thusly:
A.R:B = Q; Alice.uncle:Bob = 1;
A // The A starts the statement without punctuation. .R // The relation is preceded by a dot. :B // The B ends the statement preceded by a colon. =Q // Where Q=1 is true and Q=0 is false. ; // The statement is closed with a semicolon.
The relation "uncle" is logically equivalent to "parent's brother," which can be expressed with a relation chain:
A.Ry.Rz
:B = Q; Alice.parent.brother
:Bob = 1;
It may be unknown if Alice's uncle is Bob, but if he is, he is certainly also her parent's brother. Then these two statements are equivalent:
Alice.uncle:Bob = Alice.parent.brother
:Bob;
To encode the general rule that, "an uncle is a parent's brother," a double equals sign is used. This indicates that any true A
and B
on the left side is also true on the right side:
.Rx == .Ry.Rz
; .uncle == .parent.brother
;
Given that Alice's uncle is Bob, then Bob's niece is Alice. In Memelang, this inverse relation is encoded by replacing the dotrelation with an apostropherelation, and then swapping the positions of A and B as follows:
A.R:B = B'R
:A; Alice.uncle:Bob = Bob'uncle
:Alice;
These relations form the fundamental theorem of Memelang:
Relation chains are inverted by inverting each relation and reversing their order:
.Rx == .Ry.Rz
; 'Rx
== 'Rz
'Ry
; .uncle == .parent.brother
; 'uncle
== 'brother
'parent
;
Here we'll summarize all this notation into a small program:
// Given .uncle == .parent.brother
; // Then these statements are equivalent Alice.uncle:Bob = Bob'uncle
:Alice = Alice.parent.brother
:Bob = Bob'brother
'parent
:Alice;
So far Q
has been a true/false binary, however, Q
may also be a decimal number to describe a relation's quantity, such as, "Alice's height is 1.6 meters." Whenever Q
is a quantity, R
is a range relation and B
is a unit. An optional plus sign helps signify that Q
is a positive quantity.
element.range:unit = ±quantity; Alice.height:meter = +1.6;
The inverse of a range relation inverts the quantity to 1/Q
. Using the prior example, the inverted relation states that "one meter's height is 1/1.6 Alices."
A.R:B = Q; A'R
:B = 1/Q; Alice.height:meter = +1.6; Alice'height
:meter = 1/1.6 = +0.625; meter'height
:Alice = +1.6; meter.height:Alice = 1/1.6 = +0.625;
There are a few remarkable types of relations in Memelang.
Reciprocal relations are their own inverse. For example, "I am my sibling's sibling."
A.sibling:B = B.sibling:A;
.sibling == 'sibling
;
Reflexive relations have A=B
. This generally serves to state "A is R" such as "Bob is male." A reflexive relation is always reciprocal.
Bob.male:Bob = 1;
Recursive relations can be chained to themselves infinitely. For example, "my ancestor's ancestor is also my ancestor." A recursive relation's inverse must also be recursive.
.ancestor == .ancestor.ancestor
; 'ancestor
== 'ancestor
'ancestor
;
For convenience, we can omit the punctuation in simple statements. The following statements are equivalent:
A.R:B = Q; A R B Q; A R B; // Q=1 by default
And, for inverse relations, the following statements are equivalent:
A'R:B = Q; A 'R
B Q; A 'R
B; // Q=1 by default
Reserved Relations
Reserved relations have particular meanings in Memelang as explained below.
// Given
A.R:A = 1;
Bob.male:Bob = 1;
// Then
A.is :R = 1;
Bob.is :male = 1;  The reserved is relation states that an A has the reflexive relation R.

// Given
A.R:B = 1;
Alice.uncle:Bob = 1;
// Then
A.ar :R = 1;
Alice.ar :uncle = 1;  The reserved ar relation states that an A does have at least one true relation R to any B.

// Given
A.R:B = 1;
Alice.uncle:Bob = 1;
// Then
B.br :R = 1;
Bob.br :uncle = 1;  The reserved br relation states that a B does have at least one true relation R to any A.

// reciprocal
A.eq :B = B.eq :A;
// reflexive
A.eq :A = 1;
// recursive
A.eq .eq :B = A.eq :B;
// denotes all of the above
.eq == .eq 'eq ;  The reserved eq or "equals" relation is uniquely reciprocal, reflexive, and recursive.

Query Operations
Known memes are stored in the database where they can be queried. A query consists of an incomplete Memelang statement and returns a set of memes.
A  Returns the set of all memes with this A . A set of memes all having the same A value is termed an Aset.

.R  Returns the set of all memes with this R .

'R
 Returns the set of all memes with this R , where A and B are swapped.

:B  Returns the set of all memes with this B .

Alice  This example queries the database for all memes where A=Alice . It essentially asks, "What is known about Alice?" Returns a set such as (Alice.uncle:Bob = 1; ...) .

Alice.uncle  This example queries the database for all memes where A=Alice and R=uncle . It essentially asks, "Who are Alice's uncles?"

.uncle:Bob  This example queries the database for all memes where B=bob and R=uncle . It essentially asks, "Who are Bob's nieces/nephews?"

Bob'uncle
 This example is the same as .uncle:Bob stated inversely.

Alice:Bob  This example queries the database for all memes where A=Alice and B=bob . It essentially asks, "What are the direct relations between Alice and Bob?"

Quantity Comparisons
Comparison operators filter the preceding set according to the Q
values. Herein, M
and N
denote statements such as A.R:B
.
M #= Qx  For the set of memes M , return the subset of memes from M where Q equals Qx .

M > Qx  Return the subset of memes from M where Q is greater than Qx .

M < Qx  Return the subset of memes from M where Q is less than Qx .

M >= Qx  Return the subset of memes from M where Q is greater than or equal to Qx .

M <= Qx  Return the subset of memes from M where Q is less than or equal to Qx .

M != Qx  Return the subset of memes from M where Q does NOT equal Qx .

.height:meter < 1.6  This example returns a subset of all memes with R=height , B=meter , and Q<1.6 . Effectively, this is a search for all objects shorter than 1.6 meters.

Quantity Aggregators
The aggregator operator @
performs an aggregation operation on the memes in the preceding set according to the aggregator function. It returns a single meme comprising the last matching A
, the last R
, the last B
, and a Q
according to the aggregation function.
M @cnt  The @cnt function counts the number of memes in the previous set.

M @cnt #= 0  This statement is the equivalent of "There exist no memes such that M ," where M is some statement. In computer execution, this acts as a constraint that throws an error upon evaluating to false.

M @cnt #= 1  "There exists exactly one meme such that M "

M @cnt >= 1  "There exists at least one meme such that M "

M @cnt > N @cnt  This example returns true if the Mset contains more memes than the Nset. 
M @max  Select the maximum Q value.

M @min  Select the minimum Q value.

M @sum  Sum all Q values in the set.

M @prod  Multiply all Q values in the set.

M @avg  Average all Q values in the set such that @avg = @sum / @cnt .

.balance:usd<0 @cnt #= 0  In this example, a user's balance cannot fall below zero. 
Quantity Arithmetic
Arithmetic operators modify each Q
in a set.
M += Qx  For every meme in M , Q is increased by Qx .

M = Qx  For every meme in M , Q is decreased by Qx .

M *= Qx  For every meme in M , Q is multiplied by Qx .

M /= Qx  For every meme in M , Q is divided by Qx .

M %= Qx  For every meme in M , Q is modulated by Qx .

M ^= Qx  For every meme in M , Q is exponentiated by Qx .

.price *= 0.8  In this example, all price quantities in all units are reduced by 20%. 
.price:usd += 1.5  In this example, all price quantities using USD units are increaed by $1.50. 
Junction Operations
M & N;  The set conjunction operator (AND) merges two sets into one set where every A appears in both sets. Memes with A s in only one set are excluded.

M  N;  The set disjunction operator (OR) merges all memes from two sets into one set. It is effectively a ; in a query.

Implication Operations
M == N;  The mutual implication operator states that for every M=1 also N=1 and for every N=1 also M=1 . Especially used in defining statements whereby Mstatements are equivalent to Nstatements.

M => N;  The partial implication operator states that for every M=1 also N=1 .

.fruit => .food;  Here, every A that is a fruit is also a food.

Invalid Statements
Invalid statements are listed in red with their valid counterparts below.
Identities do not contain junctions.  
Junctions are used in only the conditional clause of an implication, never the consequential clause.  
Whenever Q is a number, B is a unit. Relative measures involving two identifiers require a third identifier for the measurement. This example measures the onedimensional distance in meters between Alice and Bob.

Development
Available development tools:
We need you to help us develop Memelang projects such as:
 MySQL plugin to accept Memelang queries
 Postgres plugin to accept Memelang queries
 SQLite plugin to accept Memelang queries
 Groundup Memelang database program
 Memelang immutable blockchain
 Memelang relation visualizer
 Memelang proof assistant
Changelog from Version 01
 Renamed the language from Memetics to Memelang.
 Simplified the
Q=truefalse
toQ=10
respectively.  Replaced the term measure relation with range relation.
 Inverting a range relation inverts the quantity.
 Added the reserved relation
.ar
.  Added the reserved relation
.br
.  Removed the matrix operation, to be readded in a later version.
License
Memelang is free for public use under the Memelicense. Patents pending. Copyright 2024 HOLTWORK LLC. Contact info@memelang.net.