Reputation: 1243
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].
Upvotes: 5
Views: 327
Reputation: 1243
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)
Upvotes: 2
Reputation: 48745
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.
Upvotes: 4