# How to do scalar multiplication and matrix inverse when variables are of size 1000 bits?

I am doing arithmetic operations on really huge numbers.

For example, I am given six variables, a_{11}, a_{12}, a_{21}, a_{22}, x_1, and x_2.

Although the above are math terms, these six variables are each 1000-bit integers.

What I want to do is to calculate (1) two numbers z_1 and z_2, and (2) the matrix inverse.

(1) z_1 = a_{11}*x_1 + a_{12}*x2 and z_2 = a_{21}*x_1 + a_{22}*x2

(2) if A is a matrix defined as A=[a_{11} a_{12}; a_{21} a_{22}], want to compute A^{-1}

I know how to do the above when these six variables are ordinary floating points.

But my question is how to compute them in C or Python when the six variables are all of size 1000-bit?

-

Python's `long` type (docs here) is arbitrary precision. So in the interest of saving a precious resource (i.e. your time) I would try that first and see if it is Good Enough™. Also take a look at NumPy if you are dealing with big chunks of big data.

Update:

Yes, you can just assign a big, honking number. E.g.

``````x = 1071508607186267320948425049060001810561404811705533607443750388370351051124936122493198378815695858127594672917553146825187145285692314043598457757469857480393456777482423098542107460506237114187795418215304647498358194126739876755916554394607706291457119647768654216766042983165262438683720566806937638839928883123
``````

or in binary

``````y = 0b1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

print x
print y
print x+y
``````
-
I noticed the sentence "Long integers have unlimited precision." However, how can I define, for example, a 1000-bit long integer in Python? Just type long a=1234? – user4478 Jan 9 '13 at 19:35
@user4478 What Peter Rowell posted is the exact syntax required. Python is a dynamically typed language, so you don't need to manually specify the type. en.wikipedia.org/wiki/Dynamic_type#Dynamic_typing – meddlingwithfire Jan 9 '13 at 21:35