Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"Implements ArrayConstraint" 

2from .single_equation import SingleEquationConstraint 

3 

4 

5class ArrayConstraint(SingleEquationConstraint, list): 

6 """A ConstraintSet for prettier array-constraint printing. 

7 

8 ArrayConstraint gets its `sub` method from ConstrainSet, 

9 and so `left` and `right` are only used for printing. 

10 

11 When created by NomialArray `left` and `right` are likely to be 

12 be either NomialArrays or Varkeys of VectorVariables. 

13 """ 

14 def __init__(self, constraints, left, oper, right): 

15 self.constraints = constraints 

16 list.__init__(self, constraints) 

17 SingleEquationConstraint.__init__(self, left, oper, right) 

18 

19 def __iter__(self): 

20 yield from self.constraints.flat 

21 

22 def lines_without(self, excluded): 

23 "Returns lines for indentation in hierarchical printing." 

24 return self.str_without(excluded).split("\n") 

25 

26 def __bool__(self): 

27 "Allows the use of '=' NomialArrays as truth elements." 

28 return False if self.oper != "=" else bool(self.constraints.all())