Beispiel #1
0
 def _read_mods(self, **mods):
     _mod = None
     for mod in mods:
         if mod == 'mod':
             int_check(mods[mod])
             pos_check(mods[mod])
             _mod = mods[mod]
             break
         elif mod == 'dfvar':
             self._dfvar = mods[mod]
         else:
             raise KeywordError('Keyword \'%s\' is not defined.' % mod)
     return _mod
Beispiel #2
0
    def _read_dict(vec):
        # DICT_FORMAT
        #     {'variable': {exponent: coefficient, ...}, ...}

        _var = []
        _vec = {}
        for var in vec:
            str_check(var)
            dict_check(vec[var])
            for exp in vec[var]:
                int_check(exp)
                number_check(vec[var][exp])
            _var.append(var)
        _vec.update(vec)
        return _var, _vec
Beispiel #3
0
    def __new__(cls, numerator, denominator=None):
        self = super(ABCSymbol, cls).__new__(cls)

        if denominator is None:
            if isinstance(numerator, ABCSymbol):
                self = numerator
                return self

            else:
                # Handle construction from strings.
                basestring_check(numerator)

                m = SYMBOL_FORMAT.match(numerator)
                if m is None:
                    raise DefinitionError('Invalid literal for symbols: %r' %
                                          numerator)

                _numerator = int(m.group('num'))
                _denominator = int(m.group('den'))

                if m.group('sign') == '-':
                    _numerator = -_numerator

        else:
            int_check(numerator, denominator)
            if denominator < 0:
                _numerator = -numerator
                _denominator = -denominator
            else:
                _numerator = numerator
                _denominator = denominator

        if _denominator == 0:
            raise ResidueError('Symbol(%s, 0)' % _numerator)

        self._numerator = _numerator
        self._denominator = _denominator
        return self
Beispiel #4
0
    def _read_poly(self, poly):
        # TUPLE_FORMAT
        #     (['variable',] (expnonet, coefficient), ...)

        tuple_check(poly)
        var = []
        vec = {}
        ec = {}
        if isinstance(poly[0], str):
            _vec = list(poly)
            _vec.reverse()
            _var = _vec.pop()
            var.append(_var)
        else:
            _var = self._dfvar
            _vec = list(poly)
            var.append(_var)

        for _ec in _vec:
            tuple_check(_ec)
            if len(_ec) != 2:
                raise DefinitionError(
                    'Tuple of coeffients and corresponding exponents in need.')

            _exp = _ec[0]
            int_check(_exp)
            notneg_check(_exp)
            _coe = _ec[1]
            number_check(_coe)
            jsupdate(ec, {_exp: _coe})

        if _var in vec:
            vec[_var] = jsupdate(vec[_var], ec)
        else:
            vec[_var] = ec
        return var, vec