Skip to content

Instantly share code, notes, and snippets.

@ananthp
Last active November 28, 2017 11:43
Show Gist options
  • Save ananthp/a21582838ee04e307fc572267a0e8bab to your computer and use it in GitHub Desktop.
Save ananthp/a21582838ee04e307fc572267a0e8bab to your computer and use it in GitHub Desktop.
sympy: Creating rich symbols
# Creating rich symbols with sympy
# Run this code on Sympy Live: http://bit.ly/rich-symbols
from sympy import *
init_printing()
# sympy.abc defines all greek alphabets.
# Even otherwise, when we create a symbol like alpha, beta etc,
# we get a nice greek alphabet representation with init_printing
alpha = symbols('alpha')
# underscore for subscripts, ^ for superscripts
ai, yn = symbols('a_i, y^n')
# can be combined
beta_i_n = symbols('beta_i^n')
vttt = symbols("upsilon^'''")
# Latex can be used to form rich symbols
vttt_latex = symbols(r"\upsilon^{'''}")
# The curious case of pi:
# We don't have to create the symbol pi, as it is defined by sympy.
# We can use pi both symbolically and numerically.
alpha, ai, yn, beta_i_n, vttt, vttt_latex, pi, N(pi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment