logicaffeine_language/ast/
logic.rs

1//! Logic expression AST types for first-order logic with modal and event extensions.
2//!
3//! This module defines the core logical expression types including:
4//!
5//! - **[`LogicExpr`]**: The main expression enum with all logical constructs
6//! - **[`Term`]**: Terms (constants, variables, function applications)
7//! - **[`NounPhrase`]**: Parsed noun phrase structure
8//! - **Semantic types**: Montague-style type markers
9//! - **Event roles**: Neo-Davidsonian thematic roles (Agent, Theme, Goal, etc.)
10//! - **Modal vectors**: Kripke semantics parameters (domain, flavor, force)
11//! - **Temporal operators**: Past, future, perfect, progressive
12//!
13//! All types use arena allocation with the `'a` lifetime parameter.
14
15use logicaffeine_base::Arena;
16use logicaffeine_base::Symbol;
17use crate::lexicon::Definiteness;
18use crate::token::TokenType;
19
20// ═══════════════════════════════════════════════════════════════════
21// Semantic Types (Montague Grammar)
22// ═══════════════════════════════════════════════════════════════════
23
24/// Montague semantic types for compositional interpretation.
25///
26/// These types classify expressions according to their denotation in
27/// a model-theoretic semantics, following Montague's "Universal Grammar".
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum LogicalType {
30    /// Type `e`: Individuals (entities) like "John" or "the ball".
31    Entity,
32    /// Type `t`: Truth values (propositions) like "John runs".
33    TruthValue,
34    /// Type `<e,t>`: Properties (one-place predicates) like "is a unicorn".
35    Property,
36    /// Type `<<e,t>,t>`: Generalized quantifiers like "every man" or "a woman".
37    Quantifier,
38}
39
40// ═══════════════════════════════════════════════════════════════════
41// Degree Semantics (Prover-Ready Number System)
42// ═══════════════════════════════════════════════════════════════════
43
44/// Physical dimension for degree semantics and unit tracking.
45///
46/// Used with [`NumberKind`] to enable dimensional analysis and prevent
47/// nonsensical comparisons (e.g., adding meters to seconds).
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub enum Dimension {
50    /// Spatial extent (meters, feet, inches).
51    Length,
52    /// Temporal duration (seconds, minutes, hours).
53    Time,
54    /// Mass (kilograms, pounds).
55    Weight,
56    /// Thermal measure (Celsius, Fahrenheit, Kelvin).
57    Temperature,
58    /// Count of discrete items.
59    Cardinality,
60}
61
62/// Numeric literal representation for degree semantics.
63///
64/// Supports exact integers, floating-point reals, and symbolic constants
65/// (e.g., π, e) for prover integration.
66#[derive(Debug, Clone, Copy, PartialEq)]
67pub enum NumberKind {
68    /// Floating-point real number (e.g., 3.14, 0.5).
69    Real(f64),
70    /// Exact integer (e.g., 42, -1, 0).
71    Integer(i64),
72    /// Symbolic constant (e.g., π, e, ∞).
73    Symbolic(Symbol),
74}
75
76// ═══════════════════════════════════════════════════════════════════
77// First-Order Logic Types (FOL Upgrade)
78// ═══════════════════════════════════════════════════════════════════
79
80/// First-order logic term representing entities or values.
81///
82/// Terms denote individuals, groups, or computed values in the domain
83/// of discourse. They serve as arguments to predicates.
84#[derive(Debug, Clone, Copy)]
85pub enum Term<'a> {
86    /// Named individual constant (e.g., `john`, `paris`).
87    Constant(Symbol),
88    /// Bound or free variable (e.g., `x`, `y`).
89    Variable(Symbol),
90    /// Function application: `f(t1, t2, ...)` (e.g., `mother(john)`).
91    Function(Symbol, &'a [Term<'a>]),
92    /// Plural group for collective readings (e.g., `john ⊕ mary`).
93    Group(&'a [Term<'a>]),
94    /// Possessive construction: `john's book` → `Poss(john, book)`.
95    Possessed { possessor: &'a Term<'a>, possessed: Symbol },
96    /// Definite description σ-term: `σx.P(x)` ("the unique x such that P").
97    Sigma(Symbol),
98    /// Intensional term (Montague up-arrow `^P`) for de dicto readings.
99    Intension(Symbol),
100    /// Sentential complement (embedded clause as propositional argument).
101    Proposition(&'a LogicExpr<'a>),
102    /// Numeric value with optional unit and dimension.
103    Value {
104        kind: NumberKind,
105        unit: Option<Symbol>,
106        dimension: Option<Dimension>,
107    },
108}
109
110/// Quantifier types for first-order and generalized quantifiers.
111///
112/// Extends standard FOL with generalized quantifiers that cannot be
113/// expressed with ∀ and ∃ alone (e.g., "most", "few", "at least 3").
114#[derive(Debug, Clone, Copy, PartialEq, Eq)]
115pub enum QuantifierKind {
116    /// Universal: ∀x ("every", "all", "each").
117    Universal,
118    /// Existential: ∃x ("some", "a", "an").
119    Existential,
120    /// Proportional: "most X are Y" (>50% of domain).
121    Most,
122    /// Proportional: "few X are Y" (<expected proportion).
123    Few,
124    /// Vague large quantity: "many X are Y".
125    Many,
126    /// Exact count: "exactly n X are Y".
127    Cardinal(u32),
128    /// Lower bound: "at least n X are Y".
129    AtLeast(u32),
130    /// Upper bound: "at most n X are Y".
131    AtMost(u32),
132    /// Generic: "cats meow" (characterizing generalization).
133    Generic,
134}
135
136/// Binary logical connectives.
137#[derive(Debug, Clone, Copy, PartialEq, Eq)]
138pub enum BinaryOpKind {
139    /// Conjunction: P ∧ Q.
140    And,
141    /// Disjunction: P ∨ Q.
142    Or,
143    /// Material implication: P → Q.
144    Implies,
145    /// Biconditional: P ↔ Q.
146    Iff,
147}
148
149/// Unary logical operators.
150#[derive(Debug, Clone, Copy, PartialEq, Eq)]
151pub enum UnaryOpKind {
152    /// Negation: ¬P.
153    Not,
154}
155
156// ═══════════════════════════════════════════════════════════════════
157// Temporal & Aspect Operators (Arthur Prior's Tense Logic)
158// ═══════════════════════════════════════════════════════════════════
159
160/// Prior-style tense logic operators.
161///
162/// Based on Arthur Prior's tense logic where P ("it was the case that")
163/// and F ("it will be the case that") are modal operators over time.
164#[derive(Debug, Clone, Copy, PartialEq, Eq)]
165pub enum TemporalOperator {
166    /// Past tense: P(φ) — "it was the case that φ".
167    Past,
168    /// Future tense: F(φ) — "it will be the case that φ".
169    Future,
170}
171
172// ═══════════════════════════════════════════════════════════════════
173// Event Semantics (Neo-Davidsonian)
174// ═══════════════════════════════════════════════════════════════════
175
176/// Neo-Davidsonian thematic roles for event semantics.
177///
178/// Following Parsons' neo-Davidsonian analysis, events are reified and
179/// participants are related to events via thematic role predicates:
180/// `∃e(Run(e) ∧ Agent(e, john) ∧ Location(e, park))`.
181#[derive(Debug, Clone, Copy, PartialEq, Eq)]
182pub enum ThematicRole {
183    /// Animate initiator of action (e.g., "John" in "John ran").
184    Agent,
185    /// Entity affected by action (e.g., "the window" in "broke the window").
186    Patient,
187    /// Entity involved without change (e.g., "the ball" in "saw the ball").
188    Theme,
189    /// Animate entity receiving something (e.g., "Mary" in "gave Mary a book").
190    Recipient,
191    /// Destination or endpoint (e.g., "Paris" in "went to Paris").
192    Goal,
193    /// Origin or starting point (e.g., "London" in "came from London").
194    Source,
195    /// Tool or means (e.g., "a knife" in "cut with a knife").
196    Instrument,
197    /// Spatial setting (e.g., "the park" in "ran in the park").
198    Location,
199    /// Temporal setting (e.g., "yesterday" in "arrived yesterday").
200    Time,
201    /// How action was performed (e.g., "quickly" in "ran quickly").
202    Manner,
203}
204
205/// Grammatical aspect operators for event structure.
206///
207/// Aspect describes the internal temporal structure of events,
208/// distinct from tense which locates events in time.
209#[derive(Debug, Clone, Copy, PartialEq, Eq)]
210pub enum AspectOperator {
211    /// Ongoing action: "is running" → PROG(Run(e)).
212    Progressive,
213    /// Completed with present relevance: "has eaten" → PERF(Eat(e)).
214    Perfect,
215    /// Characteristic pattern: "smokes" (habitually) → HAB(Smoke(e)).
216    Habitual,
217    /// Repeated action: "kept knocking" → ITER(Knock(e)).
218    Iterative,
219}
220
221/// Grammatical voice operators.
222#[derive(Debug, Clone, Copy, PartialEq, Eq)]
223pub enum VoiceOperator {
224    /// Passive voice: "was eaten" promotes patient to subject position.
225    Passive,
226}
227
228// ═══════════════════════════════════════════════════════════════════
229// Legacy Types (kept during transition)
230// ═══════════════════════════════════════════════════════════════════
231
232/// Parsed noun phrase structure for compositional interpretation.
233///
234/// Captures the internal structure of noun phrases including determiners,
235/// modifiers, and possessives for correct semantic composition.
236#[derive(Debug)]
237pub struct NounPhrase<'a> {
238    /// Definiteness: the (definite), a/an (indefinite), or bare (none).
239    pub definiteness: Option<Definiteness>,
240    /// Pre-nominal adjectives (e.g., "big red" in "big red ball").
241    pub adjectives: &'a [Symbol],
242    /// Head noun (e.g., "ball" in "big red ball").
243    pub noun: Symbol,
244    /// Possessor phrase (e.g., "John's" in "John's book").
245    pub possessor: Option<&'a NounPhrase<'a>>,
246    /// Prepositional phrase modifiers attached to noun.
247    pub pps: &'a [&'a LogicExpr<'a>],
248    /// Superlative adjective if present (e.g., "tallest").
249    pub superlative: Option<Symbol>,
250}
251
252// ═══════════════════════════════════════════════════════════════════
253// Boxed Variant Data (keeps LogicExpr enum small)
254// ═══════════════════════════════════════════════════════════════════
255
256/// Aristotelian categorical proposition data.
257///
258/// Represents the four categorical forms (A, E, I, O):
259/// - A: All S are P
260/// - E: No S are P
261/// - I: Some S are P
262/// - O: Some S are not P
263#[derive(Debug)]
264pub struct CategoricalData<'a> {
265    /// The quantifier (All, No, Some).
266    pub quantifier: TokenType,
267    /// Subject term (S in "All S are P").
268    pub subject: NounPhrase<'a>,
269    /// Whether copula is negated (for O-form: "Some S are not P").
270    pub copula_negative: bool,
271    /// Predicate term (P in "All S are P").
272    pub predicate: NounPhrase<'a>,
273}
274
275/// Simple subject-verb-object relation data.
276#[derive(Debug)]
277pub struct RelationData<'a> {
278    /// Subject noun phrase.
279    pub subject: NounPhrase<'a>,
280    /// Verb predicate.
281    pub verb: Symbol,
282    /// Object noun phrase.
283    pub object: NounPhrase<'a>,
284}
285
286/// Neo-Davidsonian event structure with thematic roles.
287///
288/// Represents a verb event with its participants decomposed into
289/// separate thematic role predicates: `∃e(Run(e) ∧ Agent(e, john))`.
290#[derive(Debug)]
291pub struct NeoEventData<'a> {
292    /// The event variable (e, e1, e2, ...).
293    pub event_var: Symbol,
294    /// The verb predicate name.
295    pub verb: Symbol,
296    /// Thematic role assignments: (Role, Filler) pairs.
297    pub roles: &'a [(ThematicRole, Term<'a>)],
298    /// Adverbial modifiers (e.g., "quickly" → Quickly(e)).
299    pub modifiers: &'a [Symbol],
300    /// When true, suppress local ∃e quantification.
301    /// Used in DRT for generic conditionals where event var is bound by outer ∀.
302    pub suppress_existential: bool,
303    /// World argument for Kripke semantics. None = implicit actual world (w₀).
304    pub world: Option<Symbol>,
305}
306
307impl<'a> NounPhrase<'a> {
308    pub fn simple(noun: Symbol) -> Self {
309        NounPhrase {
310            definiteness: None,
311            adjectives: &[],
312            noun,
313            possessor: None,
314            pps: &[],
315            superlative: None,
316        }
317    }
318
319    pub fn with_definiteness(definiteness: Definiteness, noun: Symbol) -> Self {
320        NounPhrase {
321            definiteness: Some(definiteness),
322            adjectives: &[],
323            noun,
324            possessor: None,
325            pps: &[],
326            superlative: None,
327        }
328    }
329}
330
331/// Modal logic domain classification.
332///
333/// Determines the accessibility relation in Kripke semantics:
334/// what kinds of possible worlds are relevant.
335#[derive(Debug, Clone, Copy, PartialEq)]
336pub enum ModalDomain {
337    /// Alethic modality: logical/metaphysical possibility and necessity.
338    /// "It is possible that P" = P holds in some accessible world.
339    Alethic,
340    /// Deontic modality: obligation and permission.
341    /// "It is obligatory that P" = P holds in all deontically ideal worlds.
342    Deontic,
343}
344
345/// Modal flavor affecting scope interpretation.
346///
347/// The distinction between root and epistemic modals affects
348/// quantifier scope: root modals scope under quantifiers (de re),
349/// while epistemic modals scope over quantifiers (de dicto).
350#[derive(Debug, Clone, Copy, PartialEq, Eq)]
351pub enum ModalFlavor {
352    /// Root modals express ability, obligation, or circumstantial possibility.
353    /// Verbs: can, must, should, shall, could, would.
354    /// Scope: NARROW (de re) — modal attaches inside quantifier scope.
355    /// Example: "Every student can solve this" = ∀x(Student(x) → ◇Solve(x, this))
356    Root,
357    /// Epistemic modals express possibility or deduction based on evidence.
358    /// Verbs: might, may (epistemic readings).
359    /// Scope: WIDE (de dicto) — modal wraps the entire quantified formula.
360    /// Example: "A student might win" = ◇∃x(Student(x) ∧ Win(x))
361    Epistemic,
362}
363
364/// Modal operator parameters for Kripke semantics.
365///
366/// Combines domain (what kind of modality), force (necessity vs possibility),
367/// and flavor (scope behavior) into a single modal specification.
368#[derive(Debug, Clone, Copy, PartialEq)]
369pub struct ModalVector {
370    /// The modal domain: alethic or deontic.
371    pub domain: ModalDomain,
372    /// Modal force: 1.0 = necessity (□), 0.5 = possibility (◇), graded values between.
373    pub force: f32,
374    /// Scope flavor: root (narrow scope) or epistemic (wide scope).
375    pub flavor: ModalFlavor,
376}
377
378// ═══════════════════════════════════════════════════════════════════
379// Expression Enum (hybrid: old + new variants)
380// ═══════════════════════════════════════════════════════════════════
381
382/// First-order logic expression with modal, temporal, and event extensions.
383///
384/// This is the core AST type representing logical formulas. All nodes are
385/// arena-allocated with the `'a` lifetime tracking the arena's scope.
386///
387/// # Categories
388///
389/// - **Core FOL**: [`Predicate`], [`Quantifier`], [`BinaryOp`], [`UnaryOp`], [`Identity`]
390/// - **Lambda calculus**: [`Lambda`], [`App`], [`Atom`]
391/// - **Modal logic**: [`Modal`], [`Intensional`]
392/// - **Temporal/Aspect**: [`Temporal`], [`Aspectual`], [`Voice`]
393/// - **Event semantics**: [`Event`], [`NeoEvent`]
394/// - **Questions**: [`Question`], [`YesNoQuestion`]
395/// - **Pragmatics**: [`SpeechAct`], [`Focus`], [`Presupposition`]
396/// - **Comparison**: [`Comparative`], [`Superlative`]
397/// - **Other**: [`Counterfactual`], [`Causal`], [`Control`], [`Imperative`]
398///
399/// [`Predicate`]: LogicExpr::Predicate
400/// [`Quantifier`]: LogicExpr::Quantifier
401/// [`BinaryOp`]: LogicExpr::BinaryOp
402/// [`UnaryOp`]: LogicExpr::UnaryOp
403/// [`Identity`]: LogicExpr::Identity
404/// [`Lambda`]: LogicExpr::Lambda
405/// [`App`]: LogicExpr::App
406/// [`Atom`]: LogicExpr::Atom
407/// [`Modal`]: LogicExpr::Modal
408/// [`Intensional`]: LogicExpr::Intensional
409/// [`Temporal`]: LogicExpr::Temporal
410/// [`Aspectual`]: LogicExpr::Aspectual
411/// [`Voice`]: LogicExpr::Voice
412/// [`Event`]: LogicExpr::Event
413/// [`NeoEvent`]: LogicExpr::NeoEvent
414/// [`Question`]: LogicExpr::Question
415/// [`YesNoQuestion`]: LogicExpr::YesNoQuestion
416/// [`SpeechAct`]: LogicExpr::SpeechAct
417/// [`Focus`]: LogicExpr::Focus
418/// [`Presupposition`]: LogicExpr::Presupposition
419/// [`Comparative`]: LogicExpr::Comparative
420/// [`Superlative`]: LogicExpr::Superlative
421/// [`Counterfactual`]: LogicExpr::Counterfactual
422/// [`Causal`]: LogicExpr::Causal
423/// [`Control`]: LogicExpr::Control
424/// [`Imperative`]: LogicExpr::Imperative
425#[derive(Debug)]
426pub enum LogicExpr<'a> {
427    /// Atomic predicate: `P(t1, t2, ...)` with optional world parameter.
428    Predicate {
429        name: Symbol,
430        args: &'a [Term<'a>],
431        /// World argument for Kripke semantics. None = implicit actual world (w₀).
432        world: Option<Symbol>,
433    },
434
435    /// Identity statement: `t1 = t2`.
436    Identity {
437        left: &'a Term<'a>,
438        right: &'a Term<'a>,
439    },
440
441    /// Metaphorical assertion: tenor "is" vehicle (non-literal identity).
442    Metaphor {
443        tenor: &'a Term<'a>,
444        vehicle: &'a Term<'a>,
445    },
446
447    /// Quantified formula: `∀x.φ` or `∃x.φ` with scope island tracking.
448    Quantifier {
449        kind: QuantifierKind,
450        variable: Symbol,
451        body: &'a LogicExpr<'a>,
452        /// Island ID prevents illicit scope interactions across syntactic boundaries.
453        island_id: u32,
454    },
455
456    /// Aristotelian categorical proposition (boxed to keep enum small).
457    Categorical(Box<CategoricalData<'a>>),
458
459    /// Simple S-V-O relation (boxed).
460    Relation(Box<RelationData<'a>>),
461
462    /// Modal operator: □φ (necessity) or ◇φ (possibility).
463    Modal {
464        vector: ModalVector,
465        operand: &'a LogicExpr<'a>,
466    },
467
468    /// Tense operator: PAST(φ) or FUTURE(φ).
469    Temporal {
470        operator: TemporalOperator,
471        body: &'a LogicExpr<'a>,
472    },
473
474    /// Aspect operator: PROG(φ), PERF(φ), HAB(φ), ITER(φ).
475    Aspectual {
476        operator: AspectOperator,
477        body: &'a LogicExpr<'a>,
478    },
479
480    /// Voice operator: PASSIVE(φ).
481    Voice {
482        operator: VoiceOperator,
483        body: &'a LogicExpr<'a>,
484    },
485
486    /// Binary connective: φ ∧ ψ, φ ∨ ψ, φ → ψ, φ ↔ ψ.
487    BinaryOp {
488        left: &'a LogicExpr<'a>,
489        op: TokenType,
490        right: &'a LogicExpr<'a>,
491    },
492
493    /// Unary operator: ¬φ.
494    UnaryOp {
495        op: TokenType,
496        operand: &'a LogicExpr<'a>,
497    },
498
499    /// Wh-question: λx.φ where x is the questioned variable.
500    Question {
501        wh_variable: Symbol,
502        body: &'a LogicExpr<'a>,
503    },
504
505    /// Yes/no question: ?φ (is φ true?).
506    YesNoQuestion {
507        body: &'a LogicExpr<'a>,
508    },
509
510    /// Atomic symbol (variable or constant in lambda context).
511    Atom(Symbol),
512
513    /// Lambda abstraction: λx.φ.
514    Lambda {
515        variable: Symbol,
516        body: &'a LogicExpr<'a>,
517    },
518
519    /// Function application: (φ)(ψ).
520    App {
521        function: &'a LogicExpr<'a>,
522        argument: &'a LogicExpr<'a>,
523    },
524
525    /// Intensional context: `operator[content]` for opaque verbs (believes, seeks).
526    Intensional {
527        operator: Symbol,
528        content: &'a LogicExpr<'a>,
529    },
530
531    /// Legacy event semantics (Davidson-style with adverb list).
532    Event {
533        predicate: &'a LogicExpr<'a>,
534        adverbs: &'a [Symbol],
535    },
536
537    /// Neo-Davidsonian event with thematic roles (boxed).
538    NeoEvent(Box<NeoEventData<'a>>),
539
540    /// Imperative command: !φ.
541    Imperative {
542        action: &'a LogicExpr<'a>,
543    },
544
545    /// Speech act: performative utterance with illocutionary force.
546    SpeechAct {
547        performer: Symbol,
548        act_type: Symbol,
549        content: &'a LogicExpr<'a>,
550    },
551
552    /// Counterfactual conditional: "If P had been, Q would have been".
553    Counterfactual {
554        antecedent: &'a LogicExpr<'a>,
555        consequent: &'a LogicExpr<'a>,
556    },
557
558    /// Causal relation: "effect because cause".
559    Causal {
560        effect: &'a LogicExpr<'a>,
561        cause: &'a LogicExpr<'a>,
562    },
563
564    /// Comparative: "X is taller than Y (by 2 inches)".
565    Comparative {
566        adjective: Symbol,
567        subject: &'a Term<'a>,
568        object: &'a Term<'a>,
569        difference: Option<&'a Term<'a>>,
570    },
571
572    /// Superlative: "X is the tallest among domain".
573    Superlative {
574        adjective: Symbol,
575        subject: &'a Term<'a>,
576        domain: Symbol,
577    },
578
579    /// Scopal adverb: "only", "always", etc. as operators.
580    Scopal {
581        operator: Symbol,
582        body: &'a LogicExpr<'a>,
583    },
584
585    /// Control verb: "wants to VP", "persuaded X to VP".
586    Control {
587        verb: Symbol,
588        subject: &'a Term<'a>,
589        object: Option<&'a Term<'a>>,
590        infinitive: &'a LogicExpr<'a>,
591    },
592
593    /// Presupposition-assertion structure.
594    Presupposition {
595        assertion: &'a LogicExpr<'a>,
596        presupposition: &'a LogicExpr<'a>,
597    },
598
599    /// Focus particle: "only X", "even X" with alternative set.
600    Focus {
601        kind: crate::token::FocusKind,
602        focused: &'a Term<'a>,
603        scope: &'a LogicExpr<'a>,
604    },
605
606    /// Temporal anchor: "yesterday(φ)", "now(φ)".
607    TemporalAnchor {
608        anchor: Symbol,
609        body: &'a LogicExpr<'a>,
610    },
611
612    /// Distributive operator: *P distributes P over group members.
613    Distributive {
614        predicate: &'a LogicExpr<'a>,
615    },
616
617    /// Group quantifier for collective cardinal readings.
618    /// `∃g(Group(g) ∧ Count(g,n) ∧ ∀x(Member(x,g) → Restriction(x)) ∧ Body(g))`
619    GroupQuantifier {
620        group_var: Symbol,
621        count: u32,
622        member_var: Symbol,
623        restriction: &'a LogicExpr<'a>,
624        body: &'a LogicExpr<'a>,
625    },
626}
627
628impl<'a> LogicExpr<'a> {
629    pub fn lambda(var: Symbol, body: &'a LogicExpr<'a>, arena: &'a Arena<LogicExpr<'a>>) -> &'a LogicExpr<'a> {
630        arena.alloc(LogicExpr::Lambda {
631            variable: var,
632            body,
633        })
634    }
635
636    pub fn app(func: &'a LogicExpr<'a>, arg: &'a LogicExpr<'a>, arena: &'a Arena<LogicExpr<'a>>) -> &'a LogicExpr<'a> {
637        arena.alloc(LogicExpr::App {
638            function: func,
639            argument: arg,
640        })
641    }
642}
643
644#[cfg(test)]
645mod size_tests {
646    use super::*;
647    use std::mem::size_of;
648
649    #[test]
650    fn test_ast_node_sizes() {
651        println!("LogicExpr size: {} bytes", size_of::<LogicExpr>());
652        println!("Term size: {} bytes", size_of::<Term>());
653        println!("NounPhrase size: {} bytes", size_of::<NounPhrase>());
654
655        assert!(
656            size_of::<LogicExpr>() <= 48,
657            "LogicExpr is {} bytes - consider boxing large variants",
658            size_of::<LogicExpr>()
659        );
660        assert!(
661            size_of::<Term>() <= 32,
662            "Term is {} bytes",
663            size_of::<Term>()
664        );
665    }
666}