Giter Club home page Giter Club logo

mbalgebra's Introduction

MBAlgebra

A programmatic manifestation of the mathematical concepts presented in Mac Lane & Birkhoff 1967.

Excerpts

Peano Naturals

scala> import hzuo.mbalgebra.nat._
import hzuo.mbalgebra.nat._

scala> val specs1 = new Specs(rep1)
specs1: hzuo.mbalgebra.nat.Specs = Prop

scala> specs1.check
+ Nat.Peano1: OK, passed 100 tests.
+ Nat.Peano2: OK, passed 100 tests.
+ Nat.Peano3: OK, passed 100 tests.
+ Nat.pred: OK, passed 100 tests.
+ Nat.add1=add2: OK, passed 100 tests.
+ Nat.multiply1=multiply2: OK, passed 100 tests.
+ Nat.(k^(m+n))=(k^m)*(k^n): OK, passed 100 tests.
+ Nat.k^(m*n)=(k^m)^n: OK, passed 100 tests.
+ Nat.(k^n)*(m^n)=(k*m)^n: OK, passed 100 tests.

scala> val specs2 = new Specs(rep2)
specs2: hzuo.mbalgebra.nat.Specs = Prop

scala> specs2.check
+ Nat.Peano1: OK, passed 100 tests.
+ Nat.Peano2: OK, passed 100 tests.
+ Nat.Peano3: OK, passed 100 tests.
+ Nat.pred: OK, passed 100 tests.
+ Nat.add1=add2: OK, passed 100 tests.
+ Nat.multiply1=multiply2: OK, passed 100 tests.
+ Nat.(k^(m+n))=(k^m)*(k^n): OK, passed 100 tests.
+ Nat.k^(m*n)=(k^m)^n: OK, passed 100 tests.
+ Nat.(k^n)*(m^n)=(k*m)^n: OK, passed 100 tests.

Propositional Logic

scala> import hzuo.mbalgebra.util.PropLogic._, scalaz._, Scalaz._
import hzuo.mbalgebra.util.PropLogic._
import scalaz._
import Scalaz._

scala> val Some(consensusLHS) = ui.from("x * y + !x * z + y * z")
consensusLHS: hzuo.mbalgebra.util.PropLogic.Formula = Or(Or(And(Variable('x),Variable('y)),And(Not(Variable('x)),Variable('z))),And(Variable('y),Variable('z)))

scala> val Some(consensusRHS) = ui.from("x * y + !x * z")
consensusRHS: hzuo.mbalgebra.util.PropLogic.Formula = Or(And(Variable('x),Variable('y)),And(Not(Variable('x)),Variable('z)))

scala> consensusLHS === consensusRHS
res0: Boolean = true

scala> ui.to(dnf(consensusLHS).right.get)
res1: scalaz.Scalaz.Id[String] = x * y * z + x * y * !z + !x * y * z + !x * !y * z

scala> ui.to(dnf(consensusRHS).right.get)
res2: scalaz.Scalaz.Id[String] = x * y * z + x * y * !z + !x * y * z + !x * !y * z

mbalgebra's People

Contributors

hzuo avatar

Watchers

James Cloos avatar  avatar

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.