{"id":13688427,"url":"https://github.com/sigma-py/orthopy","last_synced_at":"2025-12-12T00:54:24.662Z","repository":{"id":45637906,"uuid":"100865192","full_name":"sigma-py/orthopy","owner":"sigma-py","description":":triangular_ruler: Orthogonal polynomials in all shapes and sizes.","archived":false,"fork":false,"pushed_at":"2024-02-15T11:37:29.000Z","size":4479,"stargazers_count":185,"open_issues_count":8,"forks_count":18,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-30T01:05:42.707Z","etag":null,"topics":["chebyshev-polynomials","chemistry","engineering","legendre-polynomials","mathematics","physics","polynomials","python","quadrature","spherical-harmonics","zernike-polynomials"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigma-py.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-20T13:59:37.000Z","updated_at":"2025-03-10T02:35:05.000Z","dependencies_parsed_at":"2024-01-31T12:20:32.952Z","dependency_job_id":"6ebccc54-c5cf-44a2-8be5-79993814aa6b","html_url":"https://github.com/sigma-py/orthopy","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"fe7bd0acb2589d4486ca3285b3a658a29976dfbc"},"previous_names":["nschloe/orthopy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-py%2Forthopy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-py%2Forthopy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-py%2Forthopy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigma-py%2Forthopy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigma-py","download_url":"https://codeload.github.com/sigma-py/orthopy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423514,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chebyshev-polynomials","chemistry","engineering","legendre-polynomials","mathematics","physics","polynomials","python","quadrature","spherical-harmonics","zernike-polynomials"],"created_at":"2024-08-02T15:01:13.561Z","updated_at":"2025-12-12T00:54:24.613Z","avatar_url":"https://github.com/sigma-py.png","language":null,"funding_links":[],"categories":["Others","Other libraries and tools"],"sub_categories":["Mesh tools"],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nschloe/orthopy\"\u003e\u003cimg alt=\"orthopy\" src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/orthopy-logo-with-text.png\" width=\"30%\"\u003e\u003c/a\u003e\n  \u003cp align=\"center\"\u003eAll about orthogonal polynomials.\u003c/p\u003e\n\u003c/p\u003e\n\n[![PyPi Version](https://img.shields.io/pypi/v/orthopy.svg?style=flat-square)](https://pypi.org/project/orthopy)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/orthopy.svg?style=flat-square)](https://pypi.org/pypi/orthopy/)\n[![GitHub stars](https://img.shields.io/github/stars/nschloe/orthopy.svg?style=flat-square\u0026logo=github\u0026label=Stars\u0026logoColor=white)](https://github.com/nschloe/orthopy)\n[![Downloads](https://pepy.tech/badge/orthopy/month?style=flat-square)](https://pepy.tech/project/orthopy)\n\n\u003c!--[![PyPi downloads](https://img.shields.io/pypi/dm/orthopy.svg?style=flat-square)](https://pypistats.org/packages/orthopy)--\u003e\n\n[![Discord](https://img.shields.io/static/v1?logo=discord\u0026logoColor=white\u0026label=chat\u0026message=on%20discord\u0026color=7289da\u0026style=flat-square)](https://discord.gg/hnTJ5MRX2Y)\n[![orthogonal](https://img.shields.io/badge/orthogonal-yes-ff69b4.svg?style=flat-square)](https://github.com/nschloe/orthopy)\n\northopy provides various orthogonal polynomial classes for\n[lines](#line-segment--1-1-with-weight-function-1-x%CE%B1-1-x%CE%B2),\n[triangles](#triangle-42),\n[disks](#disk-s2),\n[spheres](#sphere-u2),\n[n-cubes](#n-cube-cn),\n[the nD space with weight function exp(-r\u003csup\u003e2\u003c/sup\u003e)](#nd-space-with-weight-function-exp-r2-enr2)\nand more.\nAll computations are done using numerically stable recurrence schemes. Furthermore, all\nfunctions are fully vectorized and can return results in _exact arithmetic_.\n\n### Installation\n\nInstall orthopy [from PyPI](https://pypi.org/project/orthopy/) with\n\n```\npip install orthopy\n```\n\n### How to get a license\n\nLicenses for personal and academic use can be purchased\n[here](https://buy.stripe.com/aEUg1H38OgDw5qMfZ3).\nYou'll receive a confirmation email with a license key.\nInstall the key with\n\n```\nplm add \u003cyour-license-key\u003e\n```\n\non your machine and you're good to go.\n\nFor commercial use, please contact support@mondaytech.com.\n\n### Basic usage\n\nThe main function of all submodules is the iterator `Eval` which evaluates the series of\northogonal polynomials with increasing degree at given points using a recurrence\nrelation, e.g.,\n\n```python\nimport orthopy\n\nx = 0.5\n\nevaluator = orthopy.c1.legendre.Eval(x, \"classical\")\nfor _ in range(5):\n     print(next(evaluator))\n```\n\n```python\n1.0          # P_0(0.5)\n0.5          # P_1(0.5)\n-0.125       # P_2(0.5)\n-0.4375      # P_3(0.5)\n-0.2890625   # P_4(0.5)\n```\n\nOther ways of getting the first `n` items are\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = Eval(x, \"normal\")\nvals = [next(evaluator) for _ in range(n)]\n\nimport itertools\nvals = list(itertools.islice(Eval(x, \"normal\"), n))\n```\n\nInstead of evaluating at only one point, you can provide any array for `x`; the\npolynomials will then be evaluated for all points at once. You can also use sympy for\nsymbolic computation:\n\n```python\nimport itertools\nimport orthopy\nimport sympy\n\nx = sympy.Symbol(\"x\")\n\nevaluator = orthopy.c1.legendre.Eval(x, \"classical\")\nfor val in itertools.islice(evaluator, 5):\n     print(sympy.expand(val))\n```\n\n```\n1\nx\n3*x**2/2 - 1/2\n5*x**3/2 - 3*x/2\n35*x**4/8 - 15*x**2/4 + 3/8\n```\n\nAll `Eval` methods have a `scaling` argument which can have three values:\n\n- `\"monic\"`: The leading coefficient is 1.\n- `\"classical\"`: The maximum value is 1 (or (n+alpha over n)).\n- `\"normal\"`: The integral of the squared function over the domain is 1.\n\nFor univariate (\"one-dimensional\") integrals, every new iteration contains one function.\nFor bivariate (\"two-dimensional\") domains, every level will contain one function more\nthan the previous, and similarly for multivariate families. See the tree plots below.\n\n### Line segment (-1, +1) with weight function (1-x)\u003csup\u003eα\u003c/sup\u003e (1+x)\u003csup\u003eβ\u003c/sup\u003e\n\n| \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/legendre.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/chebyshev1.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/chebyshev2.svg\" width=\"100%\"\u003e |\n| :---------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------: |\n|                                            Legendre                                             |                                            Chebyshev 1                                            |                                            Chebyshev 2                                            |\n\nJacobi, Gegenbauer (α=β), Chebyshev 1 (α=β=-1/2), Chebyshev 2 (α=β=1/2), Legendre\n(α=β=0) polynomials.\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nimport orthopy\n\northopy.c1.legendre.Eval(x, \"normal\")\northopy.c1.chebyshev1.Eval(x, \"normal\")\northopy.c1.chebyshev2.Eval(x, \"normal\")\northopy.c1.gegenbauer.Eval(x, \"normal\", lmbda)\northopy.c1.jacobi.Eval(x, \"normal\", alpha, beta)\n```\n\nThe plots above are generated with\n\n```python\nimport orthopy\n\northopy.c1.jacobi.show(5, \"normal\", 0.0, 0.0)\n# plot, savefig also exist\n```\n\nRecurrence coefficients can be explicitly retrieved by\n\n```python\nimport orthopy\n\nrc = orthopy.c1.jacobi.RecurrenceCoefficients(\n    \"monic\",  # or \"classical\", \"normal\"\n    alpha=0, beta=0, symbolic=True\n)\nprint(rc.p0)\nfor k in range(5):\n    print(rc[k])\n```\n\n```\n1\n(1, 0, None)\n(1, 0, 1/3)\n(1, 0, 4/15)\n(1, 0, 9/35)\n(1, 0, 16/63)\n```\n\n### 1D half-space with weight function x\u003csup\u003eα\u003c/sup\u003e exp(-r)\n\n\u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/e1r.svg\" width=\"45%\"\u003e\n\n(Generalized) Laguerre polynomials.\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = orthopy.e1r.Eval(x, alpha=0, scaling=\"normal\")\n```\n\n### 1D space with weight function exp(-r\u003csup\u003e2\u003c/sup\u003e)\n\n\u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/e1r2.svg\" width=\"45%\"\u003e\n\nHermite polynomials come in two standardizations:\n\n- `\"physicists\"` (against the weight function `exp(-x ** 2)`\n- `\"probabilists\"` (against the weight function `1 / sqrt(2 * pi) * exp(-x ** 2 / 2)`\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = orthopy.e1r2.Eval(\n    x,\n    \"probabilists\",  # or \"physicists\"\n    \"normal\"\n)\n```\n\n#### Associated Legendre \"polynomials\"\n\n\u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/associated-legendre.svg\" width=\"45%\"\u003e\n\nNot all of those are polynomials, so they should really be called associated Legendre\n_functions_. The \u003ci\u003ek\u003c/i\u003eth iteration contains _2k+1_ functions, indexed from\n_-k_ to _k_. (See the color grouping in the above plot.)\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = orthopy.c1.associated_legendre.Eval(\n    x, phi=None, standardization=\"natural\", with_condon_shortley_phase=True\n)\n```\n\n### Triangle (_T\u003csub\u003e2\u003c/sub\u003e_)\n\n\u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/triangle-tree.png\" width=\"40%\"\u003e\n\northopy's triangle orthogonal polynomials are evaluated in terms of [barycentric\ncoordinates](https://en.wikipedia.org/wiki/Barycentric_coordinate_system), so the\n`X.shape[0]` has to be 3.\n\n```python\nimport orthopy\n\nbary = [0.1, 0.7, 0.2]\nevaluator = orthopy.t2.Eval(bary, \"normal\")\n```\n\n### Disk (_S\u003csub\u003e2\u003c/sub\u003e_)\n\n| \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/disk-xu-tree.png\" width=\"70%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/disk-zernike-tree.png\" width=\"70%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/disk-zernike2-tree.png\" width=\"70%\"\u003e |\n| :------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: |\n|                                                 Xu                                                 |                      [Zernike](https://en.wikipedia.org/wiki/Zernike_polynomials)                       |                                                Zernike 2                                                 |\n\northopy contains several families of orthogonal polynomials on the unit disk: After\n[Xu](https://arxiv.org/abs/1701.02709),\n[Zernike](https://en.wikipedia.org/wiki/Zernike_polynomials), and a simplified version\nof Zernike polynomials.\n\n```python\nimport orthopy\n\nx = [0.1, -0.3]\n\nevaluator = orthopy.s2.xu.Eval(x, \"normal\")\n# evaluator = orthopy.s2.zernike.Eval(x, \"normal\")\n# evaluator = orthopy.s2.zernike2.Eval(x, \"normal\")\n```\n\n### Sphere (_U\u003csub\u003e3\u003c/sub\u003e_)\n\n\u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/sph-tree.png\" width=\"50%\"\u003e\n\nComplex-valued _spherical harmonics,_ (black=zero, green=real positive,\npink=real negative, blue=imaginary positive, yellow=imaginary negative). The\nfunctions in the middle are real-valued. The complex angle takes _n_ turns on\nthe \u003ci\u003en\u003c/i\u003eth level.\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = orthopy.u3.EvalCartesian(\n    x,\n    scaling=\"quantum mechanic\"  # or \"acoustic\", \"geodetic\", \"schmidt\"\n)\n\nevaluator = orthopy.u3.EvalSpherical(\n    theta_phi,  # polar, azimuthal angles\n    scaling=\"quantum mechanic\"  # or \"acoustic\", \"geodetic\", \"schmidt\"\n)\n```\n\n\u003c!-- To generate the above plot, write the tree mesh to a file --\u003e\n\u003c!----\u003e\n\u003c!-- ```python --\u003e\n\u003c!-- import orthopy --\u003e\n\u003c!----\u003e\n\u003c!-- orthopy.u3.write_tree(\"u3.vtk\", 5, \"quantum mechanic\") --\u003e\n\u003c!-- ``` --\u003e\n\u003c!----\u003e\n\u003c!-- and open it with [ParaView](https://www.paraview.org/). Select the _srgb1_ data set and --\u003e\n\u003c!-- turn off _Map Scalars_. --\u003e\n\n### _n_-Cube (_C\u003csub\u003en\u003c/sub\u003e_)\n\n| \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/c1.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/c2.png\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/c3.png\" width=\"100%\"\u003e |\n| :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: |\n|                                 C\u003csub\u003e1\u003c/sub\u003e (Legendre)                                  |                                       C\u003csub\u003e2\u003c/sub\u003e                                       |                                       C\u003csub\u003e3\u003c/sub\u003e                                       |\n\nJacobi product polynomials.\nAll polynomials are normalized on the n-dimensional cube. The dimensionality is\ndetermined by `X.shape[0]`.\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = orthopy.cn.Eval(X, alpha=0, beta=0)\nvalues, degrees = next(evaluator)\n```\n\n### \u003ci\u003en\u003c/i\u003eD space with weight function exp(-r\u003csup\u003e2\u003c/sup\u003e) (_E\u003csub\u003en\u003c/sub\u003e\u003csup\u003er\u003csup\u003e2\u003c/sup\u003e\u003c/sup\u003e_)\n\n| \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/e1r2.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/e2r2.png\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/sigma-py/orthopy/assets/e3r2.png\" width=\"100%\"\u003e |\n| :-----------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------: |\n|                           _E\u003csub\u003e1\u003c/sub\u003e\u003csup\u003er\u003csup\u003e2\u003c/sup\u003e\u003c/sup\u003e_                           |                           _E\u003csub\u003e2\u003c/sub\u003e\u003csup\u003er\u003csup\u003e2\u003c/sup\u003e\u003c/sup\u003e_                           |                           _E\u003csub\u003e3\u003c/sub\u003e\u003csup\u003er\u003csup\u003e2\u003c/sup\u003e\u003c/sup\u003e_                           |\n\nHermite product polynomials.\nAll polynomials are normalized over the measure. The dimensionality is determined by\n`X.shape[0]`.\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nevaluator = orthopy.enr2.Eval(\n    x,\n    standardization=\"probabilists\"  # or \"physicists\"\n)\nvalues, degrees = next(evaluator)\n```\n\n### Other tools\n\n- Generating recurrence coefficients for 1D domains with\n  [Stieltjes](https://github.com/nschloe/orthopy/wiki/Generating-1D-recurrence-coefficients-for-a-given-weight#stieltjes),\n  [Golub-Welsch](https://github.com/nschloe/orthopy/wiki/Generating-1D-recurrence-coefficients-for-a-given-weight#golub-welsch),\n  [Chebyshev](https://github.com/nschloe/orthopy/wiki/Generating-1D-recurrence-coefficients-for-a-given-weight#chebyshev), and\n  [modified\n  Chebyshev](https://github.com/nschloe/orthopy/wiki/Generating-1D-recurrence-coefficients-for-a-given-weight#modified-chebyshev).\n\n- The the sanity of recurrence coefficients with test 3 from [Gautschi's article](https://doi.org/10.1007/BF02218441):\n  computing the weighted sum of orthogonal polynomials:\n  \u003c!--pytest.mark.skip--\u003e\n\n  ```python\n  orthopy.tools.gautschi_test_3(moments, alpha, beta)\n  ```\n\n- [Clenshaw algorithm](https://en.wikipedia.org/wiki/Clenshaw_algorithm) for\n  computing the weighted sum of orthogonal polynomials:\n  \u003c!--pytest.mark.skip--\u003e\n  ```python\n  vals = orthopy.c1.clenshaw(a, alpha, beta, t)\n  ```\n\n### Relevant publications\n\n- [Robert C. Kirby, Singularity-free evaluation of collapsed-coordinate orthogonal polynomials, ACM Transactions on Mathematical Software (TOMS), Volume 37, Issue 1, January 2010](https://doi.org/10.1145/1644001.1644006)\n- [Abedallah Rababah, Recurrence Relations for Orthogonal Polynomials on Triangular Domains, MDPI Mathematics 2016, 4(2)](https://doi.org/10.3390/math4020025)\n- [Yuan Xu, Orthogonal polynomials of several variables, arxiv.org, January 2017](https://arxiv.org/abs/1701.02709)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigma-py%2Forthopy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigma-py%2Forthopy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigma-py%2Forthopy/lists"}