-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Apply in twain to enable portfolios of simplifications
- Loading branch information
1 parent
52e8057
commit 2bee5d5
Showing
6 changed files
with
68 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pub trait Compose<X> { | ||
fn compose(self) -> impl Fn(X) -> X; | ||
} | ||
|
||
impl<T: Iterator + Clone + 'static, X> Compose<X> for T | ||
where | ||
<T as Iterator>::Item: Fn(X) -> X, | ||
{ | ||
/// Composes a series of operations `f0, f1, ..., fn` into single operation `f`. | ||
/// | ||
/// The operations are applied left-to-right, i.e. `f(x) = fn( .. f1( f0(x) ) .. )`. | ||
fn compose(self) -> impl Fn(X) -> X { | ||
// CAUTION: Cloning is absolutely crucial here. | ||
// self is an Iterator that is moved into the closure and therefore | ||
// returned from the function. It is used whenever the closure is | ||
// called. If we do not clone the iterator, it will be empty after | ||
// the first call which changes the intended behavior. Besides, | ||
// cloning an Iterator is cheap since it is merely a view into the | ||
// underlying data structure. The data structure itself is not | ||
// cloned. | ||
move |x| self.clone().fold(x, |x, f| f(x)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod apply; | ||
pub mod compose; | ||
pub mod unbox; | ||
pub mod with_warnings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
use crate::syntax_tree::fol::Theory; | ||
use crate::{ | ||
convenience::{apply::Apply as _, compose::Compose as _}, | ||
simplifying::fol::intuitionistic::INTUITIONISTIC, | ||
syntax_tree::fol::{Formula, Theory}, | ||
}; | ||
|
||
pub fn simplify(theory: Theory) -> Theory { | ||
crate::simplifying::fol::intuitionistic::simplify(theory) | ||
// TODO: Add ht simplifications | ||
Theory { | ||
formulas: theory.formulas.into_iter().map(simplify_formula).collect(), | ||
} | ||
} | ||
|
||
pub fn simplify_formula(formula: Formula) -> Formula { | ||
formula.apply(&mut INTUITIONISTIC.iter().chain(HT).compose()) | ||
} | ||
|
||
pub const HT: &[fn(Formula) -> Formula] = &[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters