Assets - Liabilities = Stockholders Equity
Stockholders Equity = Common Stock + Retained Earnings + APIC (Additional Paid in Capital)
Capital Stock= Common Stock + APIC + preferred Stock
Assets – liabilities-capital stock = retained earnings
These are formulas that you can use in very straightforward RE calculations, but stockholders equity is more than that. You have treasury stocks, appropriation of RE, Quasi Reorganiztions. Stock dividends and split stock.
But I guess that for simple programs you can use them. I answer a problem today related to RE check it out, it can help you out.