croot

Crates.iocroot
lib.rscroot
version0.3.3
sourcesrc
created_at2023-04-21 21:56:39.706029
updated_at2023-05-14 22:57:33.684783
descriptionA crate for finding real and complex roots
homepage
repositoryhttps://github.com/Ross-Morgan/croot/
max_upload_size
id845678
size11,382
Cryptollusion (Ross-Morgan)

documentation

README

Croot

Build No Std Label

A Rust library for finding complex and principal roots of real and complex values;

Context

Any number, real or complex, has n nth-roots.

For example, there are 4 values for the 4th-root of 1

Usually, we ignore all but the principal root; that with the largest real component

The principal 4th-root of 1 is 1, but the others are [-1, i, -i]

Examples

Results in examples have been rounded to 5 decimal places

Principal

The root with the largest real, and positive imaginary component

Real principal

For finding the principal root of a real value, we use principal_root

principal_root(1.0, 4);  // 1.0
principal_root(-1.0, 4); // 0.707107 + 0.707107i

Complex principal

For finding the principal root of a complex value, we use complex_principal_root

let c1 = Complex64::new(3.0, 4.0);  // 3 + 4i
let c2 = Complex64::new(10.0, 2.0); // 10 + 2i

complex_principal_root(c1, 3) // 1.62894 + 0.52017
complex_principal_root(c1, 3) // 2.16387 + 0.14259

All Roots

n values which when raised to the nth-power, give the original value

All Real

For finding all roots of a real value, we use root

root(1.0, 2);  // [1.0, -1.0]
root(1.0, 4);  // [1.0, -1.0, i, -i]
root(81.0, 4); // [3.0, -3.0, 3i, -3i]

All Complex

For finding all roots of a complex number, we use complex_root

let c1 = Complex64::new(3.0, 4.0)  // 3 + 4i
let c2 = Complex64::new(10.0, 2.0) // 10 + 2i

complex_root(c1, 3) // [1.6289 + 0.5202i, -1.2650 + 1.1506i, -0.3640 - 1.6708i]
complex_root(c2, 3) // [2.1639 + 0.14259, -1.2054 + 1.8027i, -0.9585 - 1.9453i]

Roots of Unity

The nth-roots of unity are the nth-roots of 1

The nth-roots of 1 can be found with roots_of_unity

roots_of_unity(3); // [1, -0.5 + 0.8660i, -0.5 - 0.8660i]
roots_of_unity(4); // [1, i, -1, -i]
Commit count: 80

cargo fmt