Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Apr 20, 2020
1 parent 95b980f commit c2b4130
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
45 changes: 34 additions & 11 deletions galgebra/dop.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,24 @@ def _diff_op_apply(d, x):
return _diff_op_ify(d)._diff_op_apply(x)


def Sdop(*args):
if len(args) == 1 and isinstance(args[0],Symbol): # Simple Pdop of order 1
return Pdop(args[0])
elif len(args) == 2 and isinstance(args[0],list) and isinstance(args[1],list):
if len(args[0]) != len(args[1]):
raise ValueError('In Sdop.__init__ coefficent list and Pdop list must be same length.')
return sum((a * b for a, b in zip(args[0], args[1])), DiffOpAdd.identity)
elif len(args) == 1 and isinstance(args[0], (list, tuple)):
return sum((a * b for a, b in args[0]), DiffOpAdd.identity)
else:
raise ValueError('In Sdop.__init__ length of args must be 1 or 2 args = '+str(args))
import abc

class Sdop(abc.ABC):
@classmethod
def __subclasshook__(cls, c):
return issubclass(c, DiffOpExpr)

def __new__(cls, *args):
if len(args) == 1 and isinstance(args[0],Symbol): # Simple Pdop of order 1
return Pdop(args[0])
elif len(args) == 2 and isinstance(args[0],list) and isinstance(args[1],list):
if len(args[0]) != len(args[1]):
raise ValueError('In Sdop.__init__ coefficent list and Pdop list must be same length.')
return sum((a * b for a, b in zip(args[0], args[1])), DiffOpAdd.identity)
elif len(args) == 1 and isinstance(args[0], (list, tuple)):
return sum((a * b for a, b in args[0]), DiffOpAdd.identity)
else:
raise ValueError('In Sdop.__init__ length of args must be 1 or 2 args = '+str(args))


#################### Partial Derivative Operator Class #################
Expand Down Expand Up @@ -393,3 +400,19 @@ def _eval_simplify(self, *args, **kwargs):

def diff(self, *args, **kwargs):
return super().diff(*args, simplify=False, **kwargs)


def _as_terms(d):
d = d.expand()
if isinstance(d, DiffOpAdd):
for a in d.args:
yield from _as_terms(a)
elif isinstance(d, DiffOpMul):
coeff, pdiff = d.args
yield (coeff, pdiff)
elif isinstance(d, DiffOpPartial):
yield (S(1), d)
elif isinstance(d, DiffOpZero):
pass
else:
raise NotImplementedError
4 changes: 2 additions & 2 deletions galgebra/mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ def __init__(self, *args, ga, cmpflg=False, debug=False, fmt_dop=1):
self.terms = dop._consolidate_terms(
(coef * mv, pdiff)
for (sdop, mv) in arg
for (coef, pdiff) in sdop.terms
for (coef, pdiff) in dop._as_terms(sdop)
)
else:
raise ValueError('In Dop.__init__ args[0] form not allowed. args = ' + str(args))
Expand Down Expand Up @@ -1676,7 +1676,7 @@ def is_scalar(self):

def components(self):
return tuple(
Dop([(base, sdop)], ga=self.Ga)
Dop([(sdop, Mv(base, ga=self.Ga))], ga=self.Ga)
for (sdop, base) in self.Dop_mv_expand()
)

Expand Down

0 comments on commit c2b4130

Please sign in to comment.