What is the discrepancy function in structural equation modeling? Excerpt from Book
I am currently trying to improve my knowledge of structural equation modeling, and have been reading through Structural Equation Modeling with Lavaan by Gana & Broc to do so. They have the following simple model:

The table they reference thereafter looks like this, which is a collection of iteration cycles:

To explain this table, they give the following details:

Question
However, I'm still not entirely sure what they are getting at here. Does SEM software simply start off with some prior estimate of what a regression path should be, then take multiple "guesses" until it is the most accurate? It appears the residual matrix is based off the "misfires" of these guesses, which seems functionally similar to how residuals normally work in regression.
My previous assumption was this wasn't pre-specified by the user other than your normal constraints (fixing a path to be 1, etc.). I also noticed that they mentioned the iterations stop and so I assume that is just when the guessing is found to not improve. Or is there something I'm missing here? To summarize this into one question, how does the discrepancy function in SEM work? Please explain like I am a small child if possible.


I am currently trying to improve my knowledge of structural equation modeling, and have been reading through Structural Equation Modeling with Lavaan by Gana & Broc

Be wary; there are some major problems with that book that were never caught/fixed during peer review.
Jorgensen, T. D., & Jak, S. (2020). Review of Gana & Broc’s Structural Equation Modeling with lavaan. Psychometrika, 85, 373–377. https://doi.org/10.1007/s11336-020-09705-6
Preprint and spreadsheet of inaccuracies available on the OSF: https://osf.io/9up3s/

Does SEM software simply start off with some prior estimate of what a regression path should be, then take multiple "guesses" until it is the most accurate?

There are many different methods to choose starting values.  Some are simple, like setting all variances to 1 and all covariances and regression slopes to 0.  Others utilize sample statistics to make smarter guesses.
How an optimizer searches for better estimates might vary with the specific algorithm (e.g., Fisher scoring, expectation--maximization, quasi-Newton), but generally the first derivative of the (log-)likelihood function provides a gradient, which is a vector that points the optimizer in a specific direction in the parameter space that leads to larger (log-)likelihood.  After "going there", the (log-)likelihood is recalculated, then the gradient is calculated again to point further.  This continues until the likelihood changes only negligibly, according to some minimum-change criterion.

how does the discrepancy function in SEM work?

The ML discrepancy function typically used is the average casewise log-likelihood ratio comparing the SEM being fitted to the unconstrained sample statistics (a saturated model). That is the (log-)likelihood function I referred to above, evaluated each time new estimates are chosen by "following" the gradient through the parameter space.
