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

In summary: 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
  • #1
Worm
2
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
  • #2
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:
  • #3
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.
 
  • #4
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:
  • #5
Thank you for your responses.
 
  • #6
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").
 

1. How can I use math in my program without having extensive math knowledge?

There are many ways to incorporate math into your program without needing advanced math skills. One approach is to use built-in functions and libraries that handle complex mathematical operations. Another option is to break down the problem into smaller, more manageable parts and use basic arithmetic operations to solve them.

2. What are some common mathematical concepts that are useful in programming?

Some common math concepts that are useful in programming include algebra, geometry, statistics, and calculus. Basic understanding of these concepts can help with problem-solving and writing efficient code.

3. How can I improve my problem-solving skills when it comes to mathematical challenges in programming?

One way to improve your problem-solving skills is to practice regularly and challenge yourself with different types of mathematical problems. You can also seek help from online resources, books, or colleagues who have more experience with math in programming.

4. Are there any specific programming languages that are better suited for incorporating math?

There are several programming languages that are commonly used for mathematical and scientific applications, such as Python, MATLAB, and R. However, most languages have built-in functions and libraries that can handle mathematical operations, so it ultimately depends on your specific project and preferences.

5. How can I check if my mathematical calculations in the program are accurate?

One way to ensure accuracy in your mathematical calculations is to test them with different inputs and compare the results to established solutions. You can also use debugging tools to step through the code and identify any errors in your calculations.

Similar threads

  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
2
Replies
49
Views
3K
  • Programming and Computer Science
Replies
8
Views
832
  • Programming and Computer Science
Replies
22
Views
868
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
2
Views
726
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top