Exemplo n.º 1
0
        public void PointedFlowers_AreSelfInjective_WithUnusualFirstVertex()
        {
            const int FirstVertex = -123;
            var       qps         = Utility.InfiniteRange(3, 2).Select(k => UsefulQPs.GetPointedFlowerQP(k, FirstVertex)).TakeWhile(qp => qp.Quiver.Vertices.Count <= 49);

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 2
0
        public void EvenFlowersOfType2_AreSelfInjective_WithUnusualFirstVertex()
        {
            const int FirstVertex = -123;
            var       qps         = Utility.InfiniteRange(4, 2).Select(k => UsefulQPs.GetEvenFlowerType2QP(k, FirstVertex)).TakeWhile(qp => qp.Quiver.Vertices.Count <= 36);

            AssertAreSelfInjective(qps);
        }
        public void Analyze_IndicatesCancellativityCorrectly_ForClassicWeaklyButNotStronglyCancellativeQP()
        {
            var qp       = UsefulQPs.GetClassicWeaklyButNotStronglyCancellativeQP();
            var analyzer = CreateAnalyzer();

            var settings = CreateSettings(CancellativityTypes.Cancellativity);
            var results  = analyzer.Analyze(qp, settings);

            Assert.That(
                results.MainResults.HasFlag(QPAnalysisMainResults.NotCancellative),
                $"The main result was {results.MainResults}, which does not indicate that the QP fails to be cancellative.");

            settings = CreateSettings(CancellativityTypes.WeakCancellativity);
            results  = analyzer.Analyze(qp, settings);
            Assert.That(
                !results.MainResults.HasFlag(QPAnalysisMainResults.NotWeaklyCancellative),
                $"The main result was {results.MainResults}, which indicates that the QP fails to be weakly cancellative.");

            settings = CreateSettings(CancellativityTypes.Cancellativity | CancellativityTypes.WeakCancellativity);
            results  = analyzer.Analyze(qp, settings);
            Assert.That(
                results.MainResults.HasFlag(QPAnalysisMainResults.NotCancellative),
                $"The main result was {results.MainResults}, which does not indicate that the QP fails to be cancellative.");
            Assert.That(
                !results.MainResults.HasFlag(QPAnalysisMainResults.NotWeaklyCancellative),
                $"The main result was {results.MainResults}, which indicates that the QP fails to be weakly cancellative.");
        }
Exemplo n.º 4
0
        public void GetCycleQP_GivesSelfInjectiveQP_WithUnusualFirstVertex()
        {
            const int FirstVertex = -123;
            var       qps         = Enumerable.Range(3, 28).Select(k => UsefulQPs.GetCycleQP(k, FirstVertex));

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 5
0
        public void Cobwebs_AreSelfInjective_WithUnusualFirstVertex()
        {
            const int FirstVertex = -123;
            var       qps         = Utility.InfiniteRange(5, 2).Select(k => UsefulQPs.GetCobwebQP(k, FirstVertex)).TakeWhile(qp => qp.Quiver.Vertices.Count < 30);

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 6
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_OnClassicWeaklyButNotStronglyCancellativeExample_IndicatesCancellativityCorrectly()
        {
            var qp = UsefulQPs.GetClassicNonCancellativeQP();

            DoSetup(qp, out var ruleTree);

            if (Computer.SupportsNonCancellativityDetection)
            {
                var settings = GetSettings(CancellativityTypes.Cancellativity);
                var result   = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings);
                Assert.That(result.CancellativityFailureDetected, Is.True);
            }

            if (Computer.SupportsNonWeakCancellativityDetection)
            {
                var settings = GetSettings(CancellativityTypes.WeakCancellativity);
                var result   = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings);
                Assert.That(result.WeakCancellativityFailureDetected, Is.True);
            }

            if (Computer.SupportsNonCancellativityDetection && Computer.SupportsNonWeakCancellativityDetection)
            {
                var settings = GetSettings(CancellativityTypes.WeakCancellativity | CancellativityTypes.Cancellativity);
                var result   = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings);
                Assert.That(result.CancellativityFailureDetected, Is.True);
                Assert.That(result.WeakCancellativityFailureDetected, Is.True);
            }
        }
Exemplo n.º 7
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_TetraforceCenter()
        {
            var settings = GetSettings(detectNonCancellativity: false);
            var qp       = UsefulQPs.GetSquareQP(3);

            DoSetup(qp, out var ruleTree);

            var representativePaths = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 5, ruleTree, settings).MaximalNonzeroEquivalenceClassRepresentatives.ToList();
            var expectedMaximalEquivalenceClasses = new ISet <Path <int> >[]
            {
                new HashSet <Path <int> >
                {
                    new Path <int>(5, new Arrow <int>[] { new Arrow <int>(5, 4), new Arrow <int>(4, 1), new Arrow <int>(1, 2), new Arrow <int>(2, 5) }),
                    new Path <int>(5, new Arrow <int>[] { new Arrow <int>(5, 6), new Arrow <int>(6, 3), new Arrow <int>(3, 2), new Arrow <int>(2, 5) }),
                    new Path <int>(5, new Arrow <int>[] { new Arrow <int>(5, 4), new Arrow <int>(4, 7), new Arrow <int>(7, 8), new Arrow <int>(8, 5) }),
                    new Path <int>(5, new Arrow <int>[] { new Arrow <int>(5, 6), new Arrow <int>(6, 9), new Arrow <int>(9, 8), new Arrow <int>(8, 5) }),
                },
            };

            Assert.That(representativePaths, Has.Count.EqualTo(expectedMaximalEquivalenceClasses.Length));
            foreach (var representative in representativePaths)
            {
                Assert.That(expectedMaximalEquivalenceClasses, Has.One.Contains(representative));
            }
        }
Exemplo n.º 8
0
        public void GetVerticesInGeneralizedCobwebQPLayer_ThrowsOnBadLayerIndex(int layerIndex)
        {
            int numVerticesInCenterPolygon = 5;
            int numLayers = 2;

            Assert.That(() => UsefulQPs.GetVerticesInGeneralizedCobwebQPLayer(numVerticesInCenterPolygon, numLayers, layerIndex), Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
Exemplo n.º 9
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_Cobweb5()
        {
            var settings = GetSettings(detectNonCancellativity: false);
            var qp       = UsefulQPs.GetCobwebQP(5, 0);

            DoSetup(qp, out var ruleTree);
            var representativePaths = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 0, ruleTree, settings).MaximalNonzeroEquivalenceClassRepresentatives.ToList();

            Assert.That(representativePaths, Has.Count.EqualTo(1));
            Assert.That(representativePaths.Single().EndingPoint, Is.EqualTo(2));
        }
Exemplo n.º 10
0
        public void StartGenerationFromBase_ThrowsGeneratorException_IfTooFewExplicitArrowPairs()
        {
            // The cobweb quiver has 5 implicit arrow pairs for the boundary layer
            var quiverInPlane = UsefulQuiversInPlane.GetCobwebQuiverInPlane(5, 50, firstVertex: 1);
            var potential     = UsefulQPs.GetCobwebQP(5).Potential;
            var boundaryLayer = Enumerable.Range(6, 10);
            var layerType     = CreateLayerType(10, 4, 20); // 4 < 5 explicit arrow pairs

            Assert.That(
                () => generator.StartGenerationFromBase(quiverInPlane, potential, boundaryLayer, layerType, nextVertex: 16),
                Throws.InstanceOf <GeneratorException>());
        }
Exemplo n.º 11
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_TetraforceCorner()
        {
            var settings = GetSettings(detectNonCancellativity: false);
            var qp       = UsefulQPs.GetSquareQP(3);

            DoSetup(qp, out var ruleTree);

            var representativePaths    = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings).MaximalNonzeroEquivalenceClassRepresentatives.ToList();
            var expectedRepresentative = new Path <int>(1, new Arrow <int>[] { new Arrow <int>(1, 2), new Arrow <int>(2, 5), new Arrow <int>(5, 6), new Arrow <int>(6, 9) });

            Assert.That(representativePaths, Has.Count.EqualTo(1));
            Assert.That(representativePaths.Single(), Is.EqualTo(expectedRepresentative));
        }
Exemplo n.º 12
0
        public void TryStartGenerationFromBase_ReturnsFalse_IfTooFewExplicitArrowPairs()
        {
            // The cobweb quiver has 5 implicit arrow pairs for the boundary layer
            var quiverInPlane = UsefulQuiversInPlane.GetCobwebQuiverInPlane(5, 50, firstVertex: 1);
            var potential     = UsefulQPs.GetCobwebQP(5).Potential;
            var boundaryLayer = Enumerable.Range(6, 10);
            var layerType     = CreateLayerType(10, 4, 20); // 4 < 5 explicit arrow pairs

            var result = generator.TryStartGenerationFromBase(quiverInPlane, potential, boundaryLayer, layerType, nextVertex: 16, out var nextCompositionParameters);

            Assert.That(result, Is.False);
            Assert.That(nextCompositionParameters, Is.Null);
        }
