def __call__(self, x, check=True): r""" Return ``x`` coerced into this free monoid. One can create a free radix 64 string monoid element from a Python string or a list of integers in `0, \dots, 63`, as for generic ``FreeMonoids``. EXAMPLES:: sage: S = Radix64Strings() sage: S.gen(0) A sage: S.gen(1) B sage: S.gen(62) + sage: S.gen(63) / sage: S([ i for i in range(64) ]) ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ """ ## There should really some careful type checking here... if isinstance(x, StringMonoidElement) and x.parent() == self: return x elif isinstance(x, list): return StringMonoidElement(self, x, check) elif isinstance(x, str): return StringMonoidElement(self, x, check) else: raise TypeError("Argument x (= %s) is of the wrong type." % x)
def __call__(self, x, check=True): r""" Return ``x`` coerced into this free monoid. One can create a free alphabetic string monoid element from a Python string, or a list of integers in `0, \dots,25`. EXAMPLES:: sage: S = AlphabeticStrings() sage: S.gen(0) A sage: S.gen(1) B sage: S.gen(25) Z sage: S([ i for i in range(26) ]) ABCDEFGHIJKLMNOPQRSTUVWXYZ """ ## There should really some careful type checking here... if isinstance(x, StringMonoidElement) and x.parent() == self: return x elif isinstance(x, list): return StringMonoidElement(self, x, check) elif isinstance(x, str): return StringMonoidElement(self, x, check) else: raise TypeError("Argument x (= %s) is of the wrong type." % x)
def __call__(self, x, check=True): r""" Return ``x`` coerced into this free monoid. One can create a free hexadecimal string monoid element from a Python string of a list of integers in `\{ 0, \dots, 15 \}`. EXAMPLES:: sage: S = HexadecimalStrings() sage: S('0a0a0a019f019f') 0a0a0a019f019f sage: S.gen(0) 0 sage: S.gen(1) 1 sage: S([ i for i in range(16) ]) 0123456789abcdef """ ## There should really some careful type checking here... if isinstance(x, StringMonoidElement) and x.parent() == self: return x elif isinstance(x, list): return StringMonoidElement(self, x, check) elif isinstance(x, str): return StringMonoidElement(self, x, check) else: raise TypeError("Argument x (= %s) is of the wrong type." % x)
def __call__(self, x, check=True): r""" Return ``x`` coerced into this free monoid. One can create a free octal string monoid element from a Python string of 0's to 7's or list of integers. EXAMPLES:: sage: S = OctalStrings() sage: S('07070701650165') 07070701650165 sage: S.gen(0) 0 sage: S.gen(1) 1 sage: S([ i for i in range(8) ]) 01234567 """ ## There should really some careful type checking here... if isinstance(x, StringMonoidElement) and x.parent() == self: return x elif isinstance(x, list): return StringMonoidElement(self, x, check) elif isinstance(x, str): return StringMonoidElement(self, x, check) else: raise TypeError("Argument x (= %s) is of the wrong type." % x)
def __call__(self, x, check=True): r""" Return ``x`` coerced into this free monoid. One can create a free binary string monoid element from a Python string of 0's and 1's or list of integers. NOTE: Due to the ambiguity of the second generator '1' with the identity element '' of the monoid, the syntax S(1) is not permissible. EXAMPLES:: sage: S = BinaryStrings() sage: S('101') 101 sage: S.gen(0) 0 sage: S.gen(1) 1 """ ## There should really some careful type checking here... if isinstance(x, StringMonoidElement) and x.parent() == self: return x elif isinstance(x, list): return StringMonoidElement(self, x, check) elif isinstance(x, str): return StringMonoidElement(self, x, check) else: raise TypeError("Argument x (= %s) is of the wrong type." % x)
def gen(self, i=0): r""" The `i`-th generator of the monoid. INPUT: - ``i`` -- integer (default: 0) EXAMPLES:: sage: S = BinaryStrings() sage: S.gen(0) 0 sage: S.gen(1) 1 sage: S.gen(2) Traceback (most recent call last): ... IndexError: Argument i (= 2) must be between 0 and 1. sage: S = HexadecimalStrings() sage: S.gen(0) 0 sage: S.gen(12) c sage: S.gen(16) Traceback (most recent call last): ... IndexError: Argument i (= 16) must be between 0 and 15. """ n = self.ngens() if i < 0 or not i < n: raise IndexError("Argument i (= %s) must be between 0 and %s." % (i, n - 1)) return StringMonoidElement(self, [int(i)])
def one(self): r""" Return the identity element of ``self``. EXAMPLES:: sage: b = BinaryStrings(); b Free binary string monoid sage: b.one() * b('1011') 1011 sage: b.one() * b('110') == b('110') True sage: b('10101') * b.one() == b('101011') False """ return StringMonoidElement(self, '')