Skip to content

Instantly share code, notes, and snippets.

@jonseymour
Last active March 9, 2025 09:46
Show Gist options
  • Save jonseymour/98e935d6647ae9cd5e3bd545ad02a82f to your computer and use it in GitHub Desktop.
Save jonseymour/98e935d6647ae9cd5e3bd545ad02a82f to your computer and use it in GitHub Desktop.
derivation of S_{2x+1}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "5cdc3c96-246e-4750-960e-342c9bd6ac2e",
"metadata": {},
"outputs": [],
"source": [
"import sympy as sy"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43a65d5a-63fd-4a86-b6bd-c929af36a74d",
"metadata": {},
"outputs": [],
"source": [
"S=sy.IndexedBase('S')\n",
"N,L,x = sy.symbols('N L x')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "38786401-53a5-49fc-912b-d954963a3eec",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle {S}_{x} = 2^{N} \\left(2 x + 1\\right) - 3^{L} x$"
],
"text/plain": [
"Eq(S[x], 2**N*(2*x + 1) - 3**L*x)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/latex": [
"$\\displaystyle {S}_{2 x + 1} = 2^{N} \\left(4 x + 2\\right) - 3^{L} \\left(2 x + 1\\right)$"
],
"text/plain": [
"Eq(S[2*x + 1], 2**N*(4*x + 2) - 3**L*(2*x + 1))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# S[x] = -3L(x) + 2N(2x + 1)\n",
"eqn1=sy.Eq(S[x], -3**L*x + 2**N*(2*x + 1))\n",
"# S[2x+1] = -3L(2x + 1) + 2N(4x + 2)\n",
"eqn2=sy.Eq(S[2*x+1], (-3**L)*(2*x + 1) + (2**N)*(4*x + 2))\n",
"\n",
"display(eqn1, eqn2)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "d925482f-1e63-42c9-9639-b5a55cd6fdea",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle 2 x + 1 = 2^{- N} \\left(3^{L} x + {S}_{x}\\right)$"
],
"text/plain": [
"Eq(2*x + 1, (3**L*x + S[x])/2**N)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/latex": [
"$\\displaystyle 2 x + 1 = 3^{- L} \\left(2^{N + 1} + 2^{N + 2} x - {S}_{2 x + 1}\\right)$"
],
"text/plain": [
"Eq(2*x + 1, (2**(N + 1) + 2**(N + 2)*x - S[2*x + 1])/3**L)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/latex": [
"$\\displaystyle 2^{- N} \\left(3^{L} x + {S}_{x}\\right) = 3^{- L} \\left(2^{N + 1} + 2^{N + 2} x - {S}_{2 x + 1}\\right)$"
],
"text/plain": [
"Eq((3**L*x + S[x])/2**N, (2**(N + 1) + 2**(N + 2)*x - S[2*x + 1])/3**L)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"expr1=sy.solve(eqn1, (2*x+1))[0]\n",
"expr2=sy.solve(eqn2, (2*x+1))[0]\n",
"eqn3=sy.Eq(expr1, expr2)\n",
"display(sy.Eq(2*x+1, expr1), sy.Eq(2*x+1, expr2), eqn3)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "1599d460-2d6c-48a8-a170-7005390a298a",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle {S}_{2 x + 1} = 2^{- N} \\left(2^{2 N + 1} \\left(2 x + 1\\right) - 3^{L} {S}_{x} - 9^{L} x\\right)$"
],
"text/plain": [
"Eq(S[2*x + 1], (2**(2*N + 1)*(2*x + 1) - 3**L*S[x] - 9**L*x)/2**N)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"eqn4=sy.Eq(S[2*x+1], sy.solve(eqn3, S[2*x+1])[0])\n",
"display(eqn4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "707c0fa9-2d5b-4544-8790-2b163f16425b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment