Comment #1 on issue 1843 by smichr: Increase coverage of ode.py
http://code.google.com/p/sympy/issues/detail?id=1843
I only looked at the ode part and would add the following (besides the
comments that
I made on your github page).
Here are some typos:
--------------------
- # here should be raise accordingly, or constantsimp() rewritten to
handle
+ # here should be raised accordingly, or constantsimp() rewritten to
handle
- # Collect termms to make the solution look nice.
+ # Collect terms to make the solution look nice.
This can be thinned out a bit:
------------------------------
# Special handling for certain hints that we know will usually
take a
# certain form
if hint[:21] == "1st_homogeneous_coeff":
- neweq = []
- for i in eq:
- newi = logcombine(i, assume_pos_real=True)
+ for i, eqi in enumerate(eq):
+ newi = logcombine(eqi, assume_pos_real=True)
if newi.lhs.is_Function and newi.lhs.func is log and
newi.rhs == 0:
newi = Eq(newi.lhs.args[0]*C1,C1)
- neweq.append(newi)
- eq = neweq
- if len(eq) == 1:
- eq = eq[0] # We only want a list if there are multiple
solutions
+ eq[i] = newi
I would recomment powsimp'ing the solution:
-------------------------------------------
del collectterms
- eq = Eq(f(x), sol)
+ sol = powsimp(sol, combine='exp', deep=True)
+ eq = [Eq(f(x), sol)]
When checking a solution, let the condition where a constant is being tested
against symbol-free quantities pass and use less expansion:
----------------------------------------------------------------------------
ss = simplify(s.lhs - s.rhs)
- if ss:
+ if x not in ss and ss.is_Add:
+ i, d = ss.as_independent(*ss.atoms(Symbol))
+ if i: #symbols equal a number
+ s = 0
+ elif ss:
# with the new numer_denom in power.py, if we do a simple
# expansion then testnum == 0 verifies all solutions.
- s = (s.lhs - s.rhs).expand()
+ s = expand_mul(s.lhs - s.rhs)
Do a little more simplification in constantsimp:
------------------------------------------------
- Absorption is done naively. constantsimp() does not attempt to
+ Absorption is done mostly naively. constantsimp() does not attempt to
expand or simplify the expression first to obtain better absorption.
So for example, exp(C1)*exp(x) will be simplified to C1*exp(x), but
- exp(C1 + x) will be left alone.
+ exp(C1 + x) will be left alone. The exception to this is that terms
+ of an Add will be collected so C1*x + x will be simplified to C1*x.
elif not any(expr.has(t) for t in constantsymbols):
return expr
else:
+ if expr.is_Add:
+ for a in expr.args:
+ if a.is_Mul:
+ i, d = a.as_independent(*constantsymbols)
+ if i != S.One:
+ expr = collect(expr, i)
>>> constantsimp(C1*C2 + 2 + x + y + C3*x, x, 3)
- C2 + x + C3*x
+ C2 + C3*x
Th constantsymbols list is just being used to test whether something is
in it or not. The query "is x in s" will give a quicker answer on average
if s is a set rather than a list:
tot=0
for i in range(6):
... tot+=timeit('%i in s'%i,'s=([0,1,2,3,4,5])')
...
print tot
1.66324071914
tot=0
for i in range(6):
... tot+=timeit('%i in s'%i,'s=set([0,1,2,3,4,5])')
...
print tot
1.12316118389
---------------------------------------------------------------------------------------
- constantsymbols = [Symbol(symbolname+"%d" % t) for t in
range(startnumber,
- endnumber + 1)]
+ constantsymbols = set([Symbol(symbolname+"%d" % t) for t in
range(startnumber,
+ endnumber + 1)])
x = independentsymbol
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-iss...@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.