New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General function decomposition #9831

Merged
merged 6 commits into from Sep 11, 2015

Conversation

Projects
None yet
3 participants
@aktech
Copy link
Member

aktech commented Aug 15, 2015

Computes General functional decomposition of f.
Given an expression f, returns a list [f_1, f_2, ..., f_n],
where::
f = f_1 o f_2 o ... f_n = f_1(f_2(... f_n))

TODO

  • General Decomposition
  • Tests
  • Support Polys' decompose
  • Doc strings
  • Add reference to sphinx docs
  • Update release notes

@hargup @flacjacket

aktech added some commits Aug 14, 2015

Implement general functional decomposition
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
Return `f` if no decomposition
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
@hargup

This comment has been minimized.

Copy link
Member

hargup commented Aug 16, 2015

This should handle most of our usecases. @aktech you can recursively apply the rule for get decompositions of more than two functions and you should call decompose from poly for polynomials. Also can you add Xfailed tests for more a few complicated cases (whatever they might me).

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Aug 16, 2015

Yes, thanks, I am working on it.

aktech added some commits Aug 20, 2015

Add decompogen to __init__.py
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
Make decompogen recursive to support more than two functions
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
Support Polynomial `decompose` in decompogen
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>

@aktech aktech changed the title [WIP] General function decomposition General function decomposition Aug 20, 2015

@aktech aktech self-assigned this Aug 20, 2015

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Aug 21, 2015

@hargup
Can you give an example of a complex case it can't decompose?

@smichr

This comment has been minimized.

Copy link
Member

smichr commented Aug 26, 2015

Can you give an example of a complex case it can't decompose?

>>> A=lambda x:1*x**2+2*x+3
>>> B=lambda x:4*x**2+5*x+6
>>> A(x*exp(x))
x**2*exp(2*x) + 2*x*exp(x) + 3
>>> decompogen(_,x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\solvers\decompogen.py", line 54, in decompogen
    result += decompose(f)
  File "sympy\polys\polytools.py", line 5437, in decompose
    result = F.decompose()
  File "sympy\polys\polytools.py", line 2869, in decompose
    result = f.rep.decompose()
  File "sympy\polys\polyclasses.py", line 715, in decompose
    raise ValueError('univariate polynomial expected')
ValueError: univariate polynomial expected

Perhaps the following is expected

>>> decompogen(A(B(x)),x)
[16*x**4 + 40*x**3 + 81*x**2 + 70*x + 51]
>>> decompogen(A(1/x),x)
[x**2 + 2*x + 3, 1/x]
>>> decompogen(A(1/x+1/x**2),x)
[2*x**2 + 2*x + (x**2 + x)**2 + 3, 1/x]  <-- only identified 1/x
>>> decompogen(A(1/x+2/(x+1)),x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\solvers\decompogen.py", line 54, in decompogen
    result += decompose(f)
  File "sympy\polys\polytools.py", line 5437, in decompose
    result = F.decompose()
  File "sympy\polys\polytools.py", line 2869, in decompose
    result = f.rep.decompose()
  File "sympy\polys\polyclasses.py", line 715, in decompose
    raise ValueError('univariate polynomial expected')
ValueError: univariate polynomial expected
Add watch for poly decompose and add XFAIL's
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Aug 27, 2015

@smichr Thanks for the examples.
I have added some XFAIL's here aktech@38d07cc .

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Sep 2, 2015

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Sep 11, 2015

This could also be useful in fixing issues like #9824

@hargup

This comment has been minimized.

Copy link
Member

hargup commented Sep 11, 2015

+1

hargup added a commit that referenced this pull request Sep 11, 2015

Merge pull request #9831 from aktech/decompose
General function decomposition

@hargup hargup merged commit 074db20 into sympy:master Sep 11, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@hargup hargup added the solvers label Sep 11, 2015

@aktech aktech deleted the aktech:decompose branch Oct 16, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment