cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-3 of 3 results.

A175330 a(n) = bitwise AND of prime(n) and prime(n+1).

Original entry on oeis.org

2, 1, 5, 3, 9, 1, 17, 19, 21, 29, 5, 33, 41, 43, 37, 49, 57, 1, 67, 65, 73, 67, 81, 65, 97, 101, 99, 105, 97, 113, 3, 129, 137, 129, 149, 149, 129, 163, 165, 161, 177, 181, 129, 193, 197, 195, 211, 195, 225, 225, 233, 225, 241, 1, 257, 261, 269, 261, 273, 281
Offset: 1

Views

Author

Leroy Quet, Apr 07 2010

Keywords

Comments

Read each binary representation of the primes from right to left and then AND respective digits to form the binary equivalent of each term of this sequence.
Indices of 1's: 2, 6, 18, 54, 564, 3512, 6542, 564163, 2063689, 54400028, ... - Alex Ratushnyak, Apr 22 2012

Examples

			For n = 15, a(15) = 37 because the 15th prime is 47 and the 16th is 53, which have binary representations of 101111 and 110101 respectively; the bitwise AND of these values is 100101 which is the binary representation of 37:
  101111
& 110101
--------
  100101
		

Crossrefs

Cf. A000040, A175329 (bitwise OR).
Cf. A129760 (bitwise AND of n and n-1).
Cf. A366550 (indices of ones).

Programs

  • Maple
    read("transforms") ; A175330 := proc(n) ANDnos(ithprime(n),ithprime(n+1)) ; end proc: seq(A175330(n),n=1..60) ; # R. J. Mathar, Apr 15 2010
    # second Maple program:
    a:= n-> Bits[And](ithprime(n), ithprime(n+1)):
    seq(a(n), n=1..70);  # Alois P. Heinz, Apr 15 2020
  • Mathematica
    a[n_] := Prime[n]~BitAnd~Prime[n+1];
    Array[a, 60] (* Jean-François Alcover, Jan 11 2021 *)
  • PARI
    a(n) = bitand(prime(n), prime(n+1)); \\ Michel Marcus, Apr 16 2020
    
  • Scala
    val prime: LazyList[Int] = 2 #:: LazyList.from(3).filter(i => prime.takeWhile {
       j => j * j <= i
    }.forall {
       k => i % k != 0
    })
    (0 to 63).map(n => prime(n) & prime(n + 1)) // Alonso del Arte, Apr 18 2020

Extensions

More terms from R. J. Mathar, Apr 15 2010

A334143 a(n) = bitwise NOR of prime(n) and prime(n+1).

Original entry on oeis.org

0, 0, 0, 0, 0, 2, 12, 8, 0, 0, 0, 18, 20, 16, 0, 0, 0, 0, 56, 48, 48, 32, 36, 6, 26, 24, 16, 16, 2, 0, 0, 116, 116, 96, 104, 96, 64, 88, 80, 64, 72, 64, 0, 58, 56, 40, 32, 0, 24, 18, 16, 0, 4, 4, 248, 240, 240, 224, 226, 228, 192, 200, 200, 192, 194, 128, 164
Offset: 1

Views

Author

Christoph Schreier, Apr 15 2020

Keywords

Examples

			a(6) = prime(6) NOR prime(7) = 13 NOR 17 = 2.
		

Crossrefs

Programs

  • Maple
    a:= n-> Bits[Nor](ithprime(n), ithprime(n+1)):
    seq(a(n), n=1..70);  # Alois P. Heinz, Apr 15 2020
  • Mathematica
    A334143[n_]:=With[{b=BitOr[Prime[n],Prime[n+1]]},2^BitLength[b]-b-1];Array[A334143,100] (* Paolo Xausa, Oct 13 2023 *)
  • PARI
    a(n) = my(x=bitor(prime(n), prime(n+1))); bitneg(x, #binary(x)); \\ Michel Marcus, Apr 16 2020
  • Python
    def NORprime(n):
        s = str(bin(primes[n]))[2:]
        t = str(bin(primes[n-1]))[2:]
        k = (len(s) -  len(t))
        t = k*'0' + t
        r = ''
        for i in range(len(s)):
            if s[i] == t[i] and s[i] == '0':
                r += '1'
            else:
                r += '0'
        return int(r,2)
    

Formula

a(n) = A035327(A175329(n)).

A334172 Bitwise XNOR of prime(n) and prime(n + 1).

Original entry on oeis.org

2, 1, 5, 3, 9, 3, 29, 27, 21, 29, 5, 51, 61, 59, 37, 49, 57, 1, 123, 113, 121, 99, 117, 71, 123, 125, 115, 121, 99, 113, 3, 245, 253, 225, 253, 245, 193, 251, 245, 225, 249, 245, 129, 251, 253, 235, 243, 195, 249, 243, 249, 225, 245, 5, 505, 501, 509, 485
Offset: 1

Views

Author

Christoph Schreier, Apr 17 2020

Keywords

Comments

XOR is exclusive OR, meaning that one bit is on and the other bit is off. XNOR is the negation of XOR, meaning that either both bits are on or both bits are off. For example, 4 in binary is 100 and 6 is 110. Then 100 XOR 110 is 010 but 100 XNOR 110 is 101.
From Bertrand's postulate it follows that prime(n + 1) requires only one bit more than prime(n) if they're not the same bit width. In most computer implementations, however, the numbers are placed zero-padded into fixed bit widths using two's complement, making it necessary to make adjustments to avoid unintentionally negative numbers. - Alonso del Arte, Apr 18 2020

Examples

			The second prime is 3 (11 in binary) and the third prime is 5 (101 in binary). We see that 011 XNOR 101 = 001. Hence a(2) = 1.
The fourth prime is 7 (111 in binary). We see that 101 XNOR 111 = 101. Hence a(3) = 5.
		

Crossrefs

Programs

  • Maple
    a:= n-> (p-> Bits[Not](Bits[Xor](p, ithprime(n+1)),
                 bits=1+ilog2(p)))(ithprime(n)):
    seq(a(n), n=1..70);  # Alois P. Heinz, Apr 17 2020
  • Mathematica
    Table[BitNot[BitXor[Prime[n], Prime[n + 1]]] + 2^Ceiling[Log[2, Prime[n + 1]]], {n, 50}] (* Alonso del Arte, Apr 17 2020 *)
  • PARI
    neg(p) = bitneg(p, #binary(p));
    a(n) = my(p=prime(n), q=nextprime(p+1)); bitor(bitand(p, q), bitand(neg(p), neg(q))); \\ Michel Marcus, Apr 17 2020
    
  • Python
    def XNORprime(n):
        return ~(primes[n] ^ primes[n+1]) + (1 << primes[n+1].bit_length())
    
  • Scala
    val prime: LazyList[Int] = 2 #:: LazyList.from(3).filter(i => prime.takeWhile {
       j => j * j <= i
    }.forall {
       k => i % k != 0
    })
    (0 to 63).map(n => ~(prime(n) ^ prime(n + 1)) + 2 * Integer.highestOneBit(prime(n + 1))) // Alonso del Arte, Apr 18 2020

Formula

a(n) = A035327(A112591(n)).
Showing 1-3 of 3 results.