Your question is "how can I show how this big thing (an equation) is made up from these little things (variables)?" This is a bill-of-materials problem, which is a special case of hierarchies. Your example is slightly (but only slightly) more complicated because it requires operators as well as variables.
To evaluate the given equation one would take the value of c, square it, multiply that by m, and assign the result to E. There is an order in which these must be performed and that order must be followed from the inner-most to the outer-most. This could be represented as a tree1:
E
|
Multiply
| |
| m
Power
| |
c 2
There are several ways to represent trees in a relational schema. For this problem I think the adjacency list would be best. The table would look something like (in very rough pseudo-code)
create table Equation_Tree
(
row_id int not null primary key,
varialbe_name string null,
function_name string null,
sequence int not null,
parent_row_id int null foreign key references Equation_Tree.row_id,
constraint (exactly one of variable_name, function_name is populated)
)
To evaluate the equation walk the tree from the leaves to the root storing working values in each intermediate node. Variable values can be substituted from local parameters or retrieved from a second table.
Another approach would be to evaluate using reverse polish notation. The operators and operands then form a sequence of tokens in a logical processing order. A talbe for such would look like:
create table Equation_RPH
(
varialbe_name string null,
function_name string null,
sequence int not null,
constraint (exactly one of variable_name, function_name is populated)
)
While having a simpler schema this does not show the relationship between parts so clearly.
1With thanks to the amazing ASCII Flow for the bestest future-retro software in existence.