kececinumbers 0.6.4__tar.gz → 0.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kececinumbers
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: Keçeci Numbers: An Exploration of a Dynamic Sequence Across Diverse Number Sets
5
5
  Home-page: https://github.com/WhiteSymmetry/kececinumbers
6
6
  Author: Mehmet Keçeci
@@ -22,7 +22,7 @@ import warnings
22
22
  # importlib.reload(kececinumbers) # F821 undefined name 'kececinumbers'
23
23
 
24
24
  # Paket sürüm numarası
25
- __version__ = "0.6.4"
25
+ __version__ = "0.6.5"
26
26
  __author__ = "Mehmet Keçeci"
27
27
  __email__ = "mkececi@yaani.com"
28
28
 
@@ -47,6 +47,9 @@ __all__ = [
47
47
  '_compute_gue_similarity',
48
48
  '_load_zeta_zeros',
49
49
  'analyze_all_types',
50
+ 'analyze_pair_correlation',
51
+ '_gue_pair_correlation',
52
+ '_pair_correlation',
50
53
 
51
54
  # --- Core Generation and Analysis ---
52
55
  'unified_generator',
@@ -105,6 +108,9 @@ try:
105
108
  _compute_gue_similarity,
106
109
  _load_zeta_zeros,
107
110
  analyze_all_types,
111
+ analyze_pair_correlation,
112
+ _gue_pair_correlation,
113
+ _pair_correlation,
108
114
 
109
115
 
110
116
  # Constants
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # _version.py
3
3
 
4
- __version__ = "0.6.4"
4
+ __version__ = "0.6.5"
5
5
  __license__ = "MIT"
6
6
  __description__ = "Keçeci Numbers: An Exploration of a Dynamic Sequence Across Diverse Number Sets."
7
7
  __author__ = "Mehmet Keçeci"
@@ -549,8 +549,11 @@ def _parse_quaternion_from_csv(s: str) -> np.quaternion:
549
549
 
550
550
  def _load_zeta_zeros(filename="zeta.txt"):
551
551
  """
552
- zeta.txt dosyasından Riemann zeta sıfırlarını yükle.
553
- Her satırda bir tane sanal kısım (t_n) olmalı.
552
+ Loads Riemann zeta zeros from a text file.
553
+ Each line should contain one floating-point number representing the imaginary part of a zeta zero.
554
+ Lines that are empty or start with '#' are ignored.
555
+ Returns:
556
+ numpy.ndarray: Array of zeta zeros, or empty array if file not found.
554
557
  """
555
558
  try:
556
559
  with open(filename, 'r', encoding='utf-8') as file:
@@ -563,18 +566,25 @@ def _load_zeta_zeros(filename="zeta.txt"):
563
566
  try:
564
567
  zeta_zeros.append(float(line))
565
568
  except ValueError:
566
- print(f"Geçersiz satır atlandı: {line}")
567
- print(f"{len(zeta_zeros)} adet zeta sıfırı yüklendi.")
569
+ print(f"Invalid line skipped: {line}")
570
+ print(f"{len(zeta_zeros)} zeta zeros loaded.")
568
571
  return np.array(zeta_zeros)
569
572
  except FileNotFoundError:
570
- print(f"'{filename}' dosyası bulunamadı.")
573
+ print(f"'{filename}' not found.")
571
574
  return np.array([])
572
575
 
576
+
573
577
  def _compute_gue_similarity(sequence, tolerance=0.5):
574
578
  """
575
- Keçeci dizisinin GUE (Gaussian Unitary Ensemble) istatistiğine ne kadar benzediğini ölçer.
579
+ Measures how closely the frequency spectrum of a Keçeci sequence matches the GUE (Gaussian Unitary Ensemble) statistics.
580
+ Uses Kolmogorov-Smirnov test against Wigner-Dyson distribution.
581
+ Args:
582
+ sequence (list): The Keçeci number sequence.
583
+ tolerance (float): Not used here; kept for interface consistency.
584
+ Returns:
585
+ tuple: (similarity_score, p_value)
576
586
  """
577
- from . import _get_integer_representation # Döngüsel import için gecikmeli import
587
+ from . import _get_integer_representation
578
588
 
579
589
  values = [val for z in sequence if (val := _get_integer_representation(z)) is not None]
580
590
  if len(values) < 10:
@@ -598,12 +608,12 @@ def _compute_gue_similarity(sequence, tolerance=0.5):
598
608
  if len(strong_freqs) < 2:
599
609
  return 0.0, 0.0
600
610
 
601
- # Ölçekleme: en güçlü pik 14.134725
611
+ # Scale so the strongest peak aligns with the first Riemann zeta zero
602
612
  peak_freq = strong_freqs[np.argmax(powers_pos[peaks])]
603
613
  scale_factor = 14.134725 / peak_freq
604
614
  scaled_freqs = np.sort(strong_freqs * scale_factor)
605
615
 
606
- # Level spacings (frekans farkları)
616
+ # Compute level spacings
607
617
  if len(scaled_freqs) < 2:
608
618
  return 0.0, 0.0
609
619
  diffs = np.diff(scaled_freqs)
@@ -611,7 +621,7 @@ def _compute_gue_similarity(sequence, tolerance=0.5):
611
621
  return 0.0, 0.0
612
622
  diffs_norm = diffs / np.mean(diffs)
613
623
 
614
- # GUE örnek üret (Wigner-Dyson)
624
+ # Generate GUE sample using Wigner-Dyson distribution
615
625
  def wigner_dyson(s):
616
626
  return (32 / np.pi) * s**2 * np.exp(-4 * s**2 / np.pi)
617
627
 
@@ -620,15 +630,22 @@ def _compute_gue_similarity(sequence, tolerance=0.5):
620
630
  p_gue = p_gue / np.sum(p_gue)
621
631
  sample_gue = np.random.choice(s_gue, size=1000, p=p_gue)
622
632
 
623
- # KS test: Keçeci vs GUE
633
+ # Perform KS test
624
634
  ks_stat, ks_p = ks_2samp(diffs_norm, sample_gue)
625
- similarity_score = 1.0 - ks_stat # Ne kadar küçükse, o kadar benzer
635
+ similarity_score = 1.0 - ks_stat
626
636
 
627
637
  return similarity_score, ks_p
628
638
 
639
+
629
640
  def _find_kececi_zeta_zeros(sequence, tolerance=0.5):
630
641
  """
631
- Keçeci dizisinin spektrumundan zeta sıfırlarını tahmin et.
642
+ Estimates the zeros of the Keçeci Zeta Function from the spectral peaks of the sequence.
643
+ Compares them to known Riemann zeta zeros.
644
+ Args:
645
+ sequence (list): The Keçeci number sequence.
646
+ tolerance (float): Maximum distance for a match between Keçeci and Riemann zeros.
647
+ Returns:
648
+ tuple: (list of Keçeci zeta zeros, matching score)
632
649
  """
633
650
  from . import _get_integer_representation
634
651
 
@@ -654,33 +671,39 @@ def _find_kececi_zeta_zeros(sequence, tolerance=0.5):
654
671
  if len(strong_freqs) < 2:
655
672
  return [], 0.0
656
673
 
657
- # Ölçekleme: en güçlü pik 14.134725
674
+ # Scale so the strongest peak aligns with the first Riemann zeta zero
658
675
  peak_freq = strong_freqs[np.argmax(powers_pos[peaks])]
659
676
  scale_factor = 14.134725 / peak_freq
660
677
  scaled_freqs = np.sort(strong_freqs * scale_factor)
661
678
 
662
- # Sıfır adayları (minimumlar)
679
+ # Find candidate zeros by analyzing the Keçeci Zeta Function
663
680
  t_vals = np.linspace(0, 650, 10000)
664
681
  zeta_vals = np.array([sum((scaled_freqs + 1e-10)**(- (0.5 + 1j * t))) for t in t_vals])
665
682
  minima, _ = find_peaks(-np.abs(zeta_vals), height=-0.5*np.max(np.abs(zeta_vals)), distance=5)
666
683
  kececi_zeta_zeros = t_vals[minima]
667
684
 
668
- # Eşleşme kontrolü
685
+ # Load Riemann zeta zeros for comparison
669
686
  zeta_zeros_imag = _load_zeta_zeros("zeta.txt")
670
687
  if len(zeta_zeros_imag) == 0:
671
688
  return kececi_zeta_zeros, 0.0
672
689
 
690
+ # Calculate matching score
673
691
  close_matches = [kz for kz in kececi_zeta_zeros if min(abs(kz - zeta_zeros_imag)) < tolerance]
674
692
  score = len(close_matches) / len(kececi_zeta_zeros) if kececi_zeta_zeros.size > 0 else 0.0
675
693
 
676
694
  return kececi_zeta_zeros, score
677
695
 
696
+
678
697
  def analyze_all_types(iterations=120):
679
698
  """
680
- 11 Keçeci sayı türü için otomatik GUE ve Riemann Zeta karşılaştırması yap.
681
- Sonuçları sıralar ve grafiklerle gösterir.
699
+ Performs automated analysis on all 11 Keçeci number types.
700
+ For each type, it tests multiple parameter sets, computes similarity to Riemann zeta zeros and GUE statistics,
701
+ then reports and plots the results.
702
+ Args:
703
+ iterations (int): Number of Keçeci steps to generate for each sequence.
704
+ Returns:
705
+ tuple: (sorted_by_zeta, sorted_by_gue) - Lists of results sorted by performance.
682
706
  """
683
-
684
707
  from . import (
685
708
  get_with_params,
686
709
  TYPE_POSITIVE_REAL,
@@ -696,14 +719,13 @@ def analyze_all_types(iterations=120):
696
719
  TYPE_NEUTROSOPHIC_BICOMPLEX
697
720
  )
698
721
 
699
-
700
- print("🔍 11 Keçeci Türü için Otomatik Analiz")
701
- print("="*80)
722
+ print("Automated Analysis for 11 Keçeci Types")
723
+ print("=" * 80)
702
724
 
703
725
  include_intermediate = True
704
726
  results = []
705
727
 
706
- # Parametre setleri
728
+ # Parameter sets to test
707
729
  param_sets = [
708
730
  ('0.0', '9.0'),
709
731
  ('1.0', '7.0'),
@@ -733,11 +755,11 @@ def analyze_all_types(iterations=120):
733
755
  best_gue_score = 0.0
734
756
  best_params = None
735
757
 
736
- print(f"🔄 Tür {kececi_type} ({name}) taranıyor...")
758
+ print(f"Analyzing type {kececi_type} ({name})...")
737
759
 
738
760
  for start, add in param_sets:
739
761
  try:
740
- # Özel formatlar
762
+ # Special formatting for complex types
741
763
  if kececi_type == 3 and '+' not in start:
742
764
  start = f"{start}+{start}j"
743
765
  if kececi_type == 10 and '+' not in start:
@@ -775,71 +797,198 @@ def analyze_all_types(iterations=120):
775
797
  'gue_score': best_gue_score
776
798
  })
777
799
 
778
- # Sonuçları sırala
800
+ # Sort results
779
801
  sorted_by_zeta = sorted(results, key=lambda x: x['zeta_score'], reverse=True)
780
802
  sorted_by_gue = sorted(results, key=lambda x: x['gue_score'], reverse=True)
781
803
 
782
- print("\n" + "="*100)
783
- print(" EN YÜKSEK RİEMANN ZETA EŞLEŞME SKORLARI (TOP 11)")
784
- print("="*100)
785
- print(f"{'Tür':<20} {'Skor':<8} {'Başlangıç':<12} {'Artım':<12}")
804
+ print("\n" + "=" * 100)
805
+ print("HIGHEST RIEMANN ZETA MATCHING SCORES (TOP 11)")
806
+ print("=" * 100)
807
+ print(f"{'Type':<20} {'Score':<8} {'Start':<12} {'Increment':<12}")
786
808
  print("-" * 100)
787
809
  for r in sorted_by_zeta:
788
810
  print(f"{r['name']:<20} {r['zeta_score']:<8.3f} {r['start']:<12} {r['add']:<12}")
789
811
 
790
- print("\n" + "="*100)
791
- print(" EN YÜKSEK GUE BENZERLİK SKORLARI (TOP 11)")
792
- print("="*100)
793
- print(f"{'Tür':<20} {'Skor':<8} {'Başlangıç':<12} {'Artım':<12}")
812
+ print("\n" + "=" * 100)
813
+ print("HIGHEST GUE SIMILARITY SCORES (TOP 11)")
814
+ print("=" * 100)
815
+ print(f"{'Type':<20} {'Score':<8} {'Start':<12} {'Increment':<12}")
794
816
  print("-" * 100)
