Skip to content

Commit

Permalink
Merge pull request advancedresearch#508 from bvssvni/master
Browse files Browse the repository at this point in the history
Make inline succeed by success of at least one sub-branch
  • Loading branch information
bvssvni committed May 29, 2020
2 parents 1c9fcfb + 59915cf commit 1c39ab5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "poi"
version = "0.10.0"
version = "0.10.1"
authors = ["Sven Nilsen <bvssvni@gmail.com>"]
edition = "2018"
keywords = ["advancedresearch", "theorem", "proving", "assistant", "point-free"]
Expand Down
35 changes: 30 additions & 5 deletions src/lib.rs
Expand Up @@ -499,11 +499,24 @@ impl Expr {
Ok(b) => Ok(constr(a, b)),
}
} else {
Ok(Op(
*op,
Box::new(a.inline_all(knowledge)?),
Box::new(b.inline_all(knowledge)?)
))
match (a.inline_all(knowledge), b.inline_all(knowledge)) {
(Ok(a), Ok(b)) => Ok(Op(
*op,
Box::new(a),
Box::new(b)
)),
(Ok(a), Err(_)) => Ok(Op(
*op,
Box::new(a),
b.clone()
)),
(Err(_), Ok(b)) => Ok(Op(
*op,
a.clone(),
Box::new(b)
)),
(err, _) => err,
}
}
}
Tup(a) => {
Expand Down Expand Up @@ -1323,4 +1336,16 @@ mod tests {
let f: Expr = true.into();
assert_eq!(f.has_constraint(0), false);
}

#[test]
fn eval_var() {
let def = &[Def("x".into(), 0.0.into())];
let f: Expr = "x".into();
assert_eq!(f.eval(def).unwrap(), Ret(F64(0.0)));

let mut def = std();
def.push(Def("x".into(), 2.0.into()));
let f: Expr = app2(Add, 1.0, "x");
assert_eq!(f.eval(&def).unwrap(), Ret(F64(3.0)));
}
}

0 comments on commit 1c39ab5

Please sign in to comment.