Skip to main content

A library for manipulating expressions in both infix and postfix notation (Reverse Polish Notation or RPN)

Project description

pypostfix

https://github.com/Slinky802/pypostfix

pypostfix is a Python library for manipulating expressions in both infix and postfix notation (Reverse Polish Notation or RPN).

Contents


Installation

To install the library, use pip :

pip install pypostfix

Use

You can use directly import pypostfix or use from pypostfix import RPNand from pypostfix import Stack

Basic example of calculating an infix notation by converting it to postfix and then evaluating it:

from pypostfix import RPN

expression = RPN.infix_to_rpn("sin(3*2+9)")
print(expression)
print(RPN.calc_rpn(expression))
# output : 
# 3 2 * 9 + sin
# -0.9589242746631385

Basic example of manipulating stacks :

from pypostfix import Stack

stack = Stack()
stack.push(4) # adds 4 to the stack
print(stack.size()) # outputs the size of the stack
print(stack.peek()) # outputs the top element of the stack
print(stack.size())
print(stack.pop()) # removes and outputs the top element of the stack
print(stack.isempty()) # Tests if the stack is empty

Features

Convert infix to postfix:

from pypostfix import RPN

RPN.infix_to_rpn("sin(3*2+9)")

Convert posfix to infix:

from pypostfix import RPN

RPN.rpn_to_infix("3 2 + sin dup sqrt +")
RPN.rpn_to_infix("3;2;+;sin;dup;sqrt;+", sep=";")

Test if a postfix expression is valid:

from pypostfix import RPN

RPN.rpn_is_valid("3 0 /")
RPN.rpn_is_valid("3,0,/", sep=",")

Evaluate a postfix expression:

from pypostfix import RPN

RPN.calc_rpn("3 2 5 * swap /")
RPN.calc_rpn("3:2:5:*:swap:/", sep=":")

Manipulate stacks:

from pypostfix import Stack

stack = Stack()

stack.push(4)
print(stack.size())
print(stack.peek())
print(stack.size())
print(stack.pop())
print(stack.isempty())
# output :
# 1
# 4
# 1
# 4
# True

License

This project is licensed under the MIT license - see the LICENSE file for details.


Contribute

We welcome contributions to improve and expand the pypostfix library ! Whether you want to add a feature, fix a bug, or enhance the documentation, follow these steps to contribute:

Steps to Contribute

  1. Fork the Repository: Create a copy of the project on your GitHub account using the "Fork" button.

  2. Clone the Project: Clone your fork locally to work on the code.

    git clone https://github.com/Slinky802/pypostfix
    cd pypostfix
    
  3. Create a New Branch: Before making changes, create a new branch for your work.

    git checkout -b my_new_feature
    
  4. Make Your Changes: Add your modifications or new features.

  5. Submit a Pull Request (PR): Once your changes are ready, push them to your fork, then submit a PR to the master branch of this repository.

  • Describe your changes and their purpose.
  • Mention any related issues you've resolved.
  • Request a code review.

Code Review Policy

To maintain the project's stability and security, we have implemented a branch protection policy:

  • Any changes to the main branch must go through a Pull Request.
  • Each PR requires a review and may need approval before merging.
  • Only administrators and trusted contributors can merge approved PRs.

Contact

Created by Alexandre Poggioli (Slinky802) - alexandrepoggioli09@gmail.com

More information on https://slinky-presentation.netlify.app

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypostfix-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypostfix-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pypostfix-1.0.0.tar.gz.

File metadata

  • Download URL: pypostfix-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.12

File hashes

Hashes for pypostfix-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cef5b625586390fd49e9feb93534b8e36cc511f53572ec3e87845c9f78d6008d
MD5 173cbbfd8a67b6e23ecdf28eea37ce00
BLAKE2b-256 981454fa6bc005b030863a7ca8f7f28d691ca6218b82cf29db8b1642fb04de56

See more details on using hashes here.

File details

Details for the file pypostfix-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pypostfix-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.12

File hashes

Hashes for pypostfix-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b002ce5e7fcb9b9701404f046bf93f97d7bfa0cfe1318d05440dc14e08ddaa7
MD5 fe40e5c1e5c7100c18185791fbd9ca7e
BLAKE2b-256 abc6e256374e658108af83d28ca01fbbbfd7a96318f179c097deb2e6bcd6021c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page