log-exp-solidity – 对数经验强度区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,log-exp-solidity – 对数经验强度区块链毕设代写 是一篇很好的国外资料

log-exp-solidity

Ethereum library for logarithm and exponential functions with 18 decimal precision.

Overview

This library provides math functions for natural logarithm and exponentiation, as well as logarithm and exponentiation for general positive bases. It implements low gas cost solutions, while returning low relative errors when possible.

Functions

For all of the following inputs and outputs, the last 18 decimal digits are interpreted as the fractional part of a real number.

  • Natural exponentiation

function n_exp(int256 x) public pure returns (int256)

Computes exp(x). The input must be between -41.446531673892822312 and 130.700829182905140221.

  • Natural logarithm

function n_log(int256 a) public pure returns (int256)

Computes ln(a). The input must be positive.

  • General exponentiation

function exp(int256 x, int256 y) public pure returns (int256)

Computes x to the power of y. The input x must be positive and log(x)y, interpreted as real numbers, must be between -41.446531673892822312 and 130.700829182905140221.

  • General logarithm

function log(int256 base, int256 arg) public returns (int256)

Computes the logarithm of arg for the input base. Both inputs must be positive.

The algorithms

  • Natural exponentiation

For negative inputs, it returns the inverse of n_exp(-x). For positive inputs, the algorithm has two stages. On a first stage it progressively reduces the input making use of the property exp(x+w) = exp(x)exp(w). To do it efficiently, we think of x as a sum of powers of 2, and progressively multiply the answer variable by the corresponding precomputed numbers exp(power of 2) from high to low. On the second stage, the resulting x variable is now small enough so that a Taylor expansion converges rapidly.

  • Natural logarithm

The algorithm is very similar to the one used for natural exponentiation. For arguments less than 1, it returns minus the result for the multiplicative inverse. For greater than 1 arguments, it has two stages analogous to those in n_exp. For the second stage, we use the Taylor expansion of Log((1+z)/(1-z)), and the change of variables z = (a-1) / (a+1).

  • General exponentiation

It computes x^y as exp(log(x)y). To do so, it is important that log(x) has low computational relative error. Thus, if x is close to 1 it internally computes log(x) with more than 18 digits of precision after the decimal point.

  • General logarithm

It computes log_base(arg) as log(arg)/log(base). To do so, it is important that both log(arg) and log(base) have low computational relative error. Thus, whenever one argument is close to 1, it internally computes the log with more than 18 digits of precision after the decimal point.

Error

For each function, we give an upper bound for the relative error, defined as |(computed result) / (real result) – 1|. However this upper bound does not necessarily hold when the real results are so small that it may be impossible to achieve such a relative error using only 18 digits for the fractional part. In these cases, the library shows the exact digits of the decimal expansion, with only a rounding error in the last digit.

Maximum relative errors for each function (up to the exception above)

n-exp 10^(-17) n-log 10^(-17) exp log

Note: since this library is optimized for real values, it is possible that the result of an exponentiation between two natural numbers is not a natural number.

Gas profiling

Natural Exponential n_exp(x)

min: 1280 gas

max: 2071 gas

Natural Logarithm n_log(x)

min: 883 gas

max: 1333 gas

Exponential exp(x,y)

min: 2523 gas

max: 3232 gas

Logarithm log(x,y)

min: 2032 gas

max: 2844 gas


对数经验密度

具有指数精度和18以太坊eth精度的对数函数库。

概述

这个库提供自然对数和求幂的数学函数,以及一般正基的对数和求幂函数。它实现了低成本的解决方案,同时尽可能返回较低的相对误差。

算法

对于以下所有输入和输出,最后18位小数被解释为实数的小数部分。

  • 自然指数

函数n_exp(int256 x)公共纯返回(int256)

计算exp(x)。输入必须介于-41.446531673892822312和130.700829182905140221之间。

  • 自然对数

函数n_log(int256 a)公共纯返回(int256)

计算ln(a)。输入必须为正。

  • 指数

函数exp(int256 x,int256 y)public pure returns(int256)

将x计算为y的幂。输入x必须是正的,并且log(x)y(解释为实数)必须介于-41.446531673892822312和130.700829182905140221之间。

  • 自然对数

函数log(int256 base,int256 arg)public returns(int256)

计算输入基数的arg的对数。两个输入都必须为正。

误差

  • 一般指数

对于负输入,它返回n_exp(-x)的倒数。对于正输入,该算法有两个阶段。在第一阶段,它利用exp(x+w)=exp(x)exp(w)属性逐步减少输入。为了有效地实现这一点,我们将x看作是2的幂和,并从高到低将答案变量乘以相应的预计算数exp(2的幂)。在第二阶段,得到的x变量现在足够小,所以泰勒展开式会迅速收敛。

  • 一般对数

该算法与用于自然求幂的算法非常相似。对于小于1的参数,它返回负的乘法逆结果。对于大于1的自变量,它有两个类似于n_exp的阶段,对于第二阶段,我们使用Log((1+z)/(1-z))的泰勒展开,以及变量z=(a-1)/(a+1)的变化。

  • General exponentiation

它将x^y计算为exp(log(x)y)。为此,重要的是log(x)具有较低的计算相对误差。因此,如果x接近1,它在内部计算log(x),精度在小数点后超过18位。

  • General logarithm

它将log_base(arg)计算为log(arg)/log(base)。为此,重要的是log(arg)和log(base)都具有较低的计算相对误差。因此,每当一个参数接近1时,它在内部计算小数点后精度超过18位的日志。

Error

对于每个函数,我们给出相对误差的上界,定义为|(计算结果)/(实际结果)-1 |。然而,当实际结果非常小,以至于仅使用18位数字作为小数部分可能不可能达到这样的相对误差时,这个上限并不一定成立。在这些情况下,库会显示十进制展开的精确位数,最后一位只有舍入错误。

每个函数的最大相对误差(以上例外情况除外)

n-exp 10^(-17)n-log 10^(-17)exp log

注意:由于此库针对实际值进行了优化,因此两个自然数之间的求幂结果可能不是自然数。

Gas profiling

天然气指数n经验(x)

最小值:1280气体

最大值:2071气体

自然对数n_对数(x)

最小值:883气体

最大值:1333气体

指数扩展(x,y)

最小值:2523气体

最大值:3232气体

对数对数(x,y)

最小值:2032气体

最大值:2844气体

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/16632.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » log-exp-solidity – 对数经验强度区块链毕设代写

提供最优质的资源集合

立即查看 了解详情