测试方程不合理 [英] Test for equation irrational

查看:74
本文介绍了测试方程不合理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行数字数据淋浴,显示数字的数据,如偶数或奇数。
现在我停止了无理数,我该如何测试呢?

I'm making a number data shower, which show the data of a number, like even or odd. Now I stopped at irrational numbers, how can I test for is it that?

这样的事情:

alert(isIrrational(Math.sqrt(9)));


推荐答案

这取决于上下文,但你可能想要说非常接近简单有理数的浮点数应该被认为是合理的,否则它们应该被识别为可能的无理数。您必须选择非常接近和简单有理数的定义。

It depends on the context, but you might want to say that floating point numbers that are very close to simple rational numbers should be identified as rational, and otherwise they should be identified as possible irrational numbers. You have to choose definitions for "very close" and "simple rational numbers."

对于相对较小的数字(比如100以下的绝对值),你可能会说简单的有理数是具有小分母的数字,例如2/3,说那些100以下的分母。你对非常接近的定义可能是差异的绝对大小很小,比如10 ^ -6以下,或者你可能要求数字接近分母平方的1000倍。对于大多数目的而言,这已经足够了。

For relatively small numbers (say absolute value under 100), you might say that the simple rational numbers are those with small denominators, such as 2/3, say those with denominators under 100. Your definition of "very close" might be that the absolute magnitude of the difference is small, say under 10^-6, or you might require numbers to be closer than 1000 times the square the of denominator. For most purposes, this is enough.

对具有小分母的数的有理逼近理论是称为丢番图近似的数论的一部分。您可能使用的一个工具是简单连续分数扩展数字,例如
pi = 3 + 1 /(7 + 1 /(15 + 1 /(1 + 1/292 + ...))) e -1 = 1 + 1 /(1 + 1 /(2 + 1 /(1 + 1 /(1 + 1 /(4 + 1 /(1 + 1 /(1 + 1 /(6 + ...)) )。你可以递归计算这些,虽然你的精确度很快就会耗尽。当你截断这样的表达式时,你得到一个很好的有理逼近,比如pi~3,或pi~22 / 7,pi 〜355/113,或e~193 / 71。这些给出了具有较小分母的候选有理数。简单连续分数中的大系数意味着该数具有良好的有理逼近。

The theory of rational approximations to a number with small denominators is part of number theory called Diophantine approximation. One tool you might use is the simple continued fraction expansion of a number, such as pi = 3+1/(7+1/(15+1/(1+1/292+...))) and e-1=1+1/(1+1/(2+1/(1+1/(1+1/(4+1/(1+1/(1+1/(6+...))). You can compute these recursively although you run out of precision quickly. When you truncate such an expression, you get a good rational approximation, such as pi~3, or pi~22/7, pi~355/113, or e~193/71. These give the candidate rational numbers with small denominators which are close. Large coefficients in the simple continued fraction mean the number has a good rational approximation.

一些有理数不会被检测为合理的,例如,如果你使用100的阈值作为分母,则为1/500。但是,你可以将1 / 3.0f识别为理性,和Math.sqrt(2.0)* Math.sqrt(8.0),你会拒绝Math.sqrt(2.0)。

Some rational numbers will not be detected to be rational this way, such as 1/500 if you use a threshold of 100 for the denominator. However, you would be able to identify 1/3.0f as rational, and Math.sqrt(2.0)*Math.sqrt(8.0), which you would reject Math.sqrt(2.0).

我不知道我f有一种标准方法可以确定像6.73241 x 10 ^ 31这样的大浮点数的复杂性。这甚至可能是一个整数,但你没有精确的说法。您可能会说接近平滑整数的数字很简单。平滑意味着素数因子分解中没有大质数。虽然通常很难分解大数字,但考虑平滑数字并不是那么糟糕,因为你只需要测试几个可能的素因子。如果你甚至无法测试附近数字的平滑度,你可以将数字的对数与小素数的对数组合进行比较。这可能意味着大质数不会被识别为有理数,但如果您关心,记录设置素数通常距离平滑数字1,例如2 ** 57885161-1。

I don't know if there is a standard way to determine the complexity of a large float like 6.73241 x 10^31. That could even be an integer, but you don't have the precision to tell. You might say that numbers close to smooth integers are simple. Smooth means that there are no large primes in the prime factorization. While factoring large numbers in general is hard, factoring smooth numbers is not so bad because you only have to test a few possible prime factors. When you can't even test nearby numbers for smoothness, you might compare the logarithm of the number with combinations of the logarithms of small primes. This might mean that a large prime would not be identified as a rational number, but in case you care, record-setting prime numbers are typically 1 away from smooth numbers, e.g., 2**57885161-1.

在极大的浮点数和小数之间,你可能会使用某种复杂性度量,它结合了可能的分子的简单性和可能的​​分母的简单性。 。因此,对于10 ^ 6到10 ^ 9之间的数字,您可能会认为您只能容忍最多10个分母,并且您可能要求这些数字之一的差值小于10 ^ -4。

Between extremely large floating point numbers and decimals, you might use some sort of complexity measure which uses a combination of the simplicity of the possible numerators and the simplicity of the possible denominators. So, for numbers between 10^6 and 10^9, you might decide that you only tolerate denominators up to 10, and you might require that the difference be smaller than 10^-4 from one of these numbers.

这篇关于测试方程不合理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