Skip to content

Commit

Permalink
Implement substitute for SymbolicTerms
Browse files Browse the repository at this point in the history
  • Loading branch information
teiesti committed Nov 29, 2024
1 parent 5b82f22 commit 8ebe436
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/syntax_tree/fol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ impl SymbolicTerm {
SymbolicTerm::Symbol(_) | SymbolicTerm::Variable(_) => IndexSet::new(),
}
}

pub fn substitute(self, var: Variable, term: SymbolicTerm) -> Self {
match self {
SymbolicTerm::Variable(s) if var.name == s && var.sort == Sort::Symbol => term,
_ => self,
}
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -202,6 +209,12 @@ impl GeneralTerm {
"cannot substitute general term `{term}` for the integer variable `{var}`"
),
},
GeneralTerm::SymbolicTerm(t) if var.sort == Sort::Symbol => match term {
GeneralTerm::SymbolicTerm(term) => GeneralTerm::SymbolicTerm(t.substitute(var, term)),
_ => panic!(
"cannot substitute general term `{term}` for the symbolic variable `{var}`"
),
}
t => t,
}
}
Expand Down

0 comments on commit 8ebe436

Please sign in to comment.