Crates.io | opis |
lib.rs | opis |
version | 5.7.0 |
source | src |
created_at | 2021-09-29 06:59:58.664655 |
updated_at | 2023-08-24 19:05:18.431495 |
description | Opis is a library for rational number and matrix arithmetic. |
homepage | |
repository | https://github.com/stelar-labs/opis-rs |
max_upload_size | |
id | 457903 |
size | 106,814 |
Opis is a library for rational number and matrix arithmetic.
use opis::{ Bit, Integer, Fraction, Matrix };
Add a + b
And a & b
Eq a == a
Not !a
Or a | b
Xor a ^ b
pub struct Integer(pub Vec
Addition a + b, a += b
And a & b
Base2 Integer::from_bin("1010101"), a.to_bin()
Base10 Integer::from_dec("674755"), a.to_dec()
Base16 Integer::from_hex("00ABC012"), a.to_hex()
Bytes Integer::from(&bytes), a.into()
Comparision a < b, a <= b, a > b, a >= b
Division a / b?
Equality a == b
Extended Euclidean Algorithm a.ext_gcd(&b)
Extended Bits a.to_ext_bits(256)
Extended Bytes a.to_ext_bytes(32)
Linear Feedback Shift Register a.lfsr(1)?
Modulo: a.modulo(&m)
Modular Exponentiation: base.mod_pow(&exponent, &modulus)
Multiply a * b, a *= b
Negate a.negate()
Not !a
Or a | b
Exponentiation a.pow(e)?
Remainder: a % b?
Shifts a << 1, a <<= 1, a >> 1, a >>= 1
fn try_from(value: &str) -> Result<Self, Box<dyn Error>>
Subtraction a - b, a -= b
Support: Binary, Decimal, Hexadecimal, Floating Literal
pub struct Fraction(pub Integer, pub Integer)
(a,b) + (c,d) = (ad + bc, bd)
(a,b) - (c,d) = (ad - bc, bd)
(a,b) * (c,d) = (ac, bd)
(a,b) / (c,d) = (ad, bc) with c != 0
Result<Fraction, Box<dyn Error>>
-(a,b) = (-a,b)
fraction.opposite() -> Fraction
(a,b)^-1 = (b,a)
fraction.reciprocal() -> Result<Fraction, Box<dyn Error>>
pub fn reduce(&mut self)
pub fn reduction(&self) -> Fraction
Support: Binary, Decimal, Hexadecimal, Floating Point Literal
From: Integer, u8, u16, u32, u64, u128, usize
fn add(self, b: Self) -> Result<Matrix<T>, Box<dyn Error>>
fn cofactors(&self, neg_one: T) -> Result<Matrix<T>, Box<dyn Error>>
A = [ 3 -1 -2] C = [ 3 1 -2]
[ 3 1 -1] [-3 1 1]
[ 3 4 2] [ 3 -4 2]
fn determinant(&self, neg_one: T) -> Result<T, Box<dyn std::error::Error>>
fn dimensions(&self) -> Result<(usize, usize), Box<dyn Error>>
fn eq(&self, b: &Self) -> bool
fn identity(size: usize, zero: T, one: T) -> Matrix<T>
fn inverse(&self, neg_one: T, zero: T, one: T) -> Result<Matrix<T>, Box<dyn Error>>
fn linear_regression(&self, variables: &Matrix<T>, neg_one: T, zero: T, one: T) -> Result<Matrix<T>, Box<dyn Error>>
fn minors(&self, neg_one: T) -> Result<Matrix<T>, Box<dyn Error>>
fn mul(self, b: Self) -> Result<Matrix<T>, Box<dyn Error>>
fn mul(self, b: T) -> Matrix<T>
fn sub(self, b: Self) -> Result<Matrix<T>, Box<dyn Error>>
A = [-1 2 7 0] Tr(A) = (-1 + 5 + 7 + 0) = 11
[ 3 5 -8 4]
[ 1 2 7 -3]
[ 4 -2 1 0]
fn trace(&self) -> Result<T, Box<dyn Error>>
fn transpose(&self) -> Result<Matrix<T>, Box<dyn Error>>
A = [2 0] A' = [2 1 4]
[1 1] [0 1 3]
[4 3]
MIT License
Copyright Stelar Labs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.