Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generalizing Arithmetic Operators

Multiplication of two numbers can be algorithmically defined like so: 'add the first number to itself a number of times equal to the value of the second number'. Exponentiation of two numbers can be algorithmically defined like so: 'multiply the first number by itself a number of times equal to the value of the second number'. Thinking about those definitions for multiplication and exponentiation raises a few questions...

Firstly, can a class of arithmetic operations be defined by starting with addition as the fundamental operation? I wrote up some haskell code to test that idea:

order1 x y = x + y
order2 x y = foldl (order1) x (replicate (y - 1) x)
order3 x y = foldl (order2) x (replicate (y - 1) x)
order4 x y = foldl (order3) x (replicate (y - 1) x)
order5 x y = foldl (order4) x (replicate (y - 1) x)

Sure enough, the meaning of 'order2' is multiplication and the meaning of 'order3' is exponentiation. The english language, as far as I know, lacks words for 'orderN' where N > 3. Does the mathematical community have anything interesting to say about these operations?

Also, given the recursive appearance of those 'order' functions, how might one write a function like this:

generalArithmetic :: Int -> Int -> Int -> Int
generalArithmetic n x y =   --Comment: what to put here?

that means multiplication when n equals 2, means exponentiation when n equals 3 ...?

Also, how might one generalize these arithmetic functions so that they could operate on all real numbers? The type of 'replicate' is, after all, Int -> a -> [a].

like image 612
seewalker Avatar asked Aug 05 '13 22:08

seewalker


People also ask

What are the 4 types of arithmetic operators?

These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo).

What are the 4 arithmetic functions?

…how to perform the four arithmetic operations of addition, subtraction, multiplication, and division.

Why algebra is considered as generalized arithmetic?

In one sense, what we have done is just arithmetic because it is nothing more than the application of arithmetic operations on numbers, and numbers only. At the same time, it also goes beyond arithmetic because this is a computation with unknown numbers using only the laws of operations.


2 Answers

Yes. You can start with peano arithmetic as the first order (increment)

Brainf*ck only has increment, decrement, and checks for non-zero value. Even with this it can do any computation any other computer program can do as long as it always has enough memory and you are not in a hurry to get the answer.

Such property is called Turing completeness and Brainf*ck is such even without input and output. Thus with <, >, +, -, [, and ] you can make a program to solve all math problems solvable by other programming languages.

So far I have made programs that do addition, subtraction, averages, multiplication, division, modulus and square root with it.

like image 200
Sylwester Avatar answered Sep 18 '22 15:09

Sylwester


In case anybody cares about a definition for what I earlier called 'generalArithmetic', here it is:

arithmetic n x y = if n == 0
                   then (x + y)
                   else foldl (arithmetic (n - 1)) x (replicate (y - 1) x)
like image 41
seewalker Avatar answered Sep 17 '22 15:09

seewalker