Skip to content

link-foundation/associative-dependent-logic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

associative-dependent-logic

A prototype for logic framework that can reason about anything relative to given probability of input statements.

Overview

ADL (Associative-Dependent Logic) is a minimal probabilistic logic system built on top of LiNo (Links Notation). It allows you to:

  • Define terms
  • Assign probabilities to logical expressions
  • Redefine logical operators with different semantics
  • Query the probability of complex expressions

Installation

npm install

Usage

Running a knowledge base

node src/adl-links.mjs <file.lino>

Or use the npm script:

npm run demo

Example

Create a file example.lino:

# Define a term
(a: a is a)

# Set up operators
(!=: not =)
(and: avg)
(or: max)

# Assign probabilities to axioms
((a = a) has probability 1)
((a != a) has probability 0)

# Query probabilities
(? ((a = a) and (a != a)))   # -> 0.5
(? ((a = a) or  (a != a)))   # -> 1

Run it:

node src/adl-links.mjs example.lino

Output:

0.5
1

Syntax

Term Definitions

(term_name: term_name is term_name)

Example: (a: a is a) declares a as a term.

Probability Assignments

((<expression>) has probability <value>)

Example: ((a = a) has probability 1) assigns probability 1 to the expression a = a.

Operator Redefinitions

Binary operator composition

(operator: unary_op binary_op)

Example: (!=: not =) defines != as the negation of =.

Aggregator selection

For and and or operators, you can choose different aggregators:

(and: avg)   # Average (default)
(and: min)   # Minimum
(and: max)   # Maximum
(and: prod)  # Product
(and: ps)    # Probabilistic sum: 1 - (1-p1)*(1-p2)*...

(or: max)    # Maximum (default)
(or: avg)    # Average
(or: min)    # Minimum
(or: prod)   # Product
(or: ps)     # Probabilistic sum

Queries

(? <expression>)

Queries are evaluated and their probability is printed to stdout.

Comments

# Line comments start with #
(a: a is a)  # Inline comments are also supported

Built-in Operators

  • =: Equality (syntactic by default, can be overridden with probability assignments)
  • !=: Inequality (defined as not = by default)
  • not: Logical negation (1 - p)
  • and: Conjunction (average by default, configurable)
  • or: Disjunction (maximum by default, configurable)

Examples

Standard Logic (with avg semantics)

See demo.lino:

(a: a is a)
(!=: not =)
(and: avg)
(or: max)

((a = a) has probability 1)
((a != a) has probability 0)

(? ((a = a) and (a != a)))   # -> 0.5
(? ((a = a) or  (a != a)))   # -> 1

Flipped Axioms

See flipped-axioms.lino - demonstrates that the system can handle arbitrary probability assignments:

(a: a is a)
(!=: not =)
(and: avg)
(or: max)

((a = a) has probability 0)
((a != a) has probability 1)

(? ((a = a) and (a != a)))   # -> 0.5
(? ((a = a) or  (a != a)))   # -> 1

Testing

Run the test suite:

npm test

The test suite includes:

  • Unit tests for tokenization and parsing
  • Unit tests for evaluation logic
  • Integration tests with example knowledge bases
  • Tests for different operator aggregators

API

The module exports the following functions for programmatic use:

import { run, tokenizeOne, parseOne, Env, evalNode } from './src/adl-links.mjs';

// Run a complete LiNo knowledge base
const results = run(linoText);

// Parse and evaluate individual expressions
const env = new Env();
const ast = parseOne(tokenizeOne('(a = a)'));
const probability = evalNode(ast, env);

License

See LICENSE file.

About

A prototype for logic framework that can reason about anything relative to given probability of input statements.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •