Giter Club home page Giter Club logo

arithmetic-operations-for / naturals-big-endian Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 7.42 MB

:elephant: Arbitrary precision arithmetic for integers in big-endian order for JavaScript

Home Page: https://arithmetic-operations-for.github.io/naturals-big-endian

License: GNU Affero General Public License v3.0

JavaScript 99.36% Shell 0.64%
agpl algorithms arithmetic base-conversion big-endian biginteger divide-and-conquer divide-and-conquer-division euclidean-algorithm exponentiation-by-squaring extended-euclidean-algorithm integer javascript karatsuba-multiplication

naturals-big-endian's People

Contributors

a-flying-potato avatar greenkeeper[bot] avatar greenkeeperio-bot avatar make-github-pseudonymous-again avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar

naturals-big-endian's Issues

Getting _imul_limb is not defined in _dc_div with large numbers

With the current implementation of @aureooms/js-integer.

x = ZZ.from(1); for ( let i = 1 ; i <= 10000 ; ++i ) x = x.mul( ZZ.from(i) ) ;
> x.div(x).toString()
ReferenceError: _imul_limb is not defined
    at _dc_div (/home/aureooms/dev/js/algorithms/arithmetic/js-integer/node_modules/@aureooms/js-integer-big-endian/lib/1-new/arithmetic/div/_dc_div.js:65:3)
    at _div (/home/aureooms/dev/js/algorithms/arithmetic/js-integer/node_modules/@aureooms/js-integer-big-endian/lib/2-api/_div.js:22:27)
    at Integer.divmod (/home/aureooms/dev/js/algorithms/arithmetic/js-integer/lib/Integer.js:145:33)
    at Integer.div (/home/aureooms/dev/js/algorithms/arithmetic/js-integer/lib/Integer.js:120:16)
    at repl:1:3
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:336:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:533:10)

Implement _complement

Compute the result of [1, 0, 0, 0] - [ x , y , z ] = increment_with_wrap([ r-1-x , r-1-y , r-1-z ]).

radix change

e.g. bit to digit (log is base 10 log)

N = number of bits
X = number of digits

2^n = 10^x
log(2^n) = x
n * log(2) = x
X = log(2)*n
X = n * ln(2)/ln(10)

Squaring

Karatsuba's algorithm can be simplified for squaring.

(A1 * b + A0)^2 = A1^2 b^2 + 2 A1 A0 b + A0^2

Which yields three multiplications of half the size without any complicated rearrangement. Two of the recursive multiplications are squares. The multiplication by 2 is a limb multiplication (or a shift in base 2) Constant factors should be smaller because of all that.

implement gcd algorithms

knuth's and euclid's, e.g.

  1. repeat until a = 0
    a, b = abs( a − b ), min( a, b )
    strip factors of 2 from a

  2. repeat until a = 0
    a, b = abs( a − b ), min( a, b )
    a = a / 2 if even
    b = b / 2 if even

  3. function gcd( a, b )
    if b = 0
    return a
    else
    return gcd( b, a mod b )

  4. function gcd( a, b )
    while b ≠ 0
    t = b
    b = a mod b
    a = t
    return a

  5. function gcd( a, b )
    repeat
    if a = 0
    return b
    b = a mod b
    if b = 0
    return a
    a = b mod a

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

implement signed division

simply convert r's complement -> divide -> convert r's complement should work (where r is the radix)

division algorithm quotient size

Find an elegant way to allow truncated quotients (i.e. |C| < |A|), currently all algorithms require that |A| = |C| where A is the dividend/remainder and C is the quotient. This would allow to avoid a lot of memory allocation and back and fort copying.

Explore faster implementation for _convert_slow

CLRS mentions a divide and conquer approach to convert from radix a to radix b:

  • split number x in two halves y and z such that x = y * a^n + z.
  • compute base b representations Y and Z of each half recursively.
  • return Y * a^n + Z with one multiplication, one addition, and a repeated squaring to obtain a^n in base b.

multiplication algorithms are not well tested

Should add random 27 x 27 bits operands on byte arrays tests for mul and karatusba. Could extend to other operations like add or div.

the goal is to have the correct answer on 53 bits using byte arrays (UInt8Array).

Fast conversion

Conversion can still be fast when bases have a common power. A bit of shifting needs to be done but this is pretty similar to the fast conversion methods already implemented.

An in-range update of @aureooms/js-itertools is breaking the build 🚨

Version 3.1.1 of @aureooms/js-itertools just got published.

Branch Build failing 🚨
Dependency @aureooms/js-itertools
Current Version
</td>
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @aureooms/js-itertools is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Optimize multiplication recursive fallthrough.

Add a wrapper method for each recursive multiplication method, e.g:

function _mullarge ( ... ) {
    if input is large : _karatsuba ( ... ) ;
    else : _mulsmall ( ... ) ;
}
etc...

That way we avoid redundant size tests since operands size decreases at each step.

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.