Skip to content
Snippets Groups Projects
Commit 62aad46e authored by Chris's avatar Chris
Browse files

Add variants of python datatypes with immutable datastructures.

parent 0b90d169
No related branches found
No related tags found
No related merge requests found
Showing
with 2639 additions and 0 deletions
class BBoolean:
def __init__(self, value):
if type(value) is bool:
self.__value = value
elif type(value) is str:
self.__value = str(value).lower() == "true"
def __and__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value and other.__value)
def __or__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value or other.__value)
def __rand__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value and other.__value)
def __str__(self) -> 'str':
return str(self.__value).lower()
def __ror__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value or other.__value)
def __rxor__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value ^ other.__value)
def __xor__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value ^ other.__value)
def __eq__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value == other.__value)
def __ne__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value != other.__value)
def _and(self, other: 'BBoolean') -> 'BBoolean':
return self.__and__(other)
def _or(self, other: 'BBoolean') -> 'BBoolean':
return self.__or__(other)
def _not(self) -> 'BBoolean':
return BBoolean(not self.__value)
def implies(self, other: 'BBoolean') -> 'BBoolean':
return self._not()._or(other)
def equivalent(self, other: 'BBoolean') -> 'BBoolean':
return self.implies(other)._and(other.implies(self))
def equal(self, other: 'BBoolean') -> 'BBoolean':
return self.__eq__(other)
def unequal(self, other: 'BBoolean') -> 'BBoolean':
return self.__ne__(other)
def booleanValue(self) -> 'bool':
return self.__value
def __hash__(self):
return hash(self.__value)
\ No newline at end of file
class BCouple:
def __init__(self, first, second):
self.__first = first
self.__second = second
def get_first(self):
return self.__first
def get_second(self):
return self.__second
def __eq__(self, other):
return self.__first == other.__first and self.__second == other.__second
def equal(self, other):
return self == other
def unequal(self, other):
return self != other
\ No newline at end of file
from btypes.BBoolean import *
class BInteger:
def __init__(self, value):
self.__value = value
def __add__(self, other: 'BInteger') -> 'BInteger':
if type(other) == str:
return str(self) + other
return BInteger(self.__value + other.__value)
def __sub__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value - other.__value)
def __mul__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value * other.__value)
def __mod__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value % other.__value)
def __div__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value // other.__value)
def __neg__(self) -> 'BInteger':
return BInteger(-self.__value)
def __lt__(self, other: 'BInteger') -> 'bool':
return self.__value < other.__value
def __le__(self, other: 'BInteger') -> 'bool':
return self.__value <= other.__value
def __eq__(self, other: 'BInteger') -> 'bool':
if not isinstance(other, BInteger):
return False
return self.__value == other.__value
def __ne__(self, other: 'BInteger') -> 'bool':
return self.__value != other.__value
def __gt__(self, other: 'BInteger') -> 'bool':
return self.__value > other.__value
def __ge__(self, other: 'BInteger') -> 'bool':
return self.__value >= other.__value
def __pow__(self, other: 'BInteger') -> 'BInteger':
return self.__value ** other.__value
def __str__(self) -> 'str':
return str(self.__value)
def plus(self, other: 'BInteger') -> 'BInteger':
return self.__add__(other)
def minus(self, other: 'BInteger') -> 'BInteger':
return self.__sub__(other)
def multiply(self, other: 'BInteger') -> 'BInteger':
return self.__mul__(other)
def modulo(self, other: 'BInteger') -> 'BInteger':
return self.__mod__(other)
def divide(self, other: 'BInteger') -> 'BInteger':
return self.__div__(other)
def negative(self) -> 'BInteger':
return self.__neg__()
def less(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value < other.__value)
def lessEqual(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value <= other.__value)
def equal(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value == other.__value)
def unequal(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value != other.__value)
def greater(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value > other.__value)
def greaterEqual(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value >= other.__value)
def succ(self) -> 'BInteger':
return BInteger(self.__value + 1)
def pred(self) -> 'BInteger':
return BInteger(self.__value - 1)
def power(self, other: 'BInteger') -> 'BInteger':
return self.__pow__(other)
def positive(self):
return self
def intValue(self):
return self.__value
def isInteger(self) -> 'BBoolean':
return BBoolean(true)
def isNotInteger(self) -> 'BBoolean':
return BBoolean(false)
def isNatural(self) -> 'BBoolean':
return self.greaterEqual(BInteger(0))
def isNotNatural(self) -> 'BBoolean':
return self.isNatural()._not()
def isNatural1(self) -> 'BBoolean':
return self.greater(BInteger(0))
def isNotNatural1(self) -> 'BBoolean':
return self.isNatural1()._not()
def __hash__(self):
return hash(31 + self.__value)
\ No newline at end of file
class BObject:
pass
\ No newline at end of file
This diff is collapsed.
from btypes.BInteger import *
from btypes.BBoolean import *
from btypes.BString import *
from btypes.BStruct import *
import immutables
class BSet:
def __init__(self, *args):
if len(args) == 1 and type(args[0]) is immutables.Map:
self.__set = args[0]
else:
_set = {x: x for x in args}
self.__set = immutables.Map(_set)
def __str__(self) -> 'str':
return '{' + ', '.join([str(x) for x in self.__set]) + '}'
def __eq__(self, other):
if self is other:
return True
if other is None or type(self) != type(other):
return False
if not self.__set == other.__set:
return False
return True
def __ne__(self, other):
return not self.__eq__(other)
def __len__(self):
return len(self.__set)
def union(self, other=None):
if other is None:
if len(self.__set) == 0:
return BSet()
elif type(next(iter(self.__set))) == BSet:
return reduce(lambda a, e: a.update(e), self, BSet())
elif type(next(iter(self.__set))) == BRelation:
return reduce(lambda a, e: a.update(e), self, BRelation())
return BSet(self.__set.update(other.getSet()))
def intersect(self, other=None):
if other is None:
if len(self.__set) == 0:
return BSet()
elif type(next(iter(self.__set))) == BSet:
return reduce(lambda a, e: a.intersect(e), self, BSet())
elif type(next(iter(self.__set))) == BRelation:
return reduce(lambda a, e: a.intersect(e), self, BRelation())
_set = self.__set
for element in _set:
if not element in other.__set:
_set = _set.delete(element)
return BSet(_set)
def difference(self, other: 'BSet') -> 'BSet':
_set = self.__set
for element in other.__set:
if element in _set:
_set = _set.delete(element)
return BSet(_set)
def card(self) -> 'BInteger':
return BInteger(len(self.__set))
def size(self) -> 'BInteger':
return BInteger(len(self.__set))
def elementOf(self, obj) -> 'BBoolean':
return BBoolean(obj in self.__set)
def notElementOf(self, obj) -> 'BBoolean':
return BBoolean(obj not in self.__set)
def subset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(other.containsAll(self.__set))
def notSubset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(not other.containsAll(self.__set))
def strictSubset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(other.size() != self.size() and other.containsAll(self.__set))
def strictNotSubset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(other.size() == self.size() and not other.containsAll(self.__set))
def contains(self, other):
return other in self.__set
def containsAll(self, other):
for o in other:
if o not in self.__set:
return False
return True
def isEmpty(self) -> 'int':
return len(self.__set) == 0
def equal(self, other) -> 'bool':
return self.__eq__(other)
def unequal(self, other) -> 'bool':
return self.__ne__(other)
def nondeterminism(self):
return random.choice(self.__set)
def min(self):
return min(self.__set)
def max(self):
return max(self.__set)
def pow(self) -> 'BSet':
result = BSet()
start = BSet()
queue = [start]
result = result.union(BSet(start))
while not len(queue) == 0:
currentSet = queue.pop()
for element in self.__set:
nextSet = currentSet.union(BSet(element))
previousSize = result.size()
result = result.union(BSet(nextSet))
if previousSize < result.size():
queue.append(nextSet)
return result
# s = list(self.__set)
# return BSet(frozenset(chain.from_iterable(BSet(combinations(s, r)) for r in range(len(s) + 1))))
def pow1(self) -> 'BSet':
return self.pow().difference(BSet(BSet()))
# Only finite subsets are supported so fin = pow
def fin(self) -> 'BSet':
return self.pow()
def fin1(self) -> 'BSet':
return self.pow1()
def subsetOfInteger(self) -> 'bool':
for element in self.__set:
if not isinstance(element, BInteger):
return False
return True
def strictSubsetOfInteger(self) -> 'bool':
return self.subsetOfInteger()
def notSubsetOfInteger(self) -> 'bool':
return not self.subsetOfInteger()
def notStrictSubsetOfInteger(self) -> 'bool':
return not self.strictSubsetOfInteger()
def subsetOfNatural(self) -> 'bool':
for element in self.__set:
if not (isinstance(element, BInteger) and element.isNatural().booleanValue()):
return False
return True
def strictSubsetOfNatural(self) -> 'bool':
return self.subsetOfNatural()
def notSubsetOfNatural(self) -> 'bool':
return not self.subsetOfNatural()
def notStrictSubsetOfNatural(self) -> 'bool':
return not self.strictSubsetOfNatural()
def subsetOfNatural1(self) -> 'bool':
for element in self.__set:
if not (isinstance(element, BInteger) and element.isNatural1().booleanValue()):
return False
return True
def subsetOfString(self) -> 'bool':
for element in self.__set:
if not isinstance(element, BString):
return False
return True
def strictSubsetOfString(self) -> 'bool':
return self.subsetOfString()
def notSubsetOfString(self) -> 'bool':
return not self.subsetOfString()
def notStrictSubsetOfString(self) -> 'bool':
return not self.strictSubsetOfString()
def subsetOfStruct(self) -> 'bool':
for element in self.__set:
if not isinstance(element, BStruct):
return False
return True
def strictSubsetOfStruct(self) -> 'bool':
return self.subsetOfStruct()
def notSubsetOfStruct(self) -> 'bool':
return not self.subsetOfStruct()
def notStrictSubsetOfStruct(self) -> 'bool':
return not self.strictSubsetOfStruct()
def equalInteger(self) -> 'BBoolean':
return BBoolean(False)
def unequalInteger(self) -> 'BBoolean':
return BBoolean(True)
def equalNatural(self) -> 'BBoolean':
return BBoolean(False)
def unequalNatural(self) -> 'BBoolean':
return BBoolean(True)
def equalNatural1(self) -> 'BBoolean':
return BBoolean(False)
def unequalNatural1(self) -> 'BBoolean':
return BBoolean(True)
def equalString(self) -> 'BBoolean':
return BBoolean(False)
def unequalString(self) -> 'BBoolean':
return BBoolean(True)
def equalStruct(self) -> 'BBoolean':
return BBoolean(False)
def unequalStruct(self) -> 'BBoolean':
return BBoolean(True)
def getSet(self):
return self.__set
@staticmethod
def interval(a: 'BInteger', b: 'BInteger') -> 'BSet':
r = list(map(BInteger, range(a.intValue(), b.intValue() + 1)))
return BSet(*r)
def __hash__(self):
return hash(self.__set)
def __iter__(self):
return iter(self.__set)
from btypes.BRelation import *
from btypes.BBoolean import *
class BString:
def __init__(self, value):
self.__value = value
def getValue(self):
return value
def __eq__(self, other: 'BString') -> 'BBoolean':
return BBoolean(self.__value == other.__value)
def equals(self, other) -> 'bool':
return self.__eq__(other)
def length(self) -> 'int':
return len(self.__value)
def isEmpty(self) -> 'bool':
return not self.__value
def hashCode(self):
hash(self.__value)
def toString(self) -> 'str':
return '"' + self.__value + '"'
def isCase(self, other) -> 'bool':
return self.__value.equals(other)
def isString(self) -> 'BBoolean':
return BBoolean(True)
def isNotString(self) -> 'BBoolean':
return BBoolean(False)
from btypes.BBoolean import *
class BStruct:
def isRecord(self):
return BBoolean(True)
def isNotRecord(self):
return BBoolean(False)
from btypes.BObject import *
from btypes.BBoolean import *
class BTuple(BObject):
def __init__(self, first, second):
if first is None or second is None:
raise ValueError()
self.first = first
self.second = second
def __eq__(self, other):
return self.equals(other)
def equals(self, other) -> 'bool':
if self is other:
return True
if other is None or type(self) != type(other):
return False
b_objects = other
# elements is never None
return b_objects.projection1().__eq__(self.first) and b_objects.projection2().__eq__(self.second)
def __hash__(self):
return hash(hash(self.first) + hash(self.second))
def projection1(self):
return self.first
def projection2(self):
return self.second
def __str__(self):
return "(" + str(self.projection1()) + " |-> " + str(self.projection2()) + ')'
def equal(self, other: 'BTuple') -> 'BBoolean':
return BBoolean(self.equals(other))
def unequal(self, other: 'BTuple') -> 'BBoolean':
return BBoolean(not self.equals(other))
class BBoolean:
def __init__(self, value):
if type(value) is bool:
self.__value = value
elif type(value) is str:
self.__value = str(value).lower() == "true"
def __and__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value and other.__value)
def __or__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value or other.__value)
def __rand__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value and other.__value)
def __str__(self) -> 'str':
return str(self.__value).lower()
def __ror__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value or other.__value)
def __rxor__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value ^ other.__value)
def __xor__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value ^ other.__value)
def __eq__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value == other.__value)
def __ne__(self, other: 'BBoolean') -> 'BBoolean':
return BBoolean(self.__value != other.__value)
def _and(self, other: 'BBoolean') -> 'BBoolean':
return self.__and__(other)
def _or(self, other: 'BBoolean') -> 'BBoolean':
return self.__or__(other)
def _not(self) -> 'BBoolean':
return BBoolean(not self.__value)
def implies(self, other: 'BBoolean') -> 'BBoolean':
return self._not()._or(other)
def equivalent(self, other: 'BBoolean') -> 'BBoolean':
return self.implies(other)._and(other.implies(self))
def equal(self, other: 'BBoolean') -> 'BBoolean':
return self.__eq__(other)
def unequal(self, other: 'BBoolean') -> 'BBoolean':
return self.__ne__(other)
def booleanValue(self) -> 'bool':
return self.__value
def __hash__(self):
return hash(self.__value)
\ No newline at end of file
class BCouple:
def __init__(self, first, second):
self.__first = first
self.__second = second
def get_first(self):
return self.__first
def get_second(self):
return self.__second
def __eq__(self, other):
return self.__first == other.__first and self.__second == other.__second
def equal(self, other):
return self == other
def unequal(self, other):
return self != other
\ No newline at end of file
from btypes.BBoolean import *
class BInteger:
def __init__(self, value):
self.__value = value
def __add__(self, other: 'BInteger') -> 'BInteger':
if type(other) == str:
return str(self) + other
return BInteger(self.__value + other.__value)
def __sub__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value - other.__value)
def __mul__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value * other.__value)
def __mod__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value % other.__value)
def __div__(self, other: 'BInteger') -> 'BInteger':
return BInteger(self.__value // other.__value)
def __neg__(self) -> 'BInteger':
return BInteger(-self.__value)
def __lt__(self, other: 'BInteger') -> 'bool':
return self.__value < other.__value
def __le__(self, other: 'BInteger') -> 'bool':
return self.__value <= other.__value
def __eq__(self, other: 'BInteger') -> 'bool':
if not isinstance(other, BInteger):
return False
return self.__value == other.__value
def __ne__(self, other: 'BInteger') -> 'bool':
return self.__value != other.__value
def __gt__(self, other: 'BInteger') -> 'bool':
return self.__value > other.__value
def __ge__(self, other: 'BInteger') -> 'bool':
return self.__value >= other.__value
def __pow__(self, other: 'BInteger') -> 'BInteger':
return self.__value ** other.__value
def __str__(self) -> 'str':
return str(self.__value)
def plus(self, other: 'BInteger') -> 'BInteger':
return self.__add__(other)
def minus(self, other: 'BInteger') -> 'BInteger':
return self.__sub__(other)
def multiply(self, other: 'BInteger') -> 'BInteger':
return self.__mul__(other)
def modulo(self, other: 'BInteger') -> 'BInteger':
return self.__mod__(other)
def divide(self, other: 'BInteger') -> 'BInteger':
return self.__div__(other)
def negative(self) -> 'BInteger':
return self.__neg__()
def less(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value < other.__value)
def lessEqual(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value <= other.__value)
def equal(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value == other.__value)
def unequal(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value != other.__value)
def greater(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value > other.__value)
def greaterEqual(self, other: 'BInteger') -> 'BBoolean':
return BBoolean(self.__value >= other.__value)
def succ(self) -> 'BInteger':
return BInteger(self.__value + 1)
def pred(self) -> 'BInteger':
return BInteger(self.__value - 1)
def power(self, other: 'BInteger') -> 'BInteger':
return self.__pow__(other)
def positive(self):
return self
def intValue(self):
return self.__value
def isInteger(self) -> 'BBoolean':
return BBoolean(true)
def isNotInteger(self) -> 'BBoolean':
return BBoolean(false)
def isNatural(self) -> 'BBoolean':
return self.greaterEqual(BInteger(0))
def isNotNatural(self) -> 'BBoolean':
return self.isNatural()._not()
def isNatural1(self) -> 'BBoolean':
return self.greater(BInteger(0))
def isNotNatural1(self) -> 'BBoolean':
return self.isNatural1()._not()
def __hash__(self):
return hash(31 + self.__value)
\ No newline at end of file
class BObject:
pass
\ No newline at end of file
This diff is collapsed.
from btypes.BInteger import *
from btypes.BBoolean import *
from btypes.BString import *
from btypes.BStruct import *
from pyrsistent import pset
from pyrsistent import PSet
class BSet:
def __init__(self, *args):
if len(args) == 1 and type(args[0]) is PSet:
self.__set = args[0]
else:
self.__set = pset(args)
def __str__(self) -> 'str':
return '{' + ', '.join([str(x) for x in self.__set]) + '}'
def __eq__(self, other):
if self is other:
return True
if other is None or type(self) != type(other):
return False
if not self.__set == other.__set:
return False
return True
def __ne__(self, other):
return not self.__eq__(other)
def __len__(self):
return len(self.__set)
def union(self, other=None):
if other is None:
if len(self.__set) == 0:
return BSet()
elif type(next(iter(self.__set))) == BSet:
return reduce(lambda a, e: a.union(e), self, BSet())
elif type(next(iter(self.__set))) == BRelation:
return reduce(lambda a, e: a.union(e), self, BRelation())
return BSet(self.__set.union(other.getSet()))
def intersect(self, other=None):
if other is None:
if len(self.__set) == 0:
return BSet()
elif type(next(iter(self.__set))) == BSet:
return reduce(lambda a, e: a.intersect(e), self, BSet())
elif type(next(iter(self.__set))) == BRelation:
return reduce(lambda a, e: a.intersect(e), self, BRelation())
return BSet(self.__set.intersection(other.getSet()))
def difference(self, other: 'BSet') -> 'BSet':
return BSet(self.__set.difference(other.__set))
def complement(self, other: 'BSet') -> 'BSet':
return BSet(self.__set.difference(other.__set))
def card(self) -> 'BInteger':
return BInteger(len(self.__set))
def size(self) -> 'BInteger':
return BInteger(len(self.__set))
def elementOf(self, obj) -> 'BBoolean':
return BBoolean(obj in self.__set)
def notElementOf(self, obj) -> 'BBoolean':
return BBoolean(obj not in self.__set)
def subset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(self.__set.issubset(other.__set))
def notSubset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(not self.__set.issubset(other.__set))
def strictSubset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(other.size() != self.size() and self.__set.issubset(other.__set))
def strictNotSubset(self, other: 'BSet') -> 'BBoolean':
return BBoolean(other.size() == self.size() and not self.__set.issubset(other.__set))
def contains(self, other):
return other in self.__set
def containsAll(self, other):
for o in other:
if o not in self.__set:
return False
return True
def isEmpty(self) -> 'int':
return len(self.__set) == 0
def equal(self, other) -> 'bool':
return self.__eq__(other)
def unequal(self, other) -> 'bool':
return self.__ne__(other)
def nondeterminism(self):
return random.choice(self.__set)
def min(self):
return min(self.__set)
def max(self):
return max(self.__set)
def pow(self) -> 'BSet':
result = BSet()
start = BSet()
queue = [start]
result = result.union(BSet(start))
while not len(queue) == 0:
currentSet = queue.pop()
for element in self.__set:
nextSet = currentSet.union(BSet(element))
previousSize = result.size()
result = result.union(BSet(nextSet))
if previousSize < result.size():
queue.append(nextSet)
return result
# s = list(self.__set)
# return BSet(frozenset(chain.from_iterable(BSet(combinations(s, r)) for r in range(len(s) + 1))))
def pow1(self) -> 'BSet':
return self.pow().difference(BSet(BSet()))
# Only finite subsets are supported so fin = pow
def fin(self) -> 'BSet':
return self.pow()
def fin1(self) -> 'BSet':
return self.pow1()
def subsetOfInteger(self) -> 'bool':
for element in self.__set:
if not isinstance(element, BInteger):
return False
return True
def strictSubsetOfInteger(self) -> 'bool':
return self.subsetOfInteger()
def notSubsetOfInteger(self) -> 'bool':
return not self.subsetOfInteger()
def notStrictSubsetOfInteger(self) -> 'bool':
return not self.strictSubsetOfInteger()
def subsetOfNatural(self) -> 'bool':
for element in self.__set:
if not (isinstance(element, BInteger) and element.isNatural().booleanValue()):
return False
return True
def strictSubsetOfNatural(self) -> 'bool':
return self.subsetOfNatural()
def notSubsetOfNatural(self) -> 'bool':
return not self.subsetOfNatural()
def notStrictSubsetOfNatural(self) -> 'bool':
return not self.strictSubsetOfNatural()
def subsetOfNatural1(self) -> 'bool':
for element in self.__set:
if not (isinstance(element, BInteger) and element.isNatural1().booleanValue()):
return False
return True
def subsetOfString(self) -> 'bool':
for element in self.__set:
if not isinstance(element, BString):
return False
return True
def strictSubsetOfString(self) -> 'bool':
return self.subsetOfString()
def notSubsetOfString(self) -> 'bool':
return not self.subsetOfString()
def notStrictSubsetOfString(self) -> 'bool':
return not self.strictSubsetOfString()
def subsetOfStruct(self) -> 'bool':
for element in self.__set:
if not isinstance(element, BStruct):
return False
return True
def strictSubsetOfStruct(self) -> 'bool':
return self.subsetOfStruct()
def notSubsetOfStruct(self) -> 'bool':
return not self.subsetOfStruct()
def notStrictSubsetOfStruct(self) -> 'bool':
return not self.strictSubsetOfStruct()
def equalInteger(self) -> 'BBoolean':
return BBoolean(False)
def unequalInteger(self) -> 'BBoolean':
return BBoolean(True)
def equalNatural(self) -> 'BBoolean':
return BBoolean(False)
def unequalNatural(self) -> 'BBoolean':
return BBoolean(True)
def equalNatural1(self) -> 'BBoolean':
return BBoolean(False)
def unequalNatural1(self) -> 'BBoolean':
return BBoolean(True)
def equalString(self) -> 'BBoolean':
return BBoolean(False)
def unequalString(self) -> 'BBoolean':
return BBoolean(True)
def equalStruct(self) -> 'BBoolean':
return BBoolean(False)
def unequalStruct(self) -> 'BBoolean':
return BBoolean(True)
def getSet(self):
return self.__set
@staticmethod
def interval(a: 'BInteger', b: 'BInteger') -> 'BSet':
r = list(map(BInteger, range(a.intValue(), b.intValue() + 1)))
return BSet(*r)
def __hash__(self):
return hash(self.__set)
def __iter__(self):
return iter(self.__set)
from btypes.BRelation import *
from btypes.BBoolean import *
class BString:
def __init__(self, value):
self.__value = value
def getValue(self):
return value
def __eq__(self, other: 'BString') -> 'BBoolean':
return BBoolean(self.__value == other.__value)
def equals(self, other) -> 'bool':
return self.__eq__(other)
def length(self) -> 'int':
return len(self.__value)
def isEmpty(self) -> 'bool':
return not self.__value
def hashCode(self):
hash(self.__value)
def toString(self) -> 'str':
return '"' + self.__value + '"'
def isCase(self, other) -> 'bool':
return self.__value.equals(other)
def isString(self) -> 'BBoolean':
return BBoolean(True)
def isNotString(self) -> 'BBoolean':
return BBoolean(False)
from btypes.BBoolean import *
class BStruct:
def isRecord(self):
return BBoolean(True)
def isNotRecord(self):
return BBoolean(False)
from btypes.BObject import *
from btypes.BBoolean import *
class BTuple(BObject):
def __init__(self, first, second):
if first is None or second is None:
raise ValueError()
self.first = first
self.second = second
def __eq__(self, other):
return self.equals(other)
def equals(self, other) -> 'bool':
if self is other:
return True
if other is None or type(self) != type(other):
return False
b_objects = other
# elements is never None
return b_objects.projection1().__eq__(self.first) and b_objects.projection2().__eq__(self.second)
def __hash__(self):
return hash(hash(self.first) + hash(self.second))
def projection1(self):
return self.first
def projection2(self):
return self.second
def __str__(self):
return "(" + str(self.projection1()) + " |-> " + str(self.projection2()) + ')'
def equal(self, other: 'BTuple') -> 'BBoolean':
return BBoolean(self.equals(other))
def unequal(self, other: 'BTuple') -> 'BBoolean':
return BBoolean(not self.equals(other))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment