Hamiltonian, Lagrangian things
Part1-β2.1
Dara O Shayda
dara@compclassnotes.com
In[]:=
DateObject[]
Out[]=
Sat 16 Aug 2025 18:54:23GMT+1
Abstract
These Lagrangian symbolic things called ℋsynth provide operators and functions for the programmers and students alike to code a Lagrangian in its basic mathematical forms and automatically synthesize entire symbol spaces, operator spaces and functional spaces that transform the Lagrangian to the corresponding Hamiltonian with no dot-symbols (momenta). Furthermore, automatically compute to solve the force equations and equations of motions obtained from the zeros of the Lagrange linear operator family
Λ
α
. Optional parallelizers are added to the symbolic computing core cloud object for large dynamical systems in excess of many hundreds of generalized coordinates. The entire Hamiltonian synthesizer is no more than a powerful Term Rewriting System with term substitutions as its core operations. Samples from authentic variational classical mechanics books are solved with little effort in full detail. Useful helper functions and operators are symbolically synthesized ranging from typeset to graphical animators. ​​Live Code Notebook:​https://www.wolframcloud.com/obj/ccn2/Published/Hamiltonian_things_par1.nb ​​ In case of bugs in the code or the theory please make contact to fix ASAP. ​​
Keywords: Hamiltonian mechanics, Lagrangian mechanics, Poisson bracket, Lagrangian linear operator.
​
100% Fat Free Mathematics​​
Software
Release: β2.1
Scripts: Symbolic computations performed in Wolfram Mathematica 14.3 .​​Notebook: https://www.wolframcloud.com/obj/ccn2/Published/Hamiltonian_things_par1.nb ​​Support: Contact the author for additional code, bugs, correction in maths and algebraic/mathematical mistakes or invalid inferences.​​Nomenclature: Most functions and most identifiers start with lower case letters, all native vendor identifiers start with upper case. ​​No Packaging: There is no software engineering applied to the code here nor elsewhere in the author’s technical notes to reduce the difficulties and version mismatches in future. The eager readers can simply copy paste the code or download and run the notebook. ​​TODO: ​1. Fix the evaluator for the Leibniz rules, and Jacobi Identity ASAP. ​2. Single Hamiltonian at a time, the code needs to support multiple and parallel Hamiltonian structures3. Operators
∂

and
∂
..
only operate on single functions, best to scan the expressions and apply to applicable derivatives4. ∈ operator should attach other expressions and data to the symbol ℋamiltonian other than just one Hamiltonian5. Symmetries and invariances of the Hamiltonian6. Spherical and Cylindrical coordinate systems​7. Poisson bracket, though working, does not distribute, fix ASAP. 8. Code Relativistic, Quantum mechanical and Electro Magnetics Hamiltonians 9. Code dissipative systems10. Prove that the Newtonian Classical mechanics’ vectorial formalism is consumes far less complexity in both space and time than Hamiltonian11. Conjecture: Barring fields, the Newtonian Classical mechanics is per objects of the system is completely parallelizable in general with O(1) space and time complexity per object​​TOLEARN:1. Routhian, parameter reduction and symmetries and so on2. Noether theorem in details, codexplain the poof and the theorem itself in actual working mechanical systems ​​codexplain: code explain as in explain the formal system with its construction code. ​​ Known Issues:​1. Close to 100 ball-spring chains the Symbolic computing code takes too long! We currently can simulate 100k ball-springs on Unity PhsX GPU platform, but the actual market needs are in hundreds of thousands to millions! See Theorem 1.1 the time complexity for the Term Writing Systems is cubic
O(
3

×
3

)andquadraticinspace
. ​​​
© 2012-Present CCN Studios​​Creative Commons Attribution-NonCommercial-ShareAlike 4.0​​​
​​
1. ℋsynth Overview
ℋsynth stands for Hamiltonian Synthesizer is a unique symbolic computing cloud software which serves as a multi-function symbolic calculator for the calculi of Lagrange, Hamilton and Poisson insofar as variational calculus of different physics mechanics are concerned.
​
​synthesizer: it is a software that constructs actual functioning operating algebraic formal system, in ℋsynth case symbol spaces, functional spaces, operator spaces and transformation spaces which comprise the modern mechanics theories.
​
​functional spaces: spaces of possibly or even most often undefined functions nonetheless existing functions which can serve as variables and symbols as well.
​
​symbol spaces:

