Giter Site home page Giter Site logo

numerology's Introduction

Numerology

A library demonstrating various approaches to developing a faster Nat.

See here for a blog post introduction to the main concept of the repo.

Installation

Releases are available on Maven. Add the following to your build.sbt:

"io.typechecked" %% "numerology" % "<version>"

for the version of your choice. The project is fully tagged and release versions are available to view online.

The Problem

Traditional church-encoded Nat is slow. What alternatives are there?

BNat

Binary-encoded Nat. Significantly faster, and relatively easy for programmers to reason about.

TNat

Ternary-encoded Nat. Significantly faster again. Can reach 10300 whilst performing addition and approx 1040 for multiplication.

It is harder to implement typeclasses for TNat than the alternatives.

MNat

An experiment to see if I could get a Nat specialised for multiplication.

An MNat is formed as an HList of pairs of prime numbers and exponents - the prime factorisation of the number MNat represents.

The theory was that multiplication is then reduced to simple list operations (concat, sort, etc), and it would prove faster than TNat which relies on recursing on Sum.

Unfortunately this was not the case. MNat reaches approx 1020 * 1020 (worst-case integers) before failing. About the square root of TNat's limit.

When paired with the approach in symbology, this encoding would compile primality testing typeclasses in trivial time.

numerology's People

Contributors

jbwheatley avatar jdrphillips avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sangohan

numerology's Issues

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.