{"action":"created","comment":{"url":"https://api.github.com/repos/sympy/sympy/pulls/comments/34535381","id":34535381,"diff_hunk":"@@ -0,0 +1,445 @@\n+\"\"\"Formal Power Series\"\"\"\n+\n+from __future__ import print_function, division\n+\n+from sympy import oo, zoo, nan\n+from sympy.core.expr import Expr\n+from sympy.core.add import Add\n+from sympy.core.mul import Mul\n+from sympy.core.singleton import S\n+from sympy.core.sympify import sympify\n+from sympy.core.symbol import Wild, Dummy, symbols\n+from sympy.sets.sets import Interval\n+from sympy.functions.combinatorial.factorials import binomial, factorial\n+from sympy.series.sequences import sequence\n+from sympy.series.series_class import SeriesBase\n+from sympy.series.order import Order\n+\n+\n+def rational_algorithm(f, x, k, order=4, full=False):\n+    \"\"\"Rational algorithm for computing\n+    formula of coefficients of Formal Power Series\n+    of a function.\n+\n+    Applicable when f(x) or some derivative of f(x)\n+    is a rational function in x.\n+\n+    ``rational_algorithm`` uses :func:`apart` function for partial fraction\n+    decomposition. ``apart`` by default uses 'undetermined coefficients method'.\n+    By setting full=True, 'Bronstein's algorithm' can be used instead.\n+\n+    Looks for derivative of a function upto 4'th order(by default).\n+    This can be overrided using order option.\n+\n+    returns a Tuple of (formula, series independent terms, order) if successful\n+    otherwise None.\n+\n+    Examples\n+    ========\n+\n+    >>> from sympy import log, atan, I\n+    >>> from sympy.series.formal import rational_algorithm as ra\n+    >>> from sympy.abc import x, k\n+\n+    >>> ra(1 / (1 - x), x, k)\n+    (1, 0, 0)\n+    >>> ra(log(1 + x), x, k)\n+    (-(-1)**(-k)/k, 0, 1)\n+\n+    >>> ra(atan(x), x, k, full=True)\n+    ((-I*(-I)**(-k)/2 + I*I**(-k)/2)/k, 0, 1)\n+\n+    Notes\n+    =====\n+\n+    By setting full=True, range of admissible functions increases.\n+    This option should be used carefully as it can signifcantly\n+    slow down the computation as ``doit`` is performed on the :class:`RootSum`\n+    object returned by the ``apart`` function. Use full=False whenever\n+    possible.\n+\n+    See Also\n+    ========\n+\n+    sympy.polys.partfrac.apart\n+\n+    References\n+    ==========\n+\n+    .. [1] Formal Power Series - Dominik Gruntz, Wolfram Koepf\n+    .. [2] Power Series in Computer Algebra - Wolfram Koepf\n+    \"\"\"\n+\n+    from sympy.polys import RootSum, apart\n+\n+    diff = f\n+    ds = [] # list of diff\n+\n+    for i in range(order + 1):\n+        if i:\n+            diff = diff.diff(x)\n+\n+        if diff.is_rational_function(x):\n+            coeff, sep = S.Zero, S.Zero\n+\n+            terms = apart(diff, x, full=full)\n+            if terms.has(RootSum):\n+                terms = terms.doit()\n+\n+            for t in Add.make_args(terms):\n+                num, den = t.as_numer_denom()\n+                if not den.has(x):\n+                    sep += t\n+                else:\n+                    if isinstance(den, Mul):\n+                        # m*(n*x - a)**j -> (n*x - a)**j\n+                        ind = den.as_independent(x)\n+                        den = ind[1]\n+                        num /= ind[0]\n+\n+                    # (n*x - a)**j -> (x - b)\n+                    den, j = den.as_base_exp()\n+                    a, xterm = den.as_coeff_add(x)\n+\n+                    # term -> m/x**n\n+                    if not a:\n+                        sep += t\n+                        continue\n+\n+                    xc = xterm[0].coeff(x)\n+                    a /= -xc\n+                    num /= xc**j\n+\n+                    ak = ((-1)**j * num * binomial(j + k - 1, k)\n+                          .rewrite(factorial) / a**(j + k))\n+                    coeff += ak\n+\n+            # Hacky, better way?\n+            if coeff is S.Zero:\n+                return None\n+            if coeff.has(x) or coeff.has(zoo) or coeff.has(oo) or coeff.has(nan):\n+                return None\n+\n+            from sympy.integrals import integrate","path":"sympy/series/formal.py","position":123,"original_position":123,"commit_id":"089ab77c3955dbbbe6a5870cca5d10f6227465e8","original_commit_id":"089ab77c3955dbbbe6a5870cca5d10f6227465e8","user":{"login":"jcrist","id":2783717,"avatar_url":"https://avatars.githubusercontent.com/u/2783717?v=3","gravatar_id":"","url":"https://api.github.com/users/jcrist","html_url":"https://github.com/jcrist","followers_url":"https://api.github.com/users/jcrist/followers","following_url":"https://api.github.com/users/jcrist/following{/other_user}","gists_url":"https://api.github.com/users/jcrist/gists{/gist_id}","starred_url":"https://api.github.com/users/jcrist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcrist/subscriptions","organizations_url":"https://api.github.com/users/jcrist/orgs","repos_url":"https://api.github.com/users/jcrist/repos","events_url":"https://api.github.com/users/jcrist/events{/privacy}","received_events_url":"https://api.github.com/users/jcrist/received_events","type":"User","site_admin":false},"body":"Move the import out of the loop. Can this be a top-level import? If not, top of the function would be best.","created_at":"2015-07-14T03:54:08Z","updated_at":"2015-07-14T03:54:08Z","html_url":"https://github.com/sympy/sympy/pull/9572#discussion_r34535381","pull_request_url":"https://api.github.com/repos/sympy/sympy/pulls/9572","_links":{"self":{"href":"https://api.github.com/repos/sympy/sympy/pulls/comments/34535381"},"html":{"href":"https://github.com/sympy/sympy/pull/9572#discussion_r34535381"},"pull_request":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9572"}}},"pull_request":{"url":"https://api.github.com/repos/sympy/sympy/pulls/9572","id":38521269,"html_url":"https://github.com/sympy/sympy/pull/9572","diff_url":"https://github.com/sympy/sympy/pull/9572.diff","patch_url":"https://github.com/sympy/sympy/pull/9572.patch","issue_url":"https://api.github.com/repos/sympy/sympy/issues/9572","number":9572,"state":"open","locked":false,"title":"Implementing Formal Power Series, rational algorithm","user":{"login":"leosartaj","id":6217976,"avatar_url":"https://avatars.githubusercontent.com/u/6217976?v=3","gravatar_id":"","url":"https://api.github.com/users/leosartaj","html_url":"https://github.com/leosartaj","followers_url":"https://api.github.com/users/leosartaj/followers","following_url":"https://api.github.com/users/leosartaj/following{/other_user}","gists_url":"https://api.github.com/users/leosartaj/gists{/gist_id}","starred_url":"https://api.github.com/users/leosartaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leosartaj/subscriptions","organizations_url":"https://api.github.com/users/leosartaj/orgs","repos_url":"https://api.github.com/users/leosartaj/repos","events_url":"https://api.github.com/users/leosartaj/events{/privacy}","received_events_url":"https://api.github.com/users/leosartaj/received_events","type":"User","site_admin":false},"body":"## TODO\r\n- [x] Formal Power Series Class (without operations)\r\n- [x] rational algorithm\r\n\r\nI have implemented first version of ``FormalPowerSeries`` and ``rational_algorithm``. Still needs a lot of work.\r\n\r\nPing @jcrist @flacjacket @certik ","created_at":"2015-06-25T08:02:07Z","updated_at":"2015-07-14T03:54:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1df5030a87c13fc495321668e0005498e7382a3d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sympy/sympy/pulls/9572/commits","review_comments_url":"https://api.github.com/repos/sympy/sympy/pulls/9572/comments","review_comment_url":"https://api.github.com/repos/sympy/sympy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/9572/comments","statuses_url":"https://api.github.com/repos/sympy/sympy/statuses/089ab77c3955dbbbe6a5870cca5d10f6227465e8","head":{"label":"leosartaj:fps","ref":"fps","sha":"089ab77c3955dbbbe6a5870cca5d10f6227465e8","user":{"login":"leosartaj","id":6217976,"avatar_url":"https://avatars.githubusercontent.com/u/6217976?v=3","gravatar_id":"","url":"https://api.github.com/users/leosartaj","html_url":"https://github.com/leosartaj","followers_url":"https://api.github.com/users/leosartaj/followers","following_url":"https://api.github.com/users/leosartaj/following{/other_user}","gists_url":"https://api.github.com/users/leosartaj/gists{/gist_id}","starred_url":"https://api.github.com/users/leosartaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leosartaj/subscriptions","organizations_url":"https://api.github.com/users/leosartaj/orgs","repos_url":"https://api.github.com/users/leosartaj/repos","events_url":"https://api.github.com/users/leosartaj/events{/privacy}","received_events_url":"https://api.github.com/users/leosartaj/received_events","type":"User","site_admin":false},"repo":{"id":29408196,"name":"sympy","full_name":"leosartaj/sympy","owner":{"login":"leosartaj","id":6217976,"avatar_url":"https://avatars.githubusercontent.com/u/6217976?v=3","gravatar_id":"","url":"https://api.github.com/users/leosartaj","html_url":"https://github.com/leosartaj","followers_url":"https://api.github.com/users/leosartaj/followers","following_url":"https://api.github.com/users/leosartaj/following{/other_user}","gists_url":"https://api.github.com/users/leosartaj/gists{/gist_id}","starred_url":"https://api.github.com/users/leosartaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leosartaj/subscriptions","organizations_url":"https://api.github.com/users/leosartaj/orgs","repos_url":"https://api.github.com/users/leosartaj/repos","events_url":"https://api.github.com/users/leosartaj/events{/privacy}","received_events_url":"https://api.github.com/users/leosartaj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/leosartaj/sympy","description":"A computer algebra system written in pure Python","fork":true,"url":"https://api.github.com/repos/leosartaj/sympy","forks_url":"https://api.github.com/repos/leosartaj/sympy/forks","keys_url":"https://api.github.com/repos/leosartaj/sympy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leosartaj/sympy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leosartaj/sympy/teams","hooks_url":"https://api.github.com/repos/leosartaj/sympy/hooks","issue_events_url":"https://api.github.com/repos/leosartaj/sympy/issues/events{/number}","events_url":"https://api.github.com/repos/leosartaj/sympy/events","assignees_url":"https://api.github.com/repos/leosartaj/sympy/assignees{/user}","branches_url":"https://api.github.com/repos/leosartaj/sympy/branches{/branch}","tags_url":"https://api.github.com/repos/leosartaj/sympy/tags","blobs_url":"https://api.github.com/repos/leosartaj/sympy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leosartaj/sympy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leosartaj/sympy/git/refs{/sha}","trees_url":"https://api.github.com/repos/leosartaj/sympy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leosartaj/sympy/statuses/{sha}","languages_url":"https://api.github.com/repos/leosartaj/sympy/languages","stargazers_url":"https://api.github.com/repos/leosartaj/sympy/stargazers","contributors_url":"https://api.github.com/repos/leosartaj/sympy/contributors","subscribers_url":"https://api.github.com/repos/leosartaj/sympy/subscribers","subscription_url":"https://api.github.com/repos/leosartaj/sympy/subscription","commits_url":"https://api.github.com/repos/leosartaj/sympy/commits{/sha}","git_commits_url":"https://api.github.com/repos/leosartaj/sympy/git/commits{/sha}","comments_url":"https://api.github.com/repos/leosartaj/sympy/comments{/number}","issue_comment_url":"https://api.github.com/repos/leosartaj/sympy/issues/comments{/number}","contents_url":"https://api.github.com/repos/leosartaj/sympy/contents/{+path}","compare_url":"https://api.github.com/repos/leosartaj/sympy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leosartaj/sympy/merges","archive_url":"https://api.github.com/repos/leosartaj/sympy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leosartaj/sympy/downloads","issues_url":"https://api.github.com/repos/leosartaj/sympy/issues{/number}","pulls_url":"https://api.github.com/repos/leosartaj/sympy/pulls{/number}","milestones_url":"https://api.github.com/repos/leosartaj/sympy/milestones{/number}","notifications_url":"https://api.github.com/repos/leosartaj/sympy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leosartaj/sympy/labels{/name}","releases_url":"https://api.github.com/repos/leosartaj/sympy/releases{/id}","created_at":"2015-01-17T22:39:40Z","updated_at":"2015-05-26T14:11:50Z","pushed_at":"2015-07-11T19:35:00Z","git_url":"git://github.com/leosartaj/sympy.git","ssh_url":"git@github.com:leosartaj/sympy.git","clone_url":"https://github.com/leosartaj/sympy.git","svn_url":"https://github.com/leosartaj/sympy","homepage":"http://sympy.org/","size":71514,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"sympy:master","ref":"master","sha":"2066225b9777e44b48bec074d06aa500d5b0e108","user":{"login":"sympy","id":260832,"avatar_url":"https://avatars.githubusercontent.com/u/260832?v=3","gravatar_id":"","url":"https://api.github.com/users/sympy","html_url":"https://github.com/sympy","followers_url":"https://api.github.com/users/sympy/followers","following_url":"https://api.github.com/users/sympy/following{/other_user}","gists_url":"https://api.github.com/users/sympy/gists{/gist_id}","starred_url":"https://api.github.com/users/sympy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sympy/subscriptions","organizations_url":"https://api.github.com/users/sympy/orgs","repos_url":"https://api.github.com/users/sympy/repos","events_url":"https://api.github.com/users/sympy/events{/privacy}","received_events_url":"https://api.github.com/users/sympy/received_events","type":"Organization","site_admin":false},"repo":{"id":640534,"name":"sympy","full_name":"sympy/sympy","owner":{"login":"sympy","id":260832,"avatar_url":"https://avatars.githubusercontent.com/u/260832?v=3","gravatar_id":"","url":"https://api.github.com/users/sympy","html_url":"https://github.com/sympy","followers_url":"https://api.github.com/users/sympy/followers","following_url":"https://api.github.com/users/sympy/following{/other_user}","gists_url":"https://api.github.com/users/sympy/gists{/gist_id}","starred_url":"https://api.github.com/users/sympy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sympy/subscriptions","organizations_url":"https://api.github.com/users/sympy/orgs","repos_url":"https://api.github.com/users/sympy/repos","events_url":"https://api.github.com/users/sympy/events{/privacy}","received_events_url":"https://api.github.com/users/sympy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sympy/sympy","description":"A computer algebra system written in pure Python","fork":false,"url":"https://api.github.com/repos/sympy/sympy","forks_url":"https://api.github.com/repos/sympy/sympy/forks","keys_url":"https://api.github.com/repos/sympy/sympy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sympy/sympy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sympy/sympy/teams","hooks_url":"https://api.github.com/repos/sympy/sympy/hooks","issue_events_url":"https://api.github.com/repos/sympy/sympy/issues/events{/number}","events_url":"https://api.github.com/repos/sympy/sympy/events","assignees_url":"https://api.github.com/repos/sympy/sympy/assignees{/user}","branches_url":"https://api.github.com/repos/sympy/sympy/branches{/branch}","tags_url":"https://api.github.com/repos/sympy/sympy/tags","blobs_url":"https://api.github.com/repos/sympy/sympy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sympy/sympy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sympy/sympy/git/refs{/sha}","trees_url":"https://api.github.com/repos/sympy/sympy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sympy/sympy/statuses/{sha}","languages_url":"https://api.github.com/repos/sympy/sympy/languages","stargazers_url":"https://api.github.com/repos/sympy/sympy/stargazers","contributors_url":"https://api.github.com/repos/sympy/sympy/contributors","subscribers_url":"https://api.github.com/repos/sympy/sympy/subscribers","subscription_url":"https://api.github.com/repos/sympy/sympy/subscription","commits_url":"https://api.github.com/repos/sympy/sympy/commits{/sha}","git_commits_url":"https://api.github.com/repos/sympy/sympy/git/commits{/sha}","comments_url":"https://api.github.com/repos/sympy/sympy/comments{/number}","issue_comment_url":"https://api.github.com/repos/sympy/sympy/issues/comments{/number}","contents_url":"https://api.github.com/repos/sympy/sympy/contents/{+path}","compare_url":"https://api.github.com/repos/sympy/sympy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sympy/sympy/merges","archive_url":"https://api.github.com/repos/sympy/sympy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sympy/sympy/downloads","issues_url":"https://api.github.com/repos/sympy/sympy/issues{/number}","pulls_url":"https://api.github.com/repos/sympy/sympy/pulls{/number}","milestones_url":"https://api.github.com/repos/sympy/sympy/milestones{/number}","notifications_url":"https://api.github.com/repos/sympy/sympy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sympy/sympy/labels{/name}","releases_url":"https://api.github.com/repos/sympy/sympy/releases{/id}","created_at":"2010-04-30T20:37:14Z","updated_at":"2015-07-13T16:28:07Z","pushed_at":"2015-07-14T01:07:39Z","git_url":"git://github.com/sympy/sympy.git","ssh_url":"git@github.com:sympy/sympy.git","clone_url":"https://github.com/sympy/sympy.git","svn_url":"https://github.com/sympy/sympy","homepage":"http://sympy.org/","size":149868,"stargazers_count":2222,"watchers_count":2222,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1095,"mirror_url":null,"open_issues_count":1944,"forks":1095,"open_issues":1944,"watchers":2222,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9572"},"html":{"href":"https://github.com/sympy/sympy/pull/9572"},"issue":{"href":"https://api.github.com/repos/sympy/sympy/issues/9572"},"comments":{"href":"https://api.github.com/repos/sympy/sympy/issues/9572/comments"},"review_comments":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9572/comments"},"review_comment":{"href":"https://api.github.com/repos/sympy/sympy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sympy/sympy/pulls/9572/commits"},"statuses":{"href":"https://api.github.com/repos/sympy/sympy/statuses/089ab77c3955dbbbe6a5870cca5d10f6227465e8"}}}}