{"id":35876716,"url":"https://github.com/hajimen/symengine_example","last_synced_at":"2026-01-08T17:01:49.851Z","repository":{"id":194508926,"uuid":"690396678","full_name":"hajimen/symengine_example","owner":"hajimen","description":"symengine_example is a Python application to show the ability (and the limitation) of symengine.py for realistic problem.","archived":false,"fork":false,"pushed_at":"2023-09-15T10:10:35.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-30T17:49:59.393Z","etag":null,"topics":["computer-algebra","numerical-analysis","symbolic-math","symengine","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/hajimen.png","metadata":{"files":{"readme":"ReadMe.md","changelog":"ChangeLog.md","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}},"created_at":"2023-09-12T05:51:40.000Z","updated_at":"2023-09-12T05:54:33.000Z","dependencies_parsed_at":"2023-09-13T18:22:53.428Z","dependency_job_id":null,"html_url":"https://github.com/hajimen/symengine_example","commit_stats":null,"previous_names":["hajimen/symengine_example"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hajimen/symengine_example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajimen%2Fsymengine_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajimen%2Fsymengine_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajimen%2Fsymengine_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajimen%2Fsymengine_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hajimen","download_url":"https://codeload.github.com/hajimen/symengine_example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajimen%2Fsymengine_example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28246996,"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","status":"online","status_checked_at":"2026-01-08T02:00:06.591Z","response_time":241,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["computer-algebra","numerical-analysis","symbolic-math","symengine","sympy"],"created_at":"2026-01-08T17:00:41.254Z","updated_at":"2026-01-08T17:01:49.846Z","avatar_url":"https://github.com/hajimen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# symengine_example\n\n**symengine_example** is a Python application to show the ability (and the limitation) of\n[symengine.py](https://github.com/symengine/symengine.py) for realistic problem.\n\nsymengine_example is an exhibition of the technology and its future outlook.\nsymengine_example is a learning material, not a solution for anything.\n\n## What is symengine.py?\n\nFaster alternative of [SymPy](https://www.sympy.org/en/index.html).\nNot a perfect drop-in replacement, but has many features.\n\n## Requirements\n\nPython 3.11 and later.\n\nRun `pip install -r requirements.txt`.\n\n## How to use `visualize_spline`\n\nFor example, run:\n\n```\npython -m symengine_example.visualize_spline 2 i 2d l en\n```\n\n### The args\n\nBefore digging `visualize_spline`, let's look at M-spline and I-spline.\n\nI-spline is a monotonic increasing spline. M-spline is non-negative spline,\nwhich is required to make I-spline. See [Wikipedia](https://en.wikipedia.org/wiki/I-spline).\n\nIn symengine_example, I-spline is extended to n-dimensional. It makes much harder to calculate.\nThe complexity is a good example of realistic problem, I guess. `visualize_spline` can do 1- to 3-dimension.\n\nM- and I-spline has the concept of \"degree\". More degree makes the spline smoother.\n`visualize_spline` can do 1 to 3 degree.\n\nThe first three args of `visualize_spline` is, degree (1|2|3), spline type (m|i), and dimension (1d|2d|3d).\n\nThe fourth arg chooses the processing method:\n\n1. (i) Do not use SymPy or symengine.py.\n2. (s) Use `subs()` and not `lambdify()`.\n3. (l) Use `lambdify()` and call the generated function.\n\nThe last arg chooses SymPy (py) or symengine.py (en). You can compare the processing time of both.\n\nIn summary:\n\n```\npython -m symengine_example.visualize_spline (1|2|3) (m|i) (1d|2d|3d) (i|s|l) (py|en)\n```\n\n### Performance comparison\n\nThe performance comparison with SymPy becomes like this:\n\n```\n$ python -m symengine_example.visualize_spline 2 i 2d l en\nTotal computation time: 0.8512809000094421 seconds.\n    Subtotal time for function call: 0.252729299972998 seconds.\n    Subtotal time for lambdify(): 0.5985516000364441 seconds.\n$ python -m symengine_example.visualize_spline 2 i 2d l py\nTotal computation time: 83.87184929999057 seconds.\n    Subtotal time for function call: 82.26858449997962 seconds.\n    Subtotal time for lambdify(): 1.6032648000109475 seconds.\n```\n\nsymengine.py is nearly 100 times faster even including `lambdify()` time!\nIf excluding, 300x! (symengine-0.10.0)\n\nIMPORTANT: **The result of `lambdify()` is pickle-able.**\n\n### Memory usage observation (and AMD CPU vulnerability?)\n\nOpen Task Manager (if Windows), select Performance -\u003e Memory, and run\n`python -m symengine_example.visualize_spline 2 i 3d l en`.\n\nYou can see 400MB of increasing in Committed while computing (symengine-0.10.0).\n\nSo next, close all other apps, and run `python -m symengine_example.visualize_spline 3 i 3d l en`.\nit exhausts Committed 30 GB or more, and aborts.\n\nOn one of my PCs, it crashes whole Windows (symengine-0.10.0).\nI guess it exploits a vulnerability of AMD CPU (Ryzen 5 5600X).\n\n## How to use `test_model.py`\n\nBefore digging `test_model.py`, let's look at n-dimensional I-spline a bit more.\n\nWe introduce the expression `y = f(x)` as n-dimensional I-spline.\n`x` is an n-dimensional vector, and `y` is a scalar.\n\n`visualize_spline` shows you the form of n-dimensional I-spline, and you can see that\n`y` is always 0 when `any(x == 0)`. This is a critical limitation for spline.\nSo I made a model which doesn't have the problem by combining I-spline.\nThe detail is in `model.py`. For now, leave it as \"the model\".\n\nRun `python -m unittest tests.test_model.TestModel.test_fit_params_solve_xs`\nand wait one or several minutes. It fits a 3-dimensional vector field to the model.\nYou can see the result by `python -m tests.test_model`.\n\n`test_model.py` demonstrates the outlook of symengine.py: **The integration of\nnumerical analysis and computer algebra with practical performance for realistic problem!**\nMoreover, currently `test_model.py` doesn't use `lambdify()` for the memory usage problem mentioned above.\nIf the problem has been fixed, **it will be a revolution of computing!**\n\n## License\n\nMIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhajimen%2Fsymengine_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhajimen%2Fsymengine_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhajimen%2Fsymengine_example/lists"}