Binary logic¶
In this example, we explore the application of binary logic to solve logic problems using an equation written in the Julia programming language and its implementation in a model.
Binary logic is a form of logic based on dealing with two states: true (1) and false (0). It is used to describe and solve problems where the results can be expressed in terms of yes or no. Binary logic is widely used in computer systems, digital electronics and programming.
Logic problems are problems whose solution involves the application of logical operations such as AND, OR, NOT and their combinations. Such problems often arise in the field of automation, digital circuit design and programming.
The example demonstrates how to combine a theoretical framework (a logic equation in Julia) with its practical implementation in models, allowing you to visually explore and analyse the process of solving logic problems.
Description of the binary equation¶
Let us specify the states of our system, which in this case will be three: 𝐴, 𝐵 and 𝐶. In this case, the state 𝐴 will be determined randomly: if a random value of 𝑋 is greater than 0.5, then 𝐴 is true, otherwise it is false.
X = rand()
println("X = $(X)")
A = X > 0.5
println("A = $(A)")
B = false
C = true
println("B = $(B)")
println("C = $(C)")
Now let us turn to the description of the equation. Suppose that our logic is defined by the following equation: Z = ((A and B) or (C and B)).
Z = ((A && B) || (C && B))
println("Z = $(Z)")
Now let us use this equation to build a model and compare the simulation results with the results obtained in the model.
Auxiliary functions¶
# Подключение вспомогательной функции запуска модели.
function run_model( name_model)
Path = (@__DIR__) * "/" * name_model * ".engee"
if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
model = engee.open( name_model ) # Открыть модель
model_output = engee.run( model, verbose=true ); # Запустить модель
else
model = engee.load( Path, force=true ) # Загрузить модель
model_output = engee.run( model, verbose=true ); # Запустить модель
engee.close( name_model, force=true ); # Закрыть модель
end
sleep(5)
return model_output
end
Binary logic modelling¶
run_model("Logical_Operator") # Запуск модели.
Z_model = collect(Z_model)
println("Z_model = $(Z_model.value[1])")
Let us verify by comparing the simulation results with the results obtained from Engee calculations.
println((Z_model.value[1]) == Z ? "Проверка пройдена" : "Результаты не совпали")
Conclusion¶
As a result of the study, the operation of binary logic has been demonstrated using the example of the equation implemented on Julia and in the model. The specified states of the system (𝐴, 𝐵, 𝐶) are correctly worked out and the logic operations are performed as described. The verification shows that the model and code match and the system functions without errors.