Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from ujihisa/gist:160767
Created August 3, 2009 20:06
Show Gist options
  • Save tenderlove/160802 to your computer and use it in GitHub Desktop.
Save tenderlove/160802 to your computer and use it in GitHub Desktop.
SUBJECT: About An Imaginary Number Literal (Translation)
This post is the summary of a recent discussion in [ruby-dev] about imaginary numbers.
In [ruby-dev:38843] 複素数リテラルについて http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/38843 ,
Matz suggested introducing an imaginary number literal to ruby. After his new patch is applied, we can use the following syntax:
2i
2.0i
He also showed some issues about:
* Backward compatibility
* Is i OK? (In python it's j)
* Is Numeric#i needed for imaginarization?
* If it is needed, what's the value of (an imaginary number).i or (a complex number).i ?
The discussions about the topic are outlines below.
* Numeric#i should be equivalent to Complex(0, self)
* i is better because it's more popular than j
* It is confusing to introduce both i and j because of quatenion's i, j and k
* Numeric#i should be one of them: (1) 2.0i == 2.0.i (2) returns the imaginary part (3) represents as a complex number like 2.0.i #=> 2.0 + 0i; (1) is the best
* Is Numeric#i really needed? We can write s.i as s * 1i
* The fact 1/3i in Ruby becomes (-1/3)i in Mathematics is confusing
* Actually once Numeric#i was proposed and reject on 1.9.1
* Is the literal really needed? What's the use case? Is it general enough?
* What about an "imaginariztion syntax" like 1+(2)i, 1+(n)i or 1+3#i
* Good literals matter
* Only in IRC is better or worse
* How about introducing Math::I (1 + n * Math::I)
* Complex::I already exists
* Programming language J describes 1+3i as 1j3
* Matz supposes there must be someone who use complex numbers often
* Matz supposes this topic was for 2.0, but may make in on 1.9.2
* 1+2i is too dissimilar to Complex(1, n). "1+(2)i and 1+(n)i" is better.
* "1+2i and 1+n.i" is better
* "1+2.i and 1+n.i" is better for less rules
* How about introducing this syntactic sugar: 2xxx is equivalent to 2 * Math::XXX
* Imaginary numbers and Complex numbers are fundamentally different, so 1+2i should be Complex(1, 2) rather than 1.+(Complex(0, 2))
* see also: C++0x current draft has User-defined literals
* How about 2i #=> 2.literal_i, 3/2r #=> 3 / 2.literal_r, 5C3 #=> 5.literal_C(3)
* It is useful to apply within a classbox
Although this discussion isn't concluded, there have been no new posts for 11 days.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment