Beispiel #1
0
def test_fuzzy_and():
    assert fuzzy_and([T, T]) == T
    assert fuzzy_and([T, F]) == F
    assert fuzzy_and([T, U]) == U
    assert fuzzy_and([F, F]) == F
    assert fuzzy_and([F, U]) == F
    assert fuzzy_and([U, U]) == U
    assert [fuzzy_and([w]) for w in [U, T, F]] == [U, T, F]
    assert fuzzy_and([T, F, U]) == F
    assert fuzzy_and([]) == T
    pytest.raises(TypeError, lambda: fuzzy_and())
Beispiel #2
0
    def __new__(cls, *args):
        n = args[BinomialDistribution._argnames.index('n')]
        p = args[BinomialDistribution._argnames.index('p')]
        n_sym = sympify(n)
        p_sym = sympify(p)

        if fuzzy_not(fuzzy_and((n_sym.is_integer, n_sym.is_nonnegative))):
            raise ValueError("'n' must be positive integer. n = %s." % str(n))
        elif fuzzy_not(
                fuzzy_and((p_sym.is_nonnegative, (p_sym - 1).is_nonpositive))):
            raise ValueError("'p' must be: 0 <= p <= 1 . p = %s" % str(p))
        else:
            return super(BinomialDistribution, cls).__new__(cls, *args)
Beispiel #3
0
 def cond():
     d = self._smat
     yield self.is_square
     if len(d) <= self.rows:
         yield fuzzy_and(d[i, i].is_extended_real for i, j in d
                         if i == j)
     else:
         yield fuzzy_and(d[i, i].is_extended_real
                         for i in range(self.rows) if (i, i) in d)
     yield fuzzy_and(
         ((self[i, j] -
           self[j, i].conjugate()).is_zero if (j, i) in d else False)
         for (i, j) in d)
Beispiel #4
0
    def is_hermitian(self):
        """Checks if the matrix is Hermitian.

        In a Hermitian matrix element i,j is the complex conjugate of
        element j,i.

        Examples
        ========

        >>> from diofant.matrices import SparseMatrix
        >>> from diofant import I
        >>> from diofant.abc import x
        >>> a = SparseMatrix([[1, I], [-I, 1]])
        >>> a
        Matrix([
        [ 1, I],
        [-I, 1]])
        >>> a.is_hermitian
        True
        >>> a[0, 0] = 2*I
        >>> a.is_hermitian
        False
        >>> a[0, 0] = x
        >>> a.is_hermitian
        >>> a[0, 1] = a[1, 0]*I
        >>> a.is_hermitian
        False
        """
        def cond():
            d = self._smat
            yield self.is_square
            if len(d) <= self.rows:
                yield fuzzy_and(d[i, i].is_extended_real for i, j in d
                                if i == j)
            else:
                yield fuzzy_and(d[i, i].is_extended_real
                                for i in range(self.rows) if (i, i) in d)
            yield fuzzy_and(
                ((self[i, j] -
                  self[j, i].conjugate()).is_zero if (j, i) in d else False)
                for (i, j) in d)

        return fuzzy_and(i for i in cond())
Beispiel #5
0
 def __new__(cls, sides):
     sides_sym = sympify(sides)
     if fuzzy_not(fuzzy_and((sides_sym.is_integer, sides_sym.is_positive))):
         raise ValueError("'sides' must be a positive integer.")
     else:
         return super(DieDistribution, cls).__new__(cls, sides)