Ejemplo n.º 1
0
        /// <summary>
        /// Gets colimit
        /// </summary>
        /// <param name="category">The category</param>
        /// <param name="arrows">Diagram arrows</param>
        /// <param name="coequalizer">Coequalizer</param>
        /// <param name="objectArrows">Arrows to colimit</param>
        /// <param name="productArrows">Sum arrows</param>
        /// <returns>The colimit</returns>
        public static IAdvancedCategoryObject GetColim(ICategory category, IList <IAdvancedCategoryArrow> arrows,
                                                       ref IAdvancedCategoryArrow coequalizer, ref IList <IAdvancedCategoryArrow> objectArrows, ref IList <IAdvancedCategoryArrow> productArrows)
        {
            IList <IAdvancedCategoryObject> objects = new List <IAdvancedCategoryObject>();
            IList <IAdvancedCategoryObject> sources = new List <IAdvancedCategoryObject>();
            IDirectSumCategory   direct             = category as IDirectSumCategory;
            ICoequalizerCategory coequ = category as ICoequalizerCategory;

            foreach (IAdvancedCategoryArrow arrow in arrows)
            {
                if (!objects.Contains(arrow.Source as IAdvancedCategoryObject))
                {
                    objects.Add(arrow.Source as IAdvancedCategoryObject);
                }
                if (!objects.Contains(arrow.Target as IAdvancedCategoryObject))
                {
                    objects.Add(arrow.Source as IAdvancedCategoryObject);
                }
                sources.Add(arrow.Source as IAdvancedCategoryObject);
            }
            IList <IAdvancedCategoryArrow> productSourceArrows = new List <IAdvancedCategoryArrow>();

            productArrows = new List <IAdvancedCategoryArrow>();
            IAdvancedCategoryObject        product       = direct.GetDirectSum(objects, productArrows);
            IAdvancedCategoryObject        productSource = direct.GetDirectSum(sources, productSourceArrows);
            IList <IAdvancedCategoryArrow> coequList     = new List <IAdvancedCategoryArrow>();
            IList <IAdvancedCategoryArrow> arrList       = new List <IAdvancedCategoryArrow>();

            foreach (IAdvancedCategoryArrow arr in productArrows)
            {
                IAdvancedCategoryObject target = arr.Target as IAdvancedCategoryObject;
                foreach (IAdvancedCategoryObject t in sources)
                {
                    if (t == target)
                    {
                        arrList.Add(arr);
                    }
                }
            }
            IAdvancedCategoryArrow first = direct.GetArrowFromDirectSum(product, productSource, arrList);

            foreach (IAdvancedCategoryArrow arr in arrows)
            {
                int num = objects.IndexOf(arr.Target as IAdvancedCategoryObject);
                IAdvancedCategoryArrow pr = productArrows[num] as IAdvancedCategoryArrow;
                IAdvancedCategoryArrow eq = pr.Compose(category, arr);
                coequList.Add(eq);
            }
            IAdvancedCategoryArrow second = direct.GetArrowFromDirectSum(product, productSource, coequList);

            coequalizer  = coequ.GetCoequalizer(first, second);
            objectArrows = new List <IAdvancedCategoryArrow>();
            foreach (IAdvancedCategoryArrow arrow in productArrows)
            {
                IAdvancedCategoryArrow arr = coequalizer.Compose(category, arrow);
                objectArrows.Add(arr);
            }
            return(coequalizer.Target as IAdvancedCategoryObject);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates limit
        /// </summary>
        private void CreateColim()
        {
            if (!(category is IDirectSumCategory))
            {
                throw new CategoryException(CategoryException.DirectSumNotSupported);
            }
            if (!(category is IEqualizerCategory))
            {
                throw new CategoryException(CategoryException.CoequalizerNotSupported);
            }
            IDirectSumCategory              sumCategory  = category as IDirectSumCategory;
            IList <IAdvancedCategoryArrow>  firstArrows  = new List <IAdvancedCategoryArrow>();
            IAdvancedCategoryObject         firstSum     = sumCategory.GetDirectSum(objects, firstArrows);
            IList <IAdvancedCategoryObject> beginObjects = new List <IAdvancedCategoryObject>();

            foreach (CategoryObjectPair o in arrows.Keys)
            {
                IAdvancedCategoryArrow a = arrows[o];
                beginObjects.Add(a.Source as IAdvancedCategoryObject);
            }
            IList <IAdvancedCategoryArrow> secondArrows = new List <IAdvancedCategoryArrow>();
            IAdvancedCategoryObject        secondSum    = sumCategory.GetDirectSum(beginObjects, secondArrows);

            colimIdArrows = new List <IAdvancedCategoryArrow>();
            foreach (IAdvancedCategoryArrow sar in secondArrows)
            {
                IAdvancedCategoryObject s = sar.Source as IAdvancedCategoryObject;
                foreach (IAdvancedCategoryArrow proj in firstArrows)
                {
                    if (proj.Source == s)
                    {
                        colimIdArrows.Add(proj);
                        break;
                    }
                }
            }
            colimIdArrow    = sumCategory.GetArrowFromDirectSum(firstSum, secondSum, colimIdArrows);
            colimFuncArrows = new List <IAdvancedCategoryArrow>();
            foreach (CategoryObjectPair o in arrows.Keys)
            {
                IAdvancedCategoryArrow sar = this[o];
                foreach (IAdvancedCategoryArrow proj in firstArrows)
                {
                    if (proj.Source == sar.Target)
                    {
                        IAdvancedCategoryArrow ar = proj.Compose(category, sar);
                        colimFuncArrows.Add(ar);
                        break;
                    }
                }
            }
            colimFuncArrow = sumCategory.GetArrowFromDirectSum(firstSum, secondSum, colimFuncArrows);
            ICoequalizerCategory coequalizerCategory = category as ICoequalizerCategory;

            colimArrow  = coequalizerCategory.GetCoequalizer(colimIdArrow, colimFuncArrow);
            colim       = colimArrow.Target as IAdvancedCategoryObject;
            colimArrows = new Dictionary <IAdvancedCategoryObject, IAdvancedCategoryArrow>();
            foreach (IAdvancedCategoryArrow proj in firstArrows)
            {
                IAdvancedCategoryObject s  = proj.Source as IAdvancedCategoryObject;
                IAdvancedCategoryArrow  ar = colimArrow.Compose(category, proj);
                colimArrows[s] = ar;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets arrow from colim
        /// </summary>
        /// <param name="arrows">Arrows from objects</param>
        /// <returns>Arrow from colim</returns>
        public IAdvancedCategoryArrow GetArrowFromColim(IList <IAdvancedCategoryArrow> arrows)
        {
            Dictionary <ICategoryObject, ICategoryArrow> dictionary = new Dictionary <ICategoryObject, ICategoryArrow>();
            IAdvancedCategoryObject target = null;

            foreach (IAdvancedCategoryArrow arrow in arrows)
            {
                if (target == null)
                {
                    target = arrow.Target as IAdvancedCategoryObject;
                }
                if (target != arrow.Target)
                {
                    throw new CategoryException(CategoryException.DifferentTargets,
                                                new IAdvancedCategoryObject[] { target, arrow.Target as IAdvancedCategoryObject });
                }
                if (!objects.Contains(arrow.Source as IAdvancedCategoryObject))
                {
                    throw new CategoryException(ObjectOutOfDiagram, arrow.Source);
                }
                if (dictionary.ContainsKey(arrow.Source))
                {
                    throw new CategoryException(ExtraArrow, arrow);
                }
                dictionary[arrow.Source] = arrow;
            }
            foreach (object o in objects)
            {
                if (!dictionary.ContainsKey(o as ICategoryObject))
                {
                    throw new CategoryException(ArrowsShortage, o);
                }
            }
            foreach (CategoryObjectPair pair in Keys)
            {
                IAdvancedCategoryArrow ar          = this[pair];
                IAdvancedCategoryArrow first       = dictionary[pair.Target] as IAdvancedCategoryArrow;
                IAdvancedCategoryArrow second      = dictionary[pair.Source] as IAdvancedCategoryArrow;
                IAdvancedCategoryArrow composition = first.Compose(category, ar);
                if (!composition.Equals(second))
                {
                    throw new CategoryException(CategoryException.NonCommutativePath, ar);
                }
            }
            Dictionary <int, IAdvancedCategoryArrow> sortedTable = new Dictionary <int, IAdvancedCategoryArrow>();

            foreach (IAdvancedCategoryArrow ar in arrows)
            {
                int i = objects.IndexOf(ar.Source as IAdvancedCategoryObject);
                sortedTable[i] = ar;
            }
            IList <IAdvancedCategoryArrow> sortedArrows = new List <IAdvancedCategoryArrow>();

            for (int i = 0; i < sortedTable.Count; i++)
            {
                sortedArrows.Add(sortedTable[i]);
            }
            IDirectSumCategory     sumCategory  = category as IDirectSumCategory;
            IAdvancedCategoryArrow arrowFromSum =
                sumCategory.GetArrowFromDirectSum(target, colimIdArrow.Target as IAdvancedCategoryObject, sortedArrows);
            ICoequalizerCategory   coequalizerCategory = category as ICoequalizerCategory;
            IAdvancedCategoryArrow res = coequalizerCategory.GetArrowFromCoequalizer(colimArrow,
                                                                                     arrowFromSum, colimIdArrow, colimFuncArrow);

            return(res);
        }