有理数? [英] Rationals?

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

问题描述

随着小数和int和long的统一,很自然

(对我来说,无论如何),想知道在理性类型中有多少兴趣。

有两个PEP(239和240),Guido拒绝他们没有人

似乎对做这项工作感兴趣,但指出python

发布附带示例/演示/类/ Rat.py.


我建议 - 本着包含电池的精神。 - Rat.py被清理了一些(主要是为了利用整合联盟和

多头)并进入标准库。


有没有这么好的理由呢?


< mike

-

Mike Meyer < mw*@mired.org> http://www.mired.org/home/mwm/

独立的WWW / Perforce / FreeBSD / Unix顾问,电子邮件以获取更多信息。

With the decimals and the unification of int and long coming, it''s natural
(for me, anyway) to wonder how much interest there is in a rational type.
There are two PEPs (239 and 240), and the Guido rejects them as no one
seems interested in doing the work, but points out that the python
distribution comes with examples/Demo/classes/Rat.py.

I propose - in the spirit of "batteries included" - that Rat.py be
cleaned up some (mostly to take advantage of the union of ints and
longs) and moved into the standard library.

Any good reasons not to do this?

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

推荐答案

[Mike Meyer]
[Mike Meyer]
随着小数和int和long的统一,它是自然的(对我来说,无论如何)想知道对于理性类型有多少兴趣。


很自然地想知道< wink> ;.

有两个PEP(239和240),而Guido拒绝它们为
似乎没有人对这项工作感兴趣,但指出
python发行版附带了示例/演示/类/ Rat.py。

我建议 - 本着电池的精神包括" - Rat.py被清理了一些(主要是为了利用整合和
多头)


+0

并移入标准库。


-1

有什么理由不这样做吗?
With the decimals and the unification of int and long coming, it''s
natural (for me, anyway) to wonder how much interest there is in a
rational type.
It is natural to wonder <wink>.
There are two PEPs (239 and 240), and the Guido rejects them as
no one seems interested in doing the work, but points out that the
python distribution comes with examples/Demo/classes/Rat.py.

I propose - in the spirit of "batteries included" - that Rat.py be
cleaned up some (mostly to take advantage of the union of ints and
longs)
+0
and moved into the standard library.
-1
Any good reasons not to do this?




有'没理由不清理它。但Rat.py属于它所在的地方

无论如何:它*是*演示,对于标准的

库来说太棒了。在Python沙箱中有更好的实现:

http://cvs.sf.net/viewcvs.py/python/...dbox/rational/


Moshe现在已经离开了4年前的现在,作为原型的价格是b $ 23。它还远不适合标准库:

PEP是更多的是一个想法而不是规范的草图,PEP

需要被接受,模块需要真实的文档,并且它需要一个测试套件。

需要一个测试套件。


小数PEP:

http://www.python.org/peps/pep-0327.html

可以作为PEP 239的优秀模型。我会注意到

至少一个人一年的工作已进入2.4'的十进制

实现,但即便如此,十进制仍然可能需要几年的时间

与语言完全集成。尽管如此,有几个人给小数点贡献了大部分时间,这预示着它的未来。


漏 - AAA-cells-wasn''t- ;电池包含的''意图 - 你' - 蒂姆


PS:如果你只是想*使用*一个强大的理性类型,
下载gmpy并在今晚开心。



There''s no reason not to clean it up. But Rat.py belongs where it is
regardless: it *is* "a demo", too half-baked for the standard
library. There''s a better implementation in the Python sandbox:

http://cvs.sf.net/viewcvs.py/python/...dbox/rational/

Moshe left that behind going on 4 years ago now, as a prototype for
PEP 239. It''s also far from being suitable for the standard library:
the PEP is more a sketch of an idea than a specification, the PEP
needs to be accepted, the module needs real documentation, and it
needs a test suite.

The decimal PEP:

http://www.python.org/peps/pep-0327.html

can serve as a good model for what PEP 239 should be. I''ll note that
at least a person-year of work has gone into 2.4''s decimal
implementation, but even so decimal is still likely years away from
full integration with the language. Nevertheless, several people
contributed major time to decimal, and that bodes well for its future.

leaky-AAA-cells-wasn''t-"batteries-included"''s-intent-ly y''rs - tim

PS: If you simply want to *use* a high-powered rational type,
download gmpy and be happy tonight.




Mike Meyer< mw*@mired.org>写道:

Mike Meyer <mw*@mired.org> wrote:

随着小数和int和long的统一,很自然
(对我来说,无论如何)想知道有多少兴趣理性类型。
有两个PEP(239和240),Guido拒绝它们,因为没有人似乎对这项工作感兴趣,但指出python
发行版附带的例子/Demo/classes/Rat.py。

我建议 - 本着包含电池的精神。 - 将Rat.py清理干净(主要是为了利用整合和长度的结合)并移入标准库。

