Exemple #1
0
        internal void AddPiece(Piece piece)
        {
            if (FastAddingMode)
            {
                Pieces.Add(piece);
                return;
            }

            if (!piece.IsNumeric())
            {
                if (Pieces.All(p => p != piece))
                    Pieces.Add(piece);
                return;
            }
            else if (this.Power == PowerLevel.FINITE && piece.Type == Piece.PieceType.ENTITY)
            {
                var evaled = (piece as OneElementPiece).Evaluated;
                if (Pieces.Select(p => (p as OneElementPiece).Evaluated).All(p => p != evaled))
                    Pieces.Add(piece);
                return;
            }
            var remainders = new List<Piece>{ piece };
            foreach (var p in Pieces)
            {
                if (!p.IsNumeric())
                    continue;
                var newRemainders = new List<Piece>();
                foreach (var rem in remainders)
                    newRemainders.AddRange(PieceFunctions.Subtract(rem, p));
                remainders = newRemainders;
            }

            Pieces.AddRange(remainders);
        }
        public void PieceSubtraction1()
        {
            var p    = Piece.Interval(new ComplexNumber(-1, -1), new ComplexNumber(2, 2)).AsInterval().SetLeftClosed(true, true).SetRightClosed(true, true);
            var left = PieceFunctions.Subtract(p, new OneElementPiece(0));

            Assert.IsFalse(In(0, left));
        }
        public void PieceSubtraction2()
        {
            // [3; 4]
            var p = Piece.Interval(3, 4).AsInterval().SetLeftClosed(true).SetRightClosed(true);
            // [3; 4)
            var p1 = Piece.Interval(3, 4).AsInterval().SetLeftClosed(true).SetRightClosed(false);

            var left = PieceFunctions.Subtract(p, p1);

            Assert.IsTrue(In(4, left));
            Assert.IsFalse(In(5, left));
            Assert.IsFalse(In(3.99, left));
        }
Exemple #4
0
 public override bool Contains(Piece piece)
 {
     // we will subtract each this.piece from piece and if piece finally becomes 0 then
     // there is no point outside this set
     var remainders = new List<Piece>{ piece };
     foreach (var p in this.Pieces)
     {
         var newRemainders = new List<Piece>();
         foreach (var rem in remainders)
             newRemainders.AddRange(PieceFunctions.Subtract(rem, p));
         remainders = newRemainders;
     }
     return remainders.Count == 0;
 }