{"id":18297031,"url":"https://github.com/powergee/four-square-sum-wasm","last_synced_at":"2025-10-18T12:40:18.486Z","repository":{"id":119119450,"uuid":"474401560","full_name":"powergee/four-square-sum-wasm","owner":"powergee","description":"WebAssembly package to solve Lagrange's four-square problems efficiently","archived":false,"fork":false,"pushed_at":"2024-05-20T19:41:48.000Z","size":23,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T03:15:18.474Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/powergee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","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":"2022-03-26T16:20:52.000Z","updated_at":"2022-03-27T05:45:42.000Z","dependencies_parsed_at":"2023-05-31T02:30:52.131Z","dependency_job_id":null,"html_url":"https://github.com/powergee/four-square-sum-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powergee%2Ffour-square-sum-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powergee%2Ffour-square-sum-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powergee%2Ffour-square-sum-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powergee%2Ffour-square-sum-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/powergee","download_url":"https://codeload.github.com/powergee/four-square-sum-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008615,"owners_count":21032554,"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":[],"created_at":"2024-11-05T14:46:27.503Z","updated_at":"2025-10-18T12:40:13.414Z","avatar_url":"https://github.com/powergee.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lagrange's four-square calculator (Rust, WASM)\n\n**This package is used for [four-square-sum](https://github.com/powergee/four-square-sum) project.**\n\n**Lagrange's four-square theorem**, also known as **Bachet's conjecture**, states that *every natural number can be represented as the sum of four integer squares.* ([ref](https://en.wikipedia.org/wiki/Lagrange%27s_four-square_theorem))\n\nThis algorithm can calculate one of the below:\n* **an arbitrary solution** of any non-negative integer *N* by **randomized polynomial time.**\n* **an optimal solution**, which use the fewest numbers, of any non-negative integer *N* by the time complexity proportional to the fourth square root of *N*.\n\nThe randomized polynomial algorithm is [based on MICHAEL 0. RABIN et al.](https://onlinelibrary.wiley.com/doi/10.1002/cpa.3160390713)\n\n## Usage\n\n```rust\n#[wasm_bindgen(js_name = findSolution)]\npub fn find_solution_str(n: String, find_optimal: bool) -\u003e String {}\n```\n\nImport the function above into your applications.\n\n```js\nimport init, { findSolution } from \"four-square-sum-wasm\";\ninit().then(() =\u003e {\n    findSolution(\"1000\", false); // [\"6\", \"30\", \"8\", \"0\"]\n    findSolution(\"1000\", true);  // [\"10\", \"30\", \"0\", \"0\"]\n});\n```\n\n## Build\n\n```bash\nwasm-pack build --target web\n```\n\n## Test\n\n```bash\nwasm-pack test --chrome --headless\n```\n\n## Demostration and explanation\n\nYou can run the algorithm on [GitHub-Pages](https://powergee.github.io/four-square-sum/), which is implemented by React and Rust(Wasm). **There is also a short explanation about the background.**\n\n## References\n\n* [1] Rabin, M.O. and Shallit, J.O. (1986), Randomized algorithms in number theory. Comm. Pure Appl. Math., 39: S239-S256. [https://doi.org/10.1002/cpa.3160390713](https://doi.org/10.1002/cpa.3160390713)\n* [2] Rabin, M. O., Efficient Algorithms, Lecture Notes MIT, 1977, transcribed by M. Lui.\n* [3] Lagrange's four-square theorem, [https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem\u0026oldid=1070361127](https://en.wikipedia.org/w/index.php?title=Lagrange%27s_four-square_theorem\u0026oldid=1070361127) (last visited Feb. 24, 2022).\n* [4] Legendre's three-square theorem, [https://en.wikipedia.org/w/index.php?title=Legendre%27s_three-square_theorem\u0026oldid=1030003352](https://en.wikipedia.org/w/index.php?title=Legendre%27s_three-square_theorem\u0026oldid=1030003352) (last visited Feb. 24, 2022).\n* [5] Fermat's theorem on sums of two squares, [https://en.wikipedia.org/w/index.php?title=Fermat%27s_theorem_on_sums_of_two_squares\u0026oldid=1064865677](https://en.wikipedia.org/w/index.php?title=Fermat%27s_theorem_on_sums_of_two_squares\u0026oldid=1064865677) (last visited Feb. 24, 2022).\n* [6] Pollard's rho algorithm, [https://en.wikipedia.org/w/index.php?title=Pollard%27s_rho_algorithm\u0026oldid=1044484908](https://en.wikipedia.org/w/index.php?title=Pollard%27s_rho_algorithm\u0026oldid=1044484908) (last visited Feb. 24, 2022).\n* [7] Brahmagupta–Fibonacci identity, [https://en.wikipedia.org/w/index.php?title=Brahmagupta%E2%80%93Fibonacci_identity\u0026oldid=1072168983](https://en.wikipedia.org/w/index.php?title=Brahmagupta%E2%80%93Fibonacci_identity\u0026oldid=1072168983) (last visited Feb. 24, 2022).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowergee%2Ffour-square-sum-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowergee%2Ffour-square-sum-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowergee%2Ffour-square-sum-wasm/lists"}