Roughly "translated" the java formula class to Scala.
Circuit simplification now working.
But needs to simplify the implementation