Beispiel #1
0
        public static void Run()
        {
            Sym inf       = new SymInf();
            Sym loose4    = new SymLoose(4);
            Sym loose5    = new SymLoose(5);
            Sym divs3left = new SymDivs(1, 3, 0, 0);

            var semi = new ConveyorSR();

            Console.WriteLine("Starting unit tests...");

            TestEq <Sym>("Left additive identity", semi.Add(inf, loose4), loose4);
            TestEq <Sym>("Right additive identity", semi.Add(loose4, inf), loose4);

            TestEq <Sym>("Left multiplicative zero", semi.Mult(inf, loose4), inf);
            TestEq <Sym>("Right multiplicative zero", semi.Mult(loose4, inf), inf);

            TestEq <Sym>("Left multiplicative identity", semi.Mult(new SymLoose(0), loose4), loose4);
            TestEq <Sym>("Right multiplicative identity", semi.Mult(loose4, new SymLoose(0)), loose4);

            TestEq <Sym>("Sym.Add", semi.Add(loose4, loose4), loose4);
            TestEq <Sym>("Loose 4 add Loose 5", semi.Add(loose4, loose5), loose4);
            TestEq <Sym>("Loose 5 add Loose 4", semi.Add(loose5, loose4), loose4);

            TestEq <Sym>("Loose 4 (X) Loose 5", semi.Mult(loose4, loose5), new SymLoose(9));
            TestEq <Sym>("Loose 5 (X) Divs 1 3 0 0", semi.Mult(loose5, new SymDivs(1, 3, 0, 0)), new SymDivs(1, 8, 0, 0));
            TestEq <Sym>("Divs 1 3 0 0 (X) Loose 5", semi.Mult(new SymDivs(1, 3, 0, 0), loose5), new SymDivs(1, 3, 0, 5));

            Console.WriteLine("Done unit tests...");
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            PropertyTests.Run(100);
            return;

            // UnitTests.Run();
            // return;

            var testcase = ReadInput();
            var d        = testcase.NumDividers;

            // An H-predicate that allows a count to be up to a certain amount
            var upToHP  = new UpToNPred(d);
            var multMap = new List <List <Tuple <int, int> > >();

            for (int i = 0; i <= d + 1; i++)
            {
                var range = Enumerable.Range(0, i + 1)
                            .Select(x => new Tuple <int, int>(x, i - x))
                            .ToList();

                multMap.Add(range);
            }

            var conveyorSR = new ConveyorSR();

            // Embed the UpToNPred H-predicate into ConveyorNR [Emoto theorem 14]
            INestedReducer <Sym, Marked <int, bool> > conveyorNR = new ConveyorNR();
            INestedReducer <LiftedSet <Sym, int>, Marked <int, bool> > nested =
                new LiftedNestedReducer <Sym, int, Marked <int, bool> >(conveyorNR, upToHP, multMap);

            var marks = new List <bool> {
                true, false
            };

            // All-mark the lifted nested reducer with T, F and run the
            // resulting list homomorphism [Emoto lemma 18]
            IListHomomorphism <LiftedSet <Sym, int>, int> marked =
                new AllMarked <bool, LiftedSet <Sym, int>, int>(marks, nested);

            LiftedSet <Sym, int> result = ListHomomorphism.Run(marked, testcase.Prices);

            var final = upToHP.Symbols()
                        .Where(upToHP.Accept)
                        .Select(i => result.coefficients.ElementAt(i))
                        .Aggregate(conveyorSR.Add)
                        .Price;

            Console.WriteLine("{0}", final);
        }
Beispiel #3
0
        public static void Run(int count)
        {
            var r          = new Random();
            var conveyorSR = new ConveyorSR();

            /*
             * var aa = new SymDivs(17, 5, 10, 13);
             * var bb = new SymDivs(9, 9, 5, 15);
             * var cc = new SymDivs(13, 16, 5, 5);
             *
             * Console.WriteLine("Debug: {0} {1} {2}", aa, bb, cc);
             * Console.WriteLine("b (+) c = {0}", conveyorSR.Add(bb, cc));
             * Console.WriteLine("a (X) b = {0}", conveyorSR.Mult(aa, bb));
             * Console.WriteLine("a (X) c = {0}", conveyorSR.Mult(aa, cc));
             *
             * Console.WriteLine("a (X)  (b + c) = {0}", conveyorSR.Mult(aa, conveyorSR.Add(bb, cc)));
             * Console.WriteLine("a (X) b  (+)  (a (X) c) = {0}", conveyorSR.Add(conveyorSR.Mult(aa, bb),
             *                                                                conveyorSR.Mult(aa, cc)));
             */

            Console.WriteLine("Starting property tests");

            /* Associativity of ConveyorSR.Add over Sym */
            for (int i = 1; i <= count; i++)
            {
                Sym a = RandomSym(r);
                Sym b = RandomSym(r);
                Sym c = RandomSym(r);

                var p = conveyorSR.Add(a, conveyorSR.Add(b, c));
                var q = conveyorSR.Add(conveyorSR.Add(a, b), c);

                if (!p.Equals(q))
                {
                    Console.WriteLine("{3} Found non-associative triple of Syms under addition: {0}, {1}, {2}",
                                      a.ToString(),
                                      b.ToString(),
                                      c.ToString(),
                                      i);
                }
            }

            /* Associativity of ConveyorSR.Mult over Sym */
            for (int i = 1; i <= count; i++)
            {
                Sym a = RandomSym(r);
                Sym b = RandomSym(r);
                Sym c = RandomSym(r);

                var p = conveyorSR.Mult(a, conveyorSR.Mult(b, c));
                var q = conveyorSR.Mult(conveyorSR.Mult(a, b), c);

                if (!p.Equals(q))
                {
                    Console.WriteLine("{3} Found non-associative triple of Syms under multiplication: {0}, {1}, {2} --- {4}, {5}",
                                      a.ToString(),
                                      b.ToString(),
                                      c.ToString(),
                                      i,
                                      p,
                                      q);
                }
            }

            /* Left-distributivity of ConveyorSR over Sym */
            for (int i = 1; i <= count; i++)
            {
                Sym a = RandomSym(r);
                Sym b = RandomSym(r);
                Sym c = RandomSym(r);

                var p = conveyorSR.Mult(a, conveyorSR.Add(b, c));
                var q = conveyorSR.Add(conveyorSR.Mult(a, b), conveyorSR.Mult(a, c));

                if (!p.Equals(q))
                {
                    Console.WriteLine("{3} Found non-left-distributive triple of Syms: {0}, {1}, {2} --- {4}, {5}",
                                      a.ToString(),
                                      b.ToString(),
                                      c.ToString(),
                                      i,
                                      p,
                                      q);
                }
            }

            /* Right-distributivity of ConveyorSR over Sym */
            for (int i = 1; i <= count; i++)
            {
                Sym a = RandomSym(r);
                Sym b = RandomSym(r);
                Sym c = RandomSym(r);

                var p = conveyorSR.Mult(conveyorSR.Add(a, b), c);
                var q = conveyorSR.Add(conveyorSR.Mult(a, c), conveyorSR.Mult(b, c));

                if (!p.Equals(q))
                {
                    Console.WriteLine("{3} Found non-right-distributive triple of Syms: {0}, {1}, {2}",
                                      a.ToString(),
                                      b.ToString(),
                                      c.ToString(),
                                      i);
                }
            }

            Console.WriteLine("Done property tests");
        }