795
817
  for r in sorted_by_gue:
796
818
  print(f"{r['name']:<20} {r['gue_score']:<8.3f} {r['start']:<12} {r['add']:<12}")
797
819
 
798
- # Grafikler
820
+ # Plot results
799
821
  _plot_comparison(sorted_by_zeta, sorted_by_gue)
800
822
 
801
823
  return sorted_by_zeta, sorted_by_gue
802
824
 
825
+
803
826
  def _plot_comparison(zeta_results, gue_results):
804
- """İki sonuç setini karşılaştırmak için grafikler çizer."""
805
- # --- Riemann Zeta Eşleşme Grafiği ---
827
+ """
828
+ Creates bar charts comparing the performance of Keçeci types in matching Riemann zeta zeros and GUE statistics.
829
+ Args:
830
+ zeta_results (list): Results sorted by zeta matching score.
831
+ gue_results (list): Results sorted by GUE similarity score.
832
+ """
833
+ # Riemann Zeta Matching Plot
806
834
  plt.figure(figsize=(14, 7))
807
835
  types = [r['name'] for r in zeta_results]
808
836
  scores = [r['zeta_score'] for r in zeta_results]
809
837
  colors = ['skyblue'] * len(scores)
810
838
  if scores:
811
- colors[0] = 'red' # En iyi olanı kırmızı yap
839
+ colors[0] = 'red'
812
840
  bars = plt.bar(types, scores, color=colors, edgecolor='black', alpha=0.8)
