Memetics
Version 01 · 23 Sep 2024 · Bri Holt
Memetic notation encodes logical relations for manipulation in logical arithmatic. This notation serves as a query language and formal logic language with applications in graph databases, large language models, retrieval-augmented generation, and proof assistants. Please contact info@holtwork.com with inquiries.
Memetic Units
In memetic notation, knowledge is reduced to units called memes. Each meme states that some A has some relation R to some B. For example, "Alice's uncle is Bob," where A=Alice and R=uncle, and B=Bob. A and B are members of a set of element identifiers. Any identifier may be used in an A or B position, depending on the relation's direction. R is a member of a set of relation identifiers. Element identifiers and relation identifiers preferably do not intersect. For computers, identifiers are optimally stored as binary integers elsewhere correlated to strings. For humans, identifiers are optimally written as simplified lowercase A-Z words as they are here.
Conventional Notation
The ARB relationship may be described using conventional functional notation.
R(A,B) = Q | Some function R() takes A and B as inputs and outputs a Q. The R() function essentially answers the question, is A related to B by this R() function? |
'R(B,A) = Q | Every relation R(A,B) has an inverse relation 'R(B,A). |
Q := {null, false, true, real number} | Various values of Q describe the relationship. |
Q = null | The relation is unknown. Unknown may also be assumed to be false. |
Q = false | The relation is known to be false. |
Q = true | The relation is known to be true. |
Q = real number | The R property of some A equals Q quantity of B units. B is always a unit when Q is a number. |
uncle(alice,bob) = true | In this truth example, it is true that Bob is Alice's uncle. |
height(alice,meter) = 1.6 | In this quantitative example, Alice has a height of 1.6 meters. The B in quantitative relations is always a unit. |
g(A,R,B) g(alice,uncle,*) = ((alice,uncle,bob,true),...) | A g() function takes A, R, and/or B as input and outputs a set of matching (A,R,B) coordinates. Asterisks or empties are treated as wildcards. |
ga(A,R,B) ga(*,uncle,bob)=(alice,carl,...) | The functions ga() takes A, R and B as inputs and outputs an array of As from matching coordinates. The functions gr(), gb(), gq() act likewise and output R, B, and Q arrays respectively. |
Simple Memetic Statements
The conventional notation above will prove cumbersome in complex statements. Memetic notation applies these functions implicitly. The syntax of memetic notation is chosen for ease of typing on a QWERTY keyboard. Note that the meaning of punctuation in memetic notation may differ from that of existing notations.
A.R:B=Q; A.R:B; A R B; A R B Q; | Some A is related by some R to some B. The R is preceded by a dot, the B is preceded by a colon, and Q preceded by an equals. Q=true is omittable. For simple statements, all punctuation is omittable. |
alice.uncle:bob = true; alice.uncle:bob; alice uncle bob; | In this truth example, it is true that Bob is Alice's uncle. |
alice.height:meter = +1.6; alice height meter +1.6; | In this quantitative example, Alice has a height of 1.6 meters. The B in quantitative relations is always a unit. The optional plus sign helps signify that 1.6 is a number, not a relation chain. |
B'R:A=Q; B'R:A; B 'R A; B 'R A Q; | Inverse relations are specified with an apostrophe before the R. In the character sequence dot-apostrophe is simplified to just apostrophe. |
bob'uncle:alice=true; bob'uncle:alice; bob 'uncle alice; | In this truth example, it is true that Alice is the inverse-uncle (niece) of Bob. |
Complex Memetic Statements
Memetic notation may be extended to ask questions and form logical statements. An example complex statement looks like: ((Ax.Rx & (.Ry:By > Qy)) @cnt #=0). Each expression in the statement has a special function. Certain expressions return sets and forward arrays. A set is a series of memes. An array is a series of values taken from one column (either A, R, B, or Q) from a set of memes. Each expression is explained below.
Set Query Operations
Known memes are stored in the dataset where they can be queried. On a computer, the dataset is stored in a database. On paper, the dataset is the listed memes.
A | If specified, retrieves the set of all memes with this A. If omitted, the starting set is the set of all memes. Forwards an array of the As. Only used at the start of a statement. A set of memes all having the same A value is termed an A-set. |
.R | Retrieves the set of all memes with this R and an A equal to any value from the previous forwarded array. Forwards an array of the Bs. The output set may be larger than the input set. |
'R | Retrieves the set of all memes with this R and a B equal to any value from the previous forwarded array. Forwards an array of the As. The output set may be larger than the input set. |
:B | Filters the previous set to only those memes with this B. Forwards an array of Qs. Only used at the end of a statement. A set of memes all having the same B value is termed a B-set. |
alice | This example queries the dataset for all memes where A=alice. It essentially asks, "What is known about Alice?" Returns an array such as (alice.uncle:bob=true;...). |
alice.uncle | This example queries the dataset for all memes where A=alice and R=uncle. It essentially asks, "Who are Alice's uncles?" Returns a set such as (alice.uncle:bob=true; ...). |
.uncle:bob | This example queries the dataset for all memes where B=bob and R=uncle. It essentially asks, "Who are Bob's nieces/nephews?" Returns a set such as (alice.uncle:bob=true; ...). |
bob'uncle | This example is the same as .uncle:bob stated inversely. Returns a set such as (bob'uncle:alice=true; ...). |
alice:bob | This example queries the dataset for all memes where A=alice and B=bob. It essentially asks, "What are the direct relations between Alice and Bob?" Returns a set such as (alice.uncle:bob=true;...). |
Relational Logic Operations
The above operations can be combined to form relational logic whereby one relation is comprised of two or more other relations.
alice.parent.brother:bob = true; | Relations may be chained. Here, Alice has some unnamed parent who has a brother Bob. |
bob'brother'parent:alice = true; | Inverted Rs chain A-A or B-B or A-B. The dot before an apostrophe is omittable. |
.uncle == .parent.brother; | A relation may be defined as a chain of other relations. Note the set equality in the double equals sign. |
'uncle == 'brother'parent; | The inverse of a chain is the relations inversed and reversed. |
.sibling == 'sibling; | A reciprocal relation is its own inverse. If A is the sibling of B, then B is the sibling of A. |
bob.male:bob = true; | A reflexive relation has A=B. Equivalent to "It is true that A is R." |
.ancestor == .ancestor.ancestor; | A recursive relation can be chained to itself infinitely. |
.equals == .equals'equals; | Unless explicitly stated, recursion implicitly excludes reflection (A=B) to avoid the paradox whereby my sibling's sibling is also my sibling, and I am my sibling's sibling, therefore I am my own sibling. Here, the mathematical relation equals is denoted as reciprocal, reflexive, and recursive. |
'ancestor == 'ancestor'ancestor; | A recursive relation's inversion must also be recursive. |
.brother == .sibling.male; | In a relation chain comprising at least one non-reflexive relation and at least one reflexive relation, the reflexive relations are termed reducers because their purpose is to reduce the set from the non-reflexive relations. Here, male is a reducer as it reduces the set of siblings to only males. |
'brother == 'male'sibling == .male.sibling; | Reciprocal relation inversion is arbitrary. |
.parent == .sibling.parent; | In a relation's definition that comprises the relation itself and a non-reflexive relation, the non-reflexive relation is termed the reacher as it reaches for additional relations. Here, my sibling's parent is also my parent. |
.R => .is:R; alice.human => alice.is:human; | The existential relation is returns true/false if A has any B relation. Note that B is transposed to the R position. This example reads, "Alice is a human." |
human kind species; species'kind'is:alice; 'is & .kind:species => .isSpecies; | In this example, the second row asks the question, "What kind of species is Alice?" and the third row creates a categorical relation that is a subset of the existential relation. |
.speed == .distance / .time; | A relation may be defined as an arithmetic operation between other relations. |
Quantity Comparison Operations
Comparison operators automatically receive an array of Qs and filter the preceding set accordingly. Herein, M, N, and P denote statements such as A.R:B. While X and Y denote values such as false, true, or a number.
M #= X | For the set of memes M, return the subset of memes from M where Q equals X. |
M > X | Return the subset of memes from M where Q is greater than X. |
M < X | Return the subset of memes from M where Q is less than X. |
M >= X | Return the subset of memes from M where Q is greater than or equal to X. |
M <= X | Return the subset of memes from M where Q is less than or equal to X. |
M != X | Return the subset of memes from M where Q does NOT equal X. |
.height:meter < 1.7 | This example returns a subset of all memes with any A, R=height, B=meter (meter), and Q<1.7. It effectively for all objects shorter than 1.7 meters. |
Quantity Aggregator Operations
The aggregator operator @ performs an aggregation operation on the memes in the preceding set according to the adjacent function name. The aggregator forwards a numeric value and returns a set 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 M-set contains more memes than the N-set. |
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 Operations
Arithmetic operators automatically receive an array of Qs.
M += X | For every meme in M, Q is increased by X. |
M -= X | For every meme in M, Q is decreased by X. |
M *= X | For every meme in M, Q is multiplied by X. |
M /= X | For every meme in M, Q is divided by X. |
M %= X | For every meme in M, Q is modulated by X. |
M ^= X | For every meme in M, Q is exponentiated by X. |
camera'kind.price *= 0.8 | In this example, all camera price quantities in all units are reduced by 20%. |
camera'kind.price:usd *= 0.8 | In this example, all camera price quantities using USD units are reduced by 20%. |
Set-Value Operations
M = X; A.R:B = true; | The value operator states that M-statement evaluates to X-value, and M-statement is a possible devaluation of X-value. |
M = X & Y; A.R:B = true & true; | The AND operator evaluates to true when both X-value and Y-value are true. Non-empty sets evaluate to true. Numbers greater than zero evaluate to true. |
M = X | Y; A.R:B = false | true; | The OR operator evaluates to true if either X-value or Y-value is true. |
M = null; A.R = null; A R null; .R:B= null; A:B = null; | The set nullifier syntax removes all items from the M-set. |
Set Junction Operations
M & N; | The set conjunction operator (AND) merges two sets into one set where every A appears in both sets. Memes with As in only one set are excluded. Here, M and N are sets of memes. |
M | N; | The set disjunction operator (OR) merges all memes from two sets into one set. Is optionally processed in parallel on a computing device. The (;) semicolon defaults to (|) behavior in appropriate cases. |
M ~ N; | The set non-conjunction operator (XOR) merges two sets into one set where every A appears in only one set, but not both. |
M &! N; .Rx &! .Ry:B; | The set anti-conjunction operator (NAND) removes memes from the M-set having A-values that appear in N-set. Returns the smaller M-set. |
A.Rx | A.Ry; A.Rx,Ry; | A disjunction of two relations on one A returns a set with both relations and is equivalent to SELECT Rx, Ry in SQL. This sequence is simplified to a comma for brevity. |
.kind:camera ~ .kind:phone & (.price:usd < 1000 | .resolution:megapixels >= 20); | In this example, the query finds a set where each meme belongs to a camera, or a phone, but not an item that is both camera and phone, that is priced less than $1000 or has a resolution greater than or equal to 20 megapixels. For each satisfying A, the output set includes the A.kind, A.price:usd, and A.resolution memes. |
Set Implication Operations
M == N; | The mutual implication operator states that for every M=true also N=true and for every N=true also M=true. Especially used in defining statements whereby M-statements are equivalent to N-statements. |
M => N; | The partial implication operator states that for every M=true also N=true. |
!M => N; M !> N; | Example negative implication such that if M=false then N=true. |
Af == (Af.Rx:Bx=Qx; Af.Ry:By=Qy; ...); | An identifier is defined as the set of all memes containing it. |
(Af => Ag) == (Ag.Rx:Bx=Qx; Ag.Ry:By=Qy; ...); | Here, Ag receives all of Af's relations. The partial implication operator applies the relations from the statement on the right to the statement on the left. |
(Af => Ag.R:B=!Q) == (Ag.Rx:Bx=!Qx; Ag.Ry:By=!Qy; ...); | Here, the !Q on the right applies not to all Qs in Af's relations, making Ag is the opposite of Af. |
Af:Bf => Ag:Bg; | Here, all relations between Af and Bf are applied between Ag and Bg. |
.kind:fruit => .kind:food; | Here, every A that is a fruit is also a food. |
Matrix Relation Operations
The matrix operator takes a set of disjunctive A-sets and performs the described relations on each permutation. The $ is not strictly necessary as a dot would suffice, however the distinction is a reminder that this expression creates a new A-set. Here, an example of a process calculating the hypotenuse between A=Alice and B=Bob as distance.
alice.xcoord:num=1;
alice.ycoord:num=2;
bob.xcoord:num=7;
bob.ycoord:num=12;
$hypotenuse.first:A = true;
$hypotenuse.second:B = true;
$hypotenuse.length:num = ((A.xco - B.xco)^2 + (A.yco - B.yco)^2))^0.5;
alice$hypotenuse:bob => distance;
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 one-dimensional distance in meters between alice and bob. |
SQL Implementation
Memetic-specific tools are under development. In the mean time, memetics can be implemented on conventional SQL databases. Below, the lex table translates ID numbers to strings and the mem table stores ARB memes.
CREATE TABLE lex (
aid bigint(20) UNSIGNED DEFAULT NULL,
rid bigint(20) UNSIGNED DEFAULT NULL,
str varchar(255) DEFAULT NULL,
KEY (aid),
KEY (str)
);
CREATE TABLE mem (
aid bigint(20) UNSIGNED NOT NULL,
rid bigint(20) UNSIGNED NOT NULL,
bid bigint(20) UNSIGNED NOT NULL,
qnt DECIMAL(20,6) DEFAULT NULL,
PRIMARY KEY (aid,rid,bid),
KEY (bid)
);
And here are basic memetic statements translated into SQL:
A | SELECT * FROM mem WHERE aid=A; |
A.R | SELECT * FROM mem WHERE aid=A AND rid=R; |
A.R:B | SELECT * FROM mem WHERE aid=A AND rid=R AND bid=B; |
A.Rx.Ry | SELECT * FROM mem WHERE aid IN (SELECT bid FROM mem WHERE aid=A and rid=Rx) AND rid=Ry; |
A.Rx,Ry | SELECT * FROM mem WHERE aid=A AND rid IN (Rx,Ry); |
.Rx & .Ry | SELECT * FROM mem WHERE aid IN (SELECT aid FROM mem WHERE rid=Rx) AND aid IN (SELECT aid FROM mem WHERE rid=Ry) AND rid IN (Rx,Ry); |
Development
We need you to help us develop Memetics tools such as:
- MySQL plug-in to accept memetic queries
- Postgres plug-in to accept memetic queries
- SQLite plug-in to accept memetic queries
- Ground-up memetic database program
- Memetic immutable blockchain
- Memetic relation visualizer
- Memetic proof assistant
License
Memetics is free for reciprocal public use under the Memetics Public License. Patents pending.