Exemplo n.º 13
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_TriforceCorner()
        {
            var settings = GetSettings(detectNonCancellativity: false);
            var qp       = UsefulQPs.GetTriangleQP(3);

            DoSetup(qp, out var ruleTree);

            var representatives          = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings).MaximalNonzeroEquivalenceClassRepresentatives;
            var representativeArrowPaths = representatives.Select(path => path.Arrows).ToList();
            var expectedRepresentative   = new Arrow <int>[] { new Arrow <int>(1, 3), new Arrow <int>(3, 6) };

            Assert.That(representativeArrowPaths, Has.Count.EqualTo(1));
            Assert.That(representativeArrowPaths.Single(), Is.EqualTo(expectedRepresentative));
        }
        /// <summary>
        /// Prompts the user for a QP.
        /// </summary>
        /// <param name="qp">Output parameter for the QP.</param>
        /// <param name="periods">Output parameter for the periods of the QP.</param>
        /// <param name="fixedPoint">Output parameter for the fixed-point of the QP (or
        /// <see langword="null"/> if there is none).</param>
        /// <returns><see langword="true"/> if the user specified a QP;
        /// <see langword="false"/> otherwise.</returns>
        private bool TryGetQP(
            out QuiverWithPotential <int> qp,
            out IEnumerable <IEnumerable <int> > periods,
            out int?fixedPoint)
        {
            if (!TryGetQPType(out var qpType) || !TryGetNumPeriods(qpType, out int numPeriods))
            {
                qp         = null;
                periods    = null;
                fixedPoint = null;
                return(false);
            }

            switch (qpType)
            {
            case QPType.OddFlower:
                qp         = UsefulQPs.GetOddFlowerQP(numPeriods, DefaultFirstVertex);
                periods    = UsefulQPs.GetPeriodsOfOddFlowerQP(numPeriods, DefaultFirstVertex);
                fixedPoint = null;
                break;

            case QPType.EvenFlowerType1:
                qp         = UsefulQPs.GetEvenFlowerType1QP(numPeriods, DefaultFirstVertex);
                periods    = UsefulQPs.GetPeriodsOfEvenFlowerType1QP(numPeriods, DefaultFirstVertex);
                fixedPoint = null;
                break;

            case QPType.EvenFlowerType2:
                qp         = UsefulQPs.GetEvenFlowerType2QP(numPeriods, DefaultFirstVertex);
                periods    = UsefulQPs.GetPeriodsOfEvenFlowerType2QP(numPeriods, DefaultFirstVertex);
                fixedPoint = null;
                break;

            case QPType.PointedFlower:
                qp      = UsefulQPs.GetPointedFlowerQP(numPeriods, DefaultFirstVertex);
                periods = UsefulQPs.GetPeriodsOfPointedFlowerQPWithoutFixedPoint(numPeriods, DefaultFirstVertex);
                throw new NotImplementedException();
                break;

            default:
                Debug.Fail($"Invalid QP type ({qpType}) specified.");
                qp         = null;
                periods    = null;
                fixedPoint = null;
                return(false);
            }

            return(true);
        }
Exemplo n.º 15
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativeStartingAt_Cycle(int n)
        {
            var settings = GetSettings(detectNonCancellativity: false);
            var qp       = UsefulQPs.GetCycleQP(n);

            DoSetup(qp, out var ruleTree);

            var actualRepresentativePaths = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings).MaximalNonzeroEquivalenceClassRepresentatives.ToList();

            // 1->2->...->n-1
            var expectedRepresentative = new Path <int>(1, Enumerable.Range(1, n - 2).Select(k => new Arrow <int>(k, k + 1)));

            Assert.That(actualRepresentativePaths, Has.Count.EqualTo(1));
            Assert.That(actualRepresentativePaths.Single(), Is.EqualTo(expectedRepresentative));
        }
