Coder Social home page Coder Social logo

support if_then_else op about biodivine-lib-bdd HOT 3 CLOSED

gipsyh avatar gipsyh commented on September 27, 2024
support if_then_else op

from biodivine-lib-bdd.

Comments (3)

daemontus avatar daemontus commented on September 27, 2024

Right now, this functionality can be implemented using the "ternary apply" operator:

#[test]
fn test_if_then_else() {
    let set = BddVariableSet::new_anonymous(3);
    let vars = set.variables();
    let v1 = set.mk_literal(vars[0], true);
    let v2 = set.mk_literal(vars[1], true);
    let v3 = set.mk_literal(vars[2], true);
    // ITE(v1, v2, v3) = (v1 & v2) | (!v1 & v3)
    let if_then_else = bdd![(v1 & v2) | ((!v1) & v3)];

    fn ite_function(a: Option<bool>, b: Option<bool>, c: Option<bool>) -> Option<bool> {
        match (a, b, c) {
            // If "a" is known, we can just "implement" ITE and return "b"/"c".
            (Some(true), _, _) => b,
            (Some(false), _, _) => c,
            // The next two cases are not strictly necessary, but
            // can cause the operation to finish sooner if the result
            // is already determined, even when "a" is still unknown.
            (None, Some(false), Some(false)) => Some(false),
            (None, Some(true), Some(true)) => Some(true),
            // Otherwise, we return None until "a" becomes known.
            (None, _, _) => None,
        }
    }
    let ternary = Bdd::ternary_op(&v1, &v2, &v3, ite_function);

    assert_eq!(ternary, if_then_else);
}

For now, you can use the code above as a workaround. This is still a single BDD operation, so it should be comparable in overhead to other "native" ITE implementations. However, I fully agree that this should be part of the library directly. I'll make sure to add it to the next release :)

from biodivine-lib-bdd.

gipsyh avatar gipsyh commented on September 27, 2024

thanks!

from biodivine-lib-bdd.

daemontus avatar daemontus commented on September 27, 2024

This is now supported in 0.5.0.

from biodivine-lib-bdd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.