Giter Club home page Giter Club logo

solcdf's Introduction

๐Ÿ”Ž solcdf

Approximation of the cumulative distribution function (cdf) for arbitrary 18 decimal fixed point parameters x, ฮผ, ฯƒ and a target absolute error of 1e-8.

๐Ÿงช Methodology

The complementary error function (erfc) is approximated rationally using a variant from the algorithm presented in this paper. The rational polynomial is composed of a polynomial of degree 11 as numerator, and a polynomial of degree 4 as denominator.

The coefficients of the rational polynomial are scaled by a factor of 2^96 and then codified as part of the erfc function. This scaling allows for the use of cheaper sar (shift arithmetic right) operations instead of more expensive sdiv (signed division) operations (former costs 3 gas, while latter 5). Additionally, this function always returns 0 when the input is more than 4.0523 as the maximum absolute error would not surpass the target error.

The erfc and cdf functions are differentially fuzzed against Python and Javascript implementations to ensure that they provide an absolute error of less than 1e-8. These functions are also benchmarked against solstat, gud-cdf, and solidity-cdf. It's important to note that the benchmark does not verify the precision of these external libraries, such as solidity-cdf, which has an error of more than 1e-8.

โ›ฝ Gas Benchmarks

Function min avg median max calls
cdf (solcdf) 562 657 562 876 256
cdf (solidity-cdf) 540 671 540 962 256
cdf (gud-cdf) 781 815 781 917 256
cdf (solstat) 938 4279 5159 5159 256

To run the gas benchmark: forge t --gas-report

โœ… Tests

Run the following for the dependencies used in the (differential) tests:

Python

  1. python -m venv venv && source venv/bin/activate
  2. pip install mpmath

Javascript

  1. (cd differential && yarn)

To run the tests: forge t

๐Ÿ‘‡ Acknowledgements

This repository is inspired by or directly modified from many sources, primarily:

solcdf's People

Contributors

cairoeth avatar

Watchers

 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.