Skip to content

Commit

Permalink
Implement the gamma translation
Browse files Browse the repository at this point in the history
  • Loading branch information
teiesti committed Dec 7, 2023
1 parent cb25ed4 commit caed24a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod formatting;
pub mod parsing;
pub mod simplifying;
pub mod syntax_tree;
pub mod translating;

fn main() {
// TODO
Expand Down
77 changes: 77 additions & 0 deletions src/translating/gamma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use crate::{
convenience::apply::Apply as _,
syntax_tree::fol::{AtomicFormula, BinaryConnective, Formula, UnaryConnective},
};

pub fn gamma(formula: Formula) -> Formula {
match formula {
x @ Formula::AtomicFormula(_) => here(x),

Formula::UnaryFormula {
connective: connective @ UnaryConnective::Negation,
formula,
} => Formula::UnaryFormula {
connective,
formula: there(*formula).into(),
},

Formula::BinaryFormula {
connective:
connective @ BinaryConnective::Conjunction | connective @ BinaryConnective::Disjunction,
lhs,
rhs,
} => Formula::BinaryFormula {
connective,
lhs: gamma(*lhs).into(),
rhs: gamma(*rhs).into(),
},

Formula::BinaryFormula {
connective: BinaryConnective::Implication,
lhs,
rhs,
} => Formula::BinaryFormula {
connective: BinaryConnective::Conjunction,
lhs: Formula::BinaryFormula {
connective: BinaryConnective::Implication,
lhs: gamma(*lhs.clone()).into(),
rhs: gamma(*rhs.clone()).into(),
}
.into(),
rhs: Formula::BinaryFormula {
connective: BinaryConnective::Implication,
lhs: there(*lhs).into(),
rhs: there(*rhs).into(),
}
.into(),
},

Formula::QuantifiedFormula {
quantification,
formula,
} => Formula::QuantifiedFormula {
quantification,
formula: gamma(*formula).into(),
},

_ => todo!(),
}
}

fn here(formula: Formula) -> Formula {
prepend_predicate(formula, "h")
}

fn there(formula: Formula) -> Formula {
prepend_predicate(formula, "t")
}

fn prepend_predicate(formula: Formula, prefix: &'static str) -> Formula {
formula.apply(&mut |formula| match formula {
Formula::AtomicFormula(AtomicFormula::Atom(mut a)) => {
a.predicate.insert_str(0, prefix);
Formula::AtomicFormula(AtomicFormula::Atom(a))
}
x => x,
})
}
1 change: 1 addition & 0 deletions src/translating/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod gamma;

0 comments on commit caed24a

Please sign in to comment.