813
841
  plt.xticks(rotation=45, ha='right')
814
- plt.ylabel("Riemann Zeta Eşleşme Oranı")
815
- plt.title("Keçeci Türlerinin Riemann Zeta Sıfırlarıyla Eşleşmesi")
842
+ plt.ylabel("Riemann Zeta Matching Score")
843
+ plt.title("Keçeci Types vs Riemann Zeta Zeros")
816
844
  plt.grid(True, alpha=0.3)
817
- # En iyi barı kalın yap (eğer varsa)
818
845
  if bars:
819
846
  bars[0].set_edgecolor('darkred')
820
847
  bars[0].set_linewidth(1.5)
821
848
  plt.tight_layout()
822
849
  plt.show()
823
850
 
824
- # --- GUE Benzerlik Grafiği ---
851
+ # GUE Similarity Plot
825
852
  plt.figure(figsize=(14, 7))
826
853
  types = [r['name'] for r in gue_results]
827
854
  scores = [r['gue_score'] for r in gue_results]
828
855
  colors = ['skyblue'] * len(scores)
829
856
  if scores:
830
- colors[0] = 'red' # En iyi olanı kırmızı yap
857
+ colors[0] = 'red'
831
858
  bars = plt.bar(types, scores, color=colors, edgecolor='black', alpha=0.8)
