# Micro Fractal Solution

Recently I faced a problem that was about how to apply an additional data to an entity based on circunstances. Well… I'm a software developer since 2014, so I kinda was envolved on a deja-vu feeling. I've done this before, and if you're a developer, you too faced or will face something like that someday.

But it’s called “conditionals”! “If”s, any sort of comparison. And it exists in every programming language!

You might say. And you're correct! A lot of the time what we do as developers is basically that. Provide decisions based on a logic that is simply verifying if a statement is "true" or "false", right? Establishing that as true, could we provide a generic solution that could embrace each case on logical terms? Well… My conclusion is that theoretically, yes. But in practice, it isn't that simple…

My point is that, if you have an indirection for each part of your data structure that provides specific and general information, for example an REST API environment covering your database and being well partitioned, you'll be able to infer anything based on this provisionment and a basic comparison between values and the check of all this results on an set of them.

I'll proceed to explain each of the elements on the image above, which describes the relation between them on this logic. Let's check it out!

S**ources **are, as the name suggests, all information available to do the comparisons. Sometimes, fixed values are enough to prove your possibility realm, but in complexer systems, we have some types of sources. I see them as:

**External**

All sources in which you need more information than your input provides, generally looking for databases or REST APIs;

**Variables**

Basically values that comes with you input;

**Constants**

Values that are related to formulas and don't change. And if they do, you need to keep track of all values it assumed for later audit.

F**ormulas** are the mathematical expressions that can provide the relation and proportionality between source values. They could assume any mathematical expression value in theory, but I'm not sure if in the future it will find some limitations due to differential calculus complexity (maybe not!).

R**ules** are the result of the comparison between formulas, that will always have an "boolean" result. They will use operators to compare the formulas *(=, >, <, !=, ≥, ≤)*.

C**riteria** are the set of rules, but the thing is, for a criterion to be considered, all rules within they must be true.

F**inal entity **is the value to be applied on the input if the criteria is attended. This value could also be calculated by an formula, but not necessarily the formula table of the current chain.

I consider this logic to be fractal due to it's behavior when you relate indefinetly the final entity value to another formula, to get another another final entity to be applied in other formula, and it goes on.

So basically, if you apply the final entity on as an external source of an variable, you could do this indefinetly in theory. But in practice, you'll aways have a limit for that, the limit that you propose based on how many levels you filled your "formulas" table with, which could cause some performance issues. to avoid it, you could create another layer, instead of using the output as the input of the same system, you could create another one isolated to process some of the outputs, dividing the logic.

When you think of that, is pretty basic, it's just like how things where done in the past! Manipulating small iterations and space in memory to come to small conclusions, and the set of this conclusions provides an output. And in fact it is just that! But sometimes we're just lost in tons of abstraction layers and we miss somethings that are just simple as that and try to use tons of conditionals with some arbitrary values, which cause systems to have insane amounts of conditional layers, and if they could simply obey this rule and aren't complex enough, could save you some major time, delivering all it's functionality directly to the client, for them to fill all this and have entire freedom about all the variables and logic.

That above is what happens when you apply you final entity as a part of the same formula you used to calculate itself.

Well, that was my experience! I don’t actually know if this kind of logic was already proposed, I looked for it and found nothing. It just fascinates me all the independency that us as software engineers can provide to business models, if anyone have a source that already has something such as that related and more explained (or better explained) please comment! I would love to know more about. Thank you for reading!