Task Recipes
This page answers: I have a specific modeling job to do — what are the steps?
Recipes are minimal: enough to get started, with cross-links to the chapter or RFD that explains the why.
I want to declare a new concept
- Pick the metatype from your foundational-ontology package (most commonly UFO’s
kind,subkind,role,phase, etc.). - Decide whether it specializes an existing concept and what its world assumption is.
- Add
whereclauses for structural constraints (RFD-0018). - Make it
pubif downstream packages should use it.
use ufo::prelude::*;
use std::math::Nat;
pub kind Person <: Agent
where {
age >= 0,
}
See ch02-02.
I want to declare a relation between concepts
- Decide endpoints (source and target concepts).
- If it’s a recognized algebraic shape (transitive, symmetric, …), add the matching decorator.
- If it has metarel semantics (mediation, externally-dependent), use
:: <Metarel>. - Add cardinality constraints if needed.
@[transitive]
pub rel ancestor_of(a: Person, b: Person)
pub rel mediates(c: Commitment, p: Person) :: Mediation {
cardinality: 1..1,
}
I want to write a derivation rule
- Identify the head — what fact is being derived.
- Identify the body — what facts must hold for the head to follow.
- Write
pub derive head(args) :- body_atoms. - If the rule is meant to apply only when no override fires, leave it
pub derive(defeasible). If it’s an unconditional theorem, usepub strict. - Add
@[theorem]if the rule should be machine-verified.
pub derive adult(P) :- Person(P), age(P, A), A >= 18
Multi-head disjunction: write multiple rules with the same head and consistent strength.
I want to retrieve facts by pattern
- Write a
querydeclaration with a Prolog-style:-body. - Project the result with
=> head_expression.
query adults() :-
Person(P),
age(P, A),
A >= 18,
=> P
Every result carries why-provenance. See ch02-05, RFD-0007.
I want to apply a state transition
- Write a
mutationdeclaration withrequire(preconditions),do(assignments), optionalretract(negative facts), optionalemit(events),return(response). - The mutation will record its transition trace as provenance.
mutation hire(o: Organization, p: Person) {
require { not works_at(p, _) }
do { works_at(p, o); }
emit { Hiring(o, p) }
return p;
}
See ch02-05.
I want a calculation that returns a value
- Pick the compute form (see decision-guides.md#which-compute-form).
- Form 1 for one-shot, Form 2 for multi-step tier-bounded, Form 3 for native FFI.
// Form 1
compute gain(s: Sale) -> Money = s.proceeds - s.basis
// Form 2
compute classified_gain(s: Sale) {
input { s: Sale }
out { kind: String, amount: Money }
ensure { s.proceeds >= 0 }
body {
let amount = s.proceeds - s.basis;
let kind = if amount > 0 { "gain" } else if amount < 0 { "loss" } else { "wash" };
{ kind: kind, amount: amount }
}
}
I want to write a test
- Use
test <name> { ... }. - Set up state with assertions or with a
fixture { ... }block. - Use
expectto assert specific diagnostics or values. - Mark with
#[unproven]or#[assumed]if appropriate.
test adult_classification {
fixture {
assert Person(alice);
assert age(alice, 25);
}
expect { result adult(alice) at //~ check }
} //~ check
I want to model a recurring shape (correlative pair, part-whole, etc.)
Use a pattern. Either reach for a bespoke surface form (correlative_pair, part_whole) or write pub pattern <name> { ... } and instantiate with use pattern <name><types> as <instance>.
I want to escalate beyond the default tier
- Identify which tier you need (see decision-guides.md#when-to-escalate-tier).
- Add
#dec(<tier>)at module / block / declaration scope. - For full FOL, wrap the relevant block in
unsafe logic { ... }.
#dec(tier:expressive)
pub derive complex_classification(X) :- ...
See tier-selection.md, ch05-03, RFD-0004.
I want to include a foundational ontology
- Add the package to your
ox.toml[dependencies]. usethe foundational ontology’s prelude in your modules.- Refer to its metatypes by name.
# ox.toml
[dependencies]
ufo = "0.3.0"
use ufo::prelude::*;
pub kind Person <: Agent { ... }
I want to render a diagram
- Add a
diagramblock. - Specify which concepts/relations to include and a layout algorithm.
diagram TaxRoles {
concepts { Person, Taxpayer, Withholding_Agent }
relations { works_at, withholds_from }
layout: sugiyama;
}
I see an OE#### error and don’t know what it means
- Run
ox explain OE####for the canonical long-form explanation. - Cross-reference error-recovery.md for common diagnostics with action hints.
- Full reference: Appendix C.
See also
- Quick reference — syntax for every form.
- Decision guides — picking between alternatives.
- Anti-patterns — what to avoid.
- Idioms — what works well.