arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2401.12740math.CO
收藏

控制 C3 超类线性化算法

Controlling the C3 super class linearization algorithm

Florent Hivert, Nicolas M. Thiéry

AI总结:

本文研究 C3 超类线性化因局部排序不一致而失败的问题,发现最小为 10 个元素的不可一致化偏序集,并给出由偏序集和线性扩张自动构造安全局部信息的算法,已用于 SageMath。

摘要:

C3 是一种被 Python 等多种广泛使用的编程语言采用的算法,用于支持面向对象编程(OOP)中的多重继承:对于每个类,C3 根据用户提供的局部信息(直接超类的排序),递归计算其所有超类构成的偏序集的一个线性扩张,即方法解析顺序(MRO)。如果局部信息不一致,该算法就可能失败。在 SageMath 计算系统中对抽象代数的概念层次进行建模时,会遇到大型类层次结构;在这种情况下,手工维护一致的局部信息无法扩展,并会导致不可预测的 C3 失败。本文报告了作者为分析和规避这一维护难题所做的工作。首先,通过大规模计算机探索,我们发现存在不具有任何一致局部信息的偏序集;我们给出了其中最小的一个,它有 10 个元素。随后,我们提出并分析了一种算法:给定一个偏序集和一个线性扩张,该算法自动为 C3 构造局部信息,以保证 C3 永远不会失败,其代价是对假设条件进行轻微放宽。该算法自 2013 年以来已在 SageMath 的生产环境中使用。

英文摘要:

C3 is an algorithm used by several widely used programming languages such as Python to support multiple inheritance in object oriented programming (OOP): for each class, C3 computes recursively a linear extension of the poset of all its super classes (the Method Resolution Order, MRO) from user-provided local information (an ordering of the direct super classes). This algorithm can fail if the local information is not consistent. For large hierarchies of classes, as encountered when modeling hierarchies of concepts from abstract algebra in the SageMath computational system, maintaining consistent local information by hand does not scale and leads to unpredictable C3 failures. This paper reports on the authors' work to analyze and circumvent this maintenance nightmare. First, we discovered through extensive computer exploration that there exists posets admitting no consistent local information; we exhibit the smallest one which has 10 elements. Then, we provide and analyze an algorithm that, given a poset and a linear extension, automatically builds local information for C3 in such a way that guarantees that it will never fail, at the price of a slight relaxation of the hypotheses. This algorithm has been used in production in SageMath since 2013.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