This project implements the core systems of the OpenCog cognitive architecture entirely in Pure Maude, leveraging rewriting logic to model hypergraphs, probabilistic reasoning, attention allocation, and evolutionary program search.
OpenCog's architecture revolves around a hypergraph database called the AtomSpace, where nodes and links (Atoms) represent knowledge, and cognitive processes (MindAgents) operate concurrently over this graph.
Maude is a high-performance reflective language and system supporting both equational and rewriting logic specification and programming. It turns out that Maude's algebraic data types and multiset rewriting rules are a highly natural fit for modeling OpenCog:
- AtomSpace as a Multiset: The AtomSpace is simply a multiset ("soup") of annotated atoms (Atoms paired with TruthValues and AttentionValues).
- MindAgents as Rewrite Rules: Cognitive processes like PLN inference, ECAN attention spreading, and MOSES mutation are expressed directly as conditional rewrite rules over the AtomSpace multiset.
- Control via Strategy/Search: Maude's built-in search and strategy languages naturally map to the Unified Rule Engine's (URE) forward and backward chaining.
The implementation consists of the following modules:
truth-value.maude(OC-TRUTH-VALUE): Probabilistic truth values (Strength, Confidence) and their algebraic operations (And, Or, Negate, Revision).attention-value.maude(OC-ATTENTION-VALUE): Attention values (Short-Term Importance, Long-Term Importance, VLTI) for resource allocation.atom-types.maude(OC-ATOM-TYPES): The complete OpenCog Atom type hierarchy (180+ types) encoded as a Maude sort lattice.atom-space.maude(OC-ATOM-SPACE,OC-ATOM-SPACE-QUERY): The hypergraph store, modeled as an associative-commutative multiset of annotated atoms, with query and graph traversal operations.
pln.maude(OC-PLN-FORMULAS,OC-PLN-RULES): The probabilistic reasoning engine. Implements PLN formulas (Deduction, Modus Ponens, Induction, Abduction) and the corresponding inference rules that derive new links from existing knowledge.
ecan.maude(OC-ECAN-CONFIG,OC-ECAN): The attention allocation subsystem. Implements asymmetric and symmetric Hebbian importance spreading, rent collection, forgetting (garbage collection), and Hebbian learning (link weight updates based on co-activation).
moses.maude(OC-COMBO,OC-COMBO-EVAL,OC-MOSES-POPULATION,OC-MOSES-EVOLVE): The program learning system. Implements the COMBO functional language (Boolean and Arithmetic expression trees), evaluation environments, populations (Demes), and evolutionary operators (mutation rules).
ure.maude(OC-URE-RULE-BASE,OC-URE-FORWARD-CHAINER,OC-URE-BACKWARD-CHAINER,OC-COG-SERVER,OC-PATTERN-MATCHER,OPENCOG): The Unified Rule Engine (URE) for forward and backward chaining, pattern matching via substitutions, and the CogServer which rotates execution among the MindAgents.
execution-engine.maude(OC-EXECUTION-ENGINE): Atomese Execution Engine (Lambda calculus, beta-reduction, arithmetic eval, PutLink, CondLink, SequentialAnd).pattern-matcher.maude(OC-GRAPH-MATCH): Full first-order unification and graph pattern matching (BindLink, MeetLink, QueryLink, SatisfactionLink).pattern-miner.maude(OC-PATTERN-MINER): Frequent subgraph pattern mining with support counting and I-Surprisingness.spacetime.maude(OC-SPACETIME): Allen's 13 interval relations, TimeServer, temporal inference rules, and spatial bounding boxes.ghost-psi.maude(OC-OPENPSI-ENGINE): OpenPsi motivational system (demands, modulators, action-selection) and GHOST dialogue rules (responder, gambit, rejoinder).meta-opencog.maude(OC-META): Meta-level reflection for cognitive synergy (type introspection, strategy selection, self-modification, inference monitoring).
reflective-engine.maude(OC-REFLECTIVE-INFERENCE): Gödel Machine layer — rules-as-data with effectiveness tracking, adaptive pruning, and MaudeMETA-LEVELintrospection.model-check-cog.maude(OC-COG-CHECK): LTL model-checking of cognitive safety and liveness properties over the AtomSpace as a Kripke structure.narrowing-abduce.maude(OC-NARROW-KB): Complete symbolic abduction via Maude narrowing — given a goal, find all explanatory initial states.parameterized-cog.maude(BIO-PLN,SOCIAL-PLN,PHYS-PLN): Algebraic transfer learning via parameterized PLN modules instantiated over Biology, Social, and Physics domains.cognitive-cycle.maude(OC-COGNITIVE-CYCLE): Strategy-controlled cognitive heartbeat — composablesmodstrategies for perceive, attend, reason, act, learn cycles.autogenesis.maude(OC-AUTOGENESIS): Emergent goal generation — the system introspects its own drives/metrics and generates new goals via seven autogenesis rules, with safety verification.
cognitive-chemistry.maude(OC-ELEMENTS,OC-MOLECULES,OC-REACTIONS,OC-FIVE-STONES,OC-BOOTSTRAP): The Periodic Table of Cognition — atom types mapped to chemical elements with valence/bonding rules; molecular formation via reactions; alchemical transmutation of five emergent types (OpenCog, Wisdom, Philosophia, Monad, Yggdrasil) culminating in GNOSIS; bootstrap loop installing discovered types at runtime.
You need Maude 3.0+ installed to run the system.
To run the Phase 1 core integration test suite (48 assertions):
maude test-opencog.maudeTo run the Phase 2 advanced subsystem test suite (56 assertions):
maude test-new-modules.maudeBoth test suites perform equational reductions and state-space searches, verifying everything from truth value arithmetic to URE forward chaining derivations and full lambda beta-reduction.
In Maude, PLN inference rules are applied using the search command to find paths through the state space. For example, to perform a deduction:
search [1] in OC-PLN-RULES :
[concept("cat"), stv(1.0, 0.9), defaultAV]
[concept("animal"), stv(1.0, 0.9), defaultAV]
[concept("living-thing"), stv(1.0, 0.9), defaultAV]
[inheritance(concept("cat"), concept("animal")), stv(0.9, 0.8), defaultAV]
[inheritance(concept("animal"), concept("living-thing")), stv(0.85, 0.7), defaultAV]
=>+ AS:AtomSpace
such that
hasAtom(AS:AtomSpace, inheritance(concept("cat"), concept("living-thing"))) == true .
This searches for a state where the inheritance(cat, living-thing) link has been derived, successfully returning the AtomSpace containing the new link with its calculated truth value stv(1.0, 0.6996).
The OpenPsi engine tracks demands (e.g., "energy") and selects actions based on urgency and context. As "energy" urgency increases over time, the system will eventually fire the highest-weight PsiRule that satisfies the demand (e.g., eating when hungry):
crl [psi-fire-rule] :
psiState(
[Ctx, TV, AV] AS,
psiDemand(DN, DU, DT) ;; DS,
MS,
psiRule("r", Ctx, Act, DN, RW) ;; PRS,
GRS, Topic, N)
=>
psiState(
[Ctx, TV, AV] [Act, stv(1.0, 0.9), AV] AS,
psiDemand(DN, clamp01(DU - 0.1), DT) ;; DS,
MS,
psiRule("r", Ctx, Act, DN, RW) ;; PRS,
GRS, Topic, N + 1)
if DU > 0.3 /\ tvStrength(TV) > 0.5 .
Run the full test suite (6 test files, 400+ assertions and searches):
# Phase 1 — core integration tests
python3 .github/scripts/validate-tests.py test-opencog.maude
# Phase 2 — advanced subsystem tests
python3 .github/scripts/validate-tests.py test-new-modules.maude
# Comprehensive coverage tests (all untested modules)
python3 .github/scripts/validate-tests.py test-coverage.maude
# Algebraic property tests (Phase 6.3)
python3 .github/scripts/validate-tests.py test-properties.maude
# Phase 7 AGI-native capability tests (reflection, model-checking, narrowing, etc.)
python3 .github/scripts/validate-tests.py test-phase3.maude
# Cognitive Chemistry tests (elements, bonds, molecules, alchemy, bootstrap)
python3 .github/scripts/validate-tests.py test-chemistry.maudeBenchmarks can be run directly with Maude (set show timing on reports rewrite-step counts):
maude bench-pln.maude # PLN deduction chains of depth 1–4
maude bench-ecan.maude # ECAN spreading and forgetting
maude bench-pattern-miner.maude # pattern mining at various dataset sizes- truth-value.maude: Added
tvAnd/tvOr/tvRevision/tvNegateforctvanditvvariants. General[owise]fallbacks handle mixed-type operands by projecting to strength/confidence. - attention-value.maude: Fixed non-linear
setVLTIequation (wasV = V; now uses distinctV2). - atom-space.maude: Added
mergeTV(applies PLN revision if atom already exists) andgetAtomList(enumerates all atom keys in the space). - pln.maude: Deduction rule now checks
not hasAtom(…, inheritance(A,C))to prevent duplicate derivation. Induction and abduction require minimum confidence ≥ 0.1. - ecan.maude: Added
totalSTI/normalizeSTIto the config module; newOC-ECAN-PARAMsystem module providesecanState-wrapped, fully parameterised versions of every spreading, rent, forgetting, and Hebbian rule.
- ure.maude: Added
maxWeightRulefor weighted rule selection; BC modus-ponens decomposition rule;emptyRBtotal-weight invariant. - cogserver-full.maude: New
OC-COG-SERVER-FULLmodule withCogServerFull— addsInferenceStrategyandAppRecordSetto the server state;csf-cyclerecords per-rule attempts;csf-switch-strategyrotates the strategy when success rate falls below 0.2. - pattern-matcher.maude: Multi-clause
BindLinkmatching viaandLinkpatterns; newOC-TYPED-UNIFICATIONmodule forTypedVariableLinktype-constrained unification; newOC-GLOB-MATCHmodule forGlobNodesequence matching. - moses.maude: New
OC-MOSES-FITNESSmodule addsDataSet/DataPointtypes andevalFitness : BoolExpr DataSet -> Float;OC-MOSES-FITNESS-EVOLVEwires fitness evaluation into the metapopulation loop.
- ghost-psi.maude:
psi-fire-rulenow increments STI ofCtxandActatoms (ECAN coupling); newpsi-demand-decayhomeostasis rule; newghost-rejoinderandghost-record-topicrules for multi-turn dialogue. - pattern-miner.maude:
mine-inh-patternnow injects a PLNInheritanceLinkwith TV derived from support fraction and I-Surprisingness; newOC-PATTERN-GENERALISEmodule providesgeneralise,extendPattern, andextendMinedPattern.
- meta-opencog.maude:
OC-SELF-MODIFYnow carries aURRuleBaseinSelfModState;register-typeinjects a corresponding PLN deduction rule into the base; newadapt-strategyremoves under-performing rules (success rate < 0.1 after ≥ 10 attempts); newpromote-ruleboosts well-performing rules. - meta-maude.maude (new):
OC-META-MAUDEwraps Maude's built-inMETA-LEVEL(without importingOC-ATOM-SPACEto avoid_,_conflicts); exposesdoMetaReduce,doMetaApply,doMetaSearch.OC-META-QUOTEprovides module qids and atom-quoting helpers.
- io-bridge.maude (new):
OC-SCHEME-SERIALserialises anyOcAtomto Scheme S-expression or JSON strings;OC-EXTERNAL-SYNCprovides a stubimportAtomshook for future REST/Python bridge integration;OC-ROBOTICSmodels sensor and actuator atoms (sensorSonar,motorMove,speechSay) and atick-decayrule that ages short-lived atoms by −5 STI per cycle.
- reflective-engine.maude (new):
OC-REFLECT-TERMS,OC-META-OPS,OC-REFLECTIVE-INFERENCE,OC-DERIVABILITY-CHECK— the Gödel Machine layer; rules reified as data with effectiveness tracking;mostEffective/leastEffectiveselection;adapt-rulepruning; MaudeMETA-LEVELintrospection viacogModuleName. - model-check-cog.maude (new):
OC-COG-STATE,OC-COG-PREDS,OC-COG-TRANSITIONS,OC-COG-CHECK— cognitive Kripke structure for Maude's built-in LTL model checker; propositionsnoContradiction,budgetRespected,hasKnowledge; state-space transitions for PLN inference and ECAN spreading. - narrowing-abduce.maude (new):
OC-NARROW-KB— constructor-based knowledge base enabling Maudevu-narrow/searchfor complete symbolic abduction; deduction, modus-ponens, and similarity-to-inheritance rules over a narrowing-ready term algebra. - parameterized-cog.maude (new):
COGNITIVE-DOMAINfunctional theory;PLN-CORE{D}parameterized PLN module;BIO-PLN,SOCIAL-PLN,PHYS-PLNinstantiations via views — algebraic transfer learning across Biology, Social, and Physics domains. - cognitive-cycle.maude (new):
OC-CYCLE-STATE,OC-COGNITIVE-CYCLE— strategy-controlled cognitive cycle using Maude'ssmod; composable strategiesperceive,attend,reason,act,learn,tick,basicCycle,deliberative,reactive,drainPercepts. - autogenesis.maude (new):
OC-INTROSPECTION,OC-GOAL-GENERATOR,OC-AUTOGENESIS— emergent goal generation; seven autogenesis rules (exploration, inference-boost, attention-rebalance, drive-satisfaction, meta-learning, social, creativity); six-phase autogenesis loop (introspect → analyze → generate → verify → install → execute) with bounded-iteration safety check.
- cognitive-chemistry.maude (new):
OC-ELEMENTS,OC-MOLECULES,OC-REACTIONS,OC-FIVE-STONES,OC-BOOTSTRAP— the Periodic Table of Cognition; 20 cognitive elements (helium through gold) with atomic number, symbol, period, group, valence, and electronegativity; covalent/ionic/metallic bond classification; molecular formation via synthesis reactions; five alchemical stones (OpenCog, Wisdom, Philosophia, Monad, Yggdrasil); bootstrap loop that installs discovered emergent types into aTypeRegistry.
- test-properties.maude (new): Algebraic laws —
tvAnd/tvOrcommutativity and associativity,mergeTVidempotence, ECAN rent monotonicity, forgetting termination,normalizeSTIbudget invariant,tvRevisioncommutativity, PLN duplicate-derivation guard. - bench-pln.maude (new): PLN deduction benchmarks over taxonomy chains of depth 1–4.
- bench-ecan.maude (new): ECAN benchmarks — single-hop spreading, chain spreading, symmetric equilibration, parameterised ECAN.
- bench-pattern-miner.maude (new): Pattern miner benchmarks — small/medium datasets, mixed link types, support count accuracy, I-Surprisingness range.
AGPL-3.0 (following OpenCog).