Functions are the fundamentals - Dtech-Dbug
Whether you are coming from a mathematics background or computer science background or any other background, chances are you have somewhere somehow at some point of time used this term functions. If you fall in the former two backgrounds, you are, I assume, pretty well versed with it. A programmer believes in the fact that functions are the fundamentals of programming. ๐ค
This blog is interesting and hopefully comprehensible to all the readers.๐ค
Today we will learn about :
- what are functions โ ๐ค
- what are algorithms and logic? ๐ค
๐ผ source : google
what are functions?
In a concrete mathematical definition - a function is a special kind of relation between elements. In the context of functions, the easiest way to think of these elements is as inputs and outputs. Look at the visual below.
A function takes in inputs, does something with it, and returns an output. Hence, for every input in a function - there has to be an output.
๐ผ source : google
But unfortunately, functions are not that clever. The magic is somewhere else. ๐งโโ๏ธ And, the most exciting part is that we are the wizard. The onus is on us how we tell them what to do. And this brings us to our next topic...
logic and algorithms are the heart of functions.
Imagine you are excited to prepare a new dish. You take help of a cooking manual or the internet and follow along with the steps. ๐ฉโ๐ณ
The function of the manual/internet is to provide you with the instructions that you need to follow to get the desired output, in this context -the dish. ๐ฅ
The instructions are what a function contains - and in computer speak they are called algorithms and mathematically logic.
Needless to say, a better and efficient set of instructions provide a better output than the ambiguous ones.
logic formation.
- the main concept of logic formation is the argument form.
- An argument is a typical placeholder that determines the truth value of an assertion. (more on this, shortly with an example)
- the truth value/output at the end is called conclusion or simply an output in computer lingo.
- All the preceding lines or sentences are called premises. In computer lingo, the premises are popularly called scope/block.
- For a conclusion/ output to be true, the premises have to be acceptable on their own right or follow deductions from statements that are known to be true. In other words, a wrong set of instructions(premises of the logic) will likely return unexpected outputs. Similarly, any unexpected output indicates Imprecise instructions.
Note: logical deductions don't essentially determine the intrinsic merit of the argument but, they help us analyze whether the truth value of the conclusion follows the truth of the premises.
In logic, the form of an argument is distinguished from it's content.
let us take the successor function as an example. As obvious it sounds it takes inputs and outputs the successor of the input by adding +1 to the input.
Note ๐คฃ: I made a mistake. Started doing the squaring function, that is why I had to scratch the powers off in the first three symbolic logic under mathematical representation. The squaring function simply takes in inputs and returns the square of it.
If you are into programming, you are aware of functions and their structure. Everything within the braces refers to the premises of the logic. A programmer calls it the scope of the function.
- Usually, in most cases, you don't need braces if the function is one line. But I did that in the picture to make the scope of the function more visually representable.
- The above hand note is silly as it deals with a pretty simple function but in broader cases they get complex. And logic alone can not provide the surety of a well-designed algorithm, especially in presence of constraints and tradeoffs like space ad time.
conclusions
Algorithms are everywhere. Even in denial - we indulge in them somehow or the other. Algorithms are the heart of functions. We learned the basics of it and realized how the fundamental functions are shared in both mathematics and computer science. But, ofcourse, there is more to algorithms than just logic. Algorithms have to be efficient and well designed ๐
๐ซ wrapping up :
- functions are the fundamentals of mathematics and share the same principles in computer science.
- a function takes in arguments/inputs and returns a conclusion/output.
- functions are comprised of algorithms and logic.
Interesting intersection of mathematics and programming, in turn, computer science. ๐ป