MEP
Mathematical Expression Parsing
Install / Use
/learn @yuanhang2008/MEPREADME
MEP
Mathematical Expression Parsing
Stargazers over time
install
In the directory of MEP:
pip install .
or use setup.py to install:
python setup.py install
usage
formula
Use MEP.Formula and MEP.X to product a formula.
>>>import MEP
>>>f = MEP.Formula(2 * MEP.X - 1)
Formula objects are printable and __str__ method is defined, but text method is recommended.
>>>print(f)
<Formula f(x)=2*x-1>
>>>str(f)
'<Formula f(x)=2*x-1>'
>>>f.text()
'2*x-1'
curry
curry method can curry a formula and return the curried formula.
>>>f1 = MEP.Formula(X + Y)
>>>f2 = f1.curry(x=2)
>>>print(f2.text())
2+y
symbol
A Symbol object can be defined by users, a symbol's name must be a letter.
A = MEP.Symbol('a')
f = Formula(A * 2)
A formula can contain multiple symbols, and 'x', 'y', 'z' are built-in, they are default symbols in MEP.
Use variable symbols to get all defined symbols's sign, you can also visit sign to get the sign of a symbol.
>>>MEP.symbols
{'x', 'y', 'z', 'a'}
>>>A.sign
'a'
expression
Substitute a value to build a new expression.The substituted values should correspond to the symbols by using keyword arguments, the key names are symbols's signs.
>>>f = MEP.Formula(2 * MEP.X - 1)
>>>exp = f.subs(x=2) # an Expression object
>>>exp.value()
3
>>>print(exp)
<Expression f(x=2)=2*2-1>
>>>exp.text()
'2*2-1'
math
Class Math provides with some special functions, which can participate in formula generations.
>>>f = Formula(Math.abs(9 - MEP.X)) # equal to |9-x|
>>>exp = f.subs(x=12)
>>>exp.value()
3
Features in Development
- [ ] Show functions images with tkinter.
- [ ] Code for test (too lazy to write.
- [ ] Analyze formulas, such as calculating definition domains.
- [ ] Optimize the code.
- [ ] Consider removing "draw" or verifying whether it is still required. ...
Bugs/Requests
Please send bug reports and feature requests through github issue tracker.
About Author
Bilbili: 航sail654 Github: yuanhang2008 QQ: 远航
License
Copyright yuanhang2008, 2023.
Distributed under the terms of the MIT License.
Change Log
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