Exemplo n.º 16
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_OnClassicNonCancellativeExample_IndicatesNotStronglyCancellative()
        {
            if (!Computer.SupportsNonCancellativityDetection)
            {
                return;
            }

            var settings = GetSettings(detectNonCancellativity: true);
            var qp       = UsefulQPs.GetClassicNonCancellativeQP();

            DoSetup(qp, out var ruleTree);
            var result = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 1, ruleTree, settings);

            Assert.That(result.CancellativityFailureDetected, Is.True);
        }
        /// <summary>
        /// Indicates whether the specified number of periods is valid for the specified QP type.
        /// </summary>
        /// <param name="qpType">The QP type.</param>
        /// <param name="numPeriods">The number of periods.</param>
        /// <returns><see langword="true"/> if <paramref name="numPeriods"/> is valid for QPs of
        /// type <paramref name="qpType"/>; <see langword="false"/> otherwise.</returns>
        private bool NumPeriodsIsValid(QPType qpType, int numPeriods)
        {
            switch (qpType)
            {
            case QPType.OddFlower: return(UsefulQPs.OddFlowerParameterIsValid(numPeriods));

            case QPType.EvenFlowerType1: return(UsefulQPs.EvenFlowerType1ParameterIsValid(numPeriods));

            case QPType.EvenFlowerType2: return(UsefulQPs.EvenFlowerType2ParameterIsValid(numPeriods));

            case QPType.PointedFlower: return(UsefulQPs.PointedFlowerParameterIsValid(numPeriods));
            }

            Debug.Fail($"Invalid QP type ({qpType}) specified.");
            return(false);
        }
Exemplo n.º 18
0
        public void QuiverGeneration_WithStartGenerationFromBase_GeneratesOddFlower5FromCobweb5Correctly()
        {
            var quiverInPlane = UsefulQuiversInPlane.GetCobwebQuiverInPlane(5, 50, firstVertex: 1);
            var qp            = UsefulQPs.GetCobwebQP(5, firstVertex: 1);
            var potential     = qp.Potential;
            var boundaryLayer = UsefulQPs.GetVerticesInCobwebQPLayer(5, 1, firstVertex: 1);
            var layerType     = CreateLayerType(10, 5, 20); // 5 arrow pairs, all implicit

            generator.StartGenerationFromBase(quiverInPlane, potential, boundaryLayer, layerType, nextVertex: qp.Quiver.Vertices.Count + 1);
            generator.SupplyComposition(CreateComposition(Utility.RepeatMany(5, 1, 1))); // No choice for the 5 arrow pairs
            generator.SupplyComposition(CreateComposition(Utility.RepeatMany(5, 3, 3))); // 2 steps left and right (both of which can be 0)

            var output = generator.EndGeneration();

            qp        = output.QP;
            potential = qp.Potential;
            var expectedPotential = CreatePotential(new Dictionary <DetachedCycle <int>, int>
            {
                { CreateDetachedCycle(1, 2, 3, 4, 5, 1), +1 },

                { CreateDetachedCycle(1, 2, 7, 6, 1), -1 },
                { CreateDetachedCycle(2, 3, 9, 8, 2), -1 },
                { CreateDetachedCycle(3, 4, 11, 10, 3), -1 },
                { CreateDetachedCycle(4, 5, 13, 12, 4), -1 },
                { CreateDetachedCycle(5, 1, 15, 14, 5), -1 },

                { CreateDetachedCycle(1, 15, 6, 1), +1 },
                { CreateDetachedCycle(2, 7, 8, 2), +1 },
                { CreateDetachedCycle(3, 9, 10, 3), +1 },
                { CreateDetachedCycle(4, 11, 12, 4), +1 },
                { CreateDetachedCycle(5, 13, 14, 5), +1 },

                { CreateDetachedCycle(6, 18, 17, 16, 15, 6), -1 },
                { CreateDetachedCycle(8, 22, 21, 20, 7, 8), -1 },
                { CreateDetachedCycle(10, 26, 25, 24, 9, 10), -1 },
                { CreateDetachedCycle(12, 30, 29, 28, 11, 12), -1 },
                { CreateDetachedCycle(14, 34, 33, 32, 13, 14), -1 },

                { CreateDetachedCycle(6, 18, 19, 20, 7, 6), +1 },
                { CreateDetachedCycle(8, 22, 23, 24, 9, 8), +1 },
                { CreateDetachedCycle(10, 26, 27, 28, 11, 10), +1 },
                { CreateDetachedCycle(12, 30, 31, 32, 13, 12), +1 },
                { CreateDetachedCycle(14, 34, 35, 16, 15, 14), +1 },
            });

            Assert.That(potential, Is.EqualTo(expectedPotential));
        }
