18#include <unordered_set>
22#include <initializer_list>
47 AssumptionContext(
const AssumptionContext&) =
default;
48 AssumptionContext(AssumptionContext&& other);
49 AssumptionContext& operator=(
const AssumptionContext& other);
50 AssumptionContext& operator=(AssumptionContext&& other)
noexcept;
70 PropertyStore& current_properties();
73 const PropertyStore& current_properties()
const;
76 RelationStore& current_relations();
79 const RelationStore& current_relations()
const;
87 bool has_sign(
const std::string& symbol,
Sign sign)
const;
90 bool has_domain(
const std::string& symbol,
Domain domain)
const;
93 Domain get_domain(
const std::string& symbol)
const;
96 std::unordered_set<Sign, SignHash> get_signs(
const std::string& symbol)
const;
99 Parity get_parity(
const std::string& symbol)
const;
102 Boundedness get_boundedness(
const std::string& symbol)
const;
105 std::optional<Interval> get_bounds(
const std::string& symbol)
const;
107 bool is_transcendental(
const std::string& symbol)
const;
108 Finiteness get_finiteness(
const std::string& symbol)
const;
109 Definiteness get_definiteness(
const std::string& symbol)
const;
110 std::optional<SymbolicExpr> get_period(
111 const std::string& symbol,
const std::string&
variable)
const;
112 bool is_periodic(
const std::string& symbol,
const std::string&
variable)
const;
114 bool has_period_declarations(
const std::string& symbol)
const;
116 const std::string& symbol,
const std::string&
variable,
120 bool has_relation(
const SymbolicExpr& lhs,
const SymbolicExpr&
rhs,
RelationOp op)
const;
121 std::vector<Relation> get_visible_relations()
const;
161 AssumptionVoidResult assume_conditional(
const SymbolicExpr& condition,
const SymbolicExpr& conclusion);
165 const SymbolicExpr& condition,
166 const SymbolicExpr& conclusion);
171 struct ConditionalAssumption {
172 SymbolicExpr condition;
173 SymbolicExpr conclusion;
184 std::vector<ConditionalAssumption> get_active_conditionals()
const;
196 Tribool evaluate_condition(
const SymbolicExpr& condition)
const;
257 std::string serialize()
const;
285 const std::string& symbol,
298 const std::string& symbol,
327 void set_max_query_depth(
int depth);
333 int get_max_query_depth()
const;
338 static AssumptionContext deserialize_impl(
342 PropertyStore properties;
343 RelationStore relations;
344 std::vector<ConditionalAssumption> conditionals;
345 mutable std::uint64_t observed_property_revision = 0;
346 mutable std::uint64_t observed_relation_revision = 0;
349 std::vector<Scope> scope_stack_;
350 struct RelationShadowing;
351 RelationShadowing collect_relation_shadowing(
353 static bool relation_shadowed(
356 std::vector<bool> relation_visibility(
359 std::size_t scope,
const SymbolicExpr& lhs,
const SymbolicExpr&
rhs,
363 int max_query_depth_ = 32;
366 mutable uint64_t cache_generation_ = 0;
370 uint64_t cache_generation()
const;
406 if (
const auto*
domain = std::get_if<DomainDeclaration>(&
payload_)) {
409 if (
const auto*
sign = std::get_if<SignDeclaration>(&
payload_)) {
412 throw std::logic_error(
"relational assumption has no symbol field");
416 return std::get<DomainDeclaration>(
payload_).domain;
420 return std::get<SignDeclaration>(
payload_).sign;
424 return std::get<SymbolicExpr>(
payload_);
438 using Payload = std::variant<DomainDeclaration, SignDeclaration, SymbolicExpr>;
441 :
payload_(std::move(declaration)) {}
443 :
payload_(std::move(declaration)) {}
451 AssumptionContext& ctx,
453 switch (decl.
type()) {
455 return ctx.assume_domain_checked(decl.
symbol(), decl.
domain());
457 return ctx.assume_sign_checked(decl.
symbol(), decl.
sign());
459 return ctx.assume_checked(decl.
relation());
473 const std::vector<AssumptionDecl>& decls,
475 -> std::enable_if_t<!std::is_void_v<
decltype(callable())>,
Result<
decltype(callable())>>
477 using ReturnT =
decltype(callable());
480 for (
const auto& decl : decls) {
483 auto popped = ctx.pop();
488 auto result = callable();
489 auto popped = ctx.pop();
493 auto popped = ctx.pop();
496 }
catch (
const std::bad_alloc&) {
497 auto popped = ctx.pop();
501 }
catch (
const std::exception& ex) {
502 auto popped = ctx.pop();
507 auto popped = ctx.pop();
515 const std::vector<AssumptionDecl>& decls,
521 for (
const auto& decl : decls) {
524 auto popped = ctx.pop();
530 auto popped = ctx.pop();
534 auto popped = ctx.pop();
537 }
catch (
const std::bad_alloc&) {
538 auto popped = ctx.pop();
542 }
catch (
const std::exception& ex) {
543 auto popped = ctx.pop();
548 auto popped = ctx.pop();
556 std::initializer_list<AssumptionDecl> decls,
559 ctx, std::vector<AssumptionDecl>(decls), std::forward<F>(callable)))
562 ctx, std::vector<AssumptionDecl>(decls), std::forward<F>(callable));
Core enumerations and forward declarations for the Assumption System.
Declaration of an assumption to apply within a with_assumptions block.
static AssumptionDecl make_relation(const SymbolicExpr &rel)
Construct a relational assumption declaration.
const SymbolicExpr & relation() const
Type type() const noexcept
Type
The type of assumption being declared.
AssumptionDecl(SignDeclaration declaration)
AssumptionDecl(DomainDeclaration declaration)
const std::string & symbol() const
std::variant< DomainDeclaration, SignDeclaration, SymbolicExpr > Payload
AssumptionDecl(SymbolicExpr relation)
static AssumptionDecl make_sign(const std::string &sym, Sign s)
Construct a sign assumption declaration.
static AssumptionDecl make_domain(const std::string &sym, Domain d)
Construct a domain assumption declaration.
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result success(T value)
const std::string & variable
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
ExprResult interval(ExprPtr lower, ExprPtr upper, bool lower_closed, bool upper_closed)
AssumptionVoidResult apply_assumption_decl_checked(AssumptionContext &ctx, const AssumptionDecl &decl)
Domain
Mathematical domain hierarchy (least specific → most specific). Complex ⊃ Real ⊃ Algebraic ⊃ Rational...
Boundedness
Boundedness classification for symbols.
Tribool
Tri-state logic value for property queries.
Result< Tribool > AssumptionTriboolResult
Definiteness
Matrix definiteness classification.
RelationOp
Stable relational operator used by public APIs.
const ExprPtr RelationOp op
std::size_t std::size_t depth
const NumberDomainSet & domain
auto with_assumptions(AssumptionContext &ctx, const std::vector< AssumptionDecl > &decls, F &&callable) -> std::enable_if_t<!std::is_void_v< decltype(callable())>, Result< decltype(callable())> >
Execute a callable within a temporary assumption scope.
ExprResult sym(const std::string &name)
Finiteness
Finiteness classification for limits and sequences.
Result< void > AssumptionVoidResult
ExprResult relation(const ExprPtr &lhs, const ExprPtr &rhs, RelationOp op)
Parity
Integer parity classification.
Sign
Sign classification for symbols and expressions.
A stored relational constraint between two symbolic expressions.
PropertyStore class for mapping symbol names to declared properties.
RelationStore class for storing relational constraints between symbolic expressions.