示例#1
0
 def _init(self, e):
     if is_derivative(e) or is_function(e):
         self._p.append(_Dterm(e, self._context))
     elif e.operator().__name__ == 'mul_vararg':
         self._p.append(_Dterm(e, self._context))
     else:
         for s in e.operands():
             coeff, d = [], []
             if is_derivative(s) or is_function(s):
                 d.append(s)
             else:
                 for item in s.operands():
                     (d if (is_derivative(item) or self.ctxfunc(item)) else
                      coeff).append(item)
             coeff = functools.reduce(mul, coeff, 1)
             found = False
             if d:
                 for _p in self._p:
                     if eq(_p._d, d[0]):
                         _p._coeff += coeff
                         found = True
                         break
             if not found:
                 if d:
                     self._p.append(_Dterm(coeff * d[0], self._context))
                 else:
                     self._p.append(_Dterm(coeff, self._context))
     self._p.sort(key=functools.cmp_to_key(
         lambda item1, item2: sorter(item1._d, item2._d, self._context)),
                  reverse=True)
     self.normalize()
示例#2
0
 def __str__(self):
     try:
         return "({}) * {}".format(self._coeff.expression(), self._d)
     except AttributeError:
         if eq(self._coeff, 1):
             return "{}".format(self._d)
         else:
             return "({}) * {}".format(self._coeff, self._d)
示例#3
0
def sorter(d1, d2, context=Mgrevlex):
    '''sorts two derivatives d1 and d2 using the weight matrix M
    according to the sort order given in the tuple of  dependent and
    independent variables

    >>> x, y, z = var("x y z")
    >>> u = function ("u")(x,y,z)
    >>> ctxMlex = Context((u,),(x,y,z), Mlex)
    >>> ctxMgrlex = Context((u,),(x,y,z), Mgrlex)
    >>> ctxMgrevlex = Context((u,),(x,y,z), Mgrevlex)
    >>> # this is the standard example stolen from wikipedia
    >>> u0 = diff(u,x,3)
    >>> u1 = diff(u,z,2)
    >>> u2 = diff(u,x,y,y,z)
    >>> u3 = diff(u, x,x,z,z)
    >>> l1 = [u0, u1,u2,u3]
    >>> shuffle(l1)
    >>> s = sorted(l1, key=cmp_to_key(lambda item1, item2: sorter (item1, item2, ctxMlex)))
    >>> for _ in s: print(_)
    diff(u(x, y, z), z, z)
    diff(u(x, y, z), x, y, y, z)
    diff(u(x, y, z), x, x, z, z)
    diff(u(x, y, z), x, x, x)
    >>> s = sorted(l1, key=cmp_to_key(lambda item1, item2: sorter (item1, item2, ctxMgrlex)))
    >>> for _ in s: print(_)
    diff(u(x, y, z), z, z)
    diff(u(x, y, z), x, x, x)
    diff(u(x, y, z), x, y, y, z)
    diff(u(x, y, z), x, x, z, z)
    >>> s = sorted(l1, key=cmp_to_key(lambda item1, item2: sorter (item1, item2, ctxMgrevlex)))
    >>> for _ in s: print(_)
    diff(u(x, y, z), z, z)
    diff(u(x, y, z), x, x, x)
    diff(u(x, y, z), x, x, z, z)
    diff(u(x, y, z), x, y, y, z)
    '''
    if eq(d1, d2):
        return 1
    if higher(d1, d2, context):
        return 1
    return -1
示例#4
0
def FindIntegrableConditions(S, context):
    result = list(S)
    if len(result) == 1:
        return []
    vars = list(range(len(context._independent)))
    monomials = [(_, derivative_to_vec(_.Lder(), context)) for _ in result]

    ms = tuple([_[1] for _ in monomials])
    m0 = []

    def map_old_to_new(l):
        return context._independent[vars.index(l)]

    # multiplier-collection is our M
    multiplier_collection = []
    for dp, monom in monomials:
        # S1
        # damned! Variables are messed up!
        _multipliers, _nonmultipliers = vec_multipliers(monom, ms, vars)
        multiplier_collection.append(
            (dp, [map_old_to_new(_) for _ in _multipliers],
             [map_old_to_new(_) for _ in _nonmultipliers]))
    result = []
    for e1, e2 in product(multiplier_collection, repeat=2):
        if e1 == e2: continue
        for n in e1[2]:
            for m in islice(powerset(e2[1]), 1, None):
                if eq(adiff(e1[0].Lder(), context, n),
                      adiff(e2[0].Lder(), context, *m)):
                    # integrability condition
                    # don't need leading coefficients because in DPs
                    # it is always 1
                    c = adiff(e1[0].expression(), context, n) - \
                        adiff(e2[0].expression(), context, *m)
                    result.append(c)
    return result
示例#5
0
 def __eq__(self, other):
     return eq(self._d, other._d) and eq(self._coeff, other._coeff)
示例#6
0
 def __lt__(self, other):
     return not eq(self, other) and higher(self, other, self._context)
