mirror of
https://github.com/blackboxprogramming/lucidia.git
synced 2026-03-17 09:37:56 -05:00
sync: update from blackroad-operator 2026-03-14
Synced from BlackRoad-OS-Inc/blackroad-operator/orgs/personal/lucidia BlackRoad OS — Pave Tomorrow. RoadChain-SHA2048: fe729062952871e7 RoadChain-Identity: alexa@sovereign RoadChain-Full: fe729062952871e77147cf6d938b799096e87d9024d7005a14c9e209e12e8ad0c825b624c7bc649fc7eeb4c284fdcab8231af77980065cc04d9f36fca479ffc2346ed3c1b73de6f240d8f9485f47c995ad5b81142f7179b84932c67914dff1c08db039349ba28fca36cb57688093bf0199268dd1c2f3448c9383000bc77cc9663066ff57b834370afc8838b18466ea9029908018b961555cccaabf2ce21649cf3cabc7f64bdcc4abdf2da259b210c342835a2cecf92bdd3b4e109b4d6e622f6934e13b2b123607bd61ce3d0f20454c9ab594f9284cffe18716619c52db57ce5f4ee2856cb96e1fa3748fe1fe65435bec297c5ab3ab58d570ec1064aea29931dd
This commit is contained in:
65
codex/mirror/number_mirror_mu.py
Normal file
65
codex/mirror/number_mirror_mu.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""
|
||||
number_mirror_mu.py
|
||||
|
||||
This module implements a simple Möbius mirror demonstration.
|
||||
It defines functions to compute the Möbius function µ(n), split
|
||||
positive and negative values, compute the Mertens function, and
|
||||
verify the Dirichlet generating identity.
|
||||
|
||||
Functions:
|
||||
mobius(n) -> int
|
||||
mirror_split_mu(N) -> (pos_indices, neg_indices)
|
||||
mertens(N) -> list[int]
|
||||
dirichlet_sum(s, N) -> complex
|
||||
"""
|
||||
|
||||
import cmath
|
||||
|
||||
def mobius(n: int) -> int:
|
||||
"""Compute the Möbius function µ(n)."""
|
||||
if n == 1:
|
||||
return 1
|
||||
primes = {}
|
||||
i = 2
|
||||
m = n
|
||||
while i * i <= m:
|
||||
while m % i == 0:
|
||||
primes[i] = primes.get(i, 0) + 1
|
||||
m //= i
|
||||
i += 1
|
||||
if m > 1:
|
||||
primes[m] = primes.get(m, 0) + 1
|
||||
for exp in primes.values():
|
||||
if exp > 1:
|
||||
return 0
|
||||
return -1 if len(primes) % 2 else 1
|
||||
|
||||
def mirror_split_mu(N: int):
|
||||
"""Return indices where µ(n) = +1 and µ(n) = -1 up to N."""
|
||||
pos = []
|
||||
neg = []
|
||||
for n in range(1, N + 1):
|
||||
mu = mobius(n)
|
||||
if mu == 1:
|
||||
pos.append(n)
|
||||
elif mu == -1:
|
||||
neg.append(n)
|
||||
return pos, neg
|
||||
|
||||
def mertens(N: int):
|
||||
"""Compute the Mertens function M(x) for x = 1..N."""
|
||||
total = 0
|
||||
M = []
|
||||
for n in range(1, N + 1):
|
||||
total += mobius(n)
|
||||
M.append(total)
|
||||
return M
|
||||
|
||||
def dirichlet_sum(s: complex, N: int):
|
||||
"""Compute the partial Dirichlet sum \u2211_{n=1..N} µ(n)/n^s."""
|
||||
total = 0+0j
|
||||
for n in range(1, N + 1):
|
||||
mu = mobius(n)
|
||||
if mu != 0:
|
||||
total += mu / (n ** s)
|
||||
return total
|
||||
Reference in New Issue
Block a user