1. ## Dividing

Ok I know the title makes it sound easy but that’s not the point.

The problem I’ve got is actually computer related but with a maths twist. I have a very basic programming language which has only the Add and Subtract functions, I've made a working multiply function but it only deals with whole numbers as does the whole program.

So anyway is there a method of dividing using only add and subtract and whole number multiplication. I don't know if this is making any sense it started playing with my head so sorry. But if anyone can help that would be great.

Martin

2. Perhaps you should tell us what you did to define multiplication.
Do you understand that division is the inverse of multiplication?

3. Originally Posted by borg_brain
Ok I know the title makes it sound easy but that’s not the point.

The problem I’ve got is actually computer related but with a maths twist. I have a very basic programming language which has only the Add and Subtract functions, I've made a working multiply function but it only deals with whole numbers as does the whole program.

So anyway is there a method of dividing using only add and subtract and whole number multiplication. I don't know if this is making any sense it started playing with my head so sorry. But if anyone can help that would be great.

Martin
indeed. we can actually think of division as a weird form of subtraction, or more appropriately, counting a certain number of subtractions. for example: 12 divided by 2 is 6. why? because we can subtract 2 from 12 6 times.

if your program can do "loops" this shouldn't be too hard for you to code. (note, i am not in the least adept at programming, but i've heard people talk about algorithms before, so i'll describe an algorithm to you).

Algorithm for calculating $a \div b$

Let counter = 0 and remainder = 0

if b = 0

..........print: $a \div b$ is undefined

else

..........if a < b
....................print: $a \div b = a/b$

(and you can program it to output in decimal if you want, so if a = b you will get 1)

.........else

...................while a > b, do:

...........................remainder = a - b
...........................counter = counter + 1
...........................a = remainder

...................end while loop

...................print: $a \div b =$ counter " and " remainder/b

.........end if

end if

so basically this algorithm counts the number of times you can subtract b from a, and also keeps track of the remainder when doing so. as long as the remainder is greater than zero and a is greater than b, it will keep subtracting and keep counting. in the end, the result will be the number of counts we have plus the remainder over the dividend. (at least that's what the program is supposed to do. you figure out the details, like i said, i'm not a programmer)

4. Originally Posted by Plato
Perhaps you should tell us what you did to define multiplication.
Do you understand that division is the inverse of multiplication?
indeed, but how would you code something like that? i can visualize an algorithm using subtraction in my head, but i'm a little confused as to how to tell a computer to do the inverse of multiplication

o wait, i got an idea just now while typing this, i'll think about it some more.

5. Originally Posted by Jhevon
indeed, but how would you code something like that?
Just as you did above: if we add to multiply then subtract to divide.
But note that he/she did say that these are whole numbers, no decimals.
So while multiplication has no restrictions, division does have restrictions.

I wanted to see what code he/she had. I think there is some shorter code using while and until.

6. Originally Posted by Plato
Just as you did above: if we add to multiply then subtract to divide.
But note that he/she did say that these are whole numbers, no decimals.
So while multiplication has no restrictions, division does have restrictions.

I wanted to see what code he/she had. I think there is some shorter code using while and until.
oh, ok. i wasn't thinking of the multiplication function as addition in terms of the code. since he already coded multiplication, i suppose there would have been a new function called a*b or something like that, with addition built in it, but is not really explicit

7. Here is one way using only addition.
Define a function as: D(J,K), J divides K.
D(J,K)
N:=0; Q:=0
While N<K
N:=N+J; Q:=Q+1
Loop

If N=K print Q else print “not divisible”.

Now this is only for positive integers.