Exemplo n.º 19
0
        public void ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt_TriforceInterior()
        {
            var settings = GetSettings(detectNonCancellativity: false);
            var qp       = UsefulQPs.GetTriangleQP(3);

            DoSetup(qp, out var ruleTree);

            var representatives                   = Computer.ComputeMaximalNonzeroEquivalenceClassRepresentativesStartingAt(qp.Quiver, 2, ruleTree, settings).MaximalNonzeroEquivalenceClassRepresentatives.ToList();
            var representativeArrowPaths          = representatives.Select(path => path.Arrows);
            var expectedMaximalEquivalenceClasses = new ISet <IEnumerable <Arrow <int> > >[]
            {
                new HashSet <IEnumerable <Arrow <int> > >
                {
                    new Arrow <int>[] { new Arrow <int>(2, 1), new Arrow <int>(1, 3) },
                    new Arrow <int>[] { new Arrow <int>(2, 5), new Arrow <int>(5, 3) }
                },
            };

            Assert.That(representatives, Has.Count.EqualTo(expectedMaximalEquivalenceClasses.Length));
            foreach (var representative in representativeArrowPaths)
            {
                Assert.That(expectedMaximalEquivalenceClasses, Has.One.Contains(representative));
            }
        }
Exemplo n.º 20
0
        public void EvenFlowersOfType2_AreSelfInjective()
        {
            var qps = Utility.InfiniteRange(4, 2).Select(k => UsefulQPs.GetEvenFlowerType2QP(k)).TakeWhile(qp => qp.Quiver.Vertices.Count <= 36);

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 21
0
 public void GetNumberOfLayersInPointedFlowerQP_Works(int numPeriods, int expectedNumLayers)
 {
     Assert.That(UsefulQPs.GetNumberOfLayersInPointedFlowerQP(numPeriods), Is.EqualTo(expectedNumLayers));
 }
Exemplo n.º 22
0
 public void GetVerticesInPointedFlowerQPLayer_ThrowsOnBadLayerIndex(int numPeriods, int layerIndex)
 {
     Assert.That(() => UsefulQPs.GetVerticesInPointedFlowerQPLayer(numPeriods, layerIndex), Throws.InstanceOf <ArgumentOutOfRangeException>());
 }
Exemplo n.º 23
0
        public void GetVerticesInPointedFlowerQPLayer_Works(int numPeriods, int layerIndex, int firstVertex, params int[] expectedVertices)
        {
            var actualVertices = UsefulQPs.GetVerticesInPointedFlowerQPLayer(numPeriods, layerIndex, firstVertex);

            Assert.That(actualVertices, Is.EqualTo(expectedVertices));
        }
Exemplo n.º 24
0
 public void GetPeriodsOfPointedFlowerQP_ThrowsArgumentOutOfRangeException_OnBadNumberOfVerticesInCenterPolygon(int numPeriods, int firstVertex)
 {
     Assert.That(() => UsefulQPs.GetPeriodsOfPointedFlowerQPWithoutFixedPoint(numPeriods, firstVertex), Throws.InstanceOf <ArgumentOutOfRangeException>());
 }
Exemplo n.º 25
0
        public void GetPeriodsOfPointedFlowerQP_Works(int numPeriods, int firstVertex, IEnumerable <IEnumerable <int> > expectedPeriods)
        {
            var actualPeriods = UsefulQPs.GetPeriodsOfPointedFlowerQPWithoutFixedPoint(numPeriods, firstVertex);

            Assert.That(actualPeriods, Is.EqualTo(expectedPeriods));
        }
Exemplo n.º 26
0
 public void GetVerticesInSquareQPRow_ThrowsOnBadRowIndex(int numRows, int rowIndex)
 {
     Assert.That(() => UsefulQPs.GetVerticesInSquareQPRow(numRows, rowIndex), Throws.InstanceOf <ArgumentOutOfRangeException>());
 }
Exemplo n.º 27
0
        public void GetCycleQP_GivesSelfInjectiveQP()
        {
            var qps = Enumerable.Range(3, 28).Select(k => UsefulQPs.GetCycleQP(k));

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 28
0
        public void Triangles_AreSelfInjective()
        {
            var qps = Utility.InfiniteRange(2).Select(k => UsefulQPs.GetTriangleQP(k)).TakeWhile(qp => qp.Quiver.Vertices.Count < 20);

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 29
0
        public void Cobwebs_AreSelfInjective()
        {
            var qps = Utility.InfiniteRange(5, 2).Select(k => UsefulQPs.GetCobwebQP(k)).TakeWhile(qp => qp.Quiver.Vertices.Count < 30);

            AssertAreSelfInjective(qps);
        }
Exemplo n.º 30
0
        public void OddFlowers_AreSelfInjective()
        {
            var qps = Utility.InfiniteRange(3, 2).Select(k => UsefulQPs.GetOddFlowerQP(k)).TakeWhile(qp => qp.Quiver.Vertices.Count <= 35);

            AssertAreSelfInjective(qps);
        }