任何好的理由都不要这样做?

With the decimals and the unification of int and long coming, it''s natural
(for me, anyway) to wonder how much interest there is in a rational type.
There are two PEPs (239 and 240), and the Guido rejects them as no one
seems interested in doing the work, but points out that the python
distribution comes with examples/Demo/classes/Rat.py.

I propose - in the spirit of "batteries included" - that Rat.py be
cleaned up some (mostly to take advantage of the union of ints and
longs) and moved into the standard library.

Any good reasons not to do this?




更新PEP,完成工作,并提供一个很好的有理数字对象(如果你有兴趣这么做)。我个人至少写了两个不同的理性课程,而且我知道至少有3个人知道他们的b $ b(虽然我不记得他们的名字)。 />

如果是用Python实现的话;远离二进制GCD算法,

Euclid'更快。


- Josiah



Update the PEP, do the work, and offer a good rational number object (if
you are interested in doing such). I have personally written at least
two different rational classes, and I am aware of at least 3 others
(though I can''t remember their names).

If it is implemented in Python; stay away from the binary GCD algorithm,
Euclid''s is faster.

- Josiah


2004年11月17日星期三19:47:27 -0800,Josiah Carlson< jc ****** @ uci.edu>写道:
On Wed, 17 Nov 2004 19:47:27 -0800, Josiah Carlson <jc******@uci.edu> wrote:

Mike Meyer< mw*@mired.org>写道:

Mike Meyer <mw*@mired.org> wrote:

随着小数和int和long的统一,很自然
(对我来说,无论如何)想知道有多少兴趣理性类型。
有两个PEP(239和240),Guido拒绝它们,因为没有人似乎对这项工作感兴趣,但指出python
发行版附带的例子/Demo/classes/Rat.py。

我建议 - 本着包含电池的精神。 - 将Rat.py清理干净(主要是为了利用整合和长度的结合)并移入标准库。

任何好的理由都不要这样做?

With the decimals and the unification of int and long coming, it''s natural
(for me, anyway) to wonder how much interest there is in a rational type.
There are two PEPs (239 and 240), and the Guido rejects them as no one
seems interested in doing the work, but points out that the python
distribution comes with examples/Demo/classes/Rat.py.

I propose - in the spirit of "batteries included" - that Rat.py be
cleaned up some (mostly to take advantage of the union of ints and
longs) and moved into the standard library.

Any good reasons not to do this?



更新PEP,完成工作,并提供一个合理的数字对象(如果你有兴趣这样做)。我至少亲自写了两个不同的理性课程,而且我至少知道其他3个理由课程(虽然我不记得他们的名字)。

如果是的话是用Python实现的;远离二进制GCD算法,欧几里德的速度更快。



Update the PEP, do the work, and offer a good rational number object (if
you are interested in doing such). I have personally written at least
two different rational classes, and I am aware of at least 3 others
(though I can''t remember their names).

If it is implemented in Python; stay away from the binary GCD algorithm,
Euclid''s is faster.



我只是在演示中看过Rat.py,我想知道浮点数为何

包括在内。 IMO的理性应该是准确的,除非你定义

你希望浮点值代表什么样的确切值(例如,

所有可用位,或者某些舍入规范)你没有办法

来做一个完全理性的。有多头没有合法的浮点数双b / b $ b数,其价值不能完全表示为理性,所以除了决定之外没有

问题。同样,任何浮点字符串文字都可以精确转换,例如''123.4e-5''=>大鼠(1234,1000000)等,我认为

可以派上用场。顺便说一下,IIRC复合体是用浮点对严格实现的,因为这看起来并不令人满意,除非使用

理性对实现一个新的复杂类。否则我会说离开复杂。


显然分数幂可以产生非理性结果,所以如果你想处理就会造成设计问题他们都是。


无论如何,我是唯一一个认为理性应该准确的人吗?


问候,

Bengt Richter


I just looked at Rat.py in the demos, and I am wondering why floating point
is at all included. IMO rationals should be exact, and unless you define
what exact value you would like to have a floating point value represent (e.g.,
all available bits, or some rounding specification) you don''t have a way
to make an exact rational. With longs there is no legal floating point double
number whose value can''t be represented exactly as a rational, so there''s no
problem except deciding. Likewise any floating point string literal can be
converted exactly, e.g., ''123.4e-5'' => Rat(1234, 1000000) etc., which I think
can be handy. BTW, IIRC complex is implemented strictly with floating point pairs,
so that doesn''t seem satisfactory, unless a new complex class is implemented using
rational pairs. Otherwise I''d say leave complex out.

Obviously fractional powers can produce non-rational results, so that poses
a design problem if you want to handle them at all.

Anyway, am I the only one who thinks that rational should be exact?

Regards,
Bengt Richter


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

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