demathpy 0.0.1__tar.gz → 0.0.2__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: demathpy
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: PDE/ODE math backend
5
5
  Author: Misekai
6
6
  Author-email: Misekai <mcore-us@misekai.net>
@@ -1,7 +1,7 @@
1
1
 
2
2
  [project]
3
3
  name = "demathpy"
4
- version = "0.0.1"
4
+ version = "0.0.2"
5
5
  authors = [
6
6
  { name="Misekai", email="mcore-us@misekai.net" },
7
7
  ]
@@ -22,3 +22,8 @@ license-files = ["LICEN[CS]E*"]
22
22
  requires = ["uv_build >= 0.9.26, <0.10.0"]
23
23
  build-backend = "uv_build"
24
24
 
25
+ [dependency-groups]
26
+ dev = [
27
+ "pytest>=9.0.2",
28
+ ]
29
+
@@ -287,25 +287,40 @@ def normalize_symbols(expr: str) -> str:
287
287
  "omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega"
288
288
  )
289
289
  fn_words = "sin|cos|tan|sinh|cosh|tanh|exp|log|log10|log2|sqrt|abs|sech|sign"
290
+ # Use word boundary \b to avoid matching inside words
290
291
  expr = re.sub(rf"\b({greek_words})(?=({fn_words})\b)", r"\1*", expr)
291
- # Greek word directly followed by a single-letter variable (e.g., beta u)
292
- # Greek word directly followed by a single-letter variable (e.g., beta u) or concatenated (betau).
292
+ # Greek word directly followed by a single-letter variable (e.g., beta u) or concatenated (betau).
293
293
  # BUT do not split axis-suffixed coefficients like alphax/alphaz (common in anisotropic diffusion terms).
294
294
  _axis_coeffs = {
295
295
  "alphax", "alphaz", "betax", "betaz", "gammax", "gammaz", "deltax", "deltaz",
296
296
  "sigmax", "sigmaz", "thetax", "thetaz", "kappax", "kappaz", "lambdax", "lambdaz",
297
297
  "rhox", "rhoz", "mux", "muz", "nux", "nuz",
298
+ # Also protect eps/epsilon from being split
299
+ "epsilon", "eps",
298
300
  }
299
301
 
300
302
  def _split_greek_letter_var(m: re.Match) -> str:
301
303
  greek = m.group(1)
302
304
  letter = m.group(2)
303
305
  combined = f"{greek}{letter}"
306
+ # Don't split if this creates a known coefficient (e.g., alphax, sigmaz)
304
307
  if combined in _axis_coeffs:
305
308
  return combined
309
+ # Don't split if combined is the start of a greek word (to avoid "epsi*lon" from "epsilon")
310
+ # Check if any greek word starts with the combined string
311
+ all_greek_words = {"alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta",
312
+ "iota", "kappa", "lam", "mu", "nu", "xi", "omicron", "pi", "rho",
313
+ "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega"}
314
+ for gw in all_greek_words:
315
+ if gw.startswith(combined) and len(gw) > len(combined):
316
+ # combined is a prefix of a longer greek word, so don't split
317
+ return combined
318
+ # Otherwise, insert multiplication: betau -> beta*u
306
319
  return f"{greek}*{letter}"
307
320
 
308
- expr = re.sub(rf"({greek_words})([A-Za-z])", _split_greek_letter_var, expr)
321
+ # Only match at word boundaries to avoid splitting within words like 'epsilon'
322
+ # Use lookahead to detect when a greek word is followed by a single letter that starts a new token
323
+ expr = re.sub(rf"\b({greek_words})([A-Za-z])(?=([^a-zA-Z]|$))", _split_greek_letter_var, expr)
309
324
 
310
325
  # Absolute value for variables/parentheses
311
326
  expr = re.sub(r"\|\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\|", r"abs(\1)", expr)
File without changes
File without changes
File without changes
File without changes