예제 #1
0
        ////////////////////////////////////////////////////////////
        public static PropositionalFormula operator &(PropositionalFormula x, PropositionalFormula y)
        {
            var result = new PropositionalFormula(x);

            result.andWith(y);
            return(result);
        }
예제 #2
0
 public PropositionalFormula(PropositionalFormula other)
     : this()
 {
     foreach (var d in other.myDisjuncts)
     {
         myDisjuncts.Add(new Conjunction(d));
     }
 }
예제 #3
0
        ////////////////////////////////////////////////////////////
        public void orWith(PropositionalFormula other)
        {
            if (ReferenceEquals(this, other))
            {
                return;
            }
//            Console.Write("{0} || {1}", this.ToString(), other.ToString());
            bool b = isFalse || other.isFalse;

            foreach (var c in other.myDisjuncts)
            {
                checkAddDisjunct(new Conjunction(c));
            }
            Debug.Assert(b || !isFalse);
//            Console.WriteLine(" = {0}", this.ToString());
        }
예제 #4
0
        ////////////////////////////////////////////////////////////
        public void andWith(PropositionalFormula other)
        {
            List <Conjunction> oldDisjuncts = myDisjuncts;

            myDisjuncts = new List <Conjunction>();
            foreach (var cx in oldDisjuncts)
            {
                foreach (var cy in other.myDisjuncts)
                {
                    Conjunction a = cx & cy;
                    if (a != null)
                    {
                        checkAddDisjunct(a);
                    }
                }
            }
        }
예제 #5
0
        public static PropositionalFormula or(IEnumerable <PropositionalFormula> others)
        {
            Debug.Assert(others != null);
//            Debug.Assert(predecessors.Count > 0);
            var result = new PropositionalFormula(false);

            foreach (var o in others)
            {
                result.orWith(o);
            }

/*            if (predecessors.Count()==1)
 *          {
 *              var of = predecessors.First();
 *              var nof = !of;
 *              var nr = !result;
 *              Debug.Assert((result & nof).isFalse);
 *              Debug.Assert((nr     &  of).isFalse);
 *              Debug.Assert((result | nof).isTrue);
 *              Debug.Assert((nr     | of ).isTrue);
 *          }
 * */
            return(result);
        }
예제 #6
0
        ////////////////////////////////////////////////////////////
        public static PropositionalFormula operator !(PropositionalFormula x)
        {
//            Console.WriteLine("!{0}", x.ToString());
            PropositionalFormula result;

            if (x.isTrue)
            {
                result = new PropositionalFormula(false);
            }
            else if (x.isFalse)
            {
                result = new PropositionalFormula(true);
            }
            else
            {
                result = new PropositionalFormula(false);

                var indices = new int[x.myDisjuncts.Count];
                for (int i = 0; i < indices.Length; i++)
                {
                    indices[i] = 0;
                }

                do
                {
                    {
                        var pos = new HashSet <int>();
                        var neg = new HashSet <int>();
                        for (int i = 0; i < indices.Length; i++)
                        {
                            Tuple <bool, int> t = x.disjuncts.ElementAt(i).conjuncts.ElementAt(indices[i]);
                            if (t.Item1)
                            {
                                neg.Add(t.Item2);
                            }
                            else
                            {
                                pos.Add(t.Item2);
                            }
                        }
                        if (pos.Intersect(neg).Count() == 0)
                        {
                            var disjunct = new Conjunction(pos, neg);
//                            Console.WriteLine("\t{0}", disjunct.ToString());
                            result.checkAddDisjunct(disjunct);
                            if (result.isTrue)
                            {
                                return(result);
                            }
                        }
                    }

                    int j = indices.Length - 1;
                    do
                    {
                        indices[j]++;
                        if (indices[j] < x.disjuncts.ElementAt(j).conjuncts.Count())
                        {
                            break;
                        }
                        if (j == 0)
                        {
                            break;
                        }
                        indices[j] = 0;
                        j--;
                    } while (true);
                    if (j == 0 && indices[j] == x.disjuncts.ElementAt(j).conjuncts.Count())
                    {
                        break;
                    }
                } while (true);
                //            Console.WriteLine("{0} ==> {1}", x.ToString(), result.ToString());
            }

/*            {
 *              var m = (x & result);
 *              var b = (x | result);
 *              Debug.Assert(m.isFalse);
 *              Debug.Assert(b.isTrue);
 *          }*/
            return(result);
        }