program story

카운터에 변수 "i"및 "j"가 사용되는 이유는 무엇입니까?

inputbox 2020. 9. 4. 07:22
반응형

카운터에 변수 "i"및 "j"가 사용되는 이유는 무엇입니까?


나는 이것이 물어보기에는 절대적으로 어리석은 질문처럼 보일 수 있다는 것을 알고 있지만 묻지 않기에는 너무 궁금합니다.

"i"와 "j"가 대부분의 제어 구조에서 카운터로 사용되는 변수가 된 이유는 무엇입니까?

상식적으로 알 수없는 값을 나타내는 데 사용되는 X와 똑같다고하지만 모든 사람이 같은 방식으로 계속해서 배우는 이유가있을 것 같다고 생각할 수 없습니다.

실제로 모범 사례 또는 규칙에 권장되기 때문입니까, 아니면 그 뒤에 모호한 이유가 있습니까?

이런 경우에, 내가 원하는 그 변수 이름은 관련이없는 어떤 이름을 내가 그들에게 줄 수있는 것을 알고있다.


그것은 수학에서 궁극적으로 온다 : 요약 표기법은 전통적으로 사용하는 난을 첫 번째 인덱스에 대한 J 번째에, 등등. 예 ( http://en.wikipedia.org/wiki/Summation에서 ) :

\ sum_ {i = 1} ^ {n} i = \ frac {n ^ 2 + n} {2}

또한 변수 x 1 , x 2 , ... x n 이있는 경우 임의 의 변수 가 x i 로 알려지는 것과 같이 사물 모음에 대해 그렇게 사용됩니다 .

왜 그런지에 관해서는 SLaks가 정확하다고 생각하며 Index의 첫 글자이기 때문입니다.


나는 그것이 Fortran으로 거슬러 올라간다고 믿습니다. I부터 Q로 시작하는 변수는 기본적으로 정수 였고 나머지는 실수였습니다. 이것은 그것이 I첫 번째 정수 변수이고 J두 번째 변수 라는 것을 의미 하므로 루프에서 사용됩니다.


수학자들은 컴퓨터가 주변에 있기 훨씬 전에 (예 : 1836 또는 1816 ) 대수 (아래 첨자, 시리즈, 합계 등)에서 정수를 지정하기 위해 i, j, k를 사용했습니다 (이것이 FORTRAN 변수 유형 기본값의 기원입니다). 알파벳의 끝에서 문자를 사용하는 습관이 (..., X, Y, Z)에 대한 미지의 상수와 변수 시작 (A, B, C, ...)로부터는 통상 기인데카르트 (참고 또한 여기에 ) 나는 가정하므로, J, K는 ... N (정수의 알파벳의 중간)에 너무 때문에 그 가능성이 높습니다.


i = 정수

정수 변수는 I부터 N까지의 문자로 시작해야하고 실제 변수는 다른 문자로 시작해야하는 Fortran에서 왔습니다. 따라서 나는 첫 번째이자 가장 짧은 정수 변수 이름이었습니다. Fortran은 널리 사용되는 가장 초기의 프로그래밍 언어 중 하나였으며이를 사용하는 프로그래머가 개발 한 습관은 다른 언어로 이전되었습니다.

편집 : 수학에서 파생 된 답에 문제가 없습니다. 의심 할 여지없이 Fortran 디자이너가 영감을 얻은 곳입니다. 사실은 제가 Fortran에서 프로그래밍을 시작했을 때 I, J, K, ...를 루프 카운터로 사용했습니다. 왜냐하면 그것들은 짧고 합법적으로 정수에 대해 처음으로 허용 된 변수 이름 이었기 때문입니다. 고등부 2 학년 때 나는 아마도 데카르트 (그리고 아주 소수의 다른 사람들)에 대해 들어 보았지만 프로그래밍 할 때 수학과는 거의 연관이 없었다. 사실, 제가 수강 한 첫 번째 과정은 "Fortran for Business"였으며 수학 교수가 아닌 비즈니스 / 경제 교수가 가르쳤습니다.

나에게 적어도 변수 이름 지정은 수학과는 거의 관련이 없었지만 모든 것은 내가 포트란 코드를 작성하면서 배운 습관으로 인해 다른 언어로 옮겨졌습니다.


iI ndex를 의미합니다 .
j뒤에옵니다 i.


이 기호는 전자 컴퓨터가 발명되기 훨씬 전에 수학에서 행렬 색인으로 사용되었습니다.


나는 그것이 ( 수학적 의미에서 ) 색인에서 파생되었을 가능성이 가장 높다고 생각합니다 . 합계 또는 기타 집합 기반 연산의 색인으로 일반적으로 사용되며 프로그래밍 언어가 있기 전부터 그런 방식으로 사용되었을 가능성이 큽니다.


유사한 방식으로 사용되는 "익명"변수에 대해 알파벳의 연속 문자를 사용하는 것이 수학에서 선호됩니다. 따라서 "i, j, k"뿐만 아니라 "f, g, h", "p, q, r", "x, y, z"(드물게 "u, v, w"가 앞에 추가됨), 및 "α, β, γ".

이제 "f, g, h"및 "x, y, z"는 자유롭게 사용되지 않습니다. 전자는 함수용이고 후자는 차원 용입니다. "p, q, r"은 함수에 자주 사용됩니다.

그런 다음 사용 가능한 시퀀스에 대한 다른 제약이 있습니다. "l"및 "o"는 많은 글꼴에서 "1"및 "0"과 너무 비슷해 보이기 때문에 피합니다. "t"는 종종 시간에, "d & δ"는 미분, "a, s, m, v"는 가속도, 변위, 질량 및 속도의 물리적 측정에 사용됩니다. 그것은 인덱스에 대한 수학에서 원치 않는 연관성없이 연속 된 세 글자의 간격을 많이 남기지 않습니다.

그런 다음 다른 여러 사람이 알아 차렸 듯이 수학의 규칙은 초기 프로그래밍 규칙에 큰 영향을 미쳤으며 "α, β, γ"는 많은 초기 문자 집합에서 사용할 수 없었습니다.


나는 i, j, k가 Hamilton's Quaternions.

대체 텍스트

Euler는 가상 단위로 i를 선택했습니다.

Hamilton은 -1의 두 제곱근이 더 필요했습니다. ii = jj = kk = ijk = -1

해밀턴은 정말 영향력이 있었으며 쿼터니언은 1900 년 이전에 3D 분석을 수행하는 표준 방법이었습니다. 그때까지 수학자들은 (ijk)를 일치하는 세트로 생각하는 데 익숙해졌습니다. 벡터 미적분학Maxwell의 방정식을 작성 하는 더 좋은 방법 이었기 때문에 1890 년대에 4 차 이온 분석대체 했습니다 . 그러나 사람들이 등 벡터 수량을 작성하는 경향이 : (3i-2j+k) 대신에 (3,-2,1) . 그래서 (ijk)는 R ^ 3의 표준 기저 벡터가되었습니다.

Finally, physicists started using group theory to describe symmetries in systems of differential equations. So (ijk) started to connote "vectors that get swapped around by permutation groups," then drifted towards "index-like things that take on all possible values in some specified set," which is basically what they mean in a for loop.


by discarding (a little biased)

a seems an array
b seems another array 
c seems a language name
d seems another language name
e seems exception
f looks bad in combination with "for" (for f, a pickup?)
g seems g force
h seems height

i seems an index                    
j seems i (another index)

k seems a constant k
l seems a number one (1) 
m seems a matrix
n seems a node
o seems an output
p sounds like a pointer
q seems a queue
r seems a return value
s seems a string
t looks like time
u reserved for UVW mapping or electic phase 
v reserved for UVW mapping or electic phase or a vector
w reserved for UVW mapping or electic phase or a weight
x seems an axis (or an unknown variable)
y seems an axis
z seems a third axis

One sunny afternoon, Archimedes what pondering (as was usual for sunny afternoons) and ran into his buddy Eratosthenes.

Archimedes said, "Archimedes to Eratosthenes greeting! I'm trying to come up with a solution to the ratio of several spherical rigid bodies in equilibrium. I wish to iterate over these bodies multiple times, but I'm having a frightful time keeping track of how many iterations I've done!"

Eratosthenes said, "Why Archimedes, you ripe plum of a kidder, you could merely mark successive rows of lines in the sand, each keeping track of the number of iterations you've done within iteration!"

Archimedes cried out to the world that his great friend was undeniably a shining beacon of intelligence for coming up with such a simple solution. But Archimedes remarked that he likes to walk in circles around his sand pit while he ponders. Thus, there was risk of losing track of which row was on top, and which was on bottom.

"Perhaps I should mark these rows with a letter of the alphabet just off to the side so that I will always know which row is which! What think you of that?" he asked, then added, "But Eratosthenes... whatever letters shall I use?"

Eratosthenes was sure he didn't know which letters would be best, and said as much to Archimedes. But Archimedes was unsatisfied and continued to prod the poor librarian to choose, at least, the two letters that he would require for his current sphere equilibrium solution.

Eratosthenes, finally tired of the incessant request for two letters, yelled, "I JUST DON'T KNOW!!!"

So Archimedes chose the first two letters in Eratosthenes' exclamatory sentence, and thanked his friend for the contribution.


These symbols were quickly adopted by ancient Greek Java developers, and the rest is, well... history.


i think it's because a lot of loops use an Int type variable to do the counting, like

for (int i = 0; etc

and when you type, you actually speak it out in your head (like when you read), so in your mind, you say 'int....'

and when you have to make up a letter right after that 'int....' , you say / type the 'i' because that is the first letter you think of when you've just said 'int'

like you spell a word to kids who start learning reading you spell words for them by using names, like this:

WORD spells William W, Ok O, Ruby R, Done D

So you say Int I, Double d, Float f, string s etc. based on the first letter.

And j is used because when you have done int I, J follows right after it.


I think it's a combination of the other mentioned reasons :

For starters, 'i' was commonly used by mathematicians in their notation, and in the early days of computing with languages that weren't binary (ie had to be parsed and lexed in some fashion), the vast majority of users of computers were also mathematicians (... and scientists and engineers) so the notation fell into use in computer languages for programming loops, and has kind of just stuck around ever since.

Combine this with the fact that screen space in those very early days was very limited, as was memory, it made sense to keep shorter variable names.


Possibly historical ?

FORTRAN, aurguably the first high level language, defined i,j,k,l,m as Integer datatypes by default, and loops could only be controlled by integer variable, the convention continues ?

eg:

do 100 i= j,100,5 .... 100 continue ....


i = iterator, i = index, i = integer

Which ever you figure "i" stands for it still "fits the bill".

Also, unless you have only a single line of code within that loop, you should probably be naming the iterator/index/integer variable to something more meaningful. Like: employeeIndex

BTW, I usually use "i" in my simple iterator loops; unless of course it contains multiple lines of code.


i = iota, j = jot; both small changes.

iota is the smallest letter in the greek alphabet; in the English language it's meaning is linked to small changes, as in "not one iota" (from a phrase in the New Testament: "until heaven and earth pass away, not an iota, not a dot, will pass from the Law" (Mt 5:18)).

A counter represents a small change in a value.

And from iota comes jot (iot), which is also a synonym for a small change.

cf. http://en.wikipedia.org/wiki/Iota


Well from Mathematics: (for latin letters)

a,b: used as constants or as integers for a rational number
c: a constant
d: derivative
e: Euler's number
f,g,h: functions
i,j,k: are indexes (also unit vectors and the quaternions)
l: generally not used. looks like 1
m,n: are rows and columns of matrices or as integers for rational numbers
o: also not used (unless you're in little o notation)
p,q: often used as primes
r: sometimes a spatial change of variable other times related to prime numbers
s,t: spatial and temporal variables or s is used as a change of variable for t
u,v,w: change of variable
x,y,z: variables


Many possible main reasons, I guess:

  • mathematicians use i and j for Natural Numbers in formulas (the ones that use Complex Numbers rarely, at least), so this carried over to programming
  • from C, i hints to int. And if you need another int then i2 is just way too long, so you decide to use j.
  • there are languages where the first letter decides the type, and i is then an integer.

It comes from Fortran, where i,j,k,l,m,n are implicitly integers.


It definitely comes from mathematics, which long preceded computer programming.

So, where did if come from in math? My completely uneducated guess is that it's as one fellow said, mathematicians like to use alphabetic clusters for similar things -- f, g, h for functions; x, y, z for numeric variables; p, q, r for logical variables; u, v, w for other sets of variables, especially in calculus; a, b, c for a lot of things. i, j, k comes in handy for iterative variables, and that about exhausts the possibilities. Why not m, n? Well, they are used for integers, but more often the end points of iterations rather than the iterative variables themselves.

Someone should ask a historian of mathematics.


Counters are so common in programs, and in the early days of computing, everything was at a premium...
Programmers naturally tried to conserve pixels, and the 'i' required fewer pixels than any other letter to represent. (Mathematicians, being lazy, picked it for the same reason - as the smallest glyph).
As stated previously, 'j' just naturally followed...

:)


I use it for a number of reasons.

  • Usually my loops are int based, so you make a complete triangle on the keyboard typing "int i" with the exception of the space I handle with my thumb. This is a very fast sequence to type.

  • The "i" could stand for iterator, integer, increment, or index, each of which makes logical sense.

내 개인적인 용도를 제쳐두고 정수 vars가 문자 I-N을 사용하는 FORTRAN에서 파생 된 이론은 정확합니다.


저는 1965 년 Control Data Corp. 3100에서 FORTRAN을 배웠습니다. 'I'에서 'N'으로 시작하는 변수는 정수임을 암시했습니다. 예 : 'IGGY'및 'NORB'는 정수이고 'XMAX'및 'ALPHA'는 부동 소수점입니다. 그러나 명시 적 선언을 통해이를 재정의 할 수 있습니다.

참고 URL : https://stackoverflow.com/questions/454303/why-are-we-using-i-as-a-counter-in-loops

반응형