6

Is there an algorithm to test divisibility in space $O(\log n)$, or even in space $O(\log(n)^k)$ for some $k$? Given a pair of integers $(a, b)$, the algorithm should return TRUE if $b$ is divisible by $a$, and FALSE otherwise. I understand that there is no proof that divisibility is not in $L$ since that would imply $P \ne L$ which is open. Also I understand that if there is a nondeterministic algorithm in $O(\log(n)^k)$ then there is a deterministic algorithm in $O(\log(n)^{2k})$, by Savitch's theorem. I believe I've figured out an $L$ algorithm to verify $a*b=c$, and also an $FL$ algorithm to compute $c$ (essentially the method I was taught in grade school, reusing ink when possible), but I haven't been able to adapt it to divisibility. Is such an algorithm for divisibility known?

Dan Brumleve
  • 17,735
  • Isn't the euclidean algorithm log space and with the identity $a | b$ iff $\gcd(a,b)=a$, wouldn't this give you a logspace algorithm? – JSchlather Oct 25 '11 at 06:08
  • 1
    If so, yes, but I don't know how to make the Euclidean algorithm log-space either. The way I would ordinarily implement it is O(n) space. Note that n ~ log(b) here, so log-space means O(log(log(b))) space. – Dan Brumleve Oct 25 '11 at 06:13
  • 1
    The euclidean algorithm is most certainly an overkill; if b divides a, it will be discovered in the first step of the algorithm (where we divide a by b and take the remainder)... – Gadi A Oct 25 '11 at 07:53
  • I'm not very familiar with complexity theory, but determining divisibility without examining all of the digits does not sound plausible to me... is there intuition for why such an algorithm might exist? – user7530 Oct 25 '11 at 08:30
  • 1
    @user7530, all the digits can be examined, they just can't be copied into working space at the same time. See http://en.wikipedia.org/wiki/L_(complexity%29. My intuition is that divisibility is in P and P=L might be true, and also it seems like an easy P problem compared to others. – Dan Brumleve Oct 25 '11 at 08:40
  • @Dan: I hadn't encountered $L$ before, so I don't know the definition and the Wikipedia article doesn't really provide one -- "a logarithmic amount of memory space" is rather vague. Am I right in thinking that the definition of space complexity given on slide 2 of these slides isn't the one to be applied here? If it were, the class $L$ would be rather boring, since the output couldn't depend on most of the input. Perhaps the Wikipedia article should be clarified? – joriki Oct 25 '11 at 10:00
  • 1
    Integer division is known to be in L. Page 22 of the slides “My Favorite Ten Complexity Theorems of the Past Decade II” by Lance Fortnow refers to Chiu 1995, although I cannot locate this reference right now. If you can access Chiu, Davida, and Litow 2001, I am sure that it contains the reference to it. – Tsuyoshi Ito Oct 25 '11 at 13:46
  • @Tsuyoshi: You could write that as an answer. – joriki Oct 25 '11 at 14:36
  • If you are allowed to overwrite the contents of $b$, you can just subtract $a$ from $b$ repeatedly until you get zero or a negative number. – TonyK Oct 25 '11 at 14:45
  • @TonyK, the model does not permit overwriting the input. You can imagine an "input tape" containing the input, and a separate "work tape" (which, in this problem, is supposed to be logarithmic in input size). You may, of course, copy down parts of the input, but you need to "pay" for that. – Srivatsan Oct 25 '11 at 15:38

2 Answers2

7

(This is an updated version of my comment on the question.)

Beame, Cook, and Hoover [BCH86] showed that integer divisibility is in L. More recently, Chiu, Davida, and Litow [CDL01] showed that integer division is also in L.

References

[BCH86] Paul W. Beame, Stephen A. Cook, and H. James Hoover. Log depth circuits for division and related problems. SIAM Journal on Computing, 15(4):994–1003, Nov. 1986. DOI: 10.1137/0215070

[CDL01] Andrew Chiu, George Davida, and Bruce Litow. Division in logspace-uniform NC1. Theoretical Informatics and Applications, 35(3):259–275, May 2001. DOI: 10.1051/ita:2001119.

Tsuyoshi Ito
  • 2,046
0

Edited to add: As Gadi points out in a comment, this answer is wrong.

If you have a logspace algorithm to verify $x \times y = z$, then since you're not concerned with running time, you can simply check, for all $c$ with $1 < c \le b$, whether $a \times c = b$.

TonyK
  • 68,516
  • 2
    I believe he meant that the algorithm is logspace in the sum of lengths of x,y,z. What you suggest is not logspace since writing c takes up space on the work tape. – Gadi A Oct 25 '11 at 12:32