i
,

i
,


i
,


i
,,ℊ
as examples parametrized as indexed symbols and reserved as singleton tokens immutable symbols. The term immutable means for example


i
and

i
are thought to be independent of each other insofar as differentiation operators are concerned and different than ! Even more fantastic ℋsynth distinguishes between
​
​transformation spaces: Invariant transformations, Legendre transformation between Lagrangian and Hamiltonian mechanics, Canonical transformations to name a few
Poisson bracketed
{,ℊ}

not just a function 
Lagrange and Hamilton’s world functions are first and foremost are Functionals namely they are as good as any other undefined but valid character or symbol, though they might have no body, yet they can be operated upon e.g. derivatives and so on. ​Therefore, in ℋsynth we do not directly operate on functions, all the necessary formalism is carried out through the Poisson bracket. You shall see examples below. ​​Example:

t
=
{,ℊ}

+
∂
∂t
, we compute a functional

t
an undefined function which once Term Rewriting applied to its body it simplifies to an actual Total Derivative, by indirectly computing via the Poisson bracket. Advantage is that the pass through the Poisson/Hamiltonian/Lagrangian formalisms uncovers systems of equations in terms of all variables with no Dots which completely define the mechanical system and often solvable by modern numerical solvers of differential equations. ​​Thesis 1.0: All finite Hamiltonian mechanical systems with Poisson Brackets have a computational constructor thus forth algorithmic mechanical systems. ​This methodology pretty much guarantees far less errors and misunderstandings and the fast path to the final computations.
Polynomial Time Complexity
1.1 Theorem: The time complexity of ℋsynth[ ] system is polynomial
O(
3

×
3

)
where  is the number of objects in the mechanical system and  the dimension. ​​Proof:
2×+1
is the count for the generalized coordinates of the Lagrangian in theory + time. First,
×
is the count for the dot-symbols called momenta, second the count for the Lagrange linear operator family
Λ
α
is also
×
by the definition
Λ
α
=

t
∂
∂

p
i
-
∂
∂p
where
p
is the generalized coordinate equivalent to position and

p
its corresponding momenta . Therefore,
×
dot-symbols are required to be Term Rewriting by
×
terms which bring the count to the polynomial
2
(×)
. However, during the current implementation of ℋsynth it became patently clear that each term of the Term Rewiring being a function e.g.
r
α
(
p
1
,...,
p

,
r
1
,...,
r

)
, if we linearize that read/write IO as
2
steps, then the total sum for the complexity tallies up to
2
(×)
(×)
.  ​​The third degree polynomial in both initial counters  and  is prohibitively expensive for direct applications such as polymer dynamics simulations dealing with tens of thousands of atoms or molecules (goal is millions). However most readers reader would not comprehend the polynomial time’s gargantuan magnitude until actually running code and attempting to compute a large Hamiltonian or Lagrangian system. ​​1.2 Theorem: The space complexity of ℋsynth[ ] system is polynomial
O(
2

×
2

)
where  is the number of objects in the mechanical system and  the dimension. ​​Proof. Similar combinatorial arguments as to the Theorem 1.1. ​
Initialization
In[]:=
(*TODObettersimplerinterface*)​​Notation`AutoLoadNotationPalette=False;​​Needs["Notation`"];​​ClearNotations[];​​CloudGet["https://wolfr.am/1xEVtfjBx"];​​ℋinit[];
version: β1.0
2. ℋsynth or Hsynth
2.1 Organization of Generalized Coordinates and corresponding Momenta
2.2 Get symbols and data from ℋsynth
There are several methods to get values from ℋsynth!
​● By operators like the lightbulb  :
● Or by special internal reserved ℋ symbols e.g.
Flattened dots
● By the return value, in this example called res:
● In order to seek what Keys are available within res the return value of ℋsynth, the Keys[ ] function outputs all possible available keys:
2.3 Functional spaces galore!
2.3.1 Why the coordinates are not functionals?!
This might change in next versions of the code, for now they easier left unevaluatable for the sake of internal derivations and evaluations.
2.3.2  the functionalization operator
Pure automagic!!!
Readymade list for programmers:
2.4 What is that “rp” thingy in ℋsynth[“rp”]?!
ℋsynth in this case constructs symbol and functional spaces for a variable length radial material e.g. rubber band and its rotary momenta. We will experiment with a lot such rotary systems in these Hamiltonian things.
3. Operators
3.1 Total Derivative
3.2 Partial Derivative
3.3 Poisson Bracket
3.4 Typeset operators
Thanks to indecisive mathematicians, there are many oddly different notations for all kinds of mathematical notations.
§
4. Basic Classical Mechanics examples
4.1 Quick guide
Examples are picked from the [1] reference which is the only one after Arnold’s WITH NO ERRORS AND TYPOS!
One-dimensional Harmonic Oscillator
Example 8.2 in the reference [1].
4.1.1 ℒbody
● ℒbody is the body of the Lagrangian function that normally programmers code, except there is no need it for it in ℋsynth! Simply type the algebra up, if required some loops and conditionals and whatever-else and assign it to ℒbody. Once you do that , you are done!
​
​body: This acronym is adapted from programming language theories calling a piece of code as the body of the function.
4.1.2 ∈ ℒ
● This line of code needs to be added right after the ℋsynth[ ] and before the Lagrangian definition as stated, in order to register the symbol  or any other desired fonts and symbols as the Lagrangian function.
​
​∈ : In this context ∈ operationally indicates that the left hand side belongs to the structure of the right hand side, in this case the Lagrangian structure. Some call it binding in other programming systems which is confusing and subject to gross misinterpretations by the beginners.
● Abstract form of Lagrangian to Hamiltonian transform:
● The final form of the Hamiltonian
● All Hamiltonian identities:
4.1.3 Lagrange Linear Operator family
4.1.4 Fully closed form solution
4.1.5 ≐ operator
Another helper and shortcut for the programmers to avoid messy coding of making lists of useless things!
4.2 Rod Slider
Two identical masses m are connected by a massless rigid bar of length l, and they are constrained to move in two frictionless slides, one vertical and the other horizontal as shown in the adjacent figure.
​
Example 6.6 in the reference [1].
If easier use this variable in place of the  operator bellow, since we need to use [[1]] to index the symbols contained in this array:
● Equations of motions from the Lagrangian:
Fully closed form solution
Sample animations
4.3 Simple Spring model 2D
4.4 Mass Sliding on a rotating rod
A mass with a bored hole, slides along a frictionless rotating rod!
Example 6.9 from reference [1].
IMPORTANT: Any alterations after ℋsynth[ ] call requires a fresh start!
Add alias
Alias is only in place to make formalism more human readable.
Check on your functionals:
Fully closed form solution
Let’s reduce the algebraic verbosity:
As you can see we are getting exponentially growing or decreasing functions as the solutions for a rotary mechanical system!? How is that possible?
​
What made  so precious to the accountants and mathematicians of the past was the fact that its derivative is itself:
And even sweeter:
And still valid for Complex number  factors:
Even the sweetest of all, it works for the matrices too! You cannot imagine how much cavities this one number inflicted on the pearly white teeth of mathematicians even to this day!
or the 0 matrix i.e. both terms are equal.
Back to the solutions of our differential equations:
Simplify and cancel terms and you get 0s!
So what did we accomplish, we were able to obtain rotatory solutions for mechanical system namely
and
Stated formally:
4.5 Simple 20 balls-springs Chain closed form solution
This is an investigation code to verify some results in mechanics book which are riddled with errors and typos missing formalism.
TODO: with non-zero and fixed spring position for every spring solution takes too long, not sure what is wrong.
4.6 30 balls-springs Chain model numerical solution
More than 50 balls takes too long.
Case 1-2: Uniform mass distribution
Case 3: Non-uniform mass distribution: One ball too heave
Apply Impulse forces prior to the NDSolve[ ]
Tools to measure space complexity
Case 1-2 here
Case 3 here
References
[1] Douglas Cline, VARIATIONAL PRINCIPLES IN CLASSICAL MECHANICS, University of Rochester