What is the name of the function, the result of which depends only on its parameters?

I am writing a compiler toy that can optimize function calls if the result depends only on the values ​​of the arguments. Thus, functions such as xor and concatenate depend only on their inputs, calling them with the same input always gives the same result. But functions, such as time and rand, depend on the "hidden" state of the program, and calling them with the same input can give different results. I'm just trying to figure out what an adjective is that distinguishes these two types of functions, for example, "isomorphic" or "repeat participant" or something like that. Can someone tell me the word I'm looking for?

+4
source share
3 answers

The term you are looking for is Pure

+8
source

I think it is called Pure Function :

In computer programming, a function can be described as pure if both of these statements about holding the function:

  • The function always evaluates the same value of the result, taking into account the same value (s) of the arguments. The value of the result of the function cannot depend on any hidden information or state that can change as the program continues to run or between different program executions, and also cannot depend on any external input from input / output devices.
  • Evaluation of the result does not cause any semantically observed side effects or results, such as mutation of mutable objects or output to input / output devices.

The value of the result should not depend on all (or any) values ​​of the argument. However, it should depend only on the values ​​of the arguments.

+7
source

I think you could say that the adjective is “pure” if you go for the “pure function”.

I always found out that a function whose output is always the same when the arguments are always the same is called "deterministic." Personally, I feel this is a more descriptive term. I believe that a “pure function” is by definition deterministic, and it seems that a pure function should not have any side effects either. I assume that this is not necessary for all deterministic functions (as long as the return value is always the same for the same arguments).

Wikipedia link: http://en.wikipedia.org/wiki/Deterministic_algorithm

Quote:

Given a particular input, it will always produce the same result, and the base machine will always go through the same sequence of states.

+3
source

All Articles