Skip to content

Commit f194eaf

Browse files
Refactor hypercomplex and ternary type handling
1 parent d76e602 commit f194eaf

1 file changed

Lines changed: 15 additions & 38 deletions

File tree

kececinumbers/kececinumbers.py

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,26 +4501,26 @@ def is_prime_like(value: Any, kececi_type: int = None) -> bool:
45014501
# Tip sabitleri proje içinde farklı isimlerde olabilir; burada sayısal kodlar kullanılıyor.
45024502
# Kullanıcının tanımladığı TYPE_* sabitlerini kullanıyorsanız onları import edin veya
45034503
# burada numeric karşılıklarını verin. Örnek: TYPE_HYPERCOMPLEX == 23
4504-
TYPE_HYPERCOMPLEX = 23
45054504
TYPE_QUATERNION = 6
45064505
TYPE_OCTONION = 12
45074506
TYPE_SEDENION = 13
4507+
TYPE_CLIFFORD = 14
45084508
TYPE_PATHION = 17
45094509
TYPE_CHINGON = 18
45104510
TYPE_ROUTON = 19
45114511
TYPE_VOUDON = 20
4512-
TYPE_TERNARY = 22
4513-
TYPE_CLIFFORD = 14
45144512
TYPE_SUPERREAL = 21
4513+
TYPE_TERNARY = 22
4514+
TYPE_HYPERCOMPLEX = 23
45154515

45164516
# Quaternion özel kontrol
45174517
# Quaternion ve diğer tiplerde coeffs alırken:
45184518
if kececi_type == TYPE_QUATERNION:
45194519
try:
45204520
# Eğer metot ise çağır
4521-
if hasattr(value, "coeffs") and callable(value.coeffs):
4521+
if hasattr(value, 'coeffs') and callable(value.coeffs):
45224522
comps = list(value.coeffs())
4523-
elif hasattr(value, "coeffs"):
4523+
elif hasattr(value, 'coeffs'):
45244524
comps = list(value.coeffs) # property ise direkt
45254525
else:
45264526
comps = _parse_components(value)
@@ -4551,20 +4551,12 @@ def is_prime_like(value: Any, kececi_type: int = None) -> bool:
45514551
n = int(round(float(sub)))
45524552

45534553
# Hypercomplex family (octonion, sedenion, pathion, ...)
4554-
if kececi_type in (
4555-
TYPE_OCTONION,
4556-
TYPE_SEDENION,
4557-
TYPE_PATHION,
4558-
TYPE_CHINGON,
4559-
TYPE_ROUTON,
4560-
TYPE_VOUDON,
4561-
TYPE_HYPERCOMPLEX,
4562-
):
4554+
if kececi_type in (TYPE_OCTONION, TYPE_SEDENION, TYPE_PATHION, TYPE_CHINGON, TYPE_ROUTON, TYPE_VOUDON, TYPE_HYPERCOMPLEX):
45634555
try:
45644556
# extract coeffs
4565-
if hasattr(value, "coeffs"):
4557+
if hasattr(value, 'coeffs'):
45664558
coeffs = list(value.coeffs())
4567-
elif hasattr(value, "to_list"):
4559+
elif hasattr(value, 'to_list'):
45684560
coeffs = list(value.to_list())
45694561
elif isinstance(value, (list, tuple)):
45704562
coeffs = list(value)
@@ -4584,28 +4576,13 @@ def is_prime_like(value: Any, kececi_type: int = None) -> bool:
45844576
# Ternary
45854577
if kececi_type == TYPE_TERNARY:
45864578
try:
4587-
# If object has to_decimal or digits
4588-
if hasattr(value, "to_decimal"):
4589-
dec = int(value.to_decimal())
4590-
elif hasattr(value, "digits"):
4591-
digits = list(value.digits)
4592-
dec = 0
4593-
for i, d in enumerate(reversed(digits)):
4594-
dec += int(d) * (3**i)
4595-
elif isinstance(value, (list, tuple)):
4596-
parts = list(value)
4597-
dec = 0
4598-
for i, d in enumerate(reversed(parts)):
4599-
dec += int(d) * (3**i)
4600-
else:
4601-
# try parse first component
4602-
comps = _parse_components(value)
4603-
if not comps:
4604-
return False
4605-
dec = int(round(comps[0]))
4606-
if _sympy_isprime:
4607-
return bool(_sympy_isprime(dec))
4608-
return _simple_is_prime(dec)
4579+
# Ternary sayıyı integer'a çevir
4580+
n = _get_integer_representation(value)
4581+
if n is not None and n > 1:
4582+
if _sympy_isprime:
4583+
return bool(_sympy_isprime(n))
4584+
return _simple_is_prime(n)
4585+
return False
46094586
except Exception:
46104587
return False
46114588

0 commit comments

Comments
 (0)