GithubHelp home page GithubHelp logo

yuanhang2008 / mep Goto Github PK

View Code? Open in Web Editor NEW
111.0 2.0 1.0 116 KB

Mathematical Expression Parsing

Home Page: https://github.com/yuanhang2008/MEP

License: MIT License

Python 99.92% Batchfile 0.08%
expression formula function math parsing

mep's Introduction

MEP

License Language Version Dynamic JSON Badge

Mathematical Expression Parsing.

Stargazers over time

Stargazers over time

install

Run auto_install_1.bat to install MEP, if it doesn't work, try enter pip install setuptools and pip install wheel to install the two necessary libraries, please. auto_install_2.bat can install MEP as a temporary modules, you can use it if you are just here to test the library or try some features, not at work or important occasions.

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'

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'

draw

Draw is used to draw a function plot in matplotlib.

>>>range_ = (-100, 100)

>>>f1 = Formula(2 * MEP.X + 1)
>>>f2 = Formula(MEP.X ** 2)

>>>f1.draw(range_)
>>>f2.draw(range_)

>>>Draw.display()

More functions, such as clear: clear all the formulas in Draw object.

>>>Draw.clear()
>>>Draw.display()
# Nothing to show

setprec: set the precision of the plot. the larger the precision, the more detailed the plot, but the slower the program runs.

However, drawing a formula contains multiple symbols is invalid.

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

curry

curry method can curry a formula and return the curried formula.

>>>f1 = MEP.Formula(X + Y)
>>>f2 = f1.curry(x=2)
>>>exp = f2.subs(y=3)

>>>exp.value
5

Features in Development

  • merge formulas by functions in Math
  • show functions images with tkinter
  • code for test (too lazy to write
  • analyze formulas, such as calculating definition domains
  • document strings
  • optimize the code
    ...

Bugs/Requests

Please send bug reports and feature requests through github issue tracker.

About Author

Bilbili: l_yuanhang_l Github: yuanhang2008 QQ: 远θˆͺ

License

Copyright yuanhang2008, 2023.

Distributed under the terms of the MIT License.

Change Log

ChangeLog

mep's People

Contributors

yuanhang2008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

slu010

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.