aboutsummaryrefslogtreecommitdiff
path: root/include/atp/core
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-02 04:10:53 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-02 04:10:53 +0800
commit26da267b732e28e4d9697278e735b410e50e5e08 (patch)
treec084d333f50b94e1adee6f139d463bed14ced14f /include/atp/core
downloadratp-26da267b732e28e4d9697278e735b410e50e5e08.tar.gz
ratp-26da267b732e28e4d9697278e735b410e50e5e08.tar.xz
Initial commit: Build project architecture, define interfaces, write documentation, with the help of Claude
Diffstat (limited to 'include/atp/core')
-rw-r--r--include/atp/core/clause.h53
-rw-r--r--include/atp/core/clause_store.h62
-rw-r--r--include/atp/core/literal.h40
-rw-r--r--include/atp/core/symbol_table.h68
-rw-r--r--include/atp/core/term.h43
-rw-r--r--include/atp/core/term_bank.h57
-rw-r--r--include/atp/core/types.h80
7 files changed, 403 insertions, 0 deletions
diff --git a/include/atp/core/clause.h b/include/atp/core/clause.h
new file mode 100644
index 0000000..b4d3e68
--- /dev/null
+++ b/include/atp/core/clause.h
@@ -0,0 +1,53 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file clause.h
+/// @brief A clause is a disjunction of literals, with provenance tracking.
+///
+/// NOTE: V1 uses std::vector<Literal> for simplicity.
+/// Future optimization: migrate to a Clause Arena with contiguous storage.
+
+#include <vector>
+
+#include "atp/core/literal.h"
+#include "atp/core/types.h"
+
+namespace atp {
+
+/// A clause: a disjunction of literals plus provenance for proof reconstruction.
+struct Clause {
+ ClauseId id = kInvalidId;
+ std::vector<Literal> literals;
+
+ // Provenance (for proof trace)
+ InferenceRule rule = InferenceRule::kInput;
+ ClauseId parent1 = kInvalidId;
+ ClauseId parent2 = kInvalidId;
+ uint16_t depth = 0; ///< Derivation depth (for BFS scheduling)
+
+ /// True if the clause has no literals (contradiction).
+ [[nodiscard]] bool isEmpty() const { return literals.empty(); }
+
+ /// Number of literals.
+ [[nodiscard]] size_t size() const { return literals.size(); }
+};
+
+} // namespace atp
diff --git a/include/atp/core/clause_store.h b/include/atp/core/clause_store.h
new file mode 100644
index 0000000..6e220cc
--- /dev/null
+++ b/include/atp/core/clause_store.h
@@ -0,0 +1,62 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file clause_store.h
+/// @brief Central clause storage — owns all clauses, assigns ClauseIds.
+///
+/// Extracted from Prover to separate storage responsibility from search logic.
+/// This enables swapping search strategies (OTTER loop / DISCOUNT loop)
+/// without touching clause lifecycle management.
+
+#include "atp/core/clause.h"
+#include "atp/core/types.h"
+
+#include <functional>
+#include <vector>
+
+namespace atp {
+
+/// Central clause store. Owns all clauses and assigns unique ClauseIds.
+/// All modules access clauses through this store via ClauseId references.
+class ClauseStore {
+ public:
+ ClauseStore() = default;
+
+ /// Add a clause, assign it a ClauseId, and return the ID.
+ ClauseId addClause(Clause clause);
+
+ /// Access a clause by its ID. UB if id is out of range.
+ [[nodiscard]] const Clause& getClause(ClauseId id) const;
+
+ /// Mutable access (for marking clauses as deleted, etc.)
+ [[nodiscard]] Clause& getMutableClause(ClauseId id);
+
+ /// Total number of stored clauses.
+ [[nodiscard]] size_t size() const;
+
+ /// Iterate over all clauses with a visitor.
+ void forEach(const std::function<void(const Clause&)>& visitor) const;
+
+ private:
+ std::vector<Clause> clauses_;
+};
+
+} // namespace atp
diff --git a/include/atp/core/literal.h b/include/atp/core/literal.h
new file mode 100644
index 0000000..1b4f65c
--- /dev/null
+++ b/include/atp/core/literal.h
@@ -0,0 +1,40 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file literal.h
+/// @brief A literal is a (possibly negated) atomic formula.
+
+#include "atp/core/types.h"
+
+namespace atp {
+
+/// A literal: a polarity flag plus the TermId of the atom.
+struct Literal {
+ TermId atom; ///< TermId of the predicate application
+ bool is_positive; ///< true = positive, false = negated
+
+ /// Complement: flip polarity, same atom.
+ [[nodiscard]] Literal complement() const { return {atom, !is_positive}; }
+
+ bool operator==(const Literal& other) const = default;
+};
+
+} // namespace atp
diff --git a/include/atp/core/symbol_table.h b/include/atp/core/symbol_table.h
new file mode 100644
index 0000000..ed27a4d
--- /dev/null
+++ b/include/atp/core/symbol_table.h
@@ -0,0 +1,68 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file symbol_table.h
+/// @brief Bidirectional mapping between symbol names and SymbolIds,
+/// with kind and sort metadata.
+
+#include <string>
+#include <string_view>
+
+#include "atp/core/types.h"
+
+namespace atp {
+
+/// Metadata associated with an interned symbol.
+struct SymbolInfo {
+ std::string name;
+ SymbolKind kind = SymbolKind::kFunction;
+ uint16_t arity = 0;
+ SortId sort = kUnsorted; ///< Result sort (for sorted logic)
+};
+
+/// Interns symbol names so that each unique string is stored exactly once.
+/// Also tracks symbol metadata (kind, arity, sort).
+/// Thread-safety: NOT thread-safe (single-threaded prover design).
+class SymbolTable {
+ public:
+ SymbolTable() = default;
+
+ /// Intern a symbol name with metadata. Returns existing ID if already present.
+ SymbolId intern(std::string_view name, SymbolKind kind, uint16_t arity = 0,
+ SortId sort = kUnsorted);
+
+ /// Look up the name for a given SymbolId. UB if id is out of range.
+ [[nodiscard]] std::string_view getName(SymbolId id) const;
+
+ /// Look up full metadata for a SymbolId.
+ [[nodiscard]] const SymbolInfo& getInfo(SymbolId id) const;
+
+ /// Check if a symbol is a variable.
+ [[nodiscard]] bool isVariable(SymbolId id) const;
+
+ /// Number of interned symbols.
+ [[nodiscard]] size_t size() const;
+
+ private:
+ // TODO: Phase 1 implementation
+};
+
+} // namespace atp
diff --git a/include/atp/core/term.h b/include/atp/core/term.h
new file mode 100644
index 0000000..e1edfcf
--- /dev/null
+++ b/include/atp/core/term.h
@@ -0,0 +1,43 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file term.h
+/// @brief Core Term data structure — hash-consed, immutable.
+
+#include <span>
+
+#include "atp/core/types.h"
+
+namespace atp {
+
+/// A term is a function/predicate application: f(t1, t2, ..., tn).
+/// Stored in a flat arena; args are contiguous TermIds following the header.
+/// Variables are represented as terms with a special symbol range.
+struct Term {
+ SymbolId symbol_id; ///< Index into the SymbolTable
+ uint16_t arity; ///< Number of arguments
+
+ /// Access the argument TermIds (stored immediately after this struct in the arena).
+ [[nodiscard]] std::span<const TermId> args() const;
+ [[nodiscard]] std::span<TermId> mutableArgs();
+};
+
+} // namespace atp
diff --git a/include/atp/core/term_bank.h b/include/atp/core/term_bank.h
new file mode 100644
index 0000000..a121f8a
--- /dev/null
+++ b/include/atp/core/term_bank.h
@@ -0,0 +1,57 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file term_bank.h
+/// @brief Hash-consing term pool — guarantees structural sharing.
+
+#include "atp/core/term.h"
+#include "atp/core/types.h"
+
+#include <span>
+
+namespace atp {
+
+/// Global term pool with hash-consing.
+/// Every structurally identical term maps to the same TermId.
+class TermBank {
+ public:
+ TermBank() = default;
+
+ /// Create or retrieve a term. Returns the canonical TermId.
+ TermId makeTerm(SymbolId symbol, std::span<const TermId> args);
+
+ /// Create a variable term.
+ TermId makeVar(SymbolId var_symbol);
+
+ /// Look up a term by its ID.
+ [[nodiscard]] const Term& getTerm(TermId id) const;
+
+ /// Check if a TermId represents a variable.
+ [[nodiscard]] bool isVariable(TermId id) const;
+
+ /// Total number of unique terms stored.
+ [[nodiscard]] size_t size() const;
+
+ private:
+ // TODO: Phase 1 implementation — flat arena + hash index
+};
+
+} // namespace atp
diff --git a/include/atp/core/types.h b/include/atp/core/types.h
new file mode 100644
index 0000000..c68e716
--- /dev/null
+++ b/include/atp/core/types.h
@@ -0,0 +1,80 @@
+/*
+ * richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
+ * Copyright (C) 2026 Richard Qin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/// @file types.h
+/// @brief Core type aliases for the ATP engine.
+
+#include <cstdint>
+
+namespace atp {
+
+/// Unique identifier for an interned symbol (predicate/function/constant name).
+using SymbolId = uint32_t;
+
+/// Unique identifier for a term in the Term Bank (hash-consed).
+using TermId = uint32_t;
+
+/// Unique identifier for a clause in the Clause Store.
+using ClauseId = uint32_t;
+
+/// Unique identifier for a sort/type (for sorted logic).
+using SortId = uint16_t;
+
+/// Sentinel value indicating an invalid / unassigned ID.
+inline constexpr uint32_t kInvalidId = UINT32_MAX;
+
+/// Default sort (unsorted logic).
+inline constexpr SortId kUnsorted = 0;
+
+/// Symbol kind — distinguishes variables from function/predicate symbols.
+enum class SymbolKind : uint8_t {
+ kVariable, ///< Universally quantified variable
+ kConstant, ///< 0-arity function symbol (constant)
+ kFunction, ///< Function symbol (arity >= 1)
+ kPredicate, ///< Predicate symbol (returns bool)
+ kSkolem, ///< Skolem function/constant (introduced by Skolemization)
+};
+
+/// Inference rule that produced a clause.
+/// Deliberately uses uint16_t for extensibility toward algebra/analysis rules.
+enum class InferenceRule : uint16_t {
+ // ── Core resolution rules ──
+ kInput = 0, ///< Original input clause (axiom / negated conjecture)
+ kResolution = 1, ///< Binary resolution
+ kFactoring = 2, ///< Factoring
+
+ // ── Equality rules (algebra) ──
+ kParamodulation = 100, ///< Paramodulation (equality resolution)
+ kDemodulation = 101, ///< Demodulation (simplification by rewriting)
+ kEqualityResolution = 102, ///< s != t resolved with unifier
+ kEqualityFactoring = 103, ///< Factoring with equality
+
+ // ── Simplification rules ──
+ kSubsumption = 200, ///< Removed by subsumption
+ kTautologyElim = 201, ///< Removed as tautology
+ kPureLiteralElim = 202, ///< Pure literal elimination
+
+ // ── Theory rules (analysis, arithmetic) ──
+ kTheoryResolution = 300, ///< Theory-specific resolution
+ kTheoryRewrite = 301, ///< Theory-driven rewriting
+};
+
+} // namespace atp