Named Opetopes¶
Examples¶
The point¶
1 2 3 4 | from opetopy.NamedOpetope import Point
pt = Point("x")
print(pt.eval())
|
A classic¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from opetopy.NamedOpetope import Graft, Point, Shift
beta = Shift(Graft(
Shift(Point("c"), "h"),
Shift(Point("a"), "i"),
"c"),
"β")
alpha = Shift(Graft(
Shift(Point("b"), "g"),
Shift(Point("a"), "f"),
"b"),
"α")
classic = Shift(Graft(beta, alpha, "i"), "A")
print(classic.eval())
print()
print(classic.toTex())
|
Documentation¶
Module author: Cédric HT
-
opetopy.NamedOpetope.
Arrow
(pointName: str = 'a', arrowName: str = 'f') → opetopy.NamedOpetope.RuleInstance[source]¶ Returns the proof tree of the arrow, with cell names as specified in the arguments.
-
class
opetopy.NamedOpetope.
Context
[source]¶ A context is a set of tyings (see
NamedOpetope.Typing
).-
__add__
(typing: opetopy.NamedOpetope.Typing) → opetopy.NamedOpetope.Context[source]¶ Adds a variable typing to a deep copy of the context context, if the typed variable isn’t already typed in the context.
-
__and__
(other) → opetopy.NamedOpetope.Context[source]¶ Returns the intersection of two contexts, i.e. the set of typings of the first context whose typed variable is in the second
-
__getitem__
(name: str) → opetopy.NamedOpetope.Variable[source]¶ Returns the varible term in current context whose name is
name
.
-
__next_in_mro__
¶ alias of
builtins.object
-
graftTuples
() → Set[Tuple[opetopy.NamedOpetope.Variable, opetopy.NamedOpetope.Variable]][source]¶ Returns all tuples (b, a) for \(b \leftarrow a (\ldots)\) a grafting occurring in a term in a type in the context.
See: NamedOpetope.Term.graftTuples()
See: NamedOpetopicSet.repres()
-
source
(var: opetopy.NamedOpetope.Variable, k: int = 1) → opetopy.NamedOpetope.Term[source]¶ Returns the :mathm``k``-source of a variable.
-
-
class
opetopy.NamedOpetope.
Degen
(p: opetopy.NamedOpetope.RuleInstance)[source]¶ A class representing an instance of the
degen
rule in a proof tree.-
__init__
(p: opetopy.NamedOpetope.RuleInstance) → None[source]¶ Creates an instance of the
degen
rule and plugs proof treep
on the unique premise.
-
-
class
opetopy.NamedOpetope.
DegenShift
(p: opetopy.NamedOpetope.RuleInstance, name: str)[source]¶ A class representing an instance of the
degen-shift
rule in a proof tree.-
__init__
(p: opetopy.NamedOpetope.RuleInstance, name: str) → None[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
opetopy.NamedOpetope.
EquationalTheory
[source]¶ An equational theory (among variables), is here represented as a partition of a subset of the set of all variables. Is is thus a list of sets of variables. (set of sets isn’t possible as python
set
isn’t hashable)-
__add__
(eq: Tuple[opetopy.NamedOpetope.Variable, opetopy.NamedOpetope.Variable]) → opetopy.NamedOpetope.EquationalTheory[source]¶ Adds an equality (represented by a tuple of two
NamedOpetope.Variable
) to the theory.
-
__or__
(other: opetopy.NamedOpetope.EquationalTheory) → opetopy.NamedOpetope.EquationalTheory[source]¶ Returns the union of two equational theories
-
__weakref__
¶ list of weak references to the object (if defined)
-
_index
(a: opetopy.NamedOpetope.Variable) → int[source]¶ Returns the index (in
NamedOpetope.EquationalTheory.classes
) of the class of the variablea
, or -1 of the class doesn’t exist.
-
classOf
(a: opetopy.NamedOpetope.Variable) → Set[opetopy.NamedOpetope.Variable][source]¶ Returns the class of a variable.
-
-
class
opetopy.NamedOpetope.
Graft
(p1: opetopy.NamedOpetope.RuleInstance, p2: opetopy.NamedOpetope.RuleInstance, a: str)[source]¶ A class representing an instance of the
graft
rule in a proof tree.-
__init__
(p1: opetopy.NamedOpetope.RuleInstance, p2: opetopy.NamedOpetope.RuleInstance, a: str) → None[source]¶ Creates an instance of the
graft
rule at variablea
, and plugs proof treep1
on the first premise, andp2
on the second.See: NamedOpetope.graft()
.
-
-
class
opetopy.NamedOpetope.
OCMT
(theory: opetopy.NamedOpetope.EquationalTheory, context: opetopy.NamedOpetope.Context)[source]¶ Opetopic context modulo theory. Basically the same as a
NamedOpetope.Sequent
, without the typing.-
__init__
(theory: opetopy.NamedOpetope.EquationalTheory, context: opetopy.NamedOpetope.Context) → None[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
__weakref__
¶ list of weak references to the object (if defined)
-
equal
(t: opetopy.NamedOpetope.Term, u: opetopy.NamedOpetope.Term) → bool[source]¶ Tells wether two terms
t
andu
are equal modulo the equational theory.See: Similar method for variables only: NamedOpetope.EquationalTheory.equal()
-
isIn
(var: opetopy.NamedOpetope.Variable, term: opetopy.NamedOpetope.Term) → bool[source]¶ Tells wether a variable is in a term modulo the equational theory of the sequent.
See: NamedOpetope.EquationalTheory.isIn()
See: NamedOpetope.Term.__contains__()
-
source
(var: opetopy.NamedOpetope.Variable, k: int = 1) → opetopy.NamedOpetope.Term[source]¶ Returns the :mathm``k``-source of a variable.
See: NamedOpetope.Context.source()
-
-
opetopy.NamedOpetope.
OpetopicInteger
(n: int, pointName: str = 'a', arrowName: str = 'f', cellName: str = 'A') → opetopy.NamedOpetope.RuleInstance[source]¶ Returns the proof tree of the \(n\)-th opetopic integer.
- if
n
is 0, then the unique point is namedpointName
(defaulta
), and the unique \(2\)-cell is namedcellName
(defaultA
). - otherwise, the points are named
a_1
,a_2
, …a_n-1
(with added braces if the index exceeds 10, so that it is \(\TeX\) friendly), arrowsf_1
, …f_n
. Those names can be changed by specifying thepointName
andarrowName
arguments. The unique \(2\)-cell is namedcellName
(defaultA
).
- if
-
class
opetopy.NamedOpetope.
Point
(name: str)[source]¶ A class representing an instance of the
point
rule in a proof tree.
-
class
opetopy.NamedOpetope.
Sequent
(theory: opetopy.NamedOpetope.EquationalTheory, context: opetopy.NamedOpetope.Context, typing: opetopy.NamedOpetope.Typing)[source]¶ A sequent consists of an equational theory (
NamedOpetope.EquationalTheory
), a context (NamedOpetope.Context
), and a typing (NamedOpetope.Typing
).-
__init__
(theory: opetopy.NamedOpetope.EquationalTheory, context: opetopy.NamedOpetope.Context, typing: opetopy.NamedOpetope.Typing) → None[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
graft
(t: opetopy.NamedOpetope.Term, x: opetopy.NamedOpetope.Variable, u: opetopy.NamedOpetope.Term) → opetopy.NamedOpetope.Term[source]¶ Grafts term (
NamedOpetope.Term
) u on term t via variable (NamedOpetope.Variable
) x. In other words, computes \(t(x \leftarrow u)\).
-
substitute
(u: opetopy.NamedOpetope.Term, s: opetopy.NamedOpetope.Term, a: opetopy.NamedOpetope.Variable) → Tuple[opetopy.NamedOpetope.Term, Optional[Tuple[opetopy.NamedOpetope.Variable, opetopy.NamedOpetope.Variable]]][source]¶ Substitute term (
NamedOpetope.Term
)s
for variable (NamedOpetope.Variable
)a
in termu
. In other words, computes \(u[s/a]\).Returns a tuple containing
- the resulting substitution
- an new equality to add to the equational theory, or
None
-
typing
= None¶ This variable specifies if contexts should be displayed in
NamedOpetope.Sequent.toTex()
-
-
class
opetopy.NamedOpetope.
Shift
(p: opetopy.NamedOpetope.RuleInstance, name: str)[source]¶ A class representing an instance of the
shift
rule in a proof tree.-
__init__
(p: opetopy.NamedOpetope.RuleInstance, name: str) → None[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
opetopy.NamedOpetope.
Term
(var: Optional[opetopy.NamedOpetope.Variable] = None, degen: bool = False)[source]¶ An \(n\)-term is represented as follows:
- If it is degenerate, then the boolean attribute
NamedOpetope.Term.degenerate
is set toTrue
, andNamedOpetope.Term.variable
is set to the variable name of which the current term is the degeneracy. - If it is non degenerate, then the boolean attribute
NamedOpetope.Term.degenerate
is set toFalse
,NamedOpetope.Term.variable
is set to the variable name of the root node, and this class is otherwise used as adict
mapping \((n-1)\)-variables in the source to other \(n\)-terms.
-
__contains__
(var) → bool[source]¶ Checks if a variable is in the term.
If the term is degenerate, always return
False
. Otherwise, assume the term has dimension \(n\).- If the variable has dimension \((n-1)\), then it checks against
all keys in the underlying
dict
and if not found, calls the method recursively on all values of the underlyingdict
(which by construction are also \(n\)-terms). - If the variable has \(n\), then it compares it to the root node
(
NamedOpetope.Term.variable
), and if not equal, calls the method recursively on all values of the underlyingdict
(which by construction are also \(n\)-terms).
- If the variable has dimension \((n-1)\), then it checks against
all keys in the underlying
-
__init__
(var: Optional[opetopy.NamedOpetope.Variable] = None, degen: bool = False) → None[source]¶ Creates a term from a
NamedOpetope.Variable
var
. If it isNone
(default), then this term represents the unique \((-1)\)-term.
-
__next_in_mro__
¶ alias of
builtins.object
-
__weakref__
¶ list of weak references to the object (if defined)
-
dimension
¶ Returns the dimension of the term. If its
NamedOpetope.Term.variable
isNone
, then it is \(-1\) by convention. If it is degenerate, then it is the dimension ofNamedOpetope.Term.variable
\(+1\), otherwise just the dimension ofNamedOpetope.Term.variable
.
- If it is degenerate, then the boolean attribute
-
class
opetopy.NamedOpetope.
Type
(terms: List[opetopy.NamedOpetope.Term])[source]¶ An \(n\)-type is a sequence of \((n+1)\) terms of dimension \((n-1), (n-2), \ldots, -1\).
-
__contains__
(var) → bool[source]¶ Checks wether a given variable appears in at least one term of the type.
-
__init__
(terms: List[opetopy.NamedOpetope.Term]) → None[source]¶ Creates a new type from a list of term. The dimension is inferred from the length of the list, and the terms are checked to have the correct dimension.
If the list has length \((n+1)\), then the type’s dimension will be \(n\), and the dimension of the \(i\) th term in the list must be \(n - i - 1\) (recall that Python index start at \(0\), whence the \(-1\) correction factor).
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
opetopy.NamedOpetope.
Typing
(term, type)[source]¶ - A typing is simply an \(n\)-term (
NamedOpetope.Term
) - together with an \(n\)-type (
NamedOpetope.Type
).
-
__weakref__
¶ list of weak references to the object (if defined)
- A typing is simply an \(n\)-term (
-
class
opetopy.NamedOpetope.
Variable
(name: str, dim: int)[source]¶ A variable is just a string representing its name, annotated by an integer representing its dimension.
-
__eq__
(other) → bool[source]¶ Tests syntactic equality between two variables. Two variables are equal if they have the same dimension and the same name.
-
__init__
(name: str, dim: int) → None[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
opetopy.NamedOpetope.
degen
(seq: opetopy.NamedOpetope.Sequent) → opetopy.NamedOpetope.Sequent[source]¶ The \(\textbf{Opt${}^!$}\) \(\texttt{degen}\) rule. Takes a sequent typing a variable and produces a new sequent typing the degeneracy at that variable.
-
opetopy.NamedOpetope.
degenshift
(seq: opetopy.NamedOpetope.Sequent, name: str) → opetopy.NamedOpetope.Sequent[source]¶ The \(\textbf{Opt${}^!$}\) \(\texttt{degen-shift}\) rule. Applies the degen and the shift rule consecutively.
-
opetopy.NamedOpetope.
graft
(seqt: opetopy.NamedOpetope.Sequent, seqx: opetopy.NamedOpetope.Sequent, name: str) → opetopy.NamedOpetope.Sequent[source]¶ The \(\textbf{Opt${}^!$}\) \(\texttt{graft}\) rule. Takes the following arguments:
seqt
typing an \(n\) term \(t\)seqx
second typing an \(n\) variable \(x\)- an \((n-1)\) variable
a
onto which to operate the grafting, specified by its namename
such that the two sequents are compatible, and the intersection of their context is essentially the context typing
a
and its variables. It then produces the \(n\) term \(t(a \leftarrow x)\).The way the intersection condition is checked is by verifying that the only variables typed in both contexts (modulo both theories) are those appearing in the type of
a
or of coursea
itself.