abstract_dart

extra_pedantic on pub.dev Travis CI Codecov License Pub.dev Github Stars Twitter Follow GitHub Follow

A collection of algebraic structures borrowed from abstract algebra. Semigroup, Monoid, Group, Field, and more.

Example:

/// Create a semigroup
final semigroup = Semigroup_.create<double>((a, b) => a + b);

/// Create a monoid
final monoid = Monoid_.create<double>(() => 0.0, (a, b) => a + b);

/// Create a group
final group =
    Group_.create<double>(() => 0.0, (a, b) => a + b, (a, b) => a - b);

/// Create a field
final field = Field_.create<double>(
  Group_.create<double>(() => 0.0, (a, b) => a + b, (a, b) => a - b),
  Group_.create<double>(() => 1.0, (a, b) => a * b, (a, b) => a / b),
);

/// Monoids
const bigIntSumMonoid = BigIntSumMonoid();
const bigIntProductMonoid = BigIntProductMonoid();
const decimalSumMonoid = DecimalSumMonoid();
const decimalProductMonoid = DecimalProductMonoid();
const stringConcatMonoid = StringConcatMonoid();
const numSumMonoid = NumSumMonoid();
const numProductMonoid = NumProductMonoid();
const intSumMonoid = IntSumMonoid();
const intProductMonoid = IntProductMonoid();
const doubleSumMonoid = DoubleSumMonoid();
const doubleProductMonoid = DoubleProductMonoid();

/// Groups
const bigIntSumGroup = BigIntSumGroup();
const decimalSumGroup = DecimalSumGroup();
const decimalProductGroup = DecimalProductGroup();
const doubleProductGroup = DoubleProductGroup();
const doubleSumGroup = DoubleSumGroup();
const numProductGroup = NumProductGroup();
const numSumGroup = NumSumGroup();

/// Fields
const decimalField = DecimalField();
const doubleField = DoubleField();
const numField = NumField();

Semigroup_<A>

  • An operation of type A+A => A

Monoid_<A> (a Semigroup_<A>)

  • An operation of type A+A => A
  • An identity element so that a+e = a

Group_<A> (a Monoid_<A>, a Semigroup_<A>)

  • An operation of type A+A => A
  • An inverse operation of type A-A => A
  • An identity element so that a+e = a

Field_<A>

ScalarMonoid_<K, F>

  • An operation of type K•F => K
  • An identity element so that K•e = K

VectorSpace_<K, F>

  • A Group (addition)
  • A ScalarMonoid<K, F> (scalar multiplication)

Algebra_<K, F> (a VectorSpace_<K, F>, a Field_<K>)

  • A Group (addition)
  • A Group (multiplication)
  • A ScalarMonoid<K, F> (scalar multiplication)

abstract_dart does not enforce any of the properties that these structures require in a mathematical setting.

Libraries

abstract_dart