NSR-L Language Reference
NSR-L (Neuro-Symbolic Reasoning Language) is a Prolog-inspired logic programming language designed for symbolic reasoning, constraint specification, and knowledge representation in AI systems.Table of Contents
- Overview
- Lexical Elements
- Terms
- Logical Expressions
- Statements
- Operators
- Built-in Predicates
- List Operations
- Arithmetic
- Constraints
- Negation
- Quantifiers
- Comments
- Complete Grammar
- Examples
Overview
NSR-L combines classical logic programming with modern features for AI guardrails:- First-order logic with variables, predicates, and quantifiers
- Prolog-style rules with
Head :- Bodysyntax - Classical and non-monotonic negation (
~and\+) - Hard and soft constraints for flexible validation
- Arithmetic evaluation with the
isoperator - List operations for data manipulation
- Belief revision with confidence intervals
Hello World
Lexical Elements
Atoms
Atoms are constant identifiers. They must start with a lowercase letter or be quoted.Variables
Variables start with an uppercase letter or underscore._ suppress singleton variable warnings.
Numbers
Strings
Terms
Terms are the fundamental data structures in NSR-L.Constants
Variables
Compound Terms (Functors)
Lists
Lists use square bracket notation with| for head/tail decomposition.
Logical Expressions
Atomic Propositions
Conjunction (AND)
Use& or , for conjunction:
Disjunction (OR)
Use| or ; for disjunction:
Implication
Negation
Statements
NSR-L programs consist of three types of statements:Facts
Facts are ground assertions (no variables, or universally quantified).Rules
Rules define logical implications with head and body.Queries
Queries ask the system to prove or find solutions.Operators
Logical Operators
Comparison Operators
Arithmetic Operators
Operator Precedence (lowest to highest)
:-,->,<->;,|,,&\+,not,~=,\=,<,>,=<,>=,=:=,=\=+,-*,/,//,mod- Unary
-
Built-in Predicates
Unification & Comparison
Type Checking
Arithmetic Evaluation
Arithmetic Functions
Control
List Operations
NSR-L provides Prolog-standard list predicates.member/2
Check if element is in list, or enumerate elements.append/3
Concatenate lists or split a list.length/2
Get or check list length.reverse/2
Reverse a list.nth0/3, nth1/3
Access element by index.last/2
Get last element.sort/2, msort/2
Sort lists.sumlist/2
Sum numeric elements.flatten/2
Flatten nested lists.permutation/2
Generate or check permutations.Arithmetic
The is Operator
Evaluates arithmetic expressions and binds result.
Arithmetic Comparisons
Examples
Constraints
NSR-L supports hard, soft, and weighted constraints for validation.Constraint Types
Defining Constraints in Rules
Constraint API (HTTP)
Negation
NSR-L supports two forms of negation:Classical Negation (~)
Strong negation that asserts the opposite is true.
Negation as Failure (\+ or not)
Weak negation - true if the goal cannot be proven.
Difference
Closed World Assumption
NAF follows the closed-world assumption: if something cannot be proven true, it is assumed false.Quantifiers
NSR-L supports first-order quantifiers.Universal Quantification (forall)
Existential Quantification (exists)
Scoping
Comments
Line Comments
Multi-line Comments (block style in code)
Complete Grammar
EBNF Grammar
Examples
Example 1: Family Relationships
Example 2: Customer Service Rules
Example 3: Arithmetic and Lists
Example 4: Belief Revision and Constraints
Error Messages
NSR-L provides helpful error messages with source locations:Common Errors
API Endpoints
Example API Call
Best Practices
1. Use Descriptive Predicate Names
2. Handle Edge Cases
3. Use Anonymous Variables
4. Document with Comments
5. Avoid Infinite Recursion
Related Documentation
- Temporal Agent Orchestration - Integration guide
- Recursive Policy Learning - Self-improving rules