GithubHelp home page GithubHelp logo

vlad9486 / un-algebra Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 39 KB

This repository is a mirror of https://gitlab.com/ornamentist/un-algebra. Please refer to that repository for PR's.

License: MIT License

Makefile 0.60% Rust 99.40%

un-algebra's Introduction

un_algebra

crate link documentation rustc version license

Simple Rust implementations of selected abstract algebraic structures.

Synopsis

Mathematical abstract algebra is built on a rich collection of algebraic structures. Learning about these structures can give non-mathematicians insights into the mathematical entities they need to work with--for example, real numbers, complex numbers, vectors, matrices, and permutations. By definition, these structures must comply with sets of axioms and properties, which are in turn a rich source of properties for generative testing.

un_algebra (_un_derstanding _algebra_) is a simple implementation of selected algebraic structures in Rust. I hope it is useful for developers learning abstract algebra concepts for the first time. Currently this crate provides magma, semigroup, monoid, group, ring and field implementations.

Documentation

See https://docs.rs/un_algebra

Contributions

Please refer to the contributing guide.

Installation

Add un_algebra to your Cargo.toml dependencies:

[dependencies]
un_algebra = "0.1.0"

Add a reference to un_algebra to your crate root:

extern crate un_algebra;

Production use

un_algebra is intended to support self-study of abstract algebraic structures--it is not optimized for use in a production environment. For production environments I recommend using a more sophisticated library like alga.

Compatibility

un_algebra currently requires Rust nightly as it makes use of the (experimental) external documentation feature.

Errors

I'm not a mathematician so my implementation of the various structures and their respective axioms in un_algebra may not be strictly correct. Please let me know of any errors.

Examples

un_algebra implements the relevant structure traits for all the Rust standard library integer and floating point numeric types, for example, an additive group for integer types i8, i16, i32, etc.

The Rust standard library has no support for complex numbers (โ„‚) or rational numbers (โ„š) so I've used the complex and rational types from the [num] crate and implemented the conforming traits in the [complex] and [rational] modules.

In addition, the crate examples directory contains abstract structure implementations of selected concepts, for example, finite fields.

Example

Rust's planned i128 type forms several un_algebra algebraic structures, starting with additive and multiplicative magmas (with "wrapping" or modular arithmetic):

pub use un_algebra::prelude::*;

impl AddMagma for i128 {
  fn add(&self, other: &Self) -> Self {
    self.wrapping_add(other)
  }
}

impl MulMagma for i128 {
  fn mul(&self, other: &Self) -> Self {
    self.wrapping_mul(other)
  }
}

i128 also forms additive and multiplicative semigroups:

impl AddSemigroup for i128 {}

impl MulSemigroup for i128 {}

And additive and multiplicative monoids with one and zero as the monoid identities:

impl AddMonoid for i128 {
  fn zero() -> Self {
    0
  }
}

impl MulMonoid for i128 {
  fn one() -> Self {
    1
  }
}

i128 also forms an additive group and additive commutative group (with "wrapping" or modular negation), but not a multiplicative group, as the integers have no closed division operation:

impl AddGroup for i128 {
  fn negate(&self) -> Self {
    self.wrapping_neg()
  }
}

impl AddComGroup for i128 {}

And a ring and commutative ring:

impl Ring for i128 {}

impl CommRing for i128 {}

References

Please refer to the reading document for more background on each structure and its associated axioms and properties.

To-Do

  • Research other two-operation structures like semirings, division rings, and integral domains. Adding these might make the transition from groups up to fields more granular?

  • Research structures that build on or reference, fields, for example modules or vector spaces.

  • The field traits probably need more testable derived properties.

  • Find more interesting examples for the examples directory.

  • Find a better method for embedding mathematical expressions in automatically generated Rust documentation.

License

This project is licensed under the MIT license (see LICENSE.txt or https://opensource.org/licenses/MIT).

un-algebra's People

Contributors

ornamentist avatar vlad9486 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

wisemrmusa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.