Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@ tagged after the fact, on their version-bump commits.

## [1.8.2] - Unreleased

Fixes to the v1.8.1 solver resource controls.
Fixes to the v1.8.1 solver resource controls, plus emitter, REPL and prover fixes.

### Fixed
- **Repeated bounds in generated Python and Java.** A subclass that restated an inherited
bound produced `Field(le=90, ge=0, le=130)` or two `@Max` annotations, which neither
language accepts. The IR now keeps only the tightest lower and upper bound per property.
- **Invalid `openapi.yaml` for subclasses with their own properties.** Their properties
were emitted one level too shallow under `allOf`; they are now nested correctly.
- **`:explain` / `--explain-unsat` answered SAT after `:solve` reported UNSAT.** The unsat-core
query left out the property bound assertions the consistency check makes. It now includes
them, named, so the core cites the conflicting bounds.
- **Native prover and Vampire missed plain numeric-bound conflicts** (a universal `gte 100`
with an existential `lt 50`). Both now receive background axioms for each pair of bounds
that no number satisfies together. The native prover also reads a bare property name in a
comparison as that property of the quantified entity, as the SMT and TPTP backends do,
instead of as a free variable. Conflicts that need real arithmetic (integer gaps) still need
Z3 or CVC5.
- **VS Code snippets expanded to obsolete syntax.** They now use the current grammar, and the
extension README and `build_extension.sh` report the real package version.
- **`--solve-timeout` was ignored by CVC5.** `--tlimit` was passed after the `-` stdin
marker, where cvc5 ignores options. It now comes before `-`.
- **Timeouts behave the same on every backend.** External solvers now also run under a
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/axioms-and-reasoning.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ A model is one possible world, usually a tiny one. Concepts that are empty in th
| `native` | Built into the binary (tableau and resolution). No install needed; honours `-T`; reports unknown on step or clause limits |
| `auto` | Tries `z3`, `cvc5`, `vampire` in order, skipping any that is not installed; if none is installed, falls back to `native`. A solver that is installed but fails is reported, not skipped |

Practical guidance: use `z3` or `cvc5` for ontologies with numeric property bounds. On the balance example above, `z3` and `cvc5` report UNSAT while `native` and `vampire` report SAT, because they do not reason about the numeric comparisons the way an SMT solver does. The domain fixtures in `test/fixtures/domains/` are checked with Z3 (then CVC5) for the same reason. For purely taxonomic and relational reasoning, all backends agree. If two provers disagree, trust UNSAT from an SMT solver and treat the other's SAT as incomplete.
Practical guidance: use `z3` or `cvc5` for ontologies with numeric property bounds. `native` and `vampire` have no arithmetic. OntoLogic gives them one background axiom for each pair of numeric bounds in the file that no number can meet together (such as `gte 100` and `lt 50`), so they catch contradictions like the balance example above. They still miss contradictions that need real arithmetic, such as integer gaps (`gt 5` and `lt 6` on an `Integer`) or bounds derived from sums. The domain fixtures in `test/fixtures/domains/` are checked with Z3 (then CVC5) for this reason. For purely taxonomic and relational reasoning, all backends agree. If two provers disagree, trust UNSAT from an SMT solver and treat the other's SAT as incomplete.

## Time and memory limits

Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/editor-and-lsp.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The extension activates for `.logic` files (language id `ontologic`). It finds t
### Features

- TextMate syntax highlighting and bracket/comment configuration.
- Snippets for `def-concept`, `def-concept-subclass`, `def-relation`, `axiom`, `axiom-forall`, and `import`. **Caution:** the concept, axiom, and subclass snippets were written for an older syntax (`(subclass-of ...)`, `(axiom ...)`, `=>`, inline property lists, `between`) and expand to forms the current parser rejects. Only `def-relation` and `import` expand to valid code; write concepts and axioms as shown in the [Language reference](language-reference.md).
- Snippets: `def-concept`, `def-concept-subclass`, `def-property`, `def-property-optional`, `def-relation`, `def-individual`, `forall-bound`, `forall-range`, `exists`, and `import`. Each expands to current syntax (see the [Language reference](language-reference.md)).
- Everything in the table above via the language server.