示例#7
0
    def __init__(self, S, dependent, independent, sort_order=Mgrevlex):
        """
        Parameters:
            * List of homogenous PDE's
            * List of dependent variables, i.e. the functions to searched for
            * List of variables
            * sort order, default is grevlex

        >>> vars = var ("x y")
        >>> z = function("z")(*vars)
        >>> w = function("w")(*vars)
        >>> f1 = diff(w, y) + x*diff(z,y)/(2*y*(x**2+y)) - w/y
        >>> f2 = diff(z,x,y) + y*diff(w,y)/x + 2*y*diff(z, x)/x
        >>> f3 = diff(w, x,y) - 2*x*diff(z, x,2)/y - x*diff(w,x)/y**2
        >>> f4 = diff(w, x,y) + diff(z, x,y) + diff(w, y)/(2*y) - diff(w,x)/y + x* diff(z, y)/y - w/(2*y**2)
        >>> f5 = diff(w,y,y) + diff(z,x,y) - diff(w, y)/y + w/(y**2)
        >>> system_2_24 = [f1,f2,f3,f4,f5]
        >>> checkS=Janet_Basis(system_2_24, (w,z), vars)
        >>> checkS.show()
        diff(z(x, y), y)
        diff(z(x, y), x) + (1/2/y) * w(x, y)
        diff(w(x, y), y) + (-1/y) * w(x, y)
        diff(w(x, y), x)
        >>> vars = var ("x y")
        >>> z = function("z")(*vars)
        >>> w = function("w")(*vars)
        >>> g1 = diff(z, y,y) + diff(z,y)/(2*y)
        >>> g2 = diff(w,x,x) + 4*diff(w,y)*y**2 - 8*(y**2) * diff(z,x) - 8*w*y
        >>> g3 = diff(w,x,y) - diff(z,x,x)/2 - diff(w,x)/(2*y) - 6* (y**2) * diff(z,y)
        >>> g4 = diff(w,y,y) - 2*diff(z,x,y) - diff(w,y)/(2*y) + w/(2*y**2)
        >>> system_2_25 = [g2,g3,g4,g1]
        >>> checkS=Janet_Basis(system_2_25, (w,z), vars)
        >>> checkS.show()
        diff(z(x, y), y)
        diff(z(x, y), x) + (1/2/y) * w(x, y)
        diff(w(x, y), y) + (-1/y) * w(x, y)
        diff(w(x, y), x)
        >>> vars = var ("x y")
        >>> z = function("z")(*vars)
        >>> w = function("w")(*vars)
        >>> f1 = diff(w, y) + x*diff(z,y)/(2*y*(x**2+y)) - w/y
        >>> f2 = diff(z,x,y) + y*diff(w,y)/x + 2*y*diff(z, x)/x
        >>> f3 = diff(w, x,y) - 2*x*diff(z, x,2)/y - x*diff(w,x)/y**2
        >>> f4 = diff(w, x,y) + diff(z, x,y) + diff(w, y)/(2*y) - diff(w,x)/y + x* diff(z, y)/y - w/(2*y**2)
        >>> f5 = diff(w,y,y) + diff(z,x,y) - diff(w, y)/y + w/(y**2)
        >>> system_2_24 = [f1,f2,f3,f4,f5]
        >>> checkS=Janet_Basis(system_2_24, (w,z), vars, Mgrlex)
        >>> checkS.show()
        diff(z(x, y), y)
        diff(z(x, y), x) + (1/2/y) * w(x, y)
        diff(w(x, y), y) + (-1/y) * w(x, y)
        diff(w(x, y), x)
        >>> vars = var ("x y")
        >>> z = function("z")(*vars)
        >>> w = function("w")(*vars)
        >>> g1 = diff(z, y,y) + diff(z,y)/(2*y)
        >>> g2 = diff(w,x,x) + 4*diff(w,y)*y**2 - 8*(y**2) * diff(z,x) - 8*w*y
        >>> g3 = diff(w,x,y) - diff(z,x,x)/2 - diff(w,x)/(2*y) - 6* (y**2) * diff(z,y)
        >>> g4 = diff(w,y,y) - 2*diff(z,x,y) - diff(w,y)/(2*y) + w/(2*y**2)
        >>> system_2_25 = [g2,g3,g4,g1]
        >>> checkS=Janet_Basis(system_2_25, (w,z), vars, Mgrlex)
        >>> checkS.show()
        diff(z(x, y), y)
        diff(z(x, y), x) + (1/2/y) * w(x, y)
        diff(w(x, y), y) + (-1/y) * w(x, y)
        diff(w(x, y), x)
        >>> x   = var('x')
        >>> y   = function ('y')
        >>> xi  = function('xi')(y(x), x)
        >>> eta = function ('eta')(y(x), x)
        >>> f1  = adiff (xi, y(x), 2) + 3*adiff(xi, y(x))/4
        >>> f2  = adiff (eta, x, 2) +

        
        """
        eq.cache_clear()
        context = Context(dependent, independent, sort_order)
        if not isinstance(S, Iterable):
            # bad criterion
            self.S = [S]
        else:
            self.S = S[:]
        old = []
        self.S = Reorder(
            [_Differential_Polynomial(s, context) for s in self.S],
            context,
            ascending=True)
        while 1:
            if old == self.S:
                # no change since last run
                return
            old = self.S[:]
            self.S = Autoreduce(self.S, context)
            self.S = CompleteSystem(self.S, context)
            self.conditions = split_by_function(self.S, context)
            reduced = [
                reduceS(_Differential_Polynomial(_m, context), self.S, context)
                for _m in self.conditions
            ]
            if not reduced:
                self.S = Reorder(self.S, context)
                return
            self.S += [
                _ for _ in reduced
                if not (_ in self.S or eq(_.expression(), 0))
            ]
            self.S = Reorder(self.S, context, ascending=True)
示例#8
0
 def __eq__(self, other):
     return all(eq(_[0]._d, _[1]._d) for _ in zip(self._p, other._p))
示例#9
0
 def __init__(self, e, context):
     self._context = context
     self._expression = e
     self._p = []
     if not eq(0, e):
         self._init(e.expand())