# NAL for Domain Knowledge Encoding

*A worked example from real conversation*

## 1. Motivation

Large language models can answer domain questions — but their answers are probabilistic pattern matches, not grounded inferences. When Peter asked about pigment vs dye ink under matte laminate, an LLM generates plausible text. But what if we could encode that expert knowledge formally, track evidence strength, and derive new conclusions through logic?

Non-Axiomatic Logic (NAL), implemented via MeTTa's `|-` operator, lets us do exactly this. Each fact carries a truth value `(stv frequency confidence)` — how often the relationship holds and how much evidence supports it. Inheritance chains like `pigment_ink → surface_sitting → matte_laminate_safe` become queryable, revisable, and composable.

This article walks through building a printing domain KB from scratch using real conversation data.
## 2. Building Inheritance Chains from Conversation

Peter stated three domain facts: pigment ink sits on paper surfaces, dye ink absorbs deep into pores, and matte coated paper is semi-porous. In NAL, each becomes an inheritance statement with a truth value:

```
(--> pigment_ink surface_sitting) (stv 0.95 0.9)
(--> dye_ink absorbed_deep) (stv 0.9 0.85)
(--> matte_paper semi_porous) (stv 1.0 0.9)
```

The frequency reflects how universally the claim holds; the confidence reflects evidence strength. Peter spoke from direct experience, so confidence is high but not 1.0 — we leave room for revision if contradictory evidence appears.

We then add domain rules as second-order inheritance:

```
(--> surface_sitting ([] matte_laminate_safe)) (stv 0.88 0.85)
(--> absorbed_deep ([] silvering_risk)) (stv 0.75 0.8)
```

The `|-` operator chains these via deduction automatically.

## 3. Deduction via MeTTa

With premises loaded, the MeTTa `|-` operator performs NAL deduction automatically. Given:

```
metta (|- ((--> pigment_ink surface_sitting) (stv 0.95 0.9))
          ((--> surface_sitting ([] matte_laminate_safe)) (stv 0.88 0.85)))
```

The engine returns `(--> pigment_ink ([] matte_laminate_safe)) (stv 0.836 0.6426)`. The frequency drops (0.95 x 0.88 = 0.836) because each link weakens certainty. Confidence drops further (product of all four values) reflecting compounded evidential uncertainty.

Three chains were tested:
- pigment_ink -> surface_sitting -> matte_laminate_safe: stv 0.836 0.64
- dye_ink -> absorbed_deep -> matte_laminate_unsafe: stv 0.738 0.50
- dye_ink -> absorbed_deep -> silvering_risk: stv 0.675 0.46

Each derivation is deterministic and auditable — unlike an LLM response, you can trace exactly which premises produced the conclusion and verify the arithmetic.

## 4. Revision for Evidence Accumulation

What if two independent sources both suggest matte paper causes silvering risk? NAL revision merges their evidence. Both premises must share the same statement term:

```
metta (|- ((--> matte_paper ([] silvering_risk)) (stv 0.8 0.612))
          ((--> matte_paper ([] silvering_risk)) (stv 0.7 0.5)))
```

Result: `(stv 0.7612 0.7205)`. The confidence rose from 0.612 and 0.5 to 0.72 — evidence accumulated. The frequency shifted toward a weighted average. This is not simple averaging; it follows the NAL revision rule where higher-confidence evidence pulls the merged value closer to its frequency.

Critical lesson learned during development: if the two premises have DIFFERENT subjects, the engine performs analogy or abduction instead of revision. Same-term matching is required for true evidence accumulation.

## 5. Querying the Knowledge Base

Once premises are loaded, any new question becomes a deduction query. If someone asks "Is pigment ink safe under matte laminate?" we already have the derived answer: (stv 0.836 0.64) — yes, with moderate confidence. If they ask about dye ink, we get matte_laminate_unsafe at (stv 0.738 0.50) — probable but less certain.

The KB grows with each conversation. New evidence revises existing beliefs. Contradictions surface as low-frequency truth values rather than hidden inconsistencies. And every conclusion carries its evidential provenance.

## Conclusion

This experiment demonstrates that real conversational knowledge can be encoded in NAL via MeTTa, producing auditable inferences with calibrated uncertainty. The printing domain KB built here — from pigment vs dye ink properties through lamination compatibility to silvering risk — is small but functional. The same pattern scales to any domain where expert knowledge arrives incrementally and needs formal tracking.

Key takeaways:
- Encode facts as inheritance with truth values reflecting source reliability
- Chain deductions via `|-` to derive implicit knowledge
- Use same-term revision to accumulate evidence from multiple sources
- Every conclusion is traceable and revisable
