I need to take a formula that uses the OpenDocument formula syntax, analyze it in a syntax that Python can understand, but without evaluating the variables, and then be able to repeatedly evaluate the formula when changing the values for the variables. Formulas can be entered by the user, so pyparsing allows me to effectively handle formula syntax and clean user input. There are a number of good examples of pyration, but all mathematical ones seem to suggest that everyone immediately evaluates everything in the current area.
In the context, I work with a model of an industrial economy (life cycle assessment or LCA), where these formulas represent the volume of material or energy exchanges between processes. A variable amount can be a function of several parameters, such as geographic location. The formula chain and variable references are stored in a directed acyclic graph, so that formulas can always be easily evaluated. Formulas are stored as rows in the database. My questions:
- Is it possible to analyze the formula so that the analyzed estimate can also be stored in the database (as a string to be reset to zero or something else)?
- Are there alternatives to this approach? Keep in mind that the ideal solution is to parse / write once and read many times. For example, by partially analyzing the formula and then using the ast module, although I do not know how this could work with the database repository.
- Any examples of a project or library like this that I could browse? I am not a programmer, just a student who is trying to finish his dissertation, while in his free time he is developing an open source LCA software model.
- Is this approach too slow? I would like to be able to make significant Monte Carlo runs, where each run can include tens of thousands of formula evaluations (this is a large database).