demathpy 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
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.
- demathpy/symbols.py +18 -3
- {demathpy-0.0.1.dist-info → demathpy-0.0.2.dist-info}/METADATA +1 -1
- demathpy-0.0.2.dist-info/RECORD +8 -0
- demathpy-0.0.1.dist-info/RECORD +0 -8
- {demathpy-0.0.1.dist-info → demathpy-0.0.2.dist-info}/WHEEL +0 -0
- {demathpy-0.0.1.dist-info → demathpy-0.0.2.dist-info}/licenses/LICENSE +0 -0
demathpy/symbols.py
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
demathpy/__init__.py,sha256=M9USmv1V8FoXhHVFtOlwO8zyEA1cafpubvBEDLQ4eXw,722
|
|
2
|
+
demathpy/ode.py,sha256=3SgeiYbHUov9NtrKCOhCo2I4DFLLdh5iIqkhPxwt254,4188
|
|
3
|
+
demathpy/pde.py,sha256=TjX9ICiJOO54_CPRZljRdOgMCuHwXFs-eaXDdM4O1hQ,13645
|
|
4
|
+
demathpy/symbols.py,sha256=fYCJ8ja4tgkMg1BlSGiV4bHt7i9yXSI57F8M-8nl0Qg,12957
|
|
5
|
+
demathpy-0.0.2.dist-info/licenses/LICENSE,sha256=Vofo4OGPZaOEnCixsvF2MaZSGdpDI4uVMm9GNEjSGBM,1064
|
|
6
|
+
demathpy-0.0.2.dist-info/WHEEL,sha256=e_m4S054HL0hyR3CpOk-b7Q7fDX6BuFkgL5OjAExXas,80
|
|
7
|
+
demathpy-0.0.2.dist-info/METADATA,sha256=kD-ZEpceKifIhUV2rnsRavX_hKgITfhSZWraB0Z5Io8,3118
|
|
8
|
+
demathpy-0.0.2.dist-info/RECORD,,
|
demathpy-0.0.1.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
demathpy/__init__.py,sha256=M9USmv1V8FoXhHVFtOlwO8zyEA1cafpubvBEDLQ4eXw,722
|
|
2
|
-
demathpy/ode.py,sha256=3SgeiYbHUov9NtrKCOhCo2I4DFLLdh5iIqkhPxwt254,4188
|
|
3
|
-
demathpy/pde.py,sha256=TjX9ICiJOO54_CPRZljRdOgMCuHwXFs-eaXDdM4O1hQ,13645
|
|
4
|
-
demathpy/symbols.py,sha256=LwwqdmvDX_-G2T9t885sPdI4G7bSzMY6d07-uwuzyl4,11904
|
|
5
|
-
demathpy-0.0.1.dist-info/licenses/LICENSE,sha256=Vofo4OGPZaOEnCixsvF2MaZSGdpDI4uVMm9GNEjSGBM,1064
|
|
6
|
-
demathpy-0.0.1.dist-info/WHEEL,sha256=e_m4S054HL0hyR3CpOk-b7Q7fDX6BuFkgL5OjAExXas,80
|
|
7
|
-
demathpy-0.0.1.dist-info/METADATA,sha256=wK14apREWoyXvKuekx-jcOahaG8gOk4IhmIdXj4P7P0,3118
|
|
8
|
-
demathpy-0.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|