### Commands
Expand Down
1 change: 0 additions & 1 deletion docs/user-guide/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ ontologic> :prove Vehicle Truck
- There are no `-T`/`--solve-timeout` or `--solve-memory` controls; for bounded runs use the CLI.
- `:solve` always prints the model on SAT; the CLI needs `--inspect-model`.
- `:prove` exists only here.
- `:explain` reports "No contradictory axioms or unsat cores detected" when the solver returns an empty core, which can happen even when `:solve` has just reported UNSAT. If so, rely on the `:solve` verdict and read the lint message.
- Malformed input prints a parse error with a caret and leaves the session unchanged:

```text
Expand Down
5 changes: 1 addition & 4 deletions docs/user-guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Contradictions can be reported twice (once per operand order); fix the first and

### SAT from one prover, UNSAT from another

The native prover and Vampire do not interpret numeric comparisons the way Z3 and CVC5 do. An ontology with contradictory numeric bounds that the linter did not catch (for example a universal lower bound and an existential witness below it) is UNSAT under `-p z3` or `-p cvc5` and can look SAT under `-p native` or `-p vampire`. Prefer Z3 or CVC5 whenever properties have numeric bounds.
The native prover and Vampire have no arithmetic. They are told which pairs of numeric bounds in the file exclude each other, so a plain conflict (a universal `gte 100` and an existential witness with `lt 50`) is UNSAT on every backend. A contradiction that needs real arithmetic, such as an integer gap (`gt 5` and `lt 6` on an `Integer`), is UNSAT under `-p z3` or `-p cvc5` and can look SAT under `-p native` or `-p vampire`. Prefer Z3 or CVC5 whenever properties have numeric bounds.

### Auto picked the native prover

Expand All @@ -71,14 +71,11 @@ The native prover and Vampire do not interpret numeric comparisons the way Z3 an
| No warning for `owl`, `shacl`, `smt`, `neo4j`, ... | They do not warn by default; add `--warn-unmapped` |
| Output file overwritten | File names are fixed per target; use a separate `-o` directory per ontology |
| `mmdc ... not found or failed` / `d2 CLI not found or failed` | Install the renderer or drop `--render`; see [Visualization](visualization.md) |
| Generated Python or Java has the same bound repeated | Known limitation (as of 1.8.2): when a subclass restates a bound on a property it inherits, for example `Field(le=90, ge=0, le=130)`, the emitter lists both the subclass and inherited bounds. Python rejects a repeated keyword and Java rejects a repeated annotation. Put each bound on one concept only |
| `openapi.yaml` fails to parse when a subclass has its own properties | Known limitation (as of 1.8.2): the properties of such a subclass are emitted at the wrong indentation. Check generated YAML before use, or use `jsonschema` |

## REPL and editor

| Symptom | Fix |
|---------|-----|
| REPL `:explain` says "No contradictory axioms" right after `:solve` reported UNSAT | The solver returned an empty core; rely on `:solve` and the lint message |
| REPL form spans several lines and fails | Each REPL line is parsed on its own; put the whole form on one line |
| Editor shows no diagnostics | Check the "OntoLogic" output channel; run "OntoLogic: Restart Language Server"; make sure `ontologic-lsp` is found (set `ontologic.lsp.path`) |
| Editor reports undeclared library concepts | `ONTOLOGIC_PATH` must be set in the environment the editor was launched from |
Expand Down
6 changes: 3 additions & 3 deletions editors/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ Official Visual Studio Code extension for **OntoLogic** — First-Order Logic Do
- **Context-Aware Autocompletion**: Keywords, primitive types, concept classes, and properties.
- **Type Definition & Hover**: Hover over concept names to inspect class inheritance and typed bounds.
- **Jump to Definition**: Jump directly to concept declarations across files.
- 🧩 **Code Snippets**: Quick templates for `def-concept`, `subclass-of`, `def-relation`, `axiom`, and `import`.
- 🧩 **Code Snippets**: Quick templates for `def-concept` (with or without a parent), `def-property`, `def-relation`, `def-individual`, `forall` bound/range axioms, `exists` axioms, and `import`.
- 🔍 **Interactive SMT Solver Integration**: Trigger Z3 and CVC5 satisfiability checks and concept emptiness tests directly from the editor command palette.

---

## Installation & Setup

1. Install the `ontologic-1.0.0.vsix` extension package:
1. Install the `ontologic-1.3.0.vsix` extension package:
```bash
code --install-extension ontologic-1.0.0.vsix
code --install-extension ontologic-1.3.0.vsix
```
2. Ensure `ontologic-lsp` is in your `PATH` (e.g., `~/.local/bin/ontologic-lsp`) or configure `ontologic.lsp.path` in Settings.

Expand Down
3 changes: 2 additions & 1 deletion editors/vscode/scripts/build_extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ npm run compile
echo "==> Packaging VSIX extension..."
npx @vscode/vsce package --no-git-tag-version

echo "==> VSIX Package created at $EXT_DIR/ontologic-1.0.0.vsix"
VERSION="$(node -p "require('./package.json').version")"
echo "==> VSIX Package created at $EXT_DIR/ontologic-$VERSION.vsix"
67 changes: 41 additions & 26 deletions editors/vscode/snippets/ontologic.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
{
"Define Concept": {
"prefix": "def-concept",
"body": [
"(def-concept ${1:ConceptName}",
" (${2:propertyName} ${3|String,Integer,Float,Double,Boolean,DateTime,Decimal,URI|})$0)"
],
"description": "Define a new ontology concept with properties"
"body": ["(def-concept ${1:ConceptName})$0"],
"description": "Define a new ontology concept"
},
"Define Concept with Subclass": {
"Define Concept with Parent": {
"prefix": "def-concept-subclass",
"body": [
"(def-concept ${1:SubclassName} (subclass-of ${2:ParentName})",
" (${3:propertyName} ${4|String,Integer,Float,Double,Boolean,DateTime,Decimal,URI|})$0)"
],
"description": "Define a new ontology subclass inheriting from a parent concept"
"body": ["(def-concept ${1:SubclassName} ${2:ParentName})$0"],
"description": "Define a concept that specialises (is subsumed by) a parent concept"
},
"Define Property": {
"prefix": "def-property",
"body": ["(def-property ${1:propertyName} ${2:ConceptName} ${3|Integer,Float,Double,String,Boolean|})$0"],
"description": "Define a typed data property on a concept"
},
"Define Optional Property": {
"prefix": "def-property-optional",
"body": ["(def-property ${1:propertyName} ${2:ConceptName} ${3|Integer,Float,Double,String,Boolean|} :cardinality ${4|0..1,1..1,0..*,1..*|})$0"],
"description": "Define a data property with an explicit cardinality"
},
"Define Relation": {
"prefix": "def-relation",
"body": ["(def-relation ${1:relationName} ${2:DomainConcept} ${3:RangeConcept})$0"],
"description": "Define a binary relational association between concepts"
},
"Define Individual": {
"prefix": "def-individual",
"body": ["(def-individual ${1:individualName} ${2:ConceptName})$0"],
"description": "Declare a named individual of a concept"
},
"Universal Bound Axiom": {
"prefix": "forall-bound",
"body": [
"(def-relation ${1:relationName} ${2:DomainConcept} ${3:RangeConcept})"
"(forall (${1:x})",
" (implies (${2:ConceptName} ${1:x})",
" (${3|gte,gt,lte,lt,eq,ne|} ${4:propertyName} ${5:0})))$0"
],
"description": "Define a binary relational association between concepts"
"description": "Every instance of a concept satisfies a bound on a property"
},
"Axiom Constraint": {
"prefix": "axiom",
"Universal Range Axiom": {
"prefix": "forall-range",
"body": [
"(axiom (${1|gt,gte,lt,lte,eq,neq,between|} (${2:propertyName} ${3:x}) ${4:bound}))"
"(forall (${1:x})",
" (implies (${2:ConceptName} ${1:x})",
" (and (gte ${3:propertyName} ${4:0}) (lte ${3:propertyName} ${5:100}))))$0"
],
"description": "Define an axiomatic constraint on a concept property"
"description": "Every instance of a concept keeps a property within [min, max]"
},
"Axiom Universal Quantifier": {
"prefix": "axiom-forall",
"Existential Axiom": {
"prefix": "exists",
"body": [
"(axiom (forall (${1:x})",
" (=> (${2:ConceptName} ${1:x})",
" (and (${3|gt,gte,lt,lte,eq,neq,between|} (${4:propertyName} ${1:x}) ${5:bound})))))"
"(exists (${1:x})",
" (and (${2:ConceptName} ${1:x}) (${3|gte,gt,lte,lt,eq,ne|} ${4:propertyName} ${5:0})))$0"
],
"description": "Define a quantified first-order logic axiom"
"description": "Assert that some instance of a concept exists with a property condition"
},
"Import File": {
"prefix": "import",
"body": [
"(import \"${1:ontologic-lib/bfo_2020.logic}\")"
],
"body": ["(import \"${1:ontologic-lib/bfo_2020.logic}\")$0"],
"description": "Import an external ontology definition file"
}
}
1 change: 1 addition & 0 deletions ontologic.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ test-suite ontologic-test
ProtobufSpec
PythonSpec
RegistrySpec
RegressionBugsSpec
RelationSpec
REPLSpec
ResolutionSpec
Expand Down
37 changes: 20 additions & 17 deletions src/Emitters/OpenApi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ emitOpenApiSchema cls =
propsBlock :: String -> [CompiledProperty] -> String
propsBlock indent ps
| null ps = indent ++ "properties: {}\n"
| otherwise = indent ++ "properties:\n" ++ concatMap emitOpenApiField ps
| otherwise = indent ++ "properties:\n" ++ concatMap (emitOpenApiField (indent ++ " ")) ps

emitOpenApiField :: CompiledProperty -> String
emitOpenApiField p =
-- | Emit one property entry; @ind@ is the indentation of the property key, which must sit one
-- level under its @properties:@ key (deeper for subclasses, whose properties live in @allOf@).
emitOpenApiField :: String -> CompiledProperty -> String
emitOpenApiField ind p =
let fName = sanitizeIdent (compPropName p)
pType = compPropType p
constraints = compConstraints p
Expand All @@ -66,24 +68,25 @@ emitOpenApiField p =
PTCustom c -> indent ++ "$ref: '#/components/schemas/" ++ sanitizeIdent c ++ "'\n"
_ -> indent ++ "type: " ++ openApiTypeName pType ++ "\n" ++
concatMap (emitOpenApiConstraint indent) constraints
ind2 = ind ++ " "
in case compCardinality p of
CardZeroOrMore ->
" " ++ fName ++ ":\n" ++
" type: array\n" ++
defLine " " ++
" items:\n" ++
typeLines " "
ind ++ fName ++ ":\n" ++
ind2 ++ "type: array\n" ++
defLine ind2 ++
ind2 ++ "items:\n" ++
typeLines (ind2 ++ " ")
CardOneOrMore ->
" " ++ fName ++ ":\n" ++
" type: array\n" ++
" minItems: 1\n" ++
defLine " " ++
" items:\n" ++
typeLines " "
ind ++ fName ++ ":\n" ++
ind2 ++ "type: array\n" ++
ind2 ++ "minItems: 1\n" ++
defLine ind2 ++
ind2 ++ "items:\n" ++
typeLines (ind2 ++ " ")
_ ->
" " ++ fName ++ ":\n" ++
defLine " " ++
typeLines " "
ind ++ fName ++ ":\n" ++
defLine ind2 ++
typeLines ind2

formatOpenApiDefault :: PropertyType -> String -> String
formatOpenApiDefault PTString s = show s
Expand Down
57 changes: 49 additions & 8 deletions src/Emitters/SMT.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Emitters.SMT
( emitSMT
, emitSMTDeclarations
, emitSMTDeclarationsNamed
, emitPropertyFunction
, smtNumeral
, mapSmtType
Expand Down Expand Up @@ -61,16 +62,56 @@ emitPropertyFunction cName p =
in decl ++ concatMap (emitPropertyAssertion cName fName pType) (compConstraints p)

emitPropertyAssertion :: String -> String -> PropertyType -> BoundConstraint -> String
emitPropertyAssertion cName fName pType (BoundConstraint op val) =
emitPropertyAssertion cName fName pType c =
"(assert " ++ propertyAssertionBody cName fName pType c ++ ")\n"

propertyAssertionBody :: String -> String -> PropertyType -> BoundConstraint -> String
propertyAssertionBody cName fName pType (BoundConstraint op val) =
let app = "(" ++ fName ++ " " ++ cName ++ ")"
lit = smtNumeral pType val
in case op of
OpGt -> "(assert (> " ++ app ++ " " ++ lit ++ "))\n"
OpGte -> "(assert (>= " ++ app ++ " " ++ lit ++ "))\n"
OpLt -> "(assert (< " ++ app ++ " " ++ lit ++ "))\n"
OpLte -> "(assert (<= " ++ app ++ " " ++ lit ++ "))\n"
OpEq -> "(assert (= " ++ app ++ " " ++ lit ++ "))\n"
OpNe -> "(assert (distinct " ++ app ++ " " ++ lit ++ "))\n"
rel = case op of
OpGt -> ">"
OpGte -> ">="
OpLt -> "<"
OpLte -> "<="
OpEq -> "="
OpNe -> "distinct"
in "(" ++ rel ++ " " ++ app ++ " " ++ lit ++ ")"

-- | 'emitSMTDeclarations' with every property bound assertion named, so an unsat core can
-- cite it. Returns the SMT text plus (name, description) pairs for each named bound.
-- The consistency check asserts these bounds, so the unsat-core theory must assert them too,
-- or ':explain' answers SAT for a contradiction ':solve' reported.
emitSMTDeclarationsNamed :: Registry -> (String, [(String, String)])
emitSMTDeclarationsNamed reg =
let modelIR = compileRegistry reg
classes = irClasses modelIR
bounds = [ (cls, p, c) | cls <- classes, p <- compProperties cls, c <- compConstraints p ]
named = [ ( nm
, "(assert (! " ++ propertyAssertionBody cName fName (compPropType p) c ++ " :named " ++ nm ++ "))\n"
, "Property bound: " ++ compClassName cls ++ "." ++ compPropName p ++ " "
++ compOpToString (constraintOp c) ++ " " ++ valueToString (constraintValue c)
)
| (idx, (cls, p, c)) <- zip ([1..] :: [Int]) bounds
, let cName = sanitizeIdent (compClassName cls)
fName = cName ++ "_" ++ sanitizeIdent (compPropName p)
nm = "bound_" ++ show idx
]
funDecls = concat [ "(declare-fun " ++ sanitizeIdent (compClassName cls) ++ "_" ++ sanitizeIdent (compPropName p)
++ " (Entity) " ++ mapSmtType (compPropType p) ++ ")\n"
| cls <- classes, p <- compProperties cls ]
txt = "; Sort declarations\n" ++
"(declare-sort Entity 0)\n\n" ++
"; Entity Concept Constants\n" ++
concatMap emitConceptConst classes ++ "\n" ++
"; Subclass Hierarchy\n" ++
"(declare-fun subClassOf (Entity Entity) Bool)\n" ++
concatMap emitHierarchy classes ++ "\n" ++
"; Property Functions and Bound Assertions\n" ++
funDecls ++ concat [ a | (_, a, _) <- named ] ++ "\n" ++
"; Relational Declarations\n" ++
emitRelations (irRelations modelIR) ++ "\n"
in (txt, [ (n, d) | (n, _, d) <- named ])

-- | SMT-LIB2 numeral: plain decimal notation, reals keep a fraction, negatives as (- n).
smtNumeral :: PropertyType -> Value -> String
Expand Down
Loading
Loading