Stoichiometry - Chemical Equation Balancer & Molar Mass Calculator for HP Prime

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (https://www.hpmuseum.org/forum/forum-10.html)
+--- Forum: HP Prime Software Library (https://www.hpmuseum.org/forum/forum-15.html)
+--- Thread: Stoichiometry - Chemical Equation Balancer & Molar Mass Calculator for HP Prime (/thread-24783.html)



Stoichiometry - Chemical Equation Balancer & Molar Mass Calculator for HP Prime - andrea.baccin - 2026-03-06 11:12

After experience of writing a Markdown viewer for the Prime I uses the experience to create an app for the HP Prime that balances chemical equations, calculates molar masses, and includes a library of 270 pre-balanced reactions across 7 categories (combustion, synthesis, redox, neutralization, etc.).

What it does:
  • Enter any chemical equation => get balanced integer coefficients + element-by-element verification table
  • Molar mass breakdown for any formula (element, count, atomic mass, subtotal)
  • Mass percent composition with a bar chart
  • Built-in library of 273 equations you can browse by category and add to your saved list
  • Star/favourite equations, assign aliases, filter by category or text

The balancing algorithm uses a matrix nullspace approach: the equation is parsed into a stoichiometry matrix A (elements × compounds, LHS positive, RHS negated), then we find the nullspace vector x where Ax = 0 and scale to smallest positive integers via GCD. 
All done with the built-in linalg module.
 
Everything is built from scratch on the 320×240 pixel display using only hpprime graphics primitives (fillrect, textout, line, blit). 
There are no UI frameworks, no widget libraries, nothing pre-built. That means:
 
The scrollable equation browser with sortable columns, alternating row colors, touch scrollbar drag, and category badges are all manual pixel math
  • The periodic table equation editor is a visual 72-element grid color-coded by block (s/d/p), laid out in the standard 18 column arrangement, with cursor, symbols row, number row
  • Popup menus with drop shadows, color-coded category dots, keyboard + touch navigation
  • Light/dark theme with 50+ color tokens, auto-detecting the calculator's system theme
  • 16 hand-drawn 9×9 pixel bitmap icons for menu buttons
  • Double-buffered rendering with off-screen GROBs for smooth scrolling
It's been a fun challenge making a responsive touch UI on a resistive touchscreen with no framework support. Every button hit-test, every scroll position, every text truncation is just arithmetic on pixel coordinates.

Here's a couple of screenshots, but you can see a demo video in my gh
   
   

I have been testing this in my new G2, as the emulator is good for development but the physical calculator turned out to be a bit more prone to crashes in the python environment.


GitHub: https://github.com/abaccin/hpprime-stoichiometry
 
Feedback and suggestions welcome!