Skip to content

Instantly share code, notes, and snippets.

@ian-r-rose
Created October 30, 2015 02:01
Show Gist options
  • Save ian-r-rose/f296376d0d824ee34dbe to your computer and use it in GitHub Desktop.
Save ian-r-rose/f296376d0d824ee34dbe to your computer and use it in GitHub Desktop.
Issue 10062
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import os\n",
"#os.environ['SYMPY_DEBUG'] = 'True'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class Parameter(object):\n",
" def __init__(self, symbol):\n",
" self.symbol = symbol\n",
" def _repr_latex_(self):\n",
" return '$'+self.symbol+'$'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"density = Parameter('\\\\rho')\n",
"gravity = Parameter('g')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<__main__.Parameter at 0x7ff5050c1e90>,\n",
" <__main__.Parameter at 0x7ff5050c1dd0>]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[gravity, density]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class ParameterList(list):\n",
" def _repr_latex_(self):\n",
" string = '$['\n",
" for n in range(len(self)):\n",
" string += self.__getitem__(n).symbol\n",
" if n != len(self)-1:\n",
" string += ', '\n",
" string += '$]'\n",
" return string"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$[\\rho, g$]"
],
"text/plain": [
"[<__main__.Parameter at 0x7ff5050c1dd0>,\n",
" <__main__.Parameter at 0x7ff5050c1e90>]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plist = ParameterList([density,gravity])\n",
"plist"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from sympy import *\n",
"from sympy.abc import a, b, c"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'sympy/__init__.pyc'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import sympy\n",
"sympy.__file__"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'0.7.7.dev'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sympy.__version__"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'4.0.0'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import IPython\n",
"IPython.__version__"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"init_printing()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<__main__.Parameter at 0x7ff5050c1dd0>,\n",
" <__main__.Parameter at 0x7ff5050c1e90>]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plist"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$g$"
],
"text/plain": [
"<__main__.Parameter at 0x7ff5050c1e90>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gravity"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAAsAAAAJBAMAAAAWSsseAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIquJdjLdEETvu2aZ\nVM0GsGrEAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAR0lEQVQIHWNgYFR2TWdgYOgU4PrAwMA+m4Fn\nAQMDz3cGNgcGBs4FDPUBDAz1Bgz3GQoY6i8wrOMVYOBz4E5iBqpUMRXyYAAAgLMMA5qDwz8AAAAA\nSUVORK5CYII=\n",
"text/latex": [
"$$a$$"
],
"text/plain": [
"a"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAHEAAAAbBAMAAAC5P33fAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAu90iq4l2MhBE72aZ\nVM1Y/xyvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB40lEQVQ4EZ2UO0gjURSG/yTG3DHGESsRQYlg\nIYhT2DuVWywsYYVUIjZai/Y6+GhUMAhiYaFiJVsYtt5ibFwbURHsxBRipUEQX4XGo3Nu7p1HQLyQ\n3P/85/8y9zEEkGO43ZFSzcn9Q1XUUEmrrhRuDeFX2GSnJWt9qriVug+HujDjtQOt1WwOnew1FBIv\ngTaVuxgohF1yEnaVBDLPUZlLJ8r1k/HRqEx3lBl45rA/I9o6yUi6fpeq5fx/P5kOZppsiv2jT2Dc\nYtbyrXYN615kjpPmCWDkjIkAmN5CsqSTqduLVi9zztFNB5i+OKVv34jZH2epnW1DpXLnJST5m8q9\nSsWHUWHaMF4l2Z+fdFRAklfjR8pUasWF8ciksYMO1QGT4s0xLc2WciCH1AOTi0XsS59mJmkzZk6z\npdTJYwf6fTPZWMJKFElmdbXbEE/yF0fK5Z5y+YbKJhebJ9LWZtNFhk9IPCBzJ1SPn2kWQYsJj3gz\n0nwr4hWx0pmKSLIg/ihTqfot0Ea8+7zGX1vbEZN1xZj7mRdvCvtQvVicYHJ+bGqwoLpMioOf7PU5\nqklqYfyH/42vdpms1jAspaXS3j5pARtKeiodNKiOJEO5pZDzVbL4bTIC/OJqa5BZ/r+Natf2VrP2\nO35ccY7W2jpnAAAAAElFTkSuQmCC\n",
"text/latex": [
"$$\\left [ a^{2} + b^{2}, \\quad 0\\right ]$$"
],
"text/plain": [
"⎡ 2 2 ⎤\n",
"⎣a + b , 0⎦"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[a**2 + b**2, 0]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<__main__.Parameter at 0x7ff5050c1e90>, a, b]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[gravity, a, b]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment