HandCalcs module in Python - GeeksforGeeks

05 Sep, 2020
HandCalcs is a library in Python to make calculations automatically in Latex, but in a way that imitates how the equation might be formatted when handwritten, write the mathematical formula, supported by numerical substitutions, and then the output. Since HandCalcs indicates the numerical replacement, the equations become much easier to manually check and verify. 
Run the following pip command on the terminal.
pip install handcalcs

The HandCalcs library in Python is designed to be used in Jupyter Notebook or Jupyter Lab as a cell magic.To use the render feature of the HandCalcs library, import the module by executing import handcalcs.render, after that just use the %%render on the top of the cell in which equations or variables are to be rendered with HandCalcs.
Example 1: Addition of 2 numbers 
Python3
# importing the moduleimport handcalcs.render  x = 5y = 6  # run the code below in a new Jupyter cell%%renderz = x + y
Output:  
Example 2: Calculating the tan of an expression. 
Python3
# importing the librariesimport handcalcs.renderfrom math import tan  p = 5r = 12s = 3.5  # run the code below in a new Jupyter cell%%rendert = tan(p ** r + r / s) * r
Output:  
Example 3: Quadratic equation with square root. 
Python3
# importing the moduleimport handcalcs.renderfrom math import sqrt  a = 6b = 7c = -8  # run the code below in a new Jupyter cell%%renderr = (-b + sqrt(b ** 2 - 4 * a * c)) / (2 * a)
Output:  
 
By using comments, HandCalcs make some conclusions as to how the equation to be structured. Only a single comment can be used per cell.
Three types of customizations can be created using the # comment tags at the top of the cell:  
1. # Parameters: The display structure of the variables or parameters can be controlled by using the # Parameter tag, this tag is used to classify the display structure into the vertical display or horizontal display.  
Example: Without the # Parameter comment, all the equations will be displayed vertically  
Python3
# importing the moduleimport handcalcs.render  # run the code below in a new Jupyter cell%%renderp = 5q = 4r = 3s = 2t = 1
Output:  
Example: This time the # Parameter comment is used. 
Python3
# importing the moduleimport handcalcs.render  # run the code below in a new Jupyter cell%%render  # Parameterp = 5q = 4r = 3s = 2t = 1
Output:  
2. # Long and # Short: As # Parameter comment tag is used to control the display structure of variables in the same way # Long and # Short comment tags control the display structure of equations, the # Long and # Short are used to display equations vertically and horizontally respectively. 
Example: Displaying the equations horizontally using # Short. 
Python3
# importing the modulesimport handcalcs.renderfrom math import sqrt  a = 6b = 7c = -8  # run the code below in a new Jupyter cell%%render  # Shortx = b ** 2 - 4 * a * cd = sqrt(x)r1 = (-b + d) / (2 * a) r2 = (-b - d) / (2 * a)
Output:  
Example: Displaying the equations vertically using # Long. 
Python3
# importing the modulesimport handcalcs.renderfrom math import sqrt  a = 6b = 7c = -8  # run the code below in a new Jupyter cell%%render  # Longx = b ** 2 - 4 * a * cd = sqrt(x)r1 = (-b + d) / (2 * a) r2 = (-b - d) / (2 * a)
Output:  
3. # Symbolic: The HandCalcs library’s primary objective is to make the complete equation using the numerical substitution. This makes the equation easy to track and validate. However, there might be situations where equations are represented symbolically, the # Symbolic comment tag cab symbolically render Latex equations.  
Example:  
Python3
# imporintg the modulesimport handcalcs.renderfrom math import sqrt, tan  # Parametersa = 6b = 7c = -8x = 9y = 10  # run the code below in a new Jupyter cell%%render  # Symbolicr = (-b + sqrt(b ** 2 -4 * a * c)) / (2 * a)z = tan(x ** y + y / x)
Output:  
python-modules
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install PIP on Windows ?
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Pandas dataframe.groupby()
Defaultdict in Python
Python | Get unique values from a list
Python Classes and Objects
Python | os.path.join() method
Create a directory in Python