0.1.1 • Published 2 years ago

four-square-sum-wasm v0.1.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Lagrange's four-square calculator (Rust, WASM)

This package is used for four-square-sum project.

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)

This algorithm can calculate one of the below:

  • an arbitrary solution of any non-negative integer N by randomized polynomial time.
  • 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.

The randomized polynomial algorithm is based on MICHAEL 0. RABIN et al.

Usage

#[wasm_bindgen(js_name = findSolution)]
pub fn find_solution_str(n: String, find_optimal: bool) -> String {}

Import the function above into your applications.

import init, { findSolution } from "four-square-sum-wasm";
init().then(() => {
    findSolution("1000", false); // ["6", "30", "8", "0"]
    findSolution("1000", true);  // ["10", "30", "0", "0"]
});

Build

wasm-pack build --target web

Test

wasm-pack test --chrome --headless

Demostration and explanation

You can run the algorithm on GitHub-Pages, which is implemented by React and Rust(Wasm). There is also a short explanation about the background.

References