in reply to checking a set of numbers for consistency mod p

I'm too busy right now for code or a proper proof and to be honest I don't grasp your algorithm ...

But my intuition says (examples for [ 2, [1, 0, 5, 0, 1]] )

HTH!

PS: Hey, number theory is off-topic!!! ;-)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) regarding sieves, every partial sequence is the combination of all former repeated p-1 times, just the last entry is incremented

for p=2

<0> <1> <0 2> <0 1 0 3> <0 1 0 2 0 1 0 4> <0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 5>

for p=3

<0> <0 1> <0 0 1 0 0 2> <0 0 1 0 0 1 0 0 2 0 0 1 0 0 1 0 0 3>

etc

update

You can easily precalculate the sieves if you have many sequences of a max length like m=32. You'll just calculate the sieve up to m.

Any bigger max entry will just take the place of the precaclclated max and the sieve will be correct.

Replies are listed 'Best First'.
Re^2: checking a set of numbers for consistency mod p
by hv (Prior) on Apr 09, 2022 at 20:38 UTC

    Thanks LanX, but it's not clear to me what algorithm you're proposing here. Taking my last example [1,0,0,1,0,0,1], 3, for example: you find that the biggest known entry is 1 (which presumably requires a pass through the values), now what?

    Hey, number theory is off-topic!!!

    Eh? It's just an algorithm question, right?

      > Eh? It's just an algorithm question, right?

      I was joking.

      > Taking my last example [1,0,0,1,0,0,1], 3, for example: you find that the biggest known entry is 1

      take the pre-calculated sieve for 27 entries from my post and anchor the first 1 (marked ^) from both sequences for a one-on-one comparison

      [1,0,0,1,0,0,1] <0 0 1 0 0 1 0 0 2 0 0 1 0 0 1 0 0 2 0 0 1 0 0 1 0 0 3> ^ *

      and you'll see they diverge for the last entry (marked *) hence it's a fail.

      I hope it's clearer now. :)

      If you have billions of comparisons and max m=32 length sequences for a limited number of possible p, this should be very fast.

      (disclaimer: I'm not 100% sure I covered all edge cases caused by the holes)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      update

      for the other examples given

      [0,1,0,2,0] <0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 5> ^ -> PASS

      [1,0,5,0,1] <0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 5 0 1 . +.. > ^ -> PASS

      [2,?,?,?,2] <0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 5> ^ * -> FAIL

      update

      and if you have a sequence [2,[1,0,9,0,1]] with a max (here 9) which isn't in your pre-calculated sieve, identify it with the max from your sieve (here 5)

      [1,0,9,0,1] <0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 5 0 1 . +.. > ^ -> PASS

      of course this would also work by identifying 9 with 4 or 3 or 2 because this sequence is so short. But with a possible m=32 you need that full length.

      maybe easiest if you provided more test data, like a generator producing 1e5 true and 1e5 false examples.

      I'd implement it then.

      This could be used for benchmarking, too.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Generating sets that pass is straightforward: here's code that generates full sets for a given prime, and you can mask out a subset of the values with undef. All such sets should return true when queried with the same prime:

        #!/usr/bin/perl use strict; use warnings; my($prime, $range, $count) = @ARGV; for (1 .. $count) { # report the full range for a random start point my $start = int rand(2 ** 32 - $range); print join(' ', map val($start + $_), 0 .. $range - 1), "\n"; } exit 0; # return the $p-adic order of $n sub val { my($n) = @_; my $val = 0; ++$val, $n /= $prime while 0 == $n % $prime; return $val; }

        It's less obvious how to generate a useful collection of sets that should not pass. Best I can suggest is to take one of the passing sets, randomly increment or decrement an element (that has not been masked out), and see if the valid_set() function in my original post rejects it.