How to Use Math When Writing a Program (No Math Knowledge Needed)

  • Thread starter Thread starter Worm
  • Start date Start date
  • Tags Tags
    Programs Work
AI Thread Summary
The discussion centers on the relationship between mathematics and programming, particularly how algorithms are abstracted from instructions. It clarifies that algorithms are abstract definitions of programs, which can be implemented in concrete programming languages. Pseudocode is emphasized as a tool for outlining algorithms rather than being compiled into machine language. The conversation highlights that while many programs do not require complex mathematics, designing non-trivial programs is often viewed as a mathematical activity. It also explains the process of translating abstract algorithms into concrete code, which is then compiled into machine language. The role of decision-making in programming is noted, where computers follow instructions based on input conditions. Overall, the dialogue underscores the mathematical foundation of programming and the importance of algorithms in software development.
Worm
Messages
2
Reaction score
0
Ok, real basic stuff here. I have virtually no mathematics knowledge. I think I know that pseudo code is complied and turned into machine language but what I can't figure out is how one abstracts the instructions into algorithms(?). I'm having a hard time phrasing what I what to know. To para phase: How do you use math when writing a program?
 
Technology news on Phys.org
Usually, computer scientist abstract from concrete machines and postulate that all computers are concrete instances of abstract (Von Neumann) machines. They are nothing more than machines which consist of a central processing unit and memory (plus auxilliary input/output devices). Instructions are fetched in cycles from memory (the programs), read from memory (the data), and write data back.

An algorithm is an abstract definition of a program which in a concrete form can be defined in a concrete programming language and can be compiled to concrete machine instructions interpretable by a concrete machine (with a Von Neumann architecture).

The study of algorithms is based on the fact that an algorithm is mathematical in nature, that it can be abstractly defined in terms of an abstract mathematical language, and that algorithms defined in that language can be 'run' on an abstract mathematical machine. In general, algorithms can be studied as mathematical entities, and mathematical qualities of specific algorithms tell how any concrete instance of that algorithm on any concrete machine will behave.

Now to your questions:

First, you don't abstract instructions into algorithms. A series of instructions concretely defines a program, and abstractly defines an algorithm.

Second, in an abstract sense, you always use math to define a program since concrete programs are instances of abstract algorithms [which are mathematical entities].

An example: I want to write a program which adds two numbers.

Now you need to define a program. The search for that is a mathematical activity. In your mind, you're trying to figure out the mathematical solution to a mathematical specification. You end up with something, in pseudo code, in your 'mind's eye' like:

procedure add(x, y) : return x + y

Concretely, you now need to 'translate' your abstract notion of an algorithm to a concrete program, defined in a concrete programming language, which can be translated to concrete machine code, which can be run on a concrete machine.

So, you might end up with something in Java, or C, or any other language. For example,

int add_two_numbers(int x, int y) {
return x + y;
}

(Together with the rest of the 'plumbing' you need to turn it into a 'runnable' program like a main procedure, etc.)
 
Last edited by a moderator:
Worm said:
Ok, real basic stuff here. I have virtually no mathematics knowledge. I think I know that pseudo code is complied and turned into machine language but what I can't figure out is how one abstracts the instructions into algorithms(?). I'm having a hard time phrasing what I what to know. To para phase: How do you use math when writing a program?
Pseudocode is not compiled. Pseudocode is used only to work out the details of the algorithm that is to be used. Once these details are worked out, then an implementation of the function is written in the programming language of choice.

The program instructions are then compiled, and the compiler generates machine code instructions. The linker then combines the machine language that was generated by the compiler with machine language instructions for library functions, to produce an executable program.

Not all programming languages are compiled into machine code. Languages such as python and the .NET Framework languages are translated into an intermediate language, and another program translates individual instructions to machine language, and then executes them.

Not all programs require the use of mathematics. One example is a program that just displays some text on the console.
 
Mark44 said:
Not all programs require the use of mathematics. One example is a program that just displays some text on the console.

I agree with most you said, but since the original question was also on the relation between programming and math, I would rather rephrase your last comment to: Most computing scientists believe that designing any (non-trivial) program is a mathematical activity.

EDIT: In a thread like this I can only provide short, dumbed-down, answers to questions. But you could dive into the question why students are taught pseudocode. And in finding an (historical) answer to that, if I don my CS hat, I would say that pseudocode was developed as a recognition that programs are mathematical in nature, that one can abstract from concrete programming languages, and that pseudocode should be taught to have student recognize that programs are instances of abstract algorithms (which, in later courses, can be shown to be amenable to mathematical analysis.)
 
Last edited by a moderator:
Thank you for your responses.
 
Worm said:
Pseudo code is complied and turned into machine language
I assume you mean a high level language which is compiled and turned into machine language. Normally pseudo code is a simplified description of an algorithm or process that doesn't get into all the details. Think of psuedo code as an alternative to flow charts.

How one abstracts the instructions into algorithms.
Normally it's done the other way around. The programmer(s) develop an algorithm, then implement that algorithm via some specific programming language, which could be high level or machine language. The computer just follows a stream of instructions.

How do you use math when writing a program?
Most programs don't involve a lot of math, it's more about the logic required to implement an algorithm.

How do programs work
A computer can follow a set of instructions, and has the ability to select different sub-sets of instructions based on testing of inputs (decision making). Normally this is done by branching, such as a common set of instructions for building similar items, where you skip over some instructions and follow other instructions, (if you're building "abc", then skip to step "qrs", if you're building "def", then skip to step "tuv").
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top