Skip to main content

litex/fact/
atomic_fact.rs

1use crate::prelude::*;
2use std::fmt;
3
4#[derive(Clone)]
5pub enum AtomicFact {
6    NormalAtomicFact(NormalAtomicFact),
7    EqualFact(EqualFact),
8    LessFact(LessFact),
9    GreaterFact(GreaterFact),
10    LessEqualFact(LessEqualFact),
11    GreaterEqualFact(GreaterEqualFact),
12    IsSetFact(IsSetFact),
13    IsNonemptySetFact(IsNonemptySetFact),
14    IsFiniteSetFact(IsFiniteSetFact),
15    InFact(InFact),
16    IsCartFact(IsCartFact),
17    IsTupleFact(IsTupleFact),
18    SubsetFact(SubsetFact),
19    SupersetFact(SupersetFact),
20    RestrictFact(RestrictFact),
21    NotRestrictFact(NotRestrictFact),
22    NotNormalAtomicFact(NotNormalAtomicFact),
23    NotEqualFact(NotEqualFact),
24    NotLessFact(NotLessFact),
25    NotGreaterFact(NotGreaterFact),
26    NotLessEqualFact(NotLessEqualFact),
27    NotGreaterEqualFact(NotGreaterEqualFact),
28    NotIsSetFact(NotIsSetFact),
29    NotIsNonemptySetFact(NotIsNonemptySetFact),
30    NotIsFiniteSetFact(NotIsFiniteSetFact),
31    NotInFact(NotInFact),
32    NotIsCartFact(NotIsCartFact),
33    NotIsTupleFact(NotIsTupleFact),
34    NotSubsetFact(NotSubsetFact),
35    NotSupersetFact(NotSupersetFact),
36    FnEqualInFact(FnEqualInFact),
37    FnEqualFact(FnEqualFact),
38    InjectiveFact(InjectiveFact),
39    SurjectiveFact(SurjectiveFact),
40    BijectiveFact(BijectiveFact),
41    NotInjectiveFact(NotInjectiveFact),
42    NotSurjectiveFact(NotSurjectiveFact),
43    NotBijectiveFact(NotBijectiveFact),
44}
45
46#[derive(Clone)]
47pub struct FnEqualInFact {
48    pub left: Obj,
49    pub right: Obj,
50    pub set: Obj,
51    pub line_file: LineFile,
52}
53
54impl FnEqualInFact {
55    pub fn new(left: Obj, right: Obj, set: Obj, line_file: LineFile) -> Self {
56        FnEqualInFact {
57            left,
58            right,
59            set,
60            line_file,
61        }
62    }
63}
64
65impl fmt::Display for FnEqualInFact {
66    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67        write!(
68            f,
69            "{}{}({}, {}, {})",
70            FACT_PREFIX, FN_EQ_IN, self.left, self.right, self.set
71        )
72    }
73}
74
75#[derive(Clone)]
76pub struct FnEqualFact {
77    pub left: Obj,
78    pub right: Obj,
79    pub line_file: LineFile,
80}
81
82impl FnEqualFact {
83    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
84        FnEqualFact {
85            left,
86            right,
87            line_file,
88        }
89    }
90}
91
92impl fmt::Display for FnEqualFact {
93    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94        write!(f, "{}{}({}, {})", FACT_PREFIX, FN_EQ, self.left, self.right)
95    }
96}
97
98#[derive(Clone)]
99pub struct InjectiveFact {
100    pub function: Obj,
101    pub line_file: LineFile,
102}
103
104#[derive(Clone)]
105pub struct SurjectiveFact {
106    pub function: Obj,
107    pub line_file: LineFile,
108}
109
110#[derive(Clone)]
111pub struct BijectiveFact {
112    pub function: Obj,
113    pub line_file: LineFile,
114}
115
116#[derive(Clone)]
117pub struct NotInjectiveFact {
118    pub function: Obj,
119    pub line_file: LineFile,
120}
121
122#[derive(Clone)]
123pub struct NotSurjectiveFact {
124    pub function: Obj,
125    pub line_file: LineFile,
126}
127
128#[derive(Clone)]
129pub struct NotBijectiveFact {
130    pub function: Obj,
131    pub line_file: LineFile,
132}
133
134impl InjectiveFact {
135    pub fn new(function: Obj, line_file: LineFile) -> Self {
136        InjectiveFact {
137            function,
138            line_file,
139        }
140    }
141}
142
143impl SurjectiveFact {
144    pub fn new(function: Obj, line_file: LineFile) -> Self {
145        SurjectiveFact {
146            function,
147            line_file,
148        }
149    }
150}
151
152impl BijectiveFact {
153    pub fn new(function: Obj, line_file: LineFile) -> Self {
154        BijectiveFact {
155            function,
156            line_file,
157        }
158    }
159}
160
161impl NotInjectiveFact {
162    pub fn new(function: Obj, line_file: LineFile) -> Self {
163        NotInjectiveFact {
164            function,
165            line_file,
166        }
167    }
168}
169
170impl NotSurjectiveFact {
171    pub fn new(function: Obj, line_file: LineFile) -> Self {
172        NotSurjectiveFact {
173            function,
174            line_file,
175        }
176    }
177}
178
179impl NotBijectiveFact {
180    pub fn new(function: Obj, line_file: LineFile) -> Self {
181        NotBijectiveFact {
182            function,
183            line_file,
184        }
185    }
186}
187
188impl fmt::Display for InjectiveFact {
189    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
190        write!(f, "{}{}({})", FACT_PREFIX, INJECTIVE, self.function)
191    }
192}
193
194impl fmt::Display for SurjectiveFact {
195    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
196        write!(f, "{}{}({})", FACT_PREFIX, SURJECTIVE, self.function)
197    }
198}
199
200impl fmt::Display for BijectiveFact {
201    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
202        write!(f, "{}{}({})", FACT_PREFIX, BIJECTIVE, self.function)
203    }
204}
205
206impl fmt::Display for NotInjectiveFact {
207    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
208        write!(f, "{} {}{}({})", NOT, FACT_PREFIX, INJECTIVE, self.function)
209    }
210}
211
212impl fmt::Display for NotSurjectiveFact {
213    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214        write!(
215            f,
216            "{} {}{}({})",
217            NOT, FACT_PREFIX, SURJECTIVE, self.function
218        )
219    }
220}
221
222impl fmt::Display for NotBijectiveFact {
223    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
224        write!(f, "{} {}{}({})", NOT, FACT_PREFIX, BIJECTIVE, self.function)
225    }
226}
227
228#[derive(Clone)]
229pub struct RestrictFact {
230    pub obj: Obj,
231    pub obj_can_restrict_to_fn_set: Obj,
232    pub line_file: LineFile,
233}
234
235#[derive(Clone)]
236pub struct NotRestrictFact {
237    pub obj: Obj,
238    pub obj_cannot_restrict_to_fn_set: Obj,
239    pub line_file: LineFile,
240}
241
242#[derive(Clone)]
243pub struct SupersetFact {
244    pub left: Obj,
245    pub right: Obj,
246    pub line_file: LineFile,
247}
248
249#[derive(Clone)]
250pub struct NotSupersetFact {
251    pub left: Obj,
252    pub right: Obj,
253    pub line_file: LineFile,
254}
255
256#[derive(Clone)]
257pub struct SubsetFact {
258    pub left: Obj,
259    pub right: Obj,
260    pub line_file: LineFile,
261}
262
263#[derive(Clone)]
264pub struct NotSubsetFact {
265    pub left: Obj,
266    pub right: Obj,
267    pub line_file: LineFile,
268}
269
270#[derive(Clone)]
271pub struct IsTupleFact {
272    pub set: Obj,
273    pub line_file: LineFile,
274}
275
276#[derive(Clone)]
277pub struct NotIsTupleFact {
278    pub set: Obj,
279    pub line_file: LineFile,
280}
281
282#[derive(Clone)]
283pub struct IsCartFact {
284    pub set: Obj,
285    pub line_file: LineFile,
286}
287
288#[derive(Clone)]
289pub struct NotIsCartFact {
290    pub set: Obj,
291    pub line_file: LineFile,
292}
293
294#[derive(Clone)]
295pub struct InFact {
296    pub element: Obj,
297    pub set: Obj,
298    pub line_file: LineFile,
299}
300
301#[derive(Clone)]
302pub struct NotInFact {
303    pub element: Obj,
304    pub set: Obj,
305    pub line_file: LineFile,
306}
307
308#[derive(Clone)]
309pub struct NormalAtomicFact {
310    pub predicate: AtomicName,
311    pub body: Vec<Obj>,
312    pub line_file: LineFile,
313}
314
315#[derive(Clone)]
316pub struct NotNormalAtomicFact {
317    pub predicate: AtomicName,
318    pub body: Vec<Obj>,
319    pub line_file: LineFile,
320}
321
322#[derive(Clone)]
323pub struct EqualFact {
324    pub left: Obj,
325    pub right: Obj,
326    pub line_file: LineFile,
327}
328
329#[derive(Clone)]
330pub struct NotEqualFact {
331    pub left: Obj,
332    pub right: Obj,
333    pub line_file: LineFile,
334}
335
336#[derive(Clone)]
337pub struct LessFact {
338    pub left: Obj,
339    pub right: Obj,
340    pub line_file: LineFile,
341}
342
343#[derive(Clone)]
344pub struct NotLessFact {
345    pub left: Obj,
346    pub right: Obj,
347    pub line_file: LineFile,
348}
349
350#[derive(Clone)]
351pub struct GreaterFact {
352    pub left: Obj,
353    pub right: Obj,
354    pub line_file: LineFile,
355}
356
357#[derive(Clone)]
358pub struct NotGreaterFact {
359    pub left: Obj,
360    pub right: Obj,
361    pub line_file: LineFile,
362}
363
364#[derive(Clone)]
365pub struct LessEqualFact {
366    pub left: Obj,
367    pub right: Obj,
368    pub line_file: LineFile,
369}
370
371#[derive(Clone)]
372pub struct NotLessEqualFact {
373    pub left: Obj,
374    pub right: Obj,
375    pub line_file: LineFile,
376}
377
378#[derive(Clone)]
379pub struct GreaterEqualFact {
380    pub left: Obj,
381    pub right: Obj,
382    pub line_file: LineFile,
383}
384
385#[derive(Clone)]
386pub struct NotGreaterEqualFact {
387    pub left: Obj,
388    pub right: Obj,
389    pub line_file: LineFile,
390}
391
392#[derive(Clone)]
393pub struct IsSetFact {
394    pub set: Obj,
395    pub line_file: LineFile,
396}
397
398#[derive(Clone)]
399pub struct NotIsSetFact {
400    pub set: Obj,
401    pub line_file: LineFile,
402}
403
404#[derive(Clone)]
405pub struct IsNonemptySetFact {
406    pub set: Obj,
407    pub line_file: LineFile,
408}
409
410#[derive(Clone)]
411pub struct NotIsNonemptySetFact {
412    pub set: Obj,
413    pub line_file: LineFile,
414}
415
416#[derive(Clone)]
417pub struct IsFiniteSetFact {
418    pub set: Obj,
419    pub line_file: LineFile,
420}
421
422#[derive(Clone)]
423pub struct NotIsFiniteSetFact {
424    pub set: Obj,
425    pub line_file: LineFile,
426}
427
428impl SubsetFact {
429    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
430        SubsetFact {
431            left,
432            right,
433            line_file,
434        }
435    }
436}
437
438impl NotSubsetFact {
439    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
440        NotSubsetFact {
441            left,
442            right,
443            line_file,
444        }
445    }
446}
447
448impl NormalAtomicFact {
449    pub fn new(predicate: AtomicName, body: Vec<Obj>, line_file: LineFile) -> Self {
450        NormalAtomicFact {
451            predicate,
452            body,
453            line_file,
454        }
455    }
456}
457
458impl NotNormalAtomicFact {
459    pub fn new(predicate: AtomicName, body: Vec<Obj>, line_file: LineFile) -> Self {
460        NotNormalAtomicFact {
461            predicate,
462            body,
463            line_file,
464        }
465    }
466}
467
468impl EqualFact {
469    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
470        EqualFact {
471            left,
472            right,
473            line_file,
474        }
475    }
476}
477
478impl NotEqualFact {
479    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
480        NotEqualFact {
481            left,
482            right,
483            line_file,
484        }
485    }
486}
487
488impl LessFact {
489    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
490        LessFact {
491            left,
492            right,
493            line_file,
494        }
495    }
496}
497
498impl NotLessFact {
499    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
500        NotLessFact {
501            left,
502            right,
503            line_file,
504        }
505    }
506}
507
508impl GreaterFact {
509    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
510        GreaterFact {
511            left,
512            right,
513            line_file,
514        }
515    }
516}
517
518impl NotGreaterFact {
519    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
520        NotGreaterFact {
521            left,
522            right,
523            line_file,
524        }
525    }
526}
527
528impl LessEqualFact {
529    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
530        LessEqualFact {
531            left,
532            right,
533            line_file,
534        }
535    }
536}
537
538impl NotLessEqualFact {
539    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
540        NotLessEqualFact {
541            left,
542            right,
543            line_file,
544        }
545    }
546}
547
548impl GreaterEqualFact {
549    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
550        GreaterEqualFact {
551            left,
552            right,
553            line_file,
554        }
555    }
556}
557
558impl NotGreaterEqualFact {
559    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
560        NotGreaterEqualFact {
561            left,
562            right,
563            line_file,
564        }
565    }
566}
567
568impl IsSetFact {
569    pub fn new(set: Obj, line_file: LineFile) -> Self {
570        IsSetFact { set, line_file }
571    }
572}
573
574impl NotIsSetFact {
575    pub fn new(set: Obj, line_file: LineFile) -> Self {
576        NotIsSetFact { set, line_file }
577    }
578}
579
580impl IsNonemptySetFact {
581    pub fn new(set: Obj, line_file: LineFile) -> Self {
582        IsNonemptySetFact { set, line_file }
583    }
584}
585
586impl NotIsNonemptySetFact {
587    pub fn new(set: Obj, line_file: LineFile) -> Self {
588        NotIsNonemptySetFact { set, line_file }
589    }
590}
591
592impl IsFiniteSetFact {
593    pub fn new(set: Obj, line_file: LineFile) -> Self {
594        IsFiniteSetFact { set, line_file }
595    }
596}
597
598impl NotIsFiniteSetFact {
599    pub fn new(set: Obj, line_file: LineFile) -> Self {
600        NotIsFiniteSetFact { set, line_file }
601    }
602}
603
604impl InFact {
605    pub fn new(element: Obj, set: Obj, line_file: LineFile) -> Self {
606        InFact {
607            element,
608            set,
609            line_file,
610        }
611    }
612}
613
614impl NotInFact {
615    pub fn new(element: Obj, set: Obj, line_file: LineFile) -> Self {
616        NotInFact {
617            element,
618            set,
619            line_file,
620        }
621    }
622}
623
624impl IsCartFact {
625    pub fn new(set: Obj, line_file: LineFile) -> Self {
626        IsCartFact { set, line_file }
627    }
628}
629
630impl NotIsCartFact {
631    pub fn new(set: Obj, line_file: LineFile) -> Self {
632        NotIsCartFact { set, line_file }
633    }
634}
635
636impl IsTupleFact {
637    pub fn new(tuple: Obj, line_file: LineFile) -> Self {
638        IsTupleFact {
639            set: tuple,
640            line_file,
641        }
642    }
643}
644
645impl NotIsTupleFact {
646    pub fn new(tuple: Obj, line_file: LineFile) -> Self {
647        NotIsTupleFact {
648            set: tuple,
649            line_file,
650        }
651    }
652}
653
654impl SupersetFact {
655    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
656        SupersetFact {
657            left,
658            right,
659            line_file,
660        }
661    }
662}
663
664impl NotSupersetFact {
665    pub fn new(left: Obj, right: Obj, line_file: LineFile) -> Self {
666        NotSupersetFact {
667            left,
668            right,
669            line_file,
670        }
671    }
672}
673
674impl fmt::Display for AtomicFact {
675    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
676        match self {
677            AtomicFact::NormalAtomicFact(x) => write!(f, "{}", x),
678            AtomicFact::EqualFact(x) => write!(f, "{}", x),
679            AtomicFact::LessFact(x) => write!(f, "{}", x),
680            AtomicFact::GreaterFact(x) => write!(f, "{}", x),
681            AtomicFact::LessEqualFact(x) => write!(f, "{}", x),
682            AtomicFact::GreaterEqualFact(x) => write!(f, "{}", x),
683            AtomicFact::IsSetFact(x) => write!(f, "{}", x),
684            AtomicFact::IsNonemptySetFact(x) => write!(f, "{}", x),
685            AtomicFact::IsFiniteSetFact(x) => write!(f, "{}", x),
686            AtomicFact::NotNormalAtomicFact(x) => write!(f, "{}", x),
687            AtomicFact::NotEqualFact(x) => write!(f, "{}", x),
688            AtomicFact::NotLessFact(x) => write!(f, "{}", x),
689            AtomicFact::NotGreaterFact(x) => write!(f, "{}", x),
690            AtomicFact::NotLessEqualFact(x) => write!(f, "{}", x),
691            AtomicFact::NotGreaterEqualFact(x) => write!(f, "{}", x),
692            AtomicFact::NotIsSetFact(x) => write!(f, "{}", x),
693            AtomicFact::NotIsNonemptySetFact(x) => write!(f, "{}", x),
694            AtomicFact::NotIsFiniteSetFact(x) => write!(f, "{}", x),
695            AtomicFact::InFact(x) => write!(f, "{}", x),
696            AtomicFact::NotInFact(x) => write!(f, "{}", x),
697            AtomicFact::IsCartFact(x) => write!(f, "{}", x),
698            AtomicFact::NotIsCartFact(x) => write!(f, "{}", x),
699            AtomicFact::IsTupleFact(x) => write!(f, "{}", x),
700            AtomicFact::NotIsTupleFact(x) => write!(f, "{}", x),
701            AtomicFact::SubsetFact(x) => write!(f, "{}", x),
702            AtomicFact::NotSubsetFact(x) => write!(f, "{}", x),
703            AtomicFact::SupersetFact(x) => write!(f, "{}", x),
704            AtomicFact::NotSupersetFact(x) => write!(f, "{}", x),
705            AtomicFact::RestrictFact(x) => write!(f, "{}", x),
706            AtomicFact::NotRestrictFact(x) => write!(f, "{}", x),
707            AtomicFact::FnEqualInFact(x) => write!(f, "{}", x),
708            AtomicFact::FnEqualFact(x) => write!(f, "{}", x),
709            AtomicFact::InjectiveFact(x) => write!(f, "{}", x),
710            AtomicFact::SurjectiveFact(x) => write!(f, "{}", x),
711            AtomicFact::BijectiveFact(x) => write!(f, "{}", x),
712            AtomicFact::NotInjectiveFact(x) => write!(f, "{}", x),
713            AtomicFact::NotSurjectiveFact(x) => write!(f, "{}", x),
714            AtomicFact::NotBijectiveFact(x) => write!(f, "{}", x),
715        }
716    }
717}
718
719impl fmt::Display for SupersetFact {
720    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
721        write!(
722            f,
723            "{} {}{} {}",
724            self.left, FACT_PREFIX, SUPERSET, self.right
725        )
726    }
727}
728
729impl fmt::Display for NotSupersetFact {
730    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
731        write!(
732            f,
733            "{} {} {}{} {}",
734            NOT, self.left, FACT_PREFIX, SUPERSET, self.right
735        )
736    }
737}
738
739impl fmt::Display for SubsetFact {
740    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
741        write!(f, "{} {}{} {}", self.left, FACT_PREFIX, SUBSET, self.right)
742    }
743}
744
745impl fmt::Display for NotSubsetFact {
746    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
747        write!(
748            f,
749            "{} {} {}{} {}",
750            NOT, self.left, FACT_PREFIX, SUBSET, self.right
751        )
752    }
753}
754
755impl fmt::Display for InFact {
756    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
757        write!(f, "{} {}{} {}", self.element, FACT_PREFIX, IN, self.set)
758    }
759}
760
761impl fmt::Display for NotInFact {
762    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
763        write!(
764            f,
765            "{} {} {}{} {}",
766            NOT, self.element, FACT_PREFIX, IN, self.set
767        )
768    }
769}
770
771impl fmt::Display for IsCartFact {
772    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
773        write!(f, "{}{}{}", FACT_PREFIX, IS_CART, braced_string(&self.set))
774    }
775}
776
777impl fmt::Display for NotIsCartFact {
778    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
779        write!(
780            f,
781            "{} {}{}{}",
782            NOT,
783            FACT_PREFIX,
784            IS_CART,
785            braced_string(&self.set)
786        )
787    }
788}
789
790impl fmt::Display for IsTupleFact {
791    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
792        write!(f, "{}{}{}", FACT_PREFIX, IS_TUPLE, braced_string(&self.set))
793    }
794}
795
796impl fmt::Display for NotIsTupleFact {
797    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
798        write!(
799            f,
800            "{} {}{}{}",
801            NOT,
802            FACT_PREFIX,
803            IS_TUPLE,
804            braced_string(&self.set)
805        )
806    }
807}
808
809impl fmt::Display for NormalAtomicFact {
810    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
811        write!(
812            f,
813            "{}{}{}",
814            FACT_PREFIX,
815            self.predicate,
816            braced_vec_to_string(&self.body)
817        )
818    }
819}
820
821impl fmt::Display for NotNormalAtomicFact {
822    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
823        write!(
824            f,
825            "{} {}{}{}",
826            NOT,
827            FACT_PREFIX,
828            self.predicate,
829            braced_vec_to_string(&self.body)
830        )
831    }
832}
833
834impl fmt::Display for EqualFact {
835    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
836        write!(f, "{} {} {}", self.left, EQUAL, self.right)
837    }
838}
839
840impl fmt::Display for NotEqualFact {
841    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
842        write!(f, "{} {} {}", self.left, NOT_EQUAL, self.right)
843    }
844}
845
846impl fmt::Display for LessFact {
847    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
848        write!(f, "{} {} {}", self.left, LESS, self.right)
849    }
850}
851
852impl fmt::Display for NotLessFact {
853    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
854        write!(f, "{} {} {} {}", NOT, self.left, LESS, self.right)
855    }
856}
857
858impl fmt::Display for GreaterFact {
859    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
860        write!(f, "{} {} {}", self.left, GREATER, self.right)
861    }
862}
863
864impl fmt::Display for NotGreaterFact {
865    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
866        write!(f, "{} {} {} {}", NOT, self.left, GREATER, self.right)
867    }
868}
869
870impl fmt::Display for LessEqualFact {
871    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
872        write!(f, "{} {} {}", self.left, LESS_EQUAL, self.right)
873    }
874}
875
876impl fmt::Display for NotLessEqualFact {
877    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
878        write!(f, "{} {} {} {}", NOT, self.left, LESS_EQUAL, self.right)
879    }
880}
881
882impl fmt::Display for GreaterEqualFact {
883    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
884        write!(f, "{} {} {}", self.left, GREATER_EQUAL, self.right)
885    }
886}
887
888impl fmt::Display for NotGreaterEqualFact {
889    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
890        write!(f, "{} {} {} {}", NOT, self.left, GREATER_EQUAL, self.right)
891    }
892}
893
894impl fmt::Display for IsSetFact {
895    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
896        write!(f, "{}{}{}", FACT_PREFIX, IS_SET, braced_string(&self.set))
897    }
898}
899
900impl fmt::Display for NotIsSetFact {
901    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
902        write!(
903            f,
904            "{} {}{}{}",
905            NOT,
906            FACT_PREFIX,
907            IS_SET,
908            braced_string(&self.set)
909        )
910    }
911}
912
913impl fmt::Display for IsNonemptySetFact {
914    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
915        write!(
916            f,
917            "{}{}{}",
918            FACT_PREFIX,
919            IS_NONEMPTY_SET,
920            braced_string(&self.set)
921        )
922    }
923}
924
925impl fmt::Display for NotIsNonemptySetFact {
926    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
927        write!(
928            f,
929            "{} {}{}{}",
930            NOT,
931            FACT_PREFIX,
932            IS_NONEMPTY_SET,
933            braced_string(&self.set)
934        )
935    }
936}
937
938impl fmt::Display for IsFiniteSetFact {
939    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
940        write!(
941            f,
942            "{}{}{}",
943            FACT_PREFIX,
944            IS_FINITE_SET,
945            braced_string(&self.set)
946        )
947    }
948}
949
950impl fmt::Display for NotIsFiniteSetFact {
951    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
952        write!(
953            f,
954            "{} {}{}{}",
955            NOT,
956            FACT_PREFIX,
957            IS_FINITE_SET,
958            braced_string(&self.set)
959        )
960    }
961}
962
963impl AtomicFact {
964    pub fn replace_bound_identifier(self, from: &str, to: &str) -> Self {
965        if from == to {
966            return self;
967        }
968        fn r(o: Obj, from: &str, to: &str) -> Obj {
969            Obj::replace_bound_identifier(o, from, to)
970        }
971        match self {
972            AtomicFact::NormalAtomicFact(x) => NormalAtomicFact::new(
973                x.predicate,
974                x.body.into_iter().map(|o| r(o, from, to)).collect(),
975                x.line_file,
976            )
977            .into(),
978            AtomicFact::EqualFact(x) => {
979                EqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
980            }
981            AtomicFact::LessFact(x) => {
982                LessFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
983            }
984            AtomicFact::GreaterFact(x) => {
985                GreaterFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
986            }
987            AtomicFact::LessEqualFact(x) => {
988                LessEqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
989            }
990            AtomicFact::GreaterEqualFact(x) => {
991                GreaterEqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
992            }
993            AtomicFact::IsSetFact(x) => IsSetFact::new(r(x.set, from, to), x.line_file).into(),
994            AtomicFact::IsNonemptySetFact(x) => {
995                IsNonemptySetFact::new(r(x.set, from, to), x.line_file).into()
996            }
997            AtomicFact::IsFiniteSetFact(x) => {
998                IsFiniteSetFact::new(r(x.set, from, to), x.line_file).into()
999            }
1000            AtomicFact::InFact(x) => {
1001                InFact::new(r(x.element, from, to), r(x.set, from, to), x.line_file).into()
1002            }
1003            AtomicFact::IsCartFact(x) => IsCartFact::new(r(x.set, from, to), x.line_file).into(),
1004            AtomicFact::IsTupleFact(x) => IsTupleFact::new(r(x.set, from, to), x.line_file).into(),
1005            AtomicFact::SubsetFact(x) => {
1006                SubsetFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1007            }
1008            AtomicFact::SupersetFact(x) => {
1009                SupersetFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1010            }
1011            AtomicFact::RestrictFact(x) => RestrictFact::new(
1012                r(x.obj, from, to),
1013                r(x.obj_can_restrict_to_fn_set, from, to),
1014                x.line_file,
1015            )
1016            .into(),
1017            AtomicFact::NotRestrictFact(x) => NotRestrictFact::new(
1018                r(x.obj, from, to),
1019                r(x.obj_cannot_restrict_to_fn_set, from, to),
1020                x.line_file,
1021            )
1022            .into(),
1023            AtomicFact::NotNormalAtomicFact(x) => NotNormalAtomicFact::new(
1024                x.predicate,
1025                x.body.into_iter().map(|o| r(o, from, to)).collect(),
1026                x.line_file,
1027            )
1028            .into(),
1029            AtomicFact::NotEqualFact(x) => {
1030                NotEqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1031            }
1032            AtomicFact::NotLessFact(x) => {
1033                NotLessFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1034            }
1035            AtomicFact::NotGreaterFact(x) => {
1036                NotGreaterFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1037            }
1038            AtomicFact::NotLessEqualFact(x) => {
1039                NotLessEqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1040            }
1041            AtomicFact::NotGreaterEqualFact(x) => {
1042                NotGreaterEqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file)
1043                    .into()
1044            }
1045            AtomicFact::NotIsSetFact(x) => {
1046                NotIsSetFact::new(r(x.set, from, to), x.line_file).into()
1047            }
1048            AtomicFact::NotIsNonemptySetFact(x) => {
1049                NotIsNonemptySetFact::new(r(x.set, from, to), x.line_file).into()
1050            }
1051            AtomicFact::NotIsFiniteSetFact(x) => {
1052                NotIsFiniteSetFact::new(r(x.set, from, to), x.line_file).into()
1053            }
1054            AtomicFact::NotInFact(x) => {
1055                NotInFact::new(r(x.element, from, to), r(x.set, from, to), x.line_file).into()
1056            }
1057            AtomicFact::NotIsCartFact(x) => {
1058                NotIsCartFact::new(r(x.set, from, to), x.line_file).into()
1059            }
1060            AtomicFact::NotIsTupleFact(x) => {
1061                NotIsTupleFact::new(r(x.set, from, to), x.line_file).into()
1062            }
1063            AtomicFact::NotSubsetFact(x) => {
1064                NotSubsetFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1065            }
1066            AtomicFact::NotSupersetFact(x) => {
1067                NotSupersetFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1068            }
1069            AtomicFact::FnEqualInFact(x) => FnEqualInFact::new(
1070                r(x.left, from, to),
1071                r(x.right, from, to),
1072                r(x.set, from, to),
1073                x.line_file,
1074            )
1075            .into(),
1076            AtomicFact::FnEqualFact(x) => {
1077                FnEqualFact::new(r(x.left, from, to), r(x.right, from, to), x.line_file).into()
1078            }
1079            AtomicFact::InjectiveFact(x) => {
1080                InjectiveFact::new(r(x.function, from, to), x.line_file).into()
1081            }
1082            AtomicFact::SurjectiveFact(x) => {
1083                SurjectiveFact::new(r(x.function, from, to), x.line_file).into()
1084            }
1085            AtomicFact::BijectiveFact(x) => {
1086                BijectiveFact::new(r(x.function, from, to), x.line_file).into()
1087            }
1088            AtomicFact::NotInjectiveFact(x) => {
1089                NotInjectiveFact::new(r(x.function, from, to), x.line_file).into()
1090            }
1091            AtomicFact::NotSurjectiveFact(x) => {
1092                NotSurjectiveFact::new(r(x.function, from, to), x.line_file).into()
1093            }
1094            AtomicFact::NotBijectiveFact(x) => {
1095                NotBijectiveFact::new(r(x.function, from, to), x.line_file).into()
1096            }
1097        }
1098    }
1099}
1100
1101impl AtomicFact {
1102    fn predicate_string(&self) -> String {
1103        match self {
1104            AtomicFact::NormalAtomicFact(x) => x.predicate.to_string(),
1105            AtomicFact::EqualFact(_) => EQUAL.to_string(),
1106            AtomicFact::LessFact(_) => LESS.to_string(),
1107            AtomicFact::GreaterFact(_) => GREATER.to_string(),
1108            AtomicFact::LessEqualFact(_) => LESS_EQUAL.to_string(),
1109            AtomicFact::GreaterEqualFact(_) => GREATER_EQUAL.to_string(),
1110            AtomicFact::IsSetFact(_) => IS_SET.to_string(),
1111            AtomicFact::IsNonemptySetFact(_) => IS_NONEMPTY_SET.to_string(),
1112            AtomicFact::IsFiniteSetFact(_) => IS_FINITE_SET.to_string(),
1113            AtomicFact::InFact(_) => IN.to_string(),
1114            AtomicFact::IsCartFact(_) => IS_CART.to_string(),
1115            AtomicFact::IsTupleFact(_) => IS_TUPLE.to_string(),
1116            AtomicFact::SubsetFact(_) => SUBSET.to_string(),
1117            AtomicFact::SupersetFact(_) => SUPERSET.to_string(),
1118            AtomicFact::NotNormalAtomicFact(x) => x.predicate.to_string(),
1119            AtomicFact::NotEqualFact(_) => EQUAL.to_string(),
1120            AtomicFact::NotLessFact(_) => LESS.to_string(),
1121            AtomicFact::NotGreaterFact(_) => GREATER.to_string(),
1122            AtomicFact::NotLessEqualFact(_) => LESS_EQUAL.to_string(),
1123            AtomicFact::NotGreaterEqualFact(_) => GREATER_EQUAL.to_string(),
1124            AtomicFact::NotIsSetFact(_) => IS_SET.to_string(),
1125            AtomicFact::NotIsNonemptySetFact(_) => IS_NONEMPTY_SET.to_string(),
1126            AtomicFact::NotIsFiniteSetFact(_) => IS_FINITE_SET.to_string(),
1127            AtomicFact::NotInFact(_) => IN.to_string(),
1128            AtomicFact::NotIsCartFact(_) => IS_CART.to_string(),
1129            AtomicFact::NotIsTupleFact(_) => IS_TUPLE.to_string(),
1130            AtomicFact::NotSubsetFact(_) => SUBSET.to_string(),
1131            AtomicFact::NotSupersetFact(_) => SUPERSET.to_string(),
1132            AtomicFact::RestrictFact(_) => RESTRICT_FN_IN.to_string(),
1133            AtomicFact::NotRestrictFact(_) => RESTRICT_FN_IN.to_string(),
1134            AtomicFact::FnEqualInFact(_) => FN_EQ_IN.to_string(),
1135            AtomicFact::FnEqualFact(_) => FN_EQ.to_string(),
1136            AtomicFact::InjectiveFact(_) => INJECTIVE.to_string(),
1137            AtomicFact::SurjectiveFact(_) => SURJECTIVE.to_string(),
1138            AtomicFact::BijectiveFact(_) => BIJECTIVE.to_string(),
1139            AtomicFact::NotInjectiveFact(_) => INJECTIVE.to_string(),
1140            AtomicFact::NotSurjectiveFact(_) => SURJECTIVE.to_string(),
1141            AtomicFact::NotBijectiveFact(_) => BIJECTIVE.to_string(),
1142        }
1143    }
1144
1145    pub fn is_true(&self) -> bool {
1146        match self {
1147            AtomicFact::NormalAtomicFact(_) => true,
1148            AtomicFact::EqualFact(_) => true,
1149            AtomicFact::LessFact(_) => true,
1150            AtomicFact::GreaterFact(_) => true,
1151            AtomicFact::LessEqualFact(_) => true,
1152            AtomicFact::GreaterEqualFact(_) => true,
1153            AtomicFact::IsSetFact(_) => true,
1154            AtomicFact::IsNonemptySetFact(_) => true,
1155            AtomicFact::IsFiniteSetFact(_) => true,
1156            AtomicFact::InFact(_) => true,
1157            AtomicFact::IsCartFact(_) => true,
1158            AtomicFact::IsTupleFact(_) => true,
1159            AtomicFact::SubsetFact(_) => true,
1160            AtomicFact::SupersetFact(_) => true,
1161            AtomicFact::RestrictFact(_) => true,
1162            AtomicFact::NotNormalAtomicFact(_) => false,
1163            AtomicFact::NotEqualFact(_) => false,
1164            AtomicFact::NotLessFact(_) => false,
1165            AtomicFact::NotGreaterFact(_) => false,
1166            AtomicFact::NotLessEqualFact(_) => false,
1167            AtomicFact::NotGreaterEqualFact(_) => false,
1168            AtomicFact::NotIsSetFact(_) => false,
1169            AtomicFact::NotIsNonemptySetFact(_) => false,
1170            AtomicFact::NotIsFiniteSetFact(_) => false,
1171            AtomicFact::NotInFact(_) => false,
1172            AtomicFact::NotIsCartFact(_) => false,
1173            AtomicFact::NotIsTupleFact(_) => false,
1174            AtomicFact::NotSubsetFact(_) => false,
1175            AtomicFact::NotSupersetFact(_) => false,
1176            AtomicFact::NotRestrictFact(_) => false,
1177            AtomicFact::FnEqualInFact(_) => true,
1178            AtomicFact::FnEqualFact(_) => true,
1179            AtomicFact::InjectiveFact(_) => true,
1180            AtomicFact::SurjectiveFact(_) => true,
1181            AtomicFact::BijectiveFact(_) => true,
1182            AtomicFact::NotInjectiveFact(_) => false,
1183            AtomicFact::NotSurjectiveFact(_) => false,
1184            AtomicFact::NotBijectiveFact(_) => false,
1185        }
1186    }
1187
1188    pub fn key(&self) -> String {
1189        return self.predicate_string();
1190    }
1191
1192    pub fn transposed_binary_order_equivalent(&self) -> Option<Self> {
1193        match self {
1194            AtomicFact::LessFact(f) => {
1195                Some(GreaterFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()).into())
1196            }
1197            AtomicFact::GreaterFact(f) => {
1198                Some(LessFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()).into())
1199            }
1200            AtomicFact::LessEqualFact(f) => Some(AtomicFact::GreaterEqualFact(
1201                GreaterEqualFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()),
1202            )),
1203            AtomicFact::GreaterEqualFact(f) => Some(
1204                LessEqualFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()).into(),
1205            ),
1206            AtomicFact::NotLessFact(f) => Some(
1207                NotGreaterFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()).into(),
1208            ),
1209            AtomicFact::NotGreaterFact(f) => {
1210                Some(NotLessFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()).into())
1211            }
1212            AtomicFact::NotLessEqualFact(f) => Some(AtomicFact::NotGreaterEqualFact(
1213                NotGreaterEqualFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()),
1214            )),
1215            AtomicFact::NotGreaterEqualFact(f) => Some(AtomicFact::NotLessEqualFact(
1216                NotLessEqualFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()),
1217            )),
1218            AtomicFact::FnEqualFact(f) => {
1219                Some(FnEqualFact::new(f.right.clone(), f.left.clone(), f.line_file.clone()).into())
1220            }
1221            AtomicFact::FnEqualInFact(f) => Some(
1222                FnEqualInFact::new(
1223                    f.right.clone(),
1224                    f.left.clone(),
1225                    f.set.clone(),
1226                    f.line_file.clone(),
1227                )
1228                .into(),
1229            ),
1230            _ => None,
1231        }
1232    }
1233
1234    pub fn commutative_reordered_args(&self, gather: &[usize]) -> Option<Self> {
1235        match self {
1236            AtomicFact::NormalAtomicFact(f) => {
1237                let n = f.body.len();
1238                if gather.len() != n || n < 2 {
1239                    return None;
1240                }
1241                let mut seen = vec![false; n];
1242                for &i in gather {
1243                    if i >= n || seen[i] {
1244                        return None;
1245                    }
1246                    seen[i] = true;
1247                }
1248                let new_body: Vec<Obj> = gather.iter().map(|&i| f.body[i].clone()).collect();
1249                Some(
1250                    NormalAtomicFact::new(f.predicate.clone(), new_body, f.line_file.clone())
1251                        .into(),
1252                )
1253            }
1254            _ => None,
1255        }
1256    }
1257}
1258
1259impl AtomicFact {
1260    pub fn to_atomic_fact(
1261        prop_name: AtomicName,
1262        is_true: bool,
1263        args: Vec<Obj>,
1264        line_file: LineFile,
1265    ) -> Result<AtomicFact, RuntimeError> {
1266        let prop_name_as_string = prop_name.to_string();
1267        match prop_name_as_string.as_str() {
1268            EQUAL => {
1269                if args.len() != 2 {
1270                    let msg = format!("{} requires 2 arguments, but got {}", EQUAL, args.len());
1271                    return Err(NewFactRuntimeError(
1272                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1273                    )
1274                    .into());
1275                }
1276                let mut args = args;
1277                let a0 = args.remove(0);
1278                let a1 = args.remove(0);
1279                if is_true {
1280                    Ok(EqualFact::new(a0, a1, line_file).into())
1281                } else {
1282                    Ok(NotEqualFact::new(a0, a1, line_file).into())
1283                }
1284            }
1285            NOT_EQUAL => {
1286                if args.len() != 2 {
1287                    let msg = format!("{} requires 2 arguments, but got {}", NOT_EQUAL, args.len());
1288                    return Err(NewFactRuntimeError(
1289                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1290                    )
1291                    .into());
1292                }
1293                let mut args = args;
1294                let a0 = args.remove(0);
1295                let a1 = args.remove(0);
1296                if is_true {
1297                    Ok(NotEqualFact::new(a0, a1, line_file).into())
1298                } else {
1299                    Ok(EqualFact::new(a0, a1, line_file).into())
1300                }
1301            }
1302            LESS => {
1303                if args.len() != 2 {
1304                    let msg = format!("{} requires 2 arguments, but got {}", LESS, args.len());
1305                    return Err(NewFactRuntimeError(
1306                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1307                    )
1308                    .into());
1309                }
1310                let mut args = args;
1311                let a0 = args.remove(0);
1312                let a1 = args.remove(0);
1313                if is_true {
1314                    Ok(LessFact::new(a0, a1, line_file).into())
1315                } else {
1316                    Ok(NotLessFact::new(a0, a1, line_file).into())
1317                }
1318            }
1319            GREATER => {
1320                if args.len() != 2 {
1321                    let msg = format!("{} requires 2 arguments, but got {}", GREATER, args.len());
1322                    return Err(NewFactRuntimeError(
1323                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1324                    )
1325                    .into());
1326                }
1327                let mut args = args;
1328                let a0 = args.remove(0);
1329                let a1 = args.remove(0);
1330                if is_true {
1331                    Ok(GreaterFact::new(a0, a1, line_file).into())
1332                } else {
1333                    Ok(NotGreaterFact::new(a0, a1, line_file).into())
1334                }
1335            }
1336            LESS_EQUAL => {
1337                if args.len() != 2 {
1338                    let msg = format!(
1339                        "{} requires 2 arguments, but got {}",
1340                        LESS_EQUAL,
1341                        args.len()
1342                    );
1343                    return Err(NewFactRuntimeError(
1344                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1345                    )
1346                    .into());
1347                }
1348                let mut args = args;
1349                let a0 = args.remove(0);
1350                let a1 = args.remove(0);
1351                if is_true {
1352                    Ok(LessEqualFact::new(a0, a1, line_file).into())
1353                } else {
1354                    Ok(NotLessEqualFact::new(a0, a1, line_file).into())
1355                }
1356            }
1357            GREATER_EQUAL => {
1358                if args.len() != 2 {
1359                    let msg = format!(
1360                        "{} requires 2 arguments, but got {}",
1361                        GREATER_EQUAL,
1362                        args.len()
1363                    );
1364                    return Err(NewFactRuntimeError(
1365                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1366                    )
1367                    .into());
1368                }
1369                let mut args = args;
1370                let a0 = args.remove(0);
1371                let a1 = args.remove(0);
1372                if is_true {
1373                    Ok(GreaterEqualFact::new(a0, a1, line_file).into())
1374                } else {
1375                    Ok(NotGreaterEqualFact::new(a0, a1, line_file).into())
1376                }
1377            }
1378            IS_SET => {
1379                if args.len() != 1 {
1380                    let msg = format!("{} requires 1 argument, but got {}", IS_SET, args.len());
1381                    return Err(NewFactRuntimeError(
1382                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1383                    )
1384                    .into());
1385                }
1386                let mut args = args;
1387                let a0 = args.remove(0);
1388                if is_true {
1389                    Ok(IsSetFact::new(a0, line_file).into())
1390                } else {
1391                    Ok(NotIsSetFact::new(a0, line_file).into())
1392                }
1393            }
1394            IS_NONEMPTY_SET => {
1395                if args.len() != 1 {
1396                    let msg = format!(
1397                        "{} requires 1 argument, but got {}",
1398                        IS_NONEMPTY_SET,
1399                        args.len()
1400                    );
1401                    return Err(NewFactRuntimeError(
1402                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1403                    )
1404                    .into());
1405                }
1406                let mut args = args;
1407                let a0 = args.remove(0);
1408                if is_true {
1409                    Ok(IsNonemptySetFact::new(a0, line_file).into())
1410                } else {
1411                    Ok(NotIsNonemptySetFact::new(a0, line_file).into())
1412                }
1413            }
1414            IS_FINITE_SET => {
1415                if args.len() != 1 {
1416                    let msg = format!(
1417                        "{} requires 1 argument, but got {}",
1418                        IS_FINITE_SET,
1419                        args.len()
1420                    );
1421                    return Err(NewFactRuntimeError(
1422                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1423                    )
1424                    .into());
1425                }
1426                let mut args = args;
1427                let a0 = args.remove(0);
1428                if is_true {
1429                    Ok(IsFiniteSetFact::new(a0, line_file).into())
1430                } else {
1431                    Ok(NotIsFiniteSetFact::new(a0, line_file).into())
1432                }
1433            }
1434            IN => {
1435                if args.len() != 2 {
1436                    let msg = format!("{} requires 2 arguments, but got {}", IN, args.len());
1437                    return Err(NewFactRuntimeError(
1438                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1439                    )
1440                    .into());
1441                }
1442                let mut args = args;
1443                let a0 = args.remove(0);
1444                let a1 = args.remove(0);
1445                if is_true {
1446                    Ok(InFact::new(a0, a1, line_file).into())
1447                } else {
1448                    Ok(NotInFact::new(a0, a1, line_file).into())
1449                }
1450            }
1451            IS_CART => {
1452                if args.len() != 1 {
1453                    let msg = format!("{} requires 1 argument, but got {}", IS_CART, args.len());
1454                    return Err(NewFactRuntimeError(
1455                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1456                    )
1457                    .into());
1458                }
1459                let mut args = args;
1460                let a0 = args.remove(0);
1461                if is_true {
1462                    Ok(IsCartFact::new(a0, line_file).into())
1463                } else {
1464                    Ok(NotIsCartFact::new(a0, line_file).into())
1465                }
1466            }
1467            IS_TUPLE => {
1468                if args.len() != 1 {
1469                    let msg = format!("{} requires 1 argument, but got {}", IS_TUPLE, args.len());
1470                    return Err(NewFactRuntimeError(
1471                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1472                    )
1473                    .into());
1474                }
1475                let mut args = args;
1476                let a0 = args.remove(0);
1477                if is_true {
1478                    Ok(IsTupleFact::new(a0, line_file).into())
1479                } else {
1480                    Ok(NotIsTupleFact::new(a0, line_file).into())
1481                }
1482            }
1483            SUBSET => {
1484                if args.len() != 2 {
1485                    let msg = format!("{} requires 2 arguments, but got {}", SUBSET, args.len());
1486                    return Err(NewFactRuntimeError(
1487                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1488                    )
1489                    .into());
1490                }
1491                let mut args = args;
1492                let a0 = args.remove(0);
1493                let a1 = args.remove(0);
1494                if is_true {
1495                    Ok(SubsetFact::new(a0, a1, line_file).into())
1496                } else {
1497                    Ok(NotSubsetFact::new(a0, a1, line_file).into())
1498                }
1499            }
1500            SUPERSET => {
1501                if args.len() != 2 {
1502                    let msg = format!("{} requires 2 arguments, but got {}", SUPERSET, args.len());
1503                    return Err(NewFactRuntimeError(
1504                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1505                    )
1506                    .into());
1507                }
1508                let mut args = args;
1509                let a0 = args.remove(0);
1510                let a1 = args.remove(0);
1511                if is_true {
1512                    Ok(SupersetFact::new(a0, a1, line_file).into())
1513                } else {
1514                    Ok(NotSupersetFact::new(a0, a1, line_file).into())
1515                }
1516            }
1517            RESTRICT_FN_IN => {
1518                if args.len() != 2 {
1519                    let msg = format!(
1520                        "{} requires 2 arguments, but got {}",
1521                        RESTRICT_FN_IN,
1522                        args.len()
1523                    );
1524                    return Err(NewFactRuntimeError(
1525                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1526                    )
1527                    .into());
1528                }
1529                let mut args = args;
1530                let a0 = args.remove(0);
1531                let a1 = args.remove(0);
1532                if is_true {
1533                    Ok(RestrictFact::new(a0, a1, line_file).into())
1534                } else {
1535                    Ok(NotRestrictFact::new(a0, a1, line_file).into())
1536                }
1537            }
1538            FN_EQ_IN => {
1539                if !is_true {
1540                    let msg = format!("{} does not support `not`", FN_EQ_IN);
1541                    return Err(NewFactRuntimeError(
1542                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1543                    )
1544                    .into());
1545                }
1546                if args.len() != 3 {
1547                    let msg = format!(
1548                        "{} requires 3 arguments (f, g, set), but got {}",
1549                        FN_EQ_IN,
1550                        args.len()
1551                    );
1552                    return Err(NewFactRuntimeError(
1553                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1554                    )
1555                    .into());
1556                }
1557                let mut args = args;
1558                let a0 = args.remove(0);
1559                let a1 = args.remove(0);
1560                let a2 = args.remove(0);
1561                Ok(FnEqualInFact::new(a0, a1, a2, line_file).into())
1562            }
1563            FN_EQ => {
1564                if !is_true {
1565                    let msg = format!("{} does not support `not`", FN_EQ);
1566                    return Err(NewFactRuntimeError(
1567                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1568                    )
1569                    .into());
1570                }
1571                if args.len() != 2 {
1572                    let msg = format!(
1573                        "{} requires 2 arguments (f, g), but got {}",
1574                        FN_EQ,
1575                        args.len()
1576                    );
1577                    return Err(NewFactRuntimeError(
1578                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1579                    )
1580                    .into());
1581                }
1582                let mut args = args;
1583                let a0 = args.remove(0);
1584                let a1 = args.remove(0);
1585                Ok(FnEqualFact::new(a0, a1, line_file).into())
1586            }
1587            INJECTIVE => {
1588                if args.len() != 1 {
1589                    let msg = format!("{} requires 1 argument, but got {}", INJECTIVE, args.len());
1590                    return Err(NewFactRuntimeError(
1591                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1592                    )
1593                    .into());
1594                }
1595                let mut args = args;
1596                let a0 = args.remove(0);
1597                if is_true {
1598                    Ok(InjectiveFact::new(a0, line_file).into())
1599                } else {
1600                    Ok(NotInjectiveFact::new(a0, line_file).into())
1601                }
1602            }
1603            SURJECTIVE => {
1604                if args.len() != 1 {
1605                    let msg = format!("{} requires 1 argument, but got {}", SURJECTIVE, args.len());
1606                    return Err(NewFactRuntimeError(
1607                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1608                    )
1609                    .into());
1610                }
1611                let mut args = args;
1612                let a0 = args.remove(0);
1613                if is_true {
1614                    Ok(SurjectiveFact::new(a0, line_file).into())
1615                } else {
1616                    Ok(NotSurjectiveFact::new(a0, line_file).into())
1617                }
1618            }
1619            BIJECTIVE => {
1620                if args.len() != 1 {
1621                    let msg = format!("{} requires 1 argument, but got {}", BIJECTIVE, args.len());
1622                    return Err(NewFactRuntimeError(
1623                        RuntimeErrorStruct::new_with_msg_and_line_file(msg, line_file.clone()),
1624                    )
1625                    .into());
1626                }
1627                let mut args = args;
1628                let a0 = args.remove(0);
1629                if is_true {
1630                    Ok(BijectiveFact::new(a0, line_file).into())
1631                } else {
1632                    Ok(NotBijectiveFact::new(a0, line_file).into())
1633                }
1634            }
1635            _ => {
1636                if is_true {
1637                    Ok(NormalAtomicFact::new(prop_name, args, line_file).into())
1638                } else {
1639                    Ok(NotNormalAtomicFact::new(prop_name, args, line_file).into())
1640                }
1641            }
1642        }
1643    }
1644}
1645
1646impl AtomicFact {
1647    pub fn args(&self) -> Vec<Obj> {
1648        match self {
1649            AtomicFact::NormalAtomicFact(normal_atomic_fact) => normal_atomic_fact.body.clone(),
1650            AtomicFact::EqualFact(equal_fact) => {
1651                vec![equal_fact.left.clone(), equal_fact.right.clone()]
1652            }
1653            AtomicFact::LessFact(less_fact) => {
1654                vec![less_fact.left.clone(), less_fact.right.clone()]
1655            }
1656            AtomicFact::GreaterFact(greater_fact) => {
1657                vec![greater_fact.left.clone(), greater_fact.right.clone()]
1658            }
1659            AtomicFact::LessEqualFact(less_equal_fact) => {
1660                vec![less_equal_fact.left.clone(), less_equal_fact.right.clone()]
1661            }
1662            AtomicFact::GreaterEqualFact(greater_equal_fact) => vec![
1663                greater_equal_fact.left.clone(),
1664                greater_equal_fact.right.clone(),
1665            ],
1666            AtomicFact::IsSetFact(is_set_fact) => vec![is_set_fact.set.clone()],
1667            AtomicFact::IsNonemptySetFact(is_nonempty_set_fact) => {
1668                vec![is_nonempty_set_fact.set.clone()]
1669            }
1670            AtomicFact::IsFiniteSetFact(is_finite_set_fact) => vec![is_finite_set_fact.set.clone()],
1671            AtomicFact::InFact(in_fact) => vec![in_fact.element.clone(), in_fact.set.clone()],
1672            AtomicFact::IsCartFact(is_cart_fact) => vec![is_cart_fact.set.clone()],
1673            AtomicFact::IsTupleFact(is_tuple_fact) => vec![is_tuple_fact.set.clone()],
1674            AtomicFact::SubsetFact(subset_fact) => {
1675                vec![subset_fact.left.clone(), subset_fact.right.clone()]
1676            }
1677            AtomicFact::SupersetFact(superset_fact) => {
1678                vec![superset_fact.left.clone(), superset_fact.right.clone()]
1679            }
1680            AtomicFact::NotNormalAtomicFact(not_normal_atomic_fact) => {
1681                not_normal_atomic_fact.body.clone()
1682            }
1683            AtomicFact::NotEqualFact(not_equal_fact) => {
1684                vec![not_equal_fact.left.clone(), not_equal_fact.right.clone()]
1685            }
1686            AtomicFact::NotLessFact(not_less_fact) => {
1687                vec![not_less_fact.left.clone(), not_less_fact.right.clone()]
1688            }
1689            AtomicFact::NotGreaterFact(not_greater_fact) => vec![
1690                not_greater_fact.left.clone(),
1691                not_greater_fact.right.clone(),
1692            ],
1693            AtomicFact::NotLessEqualFact(not_less_equal_fact) => vec![
1694                not_less_equal_fact.left.clone(),
1695                not_less_equal_fact.right.clone(),
1696            ],
1697            AtomicFact::NotGreaterEqualFact(not_greater_equal_fact) => vec![
1698                not_greater_equal_fact.left.clone(),
1699                not_greater_equal_fact.right.clone(),
1700            ],
1701            AtomicFact::NotIsSetFact(not_is_set_fact) => vec![not_is_set_fact.set.clone()],
1702            AtomicFact::NotIsNonemptySetFact(not_is_nonempty_set_fact) => {
1703                vec![not_is_nonempty_set_fact.set.clone()]
1704            }
1705            AtomicFact::NotIsFiniteSetFact(not_is_finite_set_fact) => {
1706                vec![not_is_finite_set_fact.set.clone()]
1707            }
1708            AtomicFact::NotInFact(not_in_fact) => {
1709                vec![not_in_fact.element.clone(), not_in_fact.set.clone()]
1710            }
1711            AtomicFact::NotIsCartFact(not_is_cart_fact) => vec![not_is_cart_fact.set.clone()],
1712            AtomicFact::NotIsTupleFact(not_is_tuple_fact) => vec![not_is_tuple_fact.set.clone()],
1713            AtomicFact::NotSubsetFact(not_subset_fact) => {
1714                vec![not_subset_fact.left.clone(), not_subset_fact.right.clone()]
1715            }
1716            AtomicFact::NotSupersetFact(not_superset_fact) => vec![
1717                not_superset_fact.left.clone(),
1718                not_superset_fact.right.clone(),
1719            ],
1720            AtomicFact::RestrictFact(restrict_fact) => vec![
1721                restrict_fact.obj.clone(),
1722                restrict_fact.obj_can_restrict_to_fn_set.clone().into(),
1723            ],
1724            AtomicFact::NotRestrictFact(not_restrict_fact) => vec![
1725                not_restrict_fact.obj.clone(),
1726                not_restrict_fact.obj_cannot_restrict_to_fn_set.clone(),
1727            ],
1728            AtomicFact::FnEqualInFact(f) => {
1729                vec![f.left.clone(), f.right.clone(), f.set.clone()]
1730            }
1731            AtomicFact::FnEqualFact(f) => vec![f.left.clone(), f.right.clone()],
1732            AtomicFact::InjectiveFact(f) => vec![f.function.clone()],
1733            AtomicFact::SurjectiveFact(f) => vec![f.function.clone()],
1734            AtomicFact::BijectiveFact(f) => vec![f.function.clone()],
1735            AtomicFact::NotInjectiveFact(f) => vec![f.function.clone()],
1736            AtomicFact::NotSurjectiveFact(f) => vec![f.function.clone()],
1737            AtomicFact::NotBijectiveFact(f) => vec![f.function.clone()],
1738        }
1739    }
1740}
1741
1742// 对每个类型的 atomic fact,都有个方法叫 required_args_len,返回该 atomic fact 需要的参数数量
1743impl AtomicFact {
1744    pub fn is_builtin_predicate_and_return_expected_args_len(&self) -> usize {
1745        match self {
1746            AtomicFact::EqualFact(_) => 2,
1747            AtomicFact::LessFact(_) => 2,
1748            AtomicFact::GreaterFact(_) => 2,
1749            AtomicFact::LessEqualFact(_) => 2,
1750            AtomicFact::GreaterEqualFact(_) => 2,
1751            AtomicFact::IsSetFact(_) => 1,
1752            AtomicFact::IsNonemptySetFact(_) => 1,
1753            AtomicFact::IsFiniteSetFact(_) => 1,
1754            AtomicFact::InFact(_) => 2,
1755            AtomicFact::IsCartFact(_) => 1,
1756            AtomicFact::IsTupleFact(_) => 1,
1757            AtomicFact::SubsetFact(_) => 2,
1758            AtomicFact::SupersetFact(_) => 2,
1759            AtomicFact::NotEqualFact(_) => 2,
1760            AtomicFact::NotLessFact(_) => 2,
1761            AtomicFact::NotGreaterFact(_) => 2,
1762            AtomicFact::NotLessEqualFact(_) => 2,
1763            AtomicFact::NotGreaterEqualFact(_) => 2,
1764            AtomicFact::NotIsSetFact(_) => 1,
1765            AtomicFact::NotIsNonemptySetFact(_) => 1,
1766            AtomicFact::NotIsFiniteSetFact(_) => 1,
1767            AtomicFact::NotInFact(_) => 2,
1768            AtomicFact::NotIsCartFact(_) => 1,
1769            AtomicFact::NotIsTupleFact(_) => 1,
1770            AtomicFact::NotSubsetFact(_) => 2,
1771            AtomicFact::NotSupersetFact(_) => 2,
1772            AtomicFact::RestrictFact(_) => 2,
1773            AtomicFact::NotRestrictFact(_) => 2,
1774            AtomicFact::FnEqualInFact(_) => 3,
1775            AtomicFact::FnEqualFact(_) => 2,
1776            AtomicFact::InjectiveFact(_) => 1,
1777            AtomicFact::SurjectiveFact(_) => 1,
1778            AtomicFact::BijectiveFact(_) => 1,
1779            AtomicFact::NotInjectiveFact(_) => 1,
1780            AtomicFact::NotSurjectiveFact(_) => 1,
1781            AtomicFact::NotBijectiveFact(_) => 1,
1782            _ => unreachable!("其他情况不是builtin predicate"),
1783        }
1784    }
1785}
1786
1787impl AtomicFact {
1788    pub fn number_of_args(&self) -> usize {
1789        match self {
1790            AtomicFact::EqualFact(_) => 2,
1791            AtomicFact::LessFact(_) => 2,
1792            AtomicFact::GreaterFact(_) => 2,
1793            AtomicFact::LessEqualFact(_) => 2,
1794            AtomicFact::GreaterEqualFact(_) => 2,
1795            AtomicFact::IsSetFact(_) => 1,
1796            AtomicFact::IsNonemptySetFact(_) => 1,
1797            AtomicFact::IsFiniteSetFact(_) => 1,
1798            AtomicFact::InFact(_) => 2,
1799            AtomicFact::IsCartFact(_) => 1,
1800            AtomicFact::IsTupleFact(_) => 1,
1801            AtomicFact::SubsetFact(_) => 2,
1802            AtomicFact::SupersetFact(_) => 2,
1803            AtomicFact::NotEqualFact(_) => 2,
1804            AtomicFact::NotLessFact(_) => 2,
1805            AtomicFact::NotGreaterFact(_) => 2,
1806            AtomicFact::NotLessEqualFact(_) => 2,
1807            AtomicFact::NotGreaterEqualFact(_) => 2,
1808            AtomicFact::NotIsSetFact(_) => 1,
1809            AtomicFact::NotIsNonemptySetFact(_) => 1,
1810            AtomicFact::NotIsFiniteSetFact(_) => 1,
1811            AtomicFact::NotInFact(_) => 2,
1812            AtomicFact::NotIsCartFact(_) => 1,
1813            AtomicFact::NotIsTupleFact(_) => 1,
1814            AtomicFact::NotSubsetFact(_) => 2,
1815            AtomicFact::NotSupersetFact(_) => 2,
1816            AtomicFact::NormalAtomicFact(a) => a.body.len(),
1817            AtomicFact::NotNormalAtomicFact(a) => a.body.len(),
1818            AtomicFact::RestrictFact(_) => 2,
1819            AtomicFact::NotRestrictFact(_) => 2,
1820            AtomicFact::FnEqualInFact(_) => 3,
1821            AtomicFact::FnEqualFact(_) => 2,
1822            AtomicFact::InjectiveFact(_) => 1,
1823            AtomicFact::SurjectiveFact(_) => 1,
1824            AtomicFact::BijectiveFact(_) => 1,
1825            AtomicFact::NotInjectiveFact(_) => 1,
1826            AtomicFact::NotSurjectiveFact(_) => 1,
1827            AtomicFact::NotBijectiveFact(_) => 1,
1828        }
1829    }
1830
1831    pub fn line_file(&self) -> LineFile {
1832        match self {
1833            AtomicFact::EqualFact(a) => a.line_file.clone(),
1834            AtomicFact::LessFact(a) => a.line_file.clone(),
1835            AtomicFact::GreaterFact(a) => a.line_file.clone(),
1836            AtomicFact::LessEqualFact(a) => a.line_file.clone(),
1837            AtomicFact::GreaterEqualFact(a) => a.line_file.clone(),
1838            AtomicFact::IsSetFact(a) => a.line_file.clone(),
1839            AtomicFact::IsNonemptySetFact(a) => a.line_file.clone(),
1840            AtomicFact::IsFiniteSetFact(a) => a.line_file.clone(),
1841            AtomicFact::InFact(a) => a.line_file.clone(),
1842            AtomicFact::IsCartFact(a) => a.line_file.clone(),
1843            AtomicFact::IsTupleFact(a) => a.line_file.clone(),
1844            AtomicFact::SubsetFact(a) => a.line_file.clone(),
1845            AtomicFact::SupersetFact(a) => a.line_file.clone(),
1846            AtomicFact::NormalAtomicFact(a) => a.line_file.clone(),
1847            AtomicFact::NotNormalAtomicFact(a) => a.line_file.clone(),
1848            AtomicFact::NotEqualFact(a) => a.line_file.clone(),
1849            AtomicFact::NotLessFact(a) => a.line_file.clone(),
1850            AtomicFact::NotGreaterFact(a) => a.line_file.clone(),
1851            AtomicFact::NotLessEqualFact(a) => a.line_file.clone(),
1852            AtomicFact::NotGreaterEqualFact(a) => a.line_file.clone(),
1853            AtomicFact::NotIsSetFact(a) => a.line_file.clone(),
1854            AtomicFact::NotIsNonemptySetFact(a) => a.line_file.clone(),
1855            AtomicFact::NotIsFiniteSetFact(a) => a.line_file.clone(),
1856            AtomicFact::NotInFact(a) => a.line_file.clone(),
1857            AtomicFact::NotIsCartFact(a) => a.line_file.clone(),
1858            AtomicFact::NotIsTupleFact(a) => a.line_file.clone(),
1859            AtomicFact::NotSubsetFact(a) => a.line_file.clone(),
1860            AtomicFact::NotSupersetFact(a) => a.line_file.clone(),
1861            AtomicFact::RestrictFact(a) => a.line_file.clone(),
1862            AtomicFact::NotRestrictFact(a) => a.line_file.clone(),
1863            AtomicFact::FnEqualInFact(a) => a.line_file.clone(),
1864            AtomicFact::FnEqualFact(a) => a.line_file.clone(),
1865            AtomicFact::InjectiveFact(a) => a.line_file.clone(),
1866            AtomicFact::SurjectiveFact(a) => a.line_file.clone(),
1867            AtomicFact::BijectiveFact(a) => a.line_file.clone(),
1868            AtomicFact::NotInjectiveFact(a) => a.line_file.clone(),
1869            AtomicFact::NotSurjectiveFact(a) => a.line_file.clone(),
1870            AtomicFact::NotBijectiveFact(a) => a.line_file.clone(),
1871        }
1872    }
1873
1874    pub fn with_line_file(mut self, line_file: LineFile) -> Self {
1875        match &mut self {
1876            AtomicFact::EqualFact(a) => a.line_file = line_file,
1877            AtomicFact::LessFact(a) => a.line_file = line_file,
1878            AtomicFact::GreaterFact(a) => a.line_file = line_file,
1879            AtomicFact::LessEqualFact(a) => a.line_file = line_file,
1880            AtomicFact::GreaterEqualFact(a) => a.line_file = line_file,
1881            AtomicFact::IsSetFact(a) => a.line_file = line_file,
1882            AtomicFact::IsNonemptySetFact(a) => a.line_file = line_file,
1883            AtomicFact::IsFiniteSetFact(a) => a.line_file = line_file,
1884            AtomicFact::InFact(a) => a.line_file = line_file,
1885            AtomicFact::IsCartFact(a) => a.line_file = line_file,
1886            AtomicFact::IsTupleFact(a) => a.line_file = line_file,
1887            AtomicFact::SubsetFact(a) => a.line_file = line_file,
1888            AtomicFact::SupersetFact(a) => a.line_file = line_file,
1889            AtomicFact::NormalAtomicFact(a) => a.line_file = line_file,
1890            AtomicFact::NotNormalAtomicFact(a) => a.line_file = line_file,
1891            AtomicFact::NotEqualFact(a) => a.line_file = line_file,
1892            AtomicFact::NotLessFact(a) => a.line_file = line_file,
1893            AtomicFact::NotGreaterFact(a) => a.line_file = line_file,
1894            AtomicFact::NotLessEqualFact(a) => a.line_file = line_file,
1895            AtomicFact::NotGreaterEqualFact(a) => a.line_file = line_file,
1896            AtomicFact::NotIsSetFact(a) => a.line_file = line_file,
1897            AtomicFact::NotIsNonemptySetFact(a) => a.line_file = line_file,
1898            AtomicFact::NotIsFiniteSetFact(a) => a.line_file = line_file,
1899            AtomicFact::NotInFact(a) => a.line_file = line_file,
1900            AtomicFact::NotIsCartFact(a) => a.line_file = line_file,
1901            AtomicFact::NotIsTupleFact(a) => a.line_file = line_file,
1902            AtomicFact::NotSubsetFact(a) => a.line_file = line_file,
1903            AtomicFact::NotSupersetFact(a) => a.line_file = line_file,
1904            AtomicFact::RestrictFact(a) => a.line_file = line_file,
1905            AtomicFact::NotRestrictFact(a) => a.line_file = line_file,
1906            AtomicFact::FnEqualInFact(a) => a.line_file = line_file,
1907            AtomicFact::FnEqualFact(a) => a.line_file = line_file,
1908            AtomicFact::InjectiveFact(a) => a.line_file = line_file,
1909            AtomicFact::SurjectiveFact(a) => a.line_file = line_file,
1910            AtomicFact::BijectiveFact(a) => a.line_file = line_file,
1911            AtomicFact::NotInjectiveFact(a) => a.line_file = line_file,
1912            AtomicFact::NotSurjectiveFact(a) => a.line_file = line_file,
1913            AtomicFact::NotBijectiveFact(a) => a.line_file = line_file,
1914        }
1915        self
1916    }
1917}
1918
1919impl RestrictFact {
1920    pub fn new(obj: Obj, obj_can_restrict_to_fn_set: Obj, line_file: LineFile) -> Self {
1921        RestrictFact {
1922            obj,
1923            obj_can_restrict_to_fn_set,
1924            line_file,
1925        }
1926    }
1927}
1928
1929impl NotRestrictFact {
1930    pub fn new(obj: Obj, obj_cannot_restrict_to_fn_set: Obj, line_file: LineFile) -> Self {
1931        NotRestrictFact {
1932            obj,
1933            obj_cannot_restrict_to_fn_set,
1934            line_file,
1935        }
1936    }
1937}
1938
1939impl fmt::Display for RestrictFact {
1940    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1941        write!(
1942            f,
1943            "{} {}{} {}",
1944            self.obj, FACT_PREFIX, RESTRICT_FN_IN, self.obj_can_restrict_to_fn_set
1945        )
1946    }
1947}
1948
1949impl fmt::Display for NotRestrictFact {
1950    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1951        write!(
1952            f,
1953            "{} {} {}{} {}",
1954            NOT, self.obj, FACT_PREFIX, RESTRICT_FN_IN, self.obj_cannot_restrict_to_fn_set
1955        )
1956    }
1957}
1958
1959impl AtomicFact {
1960    pub fn get_args_from_fact(&self) -> Vec<Obj> {
1961        self.args()
1962    }
1963}
1964
1965impl AtomicFact {
1966    pub fn make_reversed(&self) -> AtomicFact {
1967        match self {
1968            AtomicFact::NormalAtomicFact(a) => AtomicFact::NotNormalAtomicFact(
1969                NotNormalAtomicFact::new(a.predicate.clone(), a.body.clone(), a.line_file.clone()),
1970            ),
1971            AtomicFact::NotNormalAtomicFact(a) => AtomicFact::NormalAtomicFact(
1972                NormalAtomicFact::new(a.predicate.clone(), a.body.clone(), a.line_file.clone()),
1973            ),
1974            AtomicFact::EqualFact(a) => {
1975                NotEqualFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
1976            }
1977            AtomicFact::LessFact(a) => {
1978                NotLessFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
1979            }
1980            AtomicFact::GreaterFact(a) => {
1981                NotGreaterFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
1982            }
1983            AtomicFact::LessEqualFact(a) => {
1984                NotLessEqualFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
1985            }
1986            AtomicFact::GreaterEqualFact(a) => AtomicFact::NotGreaterEqualFact(
1987                NotGreaterEqualFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()),
1988            ),
1989            AtomicFact::IsSetFact(a) => {
1990                NotIsSetFact::new(a.set.clone(), a.line_file.clone()).into()
1991            }
1992            AtomicFact::IsNonemptySetFact(a) => AtomicFact::NotIsNonemptySetFact(
1993                NotIsNonemptySetFact::new(a.set.clone(), a.line_file.clone()),
1994            ),
1995            AtomicFact::IsFiniteSetFact(a) => AtomicFact::NotIsFiniteSetFact(
1996                NotIsFiniteSetFact::new(a.set.clone(), a.line_file.clone()),
1997            ),
1998            AtomicFact::InFact(a) => {
1999                NotInFact::new(a.element.clone(), a.set.clone(), a.line_file.clone()).into()
2000            }
2001            AtomicFact::IsCartFact(a) => {
2002                NotIsCartFact::new(a.set.clone(), a.line_file.clone()).into()
2003            }
2004            AtomicFact::IsTupleFact(a) => {
2005                NotIsTupleFact::new(a.set.clone(), a.line_file.clone()).into()
2006            }
2007            AtomicFact::SubsetFact(a) => {
2008                NotSubsetFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2009            }
2010            AtomicFact::SupersetFact(a) => {
2011                NotSupersetFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2012            }
2013            AtomicFact::RestrictFact(a) => NotRestrictFact::new(
2014                a.obj.clone(),
2015                a.obj_can_restrict_to_fn_set.clone(),
2016                a.line_file.clone(),
2017            )
2018            .into(),
2019            AtomicFact::NotEqualFact(a) => {
2020                EqualFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2021            }
2022            AtomicFact::NotLessFact(a) => {
2023                LessFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2024            }
2025            AtomicFact::NotGreaterFact(a) => {
2026                GreaterFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2027            }
2028            AtomicFact::NotLessEqualFact(a) => {
2029                LessEqualFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2030            }
2031            AtomicFact::NotGreaterEqualFact(a) => AtomicFact::GreaterEqualFact(
2032                GreaterEqualFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()),
2033            ),
2034            AtomicFact::NotIsSetFact(a) => {
2035                IsSetFact::new(a.set.clone(), a.line_file.clone()).into()
2036            }
2037            AtomicFact::NotIsNonemptySetFact(a) => AtomicFact::IsNonemptySetFact(
2038                IsNonemptySetFact::new(a.set.clone(), a.line_file.clone()),
2039            ),
2040            AtomicFact::NotIsFiniteSetFact(a) => {
2041                IsFiniteSetFact::new(a.set.clone(), a.line_file.clone()).into()
2042            }
2043            AtomicFact::NotInFact(a) => {
2044                InFact::new(a.element.clone(), a.set.clone(), a.line_file.clone()).into()
2045            }
2046            AtomicFact::NotIsCartFact(a) => {
2047                IsCartFact::new(a.set.clone(), a.line_file.clone()).into()
2048            }
2049            AtomicFact::NotIsTupleFact(a) => {
2050                IsTupleFact::new(a.set.clone(), a.line_file.clone()).into()
2051            }
2052            AtomicFact::NotSubsetFact(a) => {
2053                SubsetFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2054            }
2055            AtomicFact::NotSupersetFact(a) => {
2056                SupersetFact::new(a.left.clone(), a.right.clone(), a.line_file.clone()).into()
2057            }
2058            AtomicFact::NotRestrictFact(a) => RestrictFact::new(
2059                a.obj.clone(),
2060                a.obj_cannot_restrict_to_fn_set.clone(),
2061                a.line_file.clone(),
2062            )
2063            .into(),
2064            AtomicFact::FnEqualInFact(a) => FnEqualInFact::new(
2065                a.right.clone(),
2066                a.left.clone(),
2067                a.set.clone(),
2068                a.line_file.clone(),
2069            )
2070            .into(),
2071            AtomicFact::FnEqualFact(a) => {
2072                FnEqualFact::new(a.right.clone(), a.left.clone(), a.line_file.clone()).into()
2073            }
2074            AtomicFact::InjectiveFact(a) => {
2075                NotInjectiveFact::new(a.function.clone(), a.line_file.clone()).into()
2076            }
2077            AtomicFact::SurjectiveFact(a) => {
2078                NotSurjectiveFact::new(a.function.clone(), a.line_file.clone()).into()
2079            }
2080            AtomicFact::BijectiveFact(a) => {
2081                NotBijectiveFact::new(a.function.clone(), a.line_file.clone()).into()
2082            }
2083            AtomicFact::NotInjectiveFact(a) => {
2084                InjectiveFact::new(a.function.clone(), a.line_file.clone()).into()
2085            }
2086            AtomicFact::NotSurjectiveFact(a) => {
2087                SurjectiveFact::new(a.function.clone(), a.line_file.clone()).into()
2088            }
2089            AtomicFact::NotBijectiveFact(a) => {
2090                BijectiveFact::new(a.function.clone(), a.line_file.clone()).into()
2091            }
2092        }
2093    }
2094}
2095
2096impl AtomicFact {
2097    fn body_vec_after_calculate_each_calculable_arg(original_body: &Vec<Obj>) -> Vec<Obj> {
2098        let mut next_body = Vec::new();
2099        for obj in original_body {
2100            next_body.push(obj.replace_with_numeric_result_if_can_be_calculated().0);
2101        }
2102        next_body
2103    }
2104
2105    pub fn calculate_args(&self) -> (AtomicFact, bool) {
2106        let calculated_atomic_fact: AtomicFact = match self {
2107            AtomicFact::NormalAtomicFact(inner) => NormalAtomicFact::new(
2108                inner.predicate.clone(),
2109                Self::body_vec_after_calculate_each_calculable_arg(&inner.body),
2110                inner.line_file.clone(),
2111            )
2112            .into(),
2113            AtomicFact::NotNormalAtomicFact(inner) => NotNormalAtomicFact::new(
2114                inner.predicate.clone(),
2115                Self::body_vec_after_calculate_each_calculable_arg(&inner.body),
2116                inner.line_file.clone(),
2117            )
2118            .into(),
2119            AtomicFact::EqualFact(inner) => EqualFact::new(
2120                inner
2121                    .left
2122                    .replace_with_numeric_result_if_can_be_calculated()
2123                    .0,
2124                inner
2125                    .right
2126                    .replace_with_numeric_result_if_can_be_calculated()
2127                    .0,
2128                inner.line_file.clone(),
2129            )
2130            .into(),
2131            AtomicFact::NotEqualFact(inner) => NotEqualFact::new(
2132                inner
2133                    .left
2134                    .replace_with_numeric_result_if_can_be_calculated()
2135                    .0,
2136                inner
2137                    .right
2138                    .replace_with_numeric_result_if_can_be_calculated()
2139                    .0,
2140                inner.line_file.clone(),
2141            )
2142            .into(),
2143            AtomicFact::LessFact(inner) => LessFact::new(
2144                inner
2145                    .left
2146                    .replace_with_numeric_result_if_can_be_calculated()
2147                    .0,
2148                inner
2149                    .right
2150                    .replace_with_numeric_result_if_can_be_calculated()
2151                    .0,
2152                inner.line_file.clone(),
2153            )
2154            .into(),
2155            AtomicFact::NotLessFact(inner) => NotLessFact::new(
2156                inner
2157                    .left
2158                    .replace_with_numeric_result_if_can_be_calculated()
2159                    .0,
2160                inner
2161                    .right
2162                    .replace_with_numeric_result_if_can_be_calculated()
2163                    .0,
2164                inner.line_file.clone(),
2165            )
2166            .into(),
2167            AtomicFact::GreaterFact(inner) => GreaterFact::new(
2168                inner
2169                    .left
2170                    .replace_with_numeric_result_if_can_be_calculated()
2171                    .0,
2172                inner
2173                    .right
2174                    .replace_with_numeric_result_if_can_be_calculated()
2175                    .0,
2176                inner.line_file.clone(),
2177            )
2178            .into(),
2179            AtomicFact::NotGreaterFact(inner) => NotGreaterFact::new(
2180                inner
2181                    .left
2182                    .replace_with_numeric_result_if_can_be_calculated()
2183                    .0,
2184                inner
2185                    .right
2186                    .replace_with_numeric_result_if_can_be_calculated()
2187                    .0,
2188                inner.line_file.clone(),
2189            )
2190            .into(),
2191            AtomicFact::LessEqualFact(inner) => LessEqualFact::new(
2192                inner
2193                    .left
2194                    .replace_with_numeric_result_if_can_be_calculated()
2195                    .0,
2196                inner
2197                    .right
2198                    .replace_with_numeric_result_if_can_be_calculated()
2199                    .0,
2200                inner.line_file.clone(),
2201            )
2202            .into(),
2203            AtomicFact::NotLessEqualFact(inner) => NotLessEqualFact::new(
2204                inner
2205                    .left
2206                    .replace_with_numeric_result_if_can_be_calculated()
2207                    .0,
2208                inner
2209                    .right
2210                    .replace_with_numeric_result_if_can_be_calculated()
2211                    .0,
2212                inner.line_file.clone(),
2213            )
2214            .into(),
2215            AtomicFact::GreaterEqualFact(inner) => GreaterEqualFact::new(
2216                inner
2217                    .left
2218                    .replace_with_numeric_result_if_can_be_calculated()
2219                    .0,
2220                inner
2221                    .right
2222                    .replace_with_numeric_result_if_can_be_calculated()
2223                    .0,
2224                inner.line_file.clone(),
2225            )
2226            .into(),
2227            AtomicFact::NotGreaterEqualFact(inner) => NotGreaterEqualFact::new(
2228                inner
2229                    .left
2230                    .replace_with_numeric_result_if_can_be_calculated()
2231                    .0,
2232                inner
2233                    .right
2234                    .replace_with_numeric_result_if_can_be_calculated()
2235                    .0,
2236                inner.line_file.clone(),
2237            )
2238            .into(),
2239            AtomicFact::IsSetFact(inner) => IsSetFact::new(
2240                inner
2241                    .set
2242                    .replace_with_numeric_result_if_can_be_calculated()
2243                    .0,
2244                inner.line_file.clone(),
2245            )
2246            .into(),
2247            AtomicFact::NotIsSetFact(inner) => NotIsSetFact::new(
2248                inner
2249                    .set
2250                    .replace_with_numeric_result_if_can_be_calculated()
2251                    .0,
2252                inner.line_file.clone(),
2253            )
2254            .into(),
2255            AtomicFact::IsNonemptySetFact(inner) => IsNonemptySetFact::new(
2256                inner
2257                    .set
2258                    .replace_with_numeric_result_if_can_be_calculated()
2259                    .0,
2260                inner.line_file.clone(),
2261            )
2262            .into(),
2263            AtomicFact::NotIsNonemptySetFact(inner) => NotIsNonemptySetFact::new(
2264                inner
2265                    .set
2266                    .replace_with_numeric_result_if_can_be_calculated()
2267                    .0,
2268                inner.line_file.clone(),
2269            )
2270            .into(),
2271            AtomicFact::IsFiniteSetFact(inner) => IsFiniteSetFact::new(
2272                inner
2273                    .set
2274                    .replace_with_numeric_result_if_can_be_calculated()
2275                    .0,
2276                inner.line_file.clone(),
2277            )
2278            .into(),
2279            AtomicFact::NotIsFiniteSetFact(inner) => NotIsFiniteSetFact::new(
2280                inner
2281                    .set
2282                    .replace_with_numeric_result_if_can_be_calculated()
2283                    .0,
2284                inner.line_file.clone(),
2285            )
2286            .into(),
2287            AtomicFact::InFact(inner) => InFact::new(
2288                inner
2289                    .element
2290                    .replace_with_numeric_result_if_can_be_calculated()
2291                    .0,
2292                inner
2293                    .set
2294                    .replace_with_numeric_result_if_can_be_calculated()
2295                    .0,
2296                inner.line_file.clone(),
2297            )
2298            .into(),
2299            AtomicFact::NotInFact(inner) => NotInFact::new(
2300                inner
2301                    .element
2302                    .replace_with_numeric_result_if_can_be_calculated()
2303                    .0,
2304                inner
2305                    .set
2306                    .replace_with_numeric_result_if_can_be_calculated()
2307                    .0,
2308                inner.line_file.clone(),
2309            )
2310            .into(),
2311            AtomicFact::IsCartFact(inner) => IsCartFact::new(
2312                inner
2313                    .set
2314                    .replace_with_numeric_result_if_can_be_calculated()
2315                    .0,
2316                inner.line_file.clone(),
2317            )
2318            .into(),
2319            AtomicFact::NotIsCartFact(inner) => NotIsCartFact::new(
2320                inner
2321                    .set
2322                    .replace_with_numeric_result_if_can_be_calculated()
2323                    .0,
2324                inner.line_file.clone(),
2325            )
2326            .into(),
2327            AtomicFact::IsTupleFact(inner) => IsTupleFact::new(
2328                inner
2329                    .set
2330                    .replace_with_numeric_result_if_can_be_calculated()
2331                    .0,
2332                inner.line_file.clone(),
2333            )
2334            .into(),
2335            AtomicFact::NotIsTupleFact(inner) => NotIsTupleFact::new(
2336                inner
2337                    .set
2338                    .replace_with_numeric_result_if_can_be_calculated()
2339                    .0,
2340                inner.line_file.clone(),
2341            )
2342            .into(),
2343            AtomicFact::SubsetFact(inner) => SubsetFact::new(
2344                inner
2345                    .left
2346                    .replace_with_numeric_result_if_can_be_calculated()
2347                    .0,
2348                inner
2349                    .right
2350                    .replace_with_numeric_result_if_can_be_calculated()
2351                    .0,
2352                inner.line_file.clone(),
2353            )
2354            .into(),
2355            AtomicFact::NotSubsetFact(inner) => NotSubsetFact::new(
2356                inner
2357                    .left
2358                    .replace_with_numeric_result_if_can_be_calculated()
2359                    .0,
2360                inner
2361                    .right
2362                    .replace_with_numeric_result_if_can_be_calculated()
2363                    .0,
2364                inner.line_file.clone(),
2365            )
2366            .into(),
2367            AtomicFact::SupersetFact(inner) => SupersetFact::new(
2368                inner
2369                    .left
2370                    .replace_with_numeric_result_if_can_be_calculated()
2371                    .0,
2372                inner
2373                    .right
2374                    .replace_with_numeric_result_if_can_be_calculated()
2375                    .0,
2376                inner.line_file.clone(),
2377            )
2378            .into(),
2379            AtomicFact::NotSupersetFact(inner) => NotSupersetFact::new(
2380                inner
2381                    .left
2382                    .replace_with_numeric_result_if_can_be_calculated()
2383                    .0,
2384                inner
2385                    .right
2386                    .replace_with_numeric_result_if_can_be_calculated()
2387                    .0,
2388                inner.line_file.clone(),
2389            )
2390            .into(),
2391            AtomicFact::RestrictFact(inner) => RestrictFact::new(
2392                inner
2393                    .obj
2394                    .replace_with_numeric_result_if_can_be_calculated()
2395                    .0,
2396                inner
2397                    .obj_can_restrict_to_fn_set
2398                    .replace_with_numeric_result_if_can_be_calculated()
2399                    .0,
2400                inner.line_file.clone(),
2401            )
2402            .into(),
2403            AtomicFact::NotRestrictFact(inner) => NotRestrictFact::new(
2404                inner
2405                    .obj
2406                    .replace_with_numeric_result_if_can_be_calculated()
2407                    .0,
2408                inner
2409                    .obj_cannot_restrict_to_fn_set
2410                    .replace_with_numeric_result_if_can_be_calculated()
2411                    .0,
2412                inner.line_file.clone(),
2413            )
2414            .into(),
2415            AtomicFact::FnEqualInFact(inner) => FnEqualInFact::new(
2416                inner
2417                    .left
2418                    .replace_with_numeric_result_if_can_be_calculated()
2419                    .0,
2420                inner
2421                    .right
2422                    .replace_with_numeric_result_if_can_be_calculated()
2423                    .0,
2424                inner
2425                    .set
2426                    .replace_with_numeric_result_if_can_be_calculated()
2427                    .0,
2428                inner.line_file.clone(),
2429            )
2430            .into(),
2431            AtomicFact::FnEqualFact(inner) => FnEqualFact::new(
2432                inner
2433                    .left
2434                    .replace_with_numeric_result_if_can_be_calculated()
2435                    .0,
2436                inner
2437                    .right
2438                    .replace_with_numeric_result_if_can_be_calculated()
2439                    .0,
2440                inner.line_file.clone(),
2441            )
2442            .into(),
2443            AtomicFact::InjectiveFact(inner) => InjectiveFact::new(
2444                inner
2445                    .function
2446                    .replace_with_numeric_result_if_can_be_calculated()
2447                    .0,
2448                inner.line_file.clone(),
2449            )
2450            .into(),
2451            AtomicFact::SurjectiveFact(inner) => SurjectiveFact::new(
2452                inner
2453                    .function
2454                    .replace_with_numeric_result_if_can_be_calculated()
2455                    .0,
2456                inner.line_file.clone(),
2457            )
2458            .into(),
2459            AtomicFact::BijectiveFact(inner) => BijectiveFact::new(
2460                inner
2461                    .function
2462                    .replace_with_numeric_result_if_can_be_calculated()
2463                    .0,
2464                inner.line_file.clone(),
2465            )
2466            .into(),
2467            AtomicFact::NotInjectiveFact(inner) => NotInjectiveFact::new(
2468                inner
2469                    .function
2470                    .replace_with_numeric_result_if_can_be_calculated()
2471                    .0,
2472                inner.line_file.clone(),
2473            )
2474            .into(),
2475            AtomicFact::NotSurjectiveFact(inner) => NotSurjectiveFact::new(
2476                inner
2477                    .function
2478                    .replace_with_numeric_result_if_can_be_calculated()
2479                    .0,
2480                inner.line_file.clone(),
2481            )
2482            .into(),
2483            AtomicFact::NotBijectiveFact(inner) => NotBijectiveFact::new(
2484                inner
2485                    .function
2486                    .replace_with_numeric_result_if_can_be_calculated()
2487                    .0,
2488                inner.line_file.clone(),
2489            )
2490            .into(),
2491        };
2492        let any_argument_replaced = calculated_atomic_fact.to_string() != self.to_string();
2493        (calculated_atomic_fact, any_argument_replaced)
2494    }
2495}
2496
2497impl From<NormalAtomicFact> for AtomicFact {
2498    fn from(f: NormalAtomicFact) -> Self {
2499        AtomicFact::NormalAtomicFact(f)
2500    }
2501}
2502
2503impl From<EqualFact> for AtomicFact {
2504    fn from(f: EqualFact) -> Self {
2505        AtomicFact::EqualFact(f)
2506    }
2507}
2508
2509impl From<LessFact> for AtomicFact {
2510    fn from(f: LessFact) -> Self {
2511        AtomicFact::LessFact(f)
2512    }
2513}
2514
2515impl From<GreaterFact> for AtomicFact {
2516    fn from(f: GreaterFact) -> Self {
2517        AtomicFact::GreaterFact(f)
2518    }
2519}
2520
2521impl From<LessEqualFact> for AtomicFact {
2522    fn from(f: LessEqualFact) -> Self {
2523        AtomicFact::LessEqualFact(f)
2524    }
2525}
2526
2527impl From<GreaterEqualFact> for AtomicFact {
2528    fn from(f: GreaterEqualFact) -> Self {
2529        AtomicFact::GreaterEqualFact(f)
2530    }
2531}
2532
2533impl From<IsSetFact> for AtomicFact {
2534    fn from(f: IsSetFact) -> Self {
2535        AtomicFact::IsSetFact(f)
2536    }
2537}
2538
2539impl From<IsNonemptySetFact> for AtomicFact {
2540    fn from(f: IsNonemptySetFact) -> Self {
2541        AtomicFact::IsNonemptySetFact(f)
2542    }
2543}
2544
2545impl From<IsFiniteSetFact> for AtomicFact {
2546    fn from(f: IsFiniteSetFact) -> Self {
2547        AtomicFact::IsFiniteSetFact(f)
2548    }
2549}
2550
2551impl From<InFact> for AtomicFact {
2552    fn from(f: InFact) -> Self {
2553        AtomicFact::InFact(f)
2554    }
2555}
2556
2557impl From<IsCartFact> for AtomicFact {
2558    fn from(f: IsCartFact) -> Self {
2559        AtomicFact::IsCartFact(f)
2560    }
2561}
2562
2563impl From<IsTupleFact> for AtomicFact {
2564    fn from(f: IsTupleFact) -> Self {
2565        AtomicFact::IsTupleFact(f)
2566    }
2567}
2568
2569impl From<SubsetFact> for AtomicFact {
2570    fn from(f: SubsetFact) -> Self {
2571        AtomicFact::SubsetFact(f)
2572    }
2573}
2574
2575impl From<SupersetFact> for AtomicFact {
2576    fn from(f: SupersetFact) -> Self {
2577        AtomicFact::SupersetFact(f)
2578    }
2579}
2580
2581impl From<RestrictFact> for AtomicFact {
2582    fn from(f: RestrictFact) -> Self {
2583        AtomicFact::RestrictFact(f)
2584    }
2585}
2586
2587impl From<NotRestrictFact> for AtomicFact {
2588    fn from(f: NotRestrictFact) -> Self {
2589        AtomicFact::NotRestrictFact(f)
2590    }
2591}
2592
2593impl From<NotNormalAtomicFact> for AtomicFact {
2594    fn from(f: NotNormalAtomicFact) -> Self {
2595        AtomicFact::NotNormalAtomicFact(f)
2596    }
2597}
2598
2599impl From<NotEqualFact> for AtomicFact {
2600    fn from(f: NotEqualFact) -> Self {
2601        AtomicFact::NotEqualFact(f)
2602    }
2603}
2604
2605impl From<NotLessFact> for AtomicFact {
2606    fn from(f: NotLessFact) -> Self {
2607        AtomicFact::NotLessFact(f)
2608    }
2609}
2610
2611impl From<NotGreaterFact> for AtomicFact {
2612    fn from(f: NotGreaterFact) -> Self {
2613        AtomicFact::NotGreaterFact(f)
2614    }
2615}
2616
2617impl From<NotLessEqualFact> for AtomicFact {
2618    fn from(f: NotLessEqualFact) -> Self {
2619        AtomicFact::NotLessEqualFact(f)
2620    }
2621}
2622
2623impl From<NotGreaterEqualFact> for AtomicFact {
2624    fn from(f: NotGreaterEqualFact) -> Self {
2625        AtomicFact::NotGreaterEqualFact(f)
2626    }
2627}
2628
2629impl From<NotIsSetFact> for AtomicFact {
2630    fn from(f: NotIsSetFact) -> Self {
2631        AtomicFact::NotIsSetFact(f)
2632    }
2633}
2634
2635impl From<NotIsNonemptySetFact> for AtomicFact {
2636    fn from(f: NotIsNonemptySetFact) -> Self {
2637        AtomicFact::NotIsNonemptySetFact(f)
2638    }
2639}
2640
2641impl From<NotIsFiniteSetFact> for AtomicFact {
2642    fn from(f: NotIsFiniteSetFact) -> Self {
2643        AtomicFact::NotIsFiniteSetFact(f)
2644    }
2645}
2646
2647impl From<NotInFact> for AtomicFact {
2648    fn from(f: NotInFact) -> Self {
2649        AtomicFact::NotInFact(f)
2650    }
2651}
2652
2653impl From<NotIsCartFact> for AtomicFact {
2654    fn from(f: NotIsCartFact) -> Self {
2655        AtomicFact::NotIsCartFact(f)
2656    }
2657}
2658
2659impl From<NotIsTupleFact> for AtomicFact {
2660    fn from(f: NotIsTupleFact) -> Self {
2661        AtomicFact::NotIsTupleFact(f)
2662    }
2663}
2664
2665impl From<NotSubsetFact> for AtomicFact {
2666    fn from(f: NotSubsetFact) -> Self {
2667        AtomicFact::NotSubsetFact(f)
2668    }
2669}
2670
2671impl From<NotSupersetFact> for AtomicFact {
2672    fn from(f: NotSupersetFact) -> Self {
2673        AtomicFact::NotSupersetFact(f)
2674    }
2675}
2676
2677impl From<FnEqualInFact> for AtomicFact {
2678    fn from(f: FnEqualInFact) -> Self {
2679        AtomicFact::FnEqualInFact(f)
2680    }
2681}
2682
2683impl From<FnEqualFact> for AtomicFact {
2684    fn from(f: FnEqualFact) -> Self {
2685        AtomicFact::FnEqualFact(f)
2686    }
2687}
2688
2689impl From<InjectiveFact> for AtomicFact {
2690    fn from(f: InjectiveFact) -> Self {
2691        AtomicFact::InjectiveFact(f)
2692    }
2693}
2694
2695impl From<SurjectiveFact> for AtomicFact {
2696    fn from(f: SurjectiveFact) -> Self {
2697        AtomicFact::SurjectiveFact(f)
2698    }
2699}
2700
2701impl From<BijectiveFact> for AtomicFact {
2702    fn from(f: BijectiveFact) -> Self {
2703        AtomicFact::BijectiveFact(f)
2704    }
2705}
2706
2707impl From<NotInjectiveFact> for AtomicFact {
2708    fn from(f: NotInjectiveFact) -> Self {
2709        AtomicFact::NotInjectiveFact(f)
2710    }
2711}
2712
2713impl From<NotSurjectiveFact> for AtomicFact {
2714    fn from(f: NotSurjectiveFact) -> Self {
2715        AtomicFact::NotSurjectiveFact(f)
2716    }
2717}
2718
2719impl From<NotBijectiveFact> for AtomicFact {
2720    fn from(f: NotBijectiveFact) -> Self {
2721        AtomicFact::NotBijectiveFact(f)
2722    }
2723}
2724
2725impl From<NormalAtomicFact> for Fact {
2726    fn from(f: NormalAtomicFact) -> Self {
2727        Fact::AtomicFact(f.into())
2728    }
2729}
2730
2731impl From<EqualFact> for Fact {
2732    fn from(f: EqualFact) -> Self {
2733        Fact::AtomicFact(f.into())
2734    }
2735}
2736
2737impl From<LessFact> for Fact {
2738    fn from(f: LessFact) -> Self {
2739        Fact::AtomicFact(f.into())
2740    }
2741}
2742
2743impl From<GreaterFact> for Fact {
2744    fn from(f: GreaterFact) -> Self {
2745        Fact::AtomicFact(f.into())
2746    }
2747}
2748
2749impl From<LessEqualFact> for Fact {
2750    fn from(f: LessEqualFact) -> Self {
2751        Fact::AtomicFact(f.into())
2752    }
2753}
2754
2755impl From<GreaterEqualFact> for Fact {
2756    fn from(f: GreaterEqualFact) -> Self {
2757        Fact::AtomicFact(f.into())
2758    }
2759}
2760
2761impl From<IsSetFact> for Fact {
2762    fn from(f: IsSetFact) -> Self {
2763        Fact::AtomicFact(f.into())
2764    }
2765}
2766
2767impl From<IsNonemptySetFact> for Fact {
2768    fn from(f: IsNonemptySetFact) -> Self {
2769        Fact::AtomicFact(f.into())
2770    }
2771}
2772
2773impl From<IsFiniteSetFact> for Fact {
2774    fn from(f: IsFiniteSetFact) -> Self {
2775        Fact::AtomicFact(f.into())
2776    }
2777}
2778
2779impl From<InFact> for Fact {
2780    fn from(f: InFact) -> Self {
2781        Fact::AtomicFact(f.into())
2782    }
2783}
2784
2785impl From<IsCartFact> for Fact {
2786    fn from(f: IsCartFact) -> Self {
2787        Fact::AtomicFact(f.into())
2788    }
2789}
2790
2791impl From<IsTupleFact> for Fact {
2792    fn from(f: IsTupleFact) -> Self {
2793        Fact::AtomicFact(f.into())
2794    }
2795}
2796
2797impl From<SubsetFact> for Fact {
2798    fn from(f: SubsetFact) -> Self {
2799        Fact::AtomicFact(f.into())
2800    }
2801}
2802
2803impl From<SupersetFact> for Fact {
2804    fn from(f: SupersetFact) -> Self {
2805        Fact::AtomicFact(f.into())
2806    }
2807}
2808
2809impl From<RestrictFact> for Fact {
2810    fn from(f: RestrictFact) -> Self {
2811        Fact::AtomicFact(f.into())
2812    }
2813}
2814
2815impl From<NotRestrictFact> for Fact {
2816    fn from(f: NotRestrictFact) -> Self {
2817        Fact::AtomicFact(f.into())
2818    }
2819}
2820
2821impl From<FnEqualInFact> for Fact {
2822    fn from(f: FnEqualInFact) -> Self {
2823        Fact::AtomicFact(f.into())
2824    }
2825}
2826
2827impl From<FnEqualFact> for Fact {
2828    fn from(f: FnEqualFact) -> Self {
2829        Fact::AtomicFact(f.into())
2830    }
2831}
2832
2833impl From<NotNormalAtomicFact> for Fact {
2834    fn from(f: NotNormalAtomicFact) -> Self {
2835        Fact::AtomicFact(f.into())
2836    }
2837}
2838
2839impl From<NotEqualFact> for Fact {
2840    fn from(f: NotEqualFact) -> Self {
2841        Fact::AtomicFact(f.into())
2842    }
2843}
2844
2845impl From<NotLessFact> for Fact {
2846    fn from(f: NotLessFact) -> Self {
2847        Fact::AtomicFact(f.into())
2848    }
2849}
2850
2851impl From<NotGreaterFact> for Fact {
2852    fn from(f: NotGreaterFact) -> Self {
2853        Fact::AtomicFact(f.into())
2854    }
2855}
2856
2857impl From<NotLessEqualFact> for Fact {
2858    fn from(f: NotLessEqualFact) -> Self {
2859        Fact::AtomicFact(f.into())
2860    }
2861}
2862
2863impl From<NotGreaterEqualFact> for Fact {
2864    fn from(f: NotGreaterEqualFact) -> Self {
2865        Fact::AtomicFact(f.into())
2866    }
2867}
2868
2869impl From<NotIsSetFact> for Fact {
2870    fn from(f: NotIsSetFact) -> Self {
2871        Fact::AtomicFact(f.into())
2872    }
2873}
2874
2875impl From<NotIsNonemptySetFact> for Fact {
2876    fn from(f: NotIsNonemptySetFact) -> Self {
2877        Fact::AtomicFact(f.into())
2878    }
2879}
2880
2881impl From<NotIsFiniteSetFact> for Fact {
2882    fn from(f: NotIsFiniteSetFact) -> Self {
2883        Fact::AtomicFact(f.into())
2884    }
2885}
2886
2887impl From<NotInFact> for Fact {
2888    fn from(f: NotInFact) -> Self {
2889        Fact::AtomicFact(f.into())
2890    }
2891}
2892
2893impl From<NotIsCartFact> for Fact {
2894    fn from(f: NotIsCartFact) -> Self {
2895        Fact::AtomicFact(f.into())
2896    }
2897}
2898
2899impl From<NotIsTupleFact> for Fact {
2900    fn from(f: NotIsTupleFact) -> Self {
2901        Fact::AtomicFact(f.into())
2902    }
2903}
2904
2905impl From<NotSubsetFact> for Fact {
2906    fn from(f: NotSubsetFact) -> Self {
2907        Fact::AtomicFact(f.into())
2908    }
2909}
2910
2911impl From<NotSupersetFact> for Fact {
2912    fn from(f: NotSupersetFact) -> Self {
2913        Fact::AtomicFact(f.into())
2914    }
2915}