r/computerscience • • Oct 25 '26

Discussion Is simulation a function?

Question to settle a debate which I recently had with two of my colleagues.

One of my colleages argued all simulations are mathematically functions by definitions, since for every set of arguments they need to return one outcome. As an example we took a cellular automaton simulating a forest fire. They stated that everytime you give it a particular starting state, the end state will be the same, but I don't agree with that. To simulate humidity or different wind speeds and directions one might use an rng, so the same start map run twice might give 2 different results, which means it's mathematically not a function. My friend countered that because of how rngs work, with the same seed the will always be the same. You don't need to set a seed tho and I can imagine cases when it's even by design - for example when you can't be sure which direction the wind will be coming from and you want your simulation to account for any of them.

But here's the bit that we couldn't agree upon. My friend said, that even without seed, or using quantum randomness, that randomness is always based on something and as such must be treated as kind of a baked in argument. Because of that, if you manage to somehow recreate the exact same "randomness state", the outcome will never change.

From my point of view that's not the case. Even using simple time based pseudorandom number generators, to you as someone analysing such simulation, that rng should not be treated as argument. The way I see it it's just a black box, that "magically" gives you a number, you should treat it as truly random and use it to approximate all the different variables, that are too complicated to calculate each and every time you run the simulation or are just out of scope. Therefore the same input can give you different outputs, which makes the simulation itself not a function by mathematical definition.

What are your opinions on this?

0 Upvotes

41 comments sorted by

View all comments

24

u/esaule Oct 25 '26

So, you are saying it is a stochastic function...

2

u/Specialist_One_4366 Oct 25 '26

The whole debate hinges on whether you peek inside the black box. Mathematically, if you include the rng state as an input its a function, sure, but from the simulation's perspective the rng is an external input the user never provided, so calling it a function feels like a stretch. Youre basically arguing about whether hidden state counts as an argument or an implementation detail.

11

u/esaule Oct 25 '26

What I am saying is that it does not matter.

There are functions in mathematics that represent non deterministic processes. That is how the whole field of probability works. If the function is deterministic, you represent it with a regular function. If it is a stochastic function, you represent it by its underlying probability distribution function.

In either case, you can represent it with a function.

2

u/OpsikionThemed Oct 25 '26

I mean, I think it's reasonable to call it a "Input × Int* -> Output" function (or whatever sequence the rng is providing).

1

u/Patriotpl Oct 25 '26

This sounds correct and honestly the hardes one here to rebutte for me. The only thing that comes to mind is since simulation only cares about the outcome, and how to get it is just an approximation, the "x int" part is not an argument, it just happens (as in: rng just gives you a number without any reson), you can't influence it, but it does influence your result, making it possible for one input to give multiple outputs.

0

u/Patriotpl Oct 25 '26

Not really. If I recall (and please do correct me if I'm wrong) stochastic function would mean that the result varies not only on given parameters, but also on time. But for simulation this would be part of the truth, but not all of it. I'm saying that for some simulations you want to have a bit of uncertainity to accomodate for much more variables than is practical to implement as arguments. Can you calculate all (or most) of them to make it a pure function? Sure. But you sometimes shouldn't for time/cost/compute related causes or just lack of a purpose for your specific case. Which then means that your function would be able, and almost certain to return 2 different outcoms for 1 set of arguments over the same time range.

2

u/esaule Oct 25 '26

so you represent it by its underlying probability density function.