less_retarded_wiki/determinism.md
2022-09-03 14:13:46 +02:00

17 lines
4.3 KiB
Markdown

# Determinism
*"God doesn't play dice."* --[some German dude](einstein.md)
Deterministic system is one which over time evolves without any involvement of [randomness](randomness.md) and probability; i.e. its current state along with the rules according to which it behaves unambiguously and precisely determine its following state. This means that a deterministic [algorithm](algorithm.md) will always give the same result if run multiple times with the same input values. Determinism is an extremely important concept in [computer science](compsci.md) and [programming](programming.md) (and in many other fields of science and philosophy).
[Computers](computer.md) are mostly deterministic by nature and design, they operate by strict rules and engineers normally try to eliminate any random behavior as that is mostly undesirable (with certain exceptions mentioned below) -- randomness leads to hard to detect and hard to fix [bugs](bug.md), unpredictability etc. Determinism has furthermore many advantages, for example if we want to record a behavior of a deterministic system, it is enough if we record only the inputs to the system without the need to record its state which saves a great amount of space -- if we later want to replay the system's behavior we simply rerun the system with the recorded inputs and its behavior will be the same as before (this is exploited e.g. in recording gameplay demos in video [games](game.md) such as [Doom](doom.md)).
Determinism can however also pose a problem, notable e.g. in cryptography where we DO want true randomness e.g. when generating [seeds](seed.md). Determinism in this case implies an attacker knowing the conditions under which we generated the seed can exactly replicate the process and arrive at the seed value that's supposed to be random and secret. For this reason some [CPUs](cpu.md) come with special hardware for generating truly random numbers.
Despite the natural determinism of computers as such, **computer programs aren't automatically deterministic** -- if you're writing a computer program, you have to make some effort to make it deterministic. This is because there are things such as [undefined behavior](undefined_behavior.md). For example the behavior of your program may depend on timing ([critical sections](critical_section.md), ...), performance of the computer (a game running on slower computer will render fewer [frames per second](fps.md), ...), [byte sex](endianness.md) (big vs little endian), accessing uninitialized memory (which many times contains undefined values) and many more things. All this means that your program run with the same input data will produce different results on different computers or under slightly different circumstances, i.e. it would be non-deterministic.
Even if we're creating a program that somehow works with probability, we usually want to make it deterministic. This means we don't use actual random numbers but rather [pseudorandom](pseudorandomness.md) number generators that output [chaotic](chaos.md) values which simulate randomness, but which will nevertheless be exactly the same when ran multiple times with the same initial seed. This is again important e.g. for [debugging](debugging.md) the system in which replicating the bug is key to fixing it.
In theoretical computer science non-determinism means that a model of computation, such as a [Turing machine](turing_machine.md), may at certain points decide to make one of several possible actions which is somehow most convenient, e.g. which will lead to finding a solution in shortest time. Or in other words it means that the model makes many computations, each in different path, and at the end we conveniently pick the "best" one, e.g. the fastest one. Then we may talk e.g. about how the computational strength or speed of computation differ between a deterministic and non-deterministic Turing machine etc.
Determinism is also a philosophical theory that says our Universe is deterministic, i.e. that everything is already predetermined by the state of the universe and the laws of physics, i.e. that we don't have "free will" (whatever it means) etc. Many believe [quantum physics](quantum.md) disproves determinism which is however not the case, there may e.g. exist hidden variables that still make quantum physics deterministic. Anyway, this is already beyond the scope of technological determinism.