1

According to Wikipedia :

In mathematics, a tuple is a finite sequence or ordered list of numbers or, more generally, mathematical objects, which are called the elements of the tuple. An n-tuple is a tuple of n elements, where n is a non-negative integer.

I was wondering if I can call an array of 4 numbers in C programming language a 4-tuple.
So what are the differences between array and tuple and between vector and tuple?

Prem
  • 9,669
apadana
  • 191
  • 3
    This is more a computer science topic – julio_es_sui_glace Nov 24 '23 at 20:07
  • 1
    In vector are elements from one and same linear space, but in tuple (for example in Python) you can have elements from different spaces. Example [1, 2, [1, 3]] is tuple, but not vector. Meanwhile, array on C is vector. – zkutch Nov 24 '23 at 20:26
  • @zkutch, The comment was helpful. But we should remember that things with the same name are not necessarily identical. How far tuple in Python is close to tuple in mathematical sense is an open question to me. – apadana Nov 25 '23 at 05:14
  • @julio_es_sui_glace, From the three terms I used, two of them (i.e. tuple and vector) are from mathematics, not computer science. – apadana Nov 25 '23 at 05:17
  • Each programming language has its own terminology. They do not always agree. For the C language, look in the C documentation. – GEdgar Nov 25 '23 at 08:34
  • @apadana. "things with the same name are not necessarily identical" - This is not a very pleasant proposal. What is meant by the word "name"? If this is the same formal record, then in the same context it is the same object, unless, again, rules defining different behavior are formally specified. – zkutch Nov 25 '23 at 11:28
  • @zkutch, I mean there are concepts like set and tuple in mathematics, and people have tried to mimic them in some programming languages. Pascal has sets, and Python has tuples. But I doubt that any set defined by mathematicians can be represented by Pascal. For example, a mathematician may talk about a set that is a member of itself. Can this be represented by Pascal? – apadana Nov 25 '23 at 13:14
  • @apadana. May be you didn't know, but you touch very interesting question: big part of today math. stay on that object defined by $x\in x$ is not set. And the question, that how math. objects can be represented in any programming language let me leave for future. On another hand, mathematics can be viewed as some formal language. – zkutch Nov 25 '23 at 23:58

2 Answers2

2

You ask about C language, so I will try to answer in the context of computer science.

I was wondering if I can call an array of 4 numbers in C programming language a 4-tuple.

You can call it however you want, as long as whoever you talk to understands the meaning. In that case pretty much everyone will know what you are talking about.

So what are the differences between array and tuple and between vector and tuple?

In computing an array will pretty much always mean a contiguous piece of memory. And will often hold elements of the same "size", so that we can easily refer to i-th element by doing some simple arithmetic (i*size).

The term "array" is not really well defined in maths. Some people may use this word to mean tuple or matrix. But its rather rare.

Now the term tuple is rarely used in programming. Probably only Python uses it extensively. It is actually the same as array. Since Python uses objects it sounds like tuple can keep different objects inside. But technically it holds pointers to objects, which are always of fixed size. With that any array, in any language can hold different objects.

On the other hand term "tuple" has a well defined meaning in maths: an ordered sequence or an element of Cartesian product.

Vector is a term that has different meaning depending on context. In C++ or Rust it will mean "dynamic array", i.e. array that can grow and shrink. But in C# for example it is a specialized numeric array. It's purpose is to allow compiler optimizations.

It is loosely related to maths where vector means an element of vector space, which is a structure that abstracts addition and scalar multiplication. It is not necessarily a tuple (e.g. reals are vectors over rationals) but often it is a tuple.

freakish
  • 42,851
1

DISCUSSION :

Here is my attempt to show the various concepts using Venn Diagram , high-lighting the various entities :

variety

In Math , generally vectors are made of similar numbers ( Integers , rationals , reals , Complex , ETC ) which we can add & multiply. We also have Distance & Norm. There are various ways to Identify Vectors , eg $x,y,z$ Co-ordinates , Polar/Cylindrical/Spherical Co-ordinates , $\hat{i},\hat{j},\hat{k}$ ETC.
In the Venn Diagram VD , that is shown by elements 4,5,6,7.

In Math , tuples may or may not have similar numbers or entities. We can have Integer & Boolean & Set & what-not , all within a Single tuple.
That is shown by elements 1,2,3,4,5,6 in the Venn Diagram VD.

Thus , when tuple has all elements of same type which will satisfy the Criteria for vectors , we have Intersection in the VD : 4,5,6.

In C , the array can have Integers or floats or other numbers. It will then be a vector , which is also a tuple : element 4 in VD.
The array can also have Pointers or Chars or Structs. It will then not be a vector , though it is still a tuple : element 3 in VD.

In Python , the tuple can have Numbers. It will then be a vector , which is also a tuple : elements 4,5 in VD.
The tuple element numbers , which be same in C , need not be Same in Python.
The tuple elements need not be numbers in Python : Element 2 in VD.

In Math there are other Structures & Entities too , like Boolean , Number , Set , Matrix : Element 8 in VD.

Examples & SUMMARY :

1 : Math tuple $(A,B,C,1,2,3\cdots)$ : It has 3 Sets $A,B,C$ & then infinite number of elements. It is not Python tuple & not C Array & not Math vector.
2 : Python tuple $(0,\text{None},\text{""})$ : It is a Math tuple , though not C Array & not Math vector.
3 : C Array having 100 Structs : It is Python tuple & Math tuple , though not Math vector.
4 : C Array having 100 floats : It is Python tuple & Math tuple & Math vector.
5 : Python tuple $(1,2.3,0)$ : It is Python tuple & Math tuple & Math vector.
6 : Vector $(1,2,3,\cdots)$ with infinite elements : It is Math tuple too , though not Python tuple & not C Array.
7 : Vector $3\hat{i}+6\hat{j}+9\hat{k}$ : It is not Python tuple , not C Array & not Math tuple. It could be converted to the Equivalent $(3,6,9)$ which will then be Math tuple.
8 : Logical True , Integer 1 , Set $\{1,2,3\}=\{1,3,2\}=\{3,2,1\}$ , Matrix : These can be neither Math Vector nor Math tuple nor Python tuple not C Array.

Over-view :

Math Vector & Math tuple are very close : Every vector can have Equivalent tuple.
C Array is a type of Python tuple. Python tuple is a type of Math tuple.
There are Structures & Entities other than these.
We might have 8 types of Entities to consider.

ADDENDUM :

I have given very general Examples at very high-level & certain nuances might not be covered.
When the concept of Array & tuple in Programming languages will gradually change , these Examples might have to be modified.
More-over , though there is wide consensus among Mathematicians & Programming Language Designers , it is not universal.
The Vector & Tuple might have slight variations over Country & Domain & time , which will then necessitate slight modifications to the Examples.

Prem
  • 9,669
  • Let me discuss 3-d point "C Array having 100 Structs ... though not Math vector" : In C all structs should have same type, so, it is math. vector. From C standard(2011) 6.2.5 (20): " An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. " – zkutch Nov 25 '23 at 11:14
  • In my Examples , 4 is Math vector because the Array contains floats (or Ints or other numeric types) & we can make sense with (eg) Addition , Distance & Norm , while 3 is not vector when we have Array of Struct with the Struct being (eg) Name & Age , @zkutch , where we can not make sense with Addition , Distance & Norm. If the Category 3 Struct had some numerical conversions , we could again move that to Category 4. In general , Struct may not have the numeric conversions. – Prem Nov 25 '23 at 11:24
  • I understand your idea only if you require vector as element from linear space, but when we taking it only as element of Cartesian product, then C array is vector. Meanwhile, what prevents you from determining the sum and multiplication by a scalar and the norm for the structures? As a result, this is a finite-dimensional object for which all this is certain. – zkutch Nov 25 '23 at 11:35
  • Check https://mathinsight.org/vector_introduction : "A vector .. has both a magnitude and a direction." , @zkutch , Check https://en.wikipedia.org/wiki/Vector_(mathematics_and_physics) "In mathematics ... vector ... refers colloquially to some quantities that cannot be expressed by a single number (a scalar), or to elements of some vector spaces." , which is why I put the addendum "though there is wide consensus ... it is not universal" [[ I also checked E. B. Vinberg who states "Elements of a vector space are ... vectors" after stating the addition , multiplication & abelian Criteria ]] – Prem Nov 25 '23 at 12:01
  • When the C Struct is "Name,Year-of-Comment" & I have some C Array with 5 Elements , @zkutch , why would I ever want to calculate Norm $\sqrt{\text{Prem}^2+\text{2023}^2}$ ? What would Distance $\sqrt{(\text{ Prem }-\text{ zkutch })^2+(2023-2023)^2}$ mean ? When that is meaningful & useful , then yes , it is vector ! Else it is tuple ! – Prem Nov 25 '23 at 12:11
  • 1
    Thanks for this interesting answer. In particular, the 7th example was very nice (in geometry and physics if we rotate the coordinate system/frame of reference, vectors do not change, though their components change. So vectors are not the same as their components.) One note about 1st example: Wikipedia defines tuple as a finite sequence of mathematical objects. So your example does not comply with that definition. – apadana Nov 25 '23 at 12:41
  • Oh , that "rule" is not always necessary , @apadana , for Example , it is generally claimed that all vectors are tuples & then there is the Infinite Dimension vector [[ check https://math.stackexchange.com/questions/466707/what-are-some-examples-of-infinite-dimensional-vector-spaces & https://math.stackexchange.com/questions/2802565/why-would-it-be-incorrect-to-describe-to-the-vectors-of-an-infinite-dimensional & https://en.wikipedia.org/wiki/Infinite-dimensional_vector_function ]] which must use some Infinite Dimensional tuples too ! In other words , that "rule" is not always necessary ! – Prem Nov 25 '23 at 13:15