Is there an algorithm or a concept that enforces data structure to satisfy mathematical relation or formula?

Viewed 59

I'm looking for a concept which forces the system to satisfy simple mathematical (or physical) relations (or constraints). In other words, a system that always ensures consistency (consistency between internal variables) defined by the user. I have been searching for this for a few days, but I couldn't find anything similar to this. Maybe the terminology I used for a keyword is not relevant, so I would like to know the keywords if this is an existing concept/algorithm.

For clarification, suppose we have (e.g. in Python)

class Data(object):
    def __init__(self):
        self.voltage=6
        self.current=3
        self.resistance=2

class System(object):
    def __init__(self,data):
        self.data=data

    def register_relation(self,relation):
        """
        Register a relation to System.
        System finds a way to calculate each variables.
        """
        pass

    def update(self,updated_variables):
        """
        Update variable values contained in updated_variables.
        Also update dependent variables based on the relations.
        """
        pass

if __name__=='__main__':
    s=System(Data())
    s.register_relation('voltage=current*resistance')

    s.update({'current':4,'resistance':2})
    print(s.data.voltage) # 8

    s.update({'voltage':9,'current':3})
    print(s.data.resistance) # 3

In the implementation, the relation 'voltage=current*resistance' was registered in the System by register_relation method. Then, the System would know how to calculate each of voltage, current and resistance. After that, although only two of them were updated at the same time by update method, the rest was automatically calculated by the System and the consistency between variables was kept.

In further, there will be a lot of relations (constraints) in the system and it would require very complicated procedure in update method. Again, is there any concept/algorithm like this? If so, where can I find it?

0 Answers
Related