832
859
  plt.xticks(rotation=45, ha='right')
833
- plt.ylabel("GUE Benzerlik Skoru")
834
- plt.title("Keçeci Türlerinin GUE İstatistiğine Benzerliği")
860
+ plt.ylabel("GUE Similarity Score")
861
+ plt.title("Keçeci Types vs GUE Statistics")
835
862
  plt.grid(True, alpha=0.3)
836
- # En iyi barı kalın yap (eğer varsa)
837
863
  if bars:
838
864
  bars[0].set_edgecolor('darkred')
839
865
  bars[0].set_linewidth(1.5)
840
866
  plt.tight_layout()
841
867
  plt.show()
842
868
 
869
+ def _pair_correlation(ordered_zeros, max_gap=3.0, bin_size=0.1):
870
+ """
871
+ Computes the pair correlation of a list of ordered zeros.
872
+ This function calculates the normalized spacings between all pairs of zeros
873
+ and returns a histogram of their distribution.
874
+ Args:
875
+ ordered_zeros (numpy.ndarray): Sorted array of zero locations (e.g., Keçeci or Riemann zeta zeros).
876
+ max_gap (float): Maximum normalized gap to consider.
877
+ bin_size (float): Size of bins for the histogram.
878
+ Returns:
879
+ tuple: (bin_centers, histogram) - The centers of the bins and the normalized histogram values.
880
+ """
881
+ n = len(ordered_zeros)
882
+ if n < 2:
883
+ return np.array([]), np.array([])
884
+
885
+ # Compute average spacing for normalization
886
+ avg_spacing = np.mean(np.diff(ordered_zeros))
887
+ normalized_zeros = ordered_zeros / avg_spacing
888
+
889
+ # Compute all pairwise gaps within max_gap
890
+ gaps = []
891
+ for i in range(n):
892
+ for j in range(i + 1, n):
893
+ gap = abs(normalized_zeros[j] - normalized_zeros[i])
894
+ if gap <= max_gap:
895
+ gaps.append(gap)
896
+
897
+ # Create histogram
898
+ bins = np.arange(0, max_gap + bin_size, bin_size)
899
+ hist, _ = np.histogram(gaps, bins=bins, density=True)
900
+ bin_centers = (bins[:-1] + bins[1:]) / 2
901
+
902
+ return bin_centers, hist
903
+
904
+
905
+ def _gue_pair_correlation(s):
906
+ """
907
+ Theoretical pair correlation function for the Gaussian Unitary Ensemble (GUE).
908
+ This function is used as a reference for comparing the statistical distribution
909
+ of eigenvalues (or zeta zeros) in quantum chaotic systems.
910
+ Args:
911
+ s (numpy.ndarray or float): Normalized spacing(s).
912
+ Returns:
913
+ numpy.ndarray or float: The GUE pair correlation value(s) at s.
914
+ """
915
+ return 1 - np.sinc(s)**2
916
+
917
+
918
+ def analyze_pair_correlation(sequence, title="Pair Correlation of Keçeci Zeta Zeros"):
919
+ """
920
+ Analyzes and plots the pair correlation of Keçeci Zeta zeros derived from a Keçeci sequence.
921
+ Compares the empirical pair correlation to the theoretical GUE prediction.
922
+ Performs a Kolmogorov-Smirnov test to quantify the similarity.
923
+ Args:
924
+ sequence (list): A Keçeci number sequence.
925
+ title (str): Title for the resulting plot.
926
+ """
927
+ from . import _get_integer_representation
928
+
929
+ # Extract integer representations and remove DC component
930
+ values = [val for z in sequence if (val := _get_integer_representation(z)) is not None]
931
+ if len(values) < 10:
932
+ print("Insufficient data.")
933
+ return
934
+
935
+ values = np.array(values) - np.mean(values)
936
+ N = len(values)
937
+ powers = np.abs(fft(values))**2
938
+ freqs = fftfreq(N)
939
+
940
+ # Filter positive frequencies
941
+ mask = (freqs > 0)
942
+ freqs_pos = freqs[mask]
943
+ powers_pos = powers[mask]
944
+
945
+ if len(powers_pos) == 0:
946
+ print("No positive frequencies found.")
947
+ return
948
+
949
+ # Find spectral peaks
950
+ peaks, _ = find_peaks(powers_pos, height=np.max(powers_pos)*1e-7)
951
+ strong_freqs = freqs_pos[peaks]
952
+
953
+ if len(strong_freqs) < 2:
954
+ print("Insufficient frequency peaks.")
955
+ return
956
+
957
+ # Scale frequencies so the strongest peak aligns with the first Riemann zeta zero
958
+ peak_freq = strong_freqs[np.argmax(powers_pos[peaks])]
959
+ scale_factor = 14.134725 / peak_freq
960
+ scaled_freqs = np.sort(strong_freqs * scale_factor)
961
+
962
+ # Estimate Keçeci Zeta zeros by finding minima of |ζ_Kececi(0.5 + it)|
963
+ t_vals = np.linspace(0, 650, 10000)
964
+ zeta_vals = np.array([sum((scaled_freqs + 1e-10)**(- (0.5 + 1j * t))) for t in t_vals])
965
+ minima, _ = find_peaks(-np.abs(zeta_vals), height=-0.5*np.max(np.abs(zeta_vals)), distance=5)
966
+ kececi_zeta_zeros = t_vals[minima]
967
+
968
+ if len(kececi_zeta_zeros) < 2:
969
+ print("Insufficient Keçeci zeta zeros found.")
970
+ return
971
+
972
+ # Compute pair correlation
973
+ bin_centers, hist = _pair_correlation(kececi_zeta_zeros, max_gap=3.0, bin_size=0.1)
974
+ gue_corr = _gue_pair_correlation(bin_centers)
975
+
976
+ # Plot results
977
+ plt.figure(figsize=(12, 6))
978
+ plt.plot(bin_centers, hist, 'o-', label="Keçeci Zeta Zeros", linewidth=2)
979
+ plt.plot(bin_centers, gue_corr, 'r-', label="GUE (Theoretical)", linewidth=2)
980
+ plt.title(title)
981
+ plt.xlabel("Normalized Spacing (s)")
982
+ plt.ylabel("Pair Correlation Density")
983
+ plt.legend()
984
+ plt.grid(True, alpha=0.3)
985
+ plt.tight_layout()
986
+ plt.show()
987
+
988
+ # Perform Kolmogorov-Smirnov test
989
+ ks_stat, ks_p = ks_2samp(hist, gue_corr)
990
+ print(f"Pair Correlation KS Test: Statistic={ks_stat:.4f}, p-value={ks_p:.4f}")
991
+
843
992
  # ==============================================================================
844
993
  # --- CORE GENERATOR ---
845
994
  # ==============================================================================
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kececinumbers
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: Keçeci Numbers: An Exploration of a Dynamic Sequence Across Diverse Number Sets
5
5
  Home-page: https://github.com/WhiteSymmetry/kececinumbers
6
6
  Author: Mehmet Keçeci
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "kececinumbers"
9
- version = "0.6.4"
9
+ version = "0.6.5"
10
10
 
11
11
  # Diğer proje bilgileri (isteğe bağlı ama tavsiye edilir)
12
12
  authors = [
@@ -53,6 +53,7 @@ setup(
53
53
  "numpy",
54
54
  "matplotlib",
55
55
  "numpy-quaternion",
56
+ "scipy",
56
57
  "sympy",
57
58
  ],
58
59
  extras_require={
File without changes
File without changes
File without changes
File without changes