{"id":29562648,"url":"https://github.com/cybergeek1943/mathflow","last_synced_at":"2026-05-08T10:31:49.633Z","repository":{"id":301578421,"uuid":"1009704204","full_name":"cybergeek1943/MathFlow","owner":"cybergeek1943","description":"Like `requests` for mathematical computing, making complex math feel simple.","archived":false,"fork":false,"pushed_at":"2025-07-18T04:08:30.000Z","size":157,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-18T07:32:57.032Z","etag":null,"topics":["analysis","calculator","calculus","mathematics","numerical-analysis","numerical-methods","numpy","python-math","scipy","symbolic-expressions","symbolic-math","sympy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cybergeek1943.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-06-27T15:11:41.000Z","updated_at":"2025-07-18T03:59:19.000Z","dependencies_parsed_at":"2025-07-18T07:40:52.633Z","dependency_job_id":"b0430e28-5c14-4a93-a393-50074ac18f8c","html_url":"https://github.com/cybergeek1943/MathFlow","commit_stats":null,"previous_names":["cybergeek1943/funkit","cybergeek1943/mathflow"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cybergeek1943/MathFlow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybergeek1943%2FMathFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybergeek1943%2FMathFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybergeek1943%2FMathFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybergeek1943%2FMathFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cybergeek1943","download_url":"https://codeload.github.com/cybergeek1943/MathFlow/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybergeek1943%2FMathFlow/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265806301,"owners_count":23831282,"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":["analysis","calculator","calculus","mathematics","numerical-analysis","numerical-methods","numpy","python-math","scipy","symbolic-expressions","symbolic-math","sympy"],"created_at":"2025-07-18T18:01:09.384Z","updated_at":"2026-05-07T09:31:27.001Z","avatar_url":"https://github.com/cybergeek1943.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg width=\"1278\" height=\"342\" alt=\"logo\" src=\"https://github.com/user-attachments/assets/cc90652f-ff4d-4840-a43f-8cbb6b0fca83\" /\u003e\n\n# MathFlow\n**A Pythonic Interface for Symbolic and Numerical Mathematics**\n\nMathFlow bridges the gap between symbolic mathematics (SymPy) and numerical computations (NumPy/SciPy), offering a unified interface that maintains mathematical rigor while providing practical tools for real-world problems.  \n  \n![Static Badge](https://img.shields.io/badge/Python-3.11%2B-blue?logo=python)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)  \n\n**Ready to revolutionize your mathematical computing workflow?**\n```bash\npip install mathflow\n```\n\n**Have Questions? Take a look at the Q\u0026A:**\n[Questions \u0026 Answers: Addressing Potential Concerns](docs/QA.md)\n\n## Key Features\n  \n- **Operative Closure**: Mathematical operations return new Expression objects by default\n- **Mutability Control**: Choose between immutable (default) and mutable expressions for different workflows  \n- **Seamless Numerical Integration**: Every symbolic expression has a `.n` attribute providing numerical methods without manual lambdification (uses cached lambdified expression when needed)\n- **Enhanced Printing**: Flexible output formatting through the `.print` attribute (LaTeX, pretty printing, code generation)  \n- **Signal System**: Qt-like signals for tracking expression mutations and clones, enabling reactive programming  \n- **Automatic Type Conversions**: Seamlessly and automatically converts between internal Poly and Expr representations based on context\n- **Lightweight**: ~0.5 MB itself, ~100 MB including dependencies\n- **Fully backward compatible**: Seamlessly integrate SymPy and MathFlow in the same script. All methods that work on SymPy Expr or Poly objects work on MathFlow objects\n- **Exploratory**: Full IDE support, enabling easy tool finding and minimizing the learning curve.\n\n\n## Quick Start\n\n```python\nfrom mathflow import Expression, Polynomial, Rational\n\n# Create expressions naturally\nf = Expression(\"2x^2 + 3x + \\frac{1}{2}\")  # latex is automatically parsed\ng = Expression(\"sin(x) + cos(x)\")\n\n# Automatic operative closure - operations return new objects of the same type\nh = f + g  # f and g remain unchanged\nhprime = h.diff()  # hprime is still an Expression object\n\n# Numerical evaluation made easy\nresult = f(2.5)  # Numerically evaluate at x = 2.5\n\n# Use the .n attribute to access fast numerical methods\nnumerical_roots = f.n.all_roots()\n# Call f's n-prefixed methods to use variable precision numerical methods\nprecise_roots = f.nsolve_all(prec=50)  # 50 digits of accuracy\n\n# quick and easy printing\nf.print()\nf.print('latex')\nf.print('mathematica_code')\n# or\nprint(f.print.latex())    # LaTeX output\nprint(f.print.ccode())    # c code output\n```  \n\n\n## Numerical Computing\n\nMathFlow excels at bridging symbolic and numerical mathematics:  \n```python\nf = Expression(\"x^3 - 2x^2 + x - 1\")\n\n# Root finding\nall_roots = f.n.all_roots(bounds=(-5, 5))\nspecific_root = f.nsolve_all(bounds=(-5, 5), prec=50)  # High-precision solve\n\n# Numerical calculus\nderivative_func = f.n.derivative_lambda(df_order=2)  # 2nd derivative numerical function  \nintegral_result = f.n.integrate(-1, 1)               # Definite integral  \n\n# Optimization\nminimum = f.n.minimize(bounds=[(-2, 2)])\n```\n\n\n## Core Classes\n\n```mermaid\ngraph BT\n    %% Visual hierarchy with correct arrow semantics\n    sympy.Expr\n    sympy.Poly\n    BaseExpression\n    Expression\n    Polynomial\n    Rational\n    Function\n    \n    %% Arrows still point child → parent\n    BaseExpression -.-\u003e sympy.Expr\n    BaseExpression -.-\u003e sympy.Poly\n    Expression --\u003e n\n    n --\u003e |lambdified numerical representation| A[\"f(x)\"]\n    n -.-\u003e scipy.numerical_methods\n    Expression --\u003e BaseExpression\n    Polynomial --\u003e Expression\n    Rational --\u003e Expression\n    Function --\u003e |Only an Alias| Expression\n```\n\u003e Diagram Notes\n\u003e - Dotted arrows mean \"proxy to\".\n\u003e - Additional methods are not shown, only the core structure.\n\n\n### Expression\nThe primary class for general symbolic expressions with numerical and printing capabilities.\n```python\n# Create from string with natural notation\nexpr = Expression(\"2x^2 + ln(|x-1|)\")\n\n# Or from SymPy objects\nfrom sympy import sin, cos\nexpr = Expression(sin(x) + cos(x))\n\n# Symbolic operations\nderivative = expr.diff(x)\nexpanded = expr.expand()\n\n# Numerical methods via .n attribute\nroots = expr.n.all_roots(bounds=(-10, 10))\nintegral = expr.n.quad(0, 1)  # Numerical integration\n```\n\n\n### Polynomial\nSpecialized Expression subclass with polynomial-specific functionality.\n```python\n# Create from coefficients (ascending order by default)\npoly = Polynomial.from_coeffs([1, 2, 3])  # 1 + 2x + 3x²\n\n# Create from roots\npoly = Polynomial.from_roots([1, 2, 3])   # (x-1)(x-2)(x-3)  \n\n# Access polynomial-specific methods\ncoeffs = poly.all_coeffs()\ndegree = poly.degree()\nroots = poly.n.all_poly_roots()  # Optimized polynomial root finding\n```\n\n\n### Rational\nFor rational functions (quotients of polynomials).\n```python  \n# Create from numerator and denominator coefficients  \nrational = Rational.from_coeffs([1, 2], [1, 1, 1])  # (1 + 2x)/(1 + x + x²)  \n  \n# Access numerator and denominator as Expression objects  \nnum = rational.numerator  \nden = rational.denominator  \n  \n# Partial fraction decomposition\npoles = den.n.all_roots()  # numerically find the poles.\npf = rational.partial_fractions(x)\n```  \n\n\n## Advanced Features\n### Mutability Control  \n  \n```python\n# Immutable (default)\nf = Expression(\"x^2\")\ng = f + 1  # f unchanged, g is new Expression object\n\n# Mutable Mode (f is modified in-place)\nf = Expression(\"(x-1)^2\", mutable=True)\nf += 1\nf.expand()\n```\n\n\n### Flexible String Parsing  \n  \n```python\n# Natural mathematical notation\nexpr = Expression(\"2x^2 + ln(|x-1|)\")\n\n# LaTeX input support\nexpr = Expression(r\"\\frac{x^2+1}{x-1}\")\n\n# Implicit multiplication\nexpr = Expression(\"2x sin(x)\")\n```\n\n\n### Signal System for Reactive Programming  \n  \n```python  \ndef on_change(expr):  # runs whenever an operation changes f\n    print(f\"Expression changed to: {expr}\")  \nf = Expression(\"x^2\")  \nf.on_self_mutated.connect(on_change)  \nf.on_self_cloned.connect(on_change)\nf += 1  # on_change() is called\n```  \n\n\n### Padé Approximations (Useful in Engineering Applications)\n\n```python\n# High-quality Padé approximants for function approximation\nf = Expression(\"exp(x)\")\npade_approx = f.pade(m=3, n=3, x0=0)  # [3/3] Padé approximant around x=0\n  \n# Multiple backends available (returns Expression by default, but you can change return type)\npade_fast = f.pade(3, 3, backend='mpmath')      # Fast numerical\npade_exact = f.pade(3, 3, backend='symbolic')   # Exact symbolic\npade_verbose = f.pade(3, 3, backend='verbose')  # Educational output\n```\n\nWhen `backend='verbose'`, each step is displayed as the Padé approximation is computed.\n```python\nf = Expression(\"sqrt(x)\")\np = f.pade(2, 2, x0=1, backend='verbose')\n```\n\nFor example, the above displays this:\n```\nStep 1. Create rational function with numerator P and denominator Q, each with unknown coefficients:\n(a0 + a1*h + a2*h^2)/(1 + b1*h + b2*h^2)\n\nStep 2. Equate the rational function to the taylor series A so that the unknown coefficients may be solved:\n(a0 + a1*h + a2*h^2)/(1 + b1*h + b2*h^2)  =  1 + 1/2*h + -1/8*h^2 + 1/16*h^3 + -5/128*h^4\n\nStep 3. Multiply the rhs by the denominator of the lhs to get the equation in the form P = QA:\na0 + a1*h + a2*h^2  =  (1 + b1*h + b2*h^2) (1 + 1/2*h + -1/8*h^2 + 1/16*h^3 + -5/128*h^4)\n\nStep 4. Expand the RHS by performing discrete convolution on the coefficient vectors of Q and A (using a table):\n\tQ's coeffs = [1, b1, b2]\n\tA's coeffs = [1, 1/2, -1/8, 1/16, -5/128]\n╭────┬─────┬────────┬───────────┬─────────┬─────────────╮\n│    │ 1   │ 1/2    │ -1/8      │ 1/16    │ -5/128      │\n├────┼─────┼────────┼───────────┼─────────┼─────────────┤\n│ 1  │ 1   │ 1*1/2  │ 1*(-1/8)  │ 1*1/16  │ 1*(-5/128)  │\n├────┼─────┼────────┼───────────┼─────────┼─────────────┤\n│ b1 │ b1  │ b1*1/2 │ b1*(-1/8) │ b1*1/16 │ b1*(-5/128) │\n├────┼─────┼────────┼───────────┼─────────┼─────────────┤\n│ b2 │ b2  │ b2*1/2 │ b2*(-1/8) │ b2*1/16 │ b2*(-5/128) │\n╰────┴─────┴────────┴───────────┴─────────┴─────────────╯\n\nStep 5. Get the sum of the anti-diagonals from the above table to form the new coeffs (only as many terms as unknown coeffs we need to solve for, in this case 5):\n╭────────┬──────────────────────╮\n│ Term   │ Coeff                │\n├────────┼──────────────────────┤\n│ h^0    │ 1                    │\n├────────┼──────────────────────┤\n│ h^1    │ b1 + 1/2             │\n├────────┼──────────────────────┤\n│ h^2    │ b1/2 + b2 - 1/8      │\n├────────┼──────────────────────┤\n│ h^3    │ -b1/8 + b2/2 + 1/16  │\n├────────┼──────────────────────┤\n│ h^4    │ b1/16 - b2/8 - 5/128 │\n╰────────┴──────────────────────╯\n\nStep 6. Use these coefficients to setup a system of equations:\na0 = 1\na1 = b1 + 1/2\na2 = b1/2 + b2 - 1/8\n 0 = -b1/8 + b2/2 + 1/16\n 0 = b1/16 - b2/8 - 5/128\n\nStep 7. Solving the above system yields:\na0 = 1\na1 = 5/4\na2 = 5/16\nb1 = 3/4\nb2 = 1/16\n\nStep 8. Substituting these values back into the original rational function yields:\n(1 + 5/4*h + 5/16*h^2)/(1 + 3/4*h + 1/16*h^2)\n\nStep 9. `h` may be substituted for the original (x-c), and then expanded. `c` is the point at which both the Taylor series and the Padé approximation are centered at:\n(1 + 5/4*(x-c) + 5/16*(x-c)^2)/(1 + 3/4*(x-c) + 1/16*(x-c)^2)\n```\n\n\n## Design Philosophy  \n  \nMathFlow follows several key principles:\n\n1. **Intuitive API**: Mathematical operations should feel natural in Python, providing an \"exploratory\" experience\n2. **Performance**: Automatic optimizations (Horner's method, efficient algorithms, automatic numerical computing when needed)  \n3. **Flexibility**: Support both functional and OOP programming styles  \n4. **Extensibility**: Easy integration with other mathematical libraries  \n5. **Type Safety**: Comprehensive type and method hints for full IDE support\n\n\n## Next Steps \u0026 Our Vision\n\n- Provide a way to set configurations and defaults\n- Provide a better testing suite to ensure all edge cases are taken care of\n- Create an official MCP server for MathFLow. This would allow integrations with any AI tool, including local ones.\n- Integrate AI by introducing an `.ai()` method that calls a local instance of [MathΣtral](https://mistral.ai/news/mathstral) and [Project Numina](https://projectnumina.ai/) models over ollama. It would be given context of both the expressions structure and its mathematical properties. One could also use it construct expressions using natural language.\n\nAI Integration Example\n```python\n\u003e\u003e\u003e f = Expression(\"A polynomial with the first five prime numbers as coefficients\")\n\u003e\u003e\u003e f.ai(\"Have you seen a polynomial with such properties before?\")\n...\n\u003e\u003e\u003e fp = f.diff()\n\u003e\u003e\u003e fp.ai(\"How have the coefficients changed?\")\n...\n```\n\n\n## Contributing  \n\nWe welcome contributions! Soon, we will publish a list of documents covering contribution guidelines here. Come back later if you are interested in contributing!\n\n\n## Dependencies  \n\n- **SymPy**: Symbolic mathematics engine  \n\t- **mpmath**: High-precision arithmetic\n- **SciPy**: Advanced numerical algorithms  \n\t- **NumPy**: Numerical array operations    \n- **tabulate**: Pretty table printing (for verbose modes)  \n\n\n## License (MIT)\n\nThis project is licensed under the MIT License - see the LICENSE file for details.  \n\n\n## Acknowledgments\n\n- Built on the excellent [SymPy](https://www.sympy.org/) symbolic mathematics library  \n- Numerical computing powered by [NumPy](https://numpy.org/) and [SciPy](https://scipy.org/)  \n- High-precision arithmetic via [mpmath](http://mpmath.org/)  \n\n[^1]: \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybergeek1943%2Fmathflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcybergeek1943%2Fmathflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybergeek1943%2Fmathflow/lists"}