Synthesis of trees of Gates - Java