0% found this document useful (0 votes)
13 views28 pages

IDC101 Lect0 Part1

Yay

Uploaded by

vamsid216
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views28 pages

IDC101 Lect0 Part1

Yay

Uploaded by

vamsid216
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

IDC 101

Introduction to Programming

Lecture 0
https://chatgpt.com/ Lets ask a
What is programming programmed ChatGPT

Programming is the process of creating a set of instructions that a computer can follow to perform specific tasks or
solve problems. These instructions, known as code, are written in programming languages such as Python, Java,
C++, JavaScript, and many others.

Programming involves several key concepts and activities:


1. **Syntax and Semantics**: Understanding the rules and structure of a programming language to write correct
and meaningful code.
2. **Algorithms**: Designing step-by-step procedures or formulas for solving problems.
3. **Data Structures**: Organizing and managing data efficiently using structures like arrays, lists, trees, and
graphs.
4. **Debugging and Testing**: Identifying and fixing errors or bugs in the code, and testing to ensure the program
works as intended.
5. **Software Development**: Using programming to build software applications, including planning, designing,
coding, testing, and maintaining.
6. **Problem-Solving**: Applying logical and creative thinking to develop solutions to complex problems through
code.
7. **Version Control**: Managing changes to the codebase using tools like Git, allowing for collaboration and
tracking of code history.
Programming can be used to create a wide range of applications, from simple scripts to automate tasks to complex
systems like operating systems, video games, and web applications. It is a foundational skill in computer science
and is essential for developing technology solutions in various fields.
Can only computers be programmed ?

Not really ?
We can program a monkey, dog, cat, cow, and any animal to do something based on some instructions and reward
system.

We are also one neural and cellular machine.


Therefore, we are also programmed by parents, teachers, society, social platforms like twitter, FB, insta, TV, culture we
follow or live in and political entities.

What I am today is :
“ A programmed software installed in my brain without my knowledge and I am working, behaving as per the training
received by me either knowing or un-knowing”

Now coming back to this course: "The Matrix is everywhere. It is all around us. Even now in this
very room" – Morpheus (The Matrix)
IDC 101 : Introduction to programming "The Coding is everywhere. It is all around us. Even now in this
very room" – Random Person (The World named Matrix)

Plan is to make you comfortable in or start doing programming /coding.


IDC101: Introduction to Programming
IDC101
[Cr:2, Lc:1, Tt:0, Lb:3]
Course Outline
•What is computation? Input, output and data modification. What is an algorithm in conceptual terms? (Lab session on
using a computer to carry out a sequence of steps in a calculation such as finding the root of a quadratic equation.)
• Representations of numbers (integers) on a computer. (Lab session on writing addition/multiplication of decimal
numbers as a step-by-step process.)
• Representations of tuples, lists, vectors and matrices on a computer. (Lab session on working with lists and tuples.)
• Floating point numbers and intervals of real numbers. Understanding how errors accumulate during calculations.
(Lab session on floating point arithmetic with emphasis on error accumulation.)
• Looping constructions and the principle of descent. (Lab session on bisection method to solve an equation.)
• Looping constructions and the principle of induction. (Lab session factoring a number into prime factors.)
• Looping constructions with floating point numbers and errors associated with them. (Lab session of summing series
correctly and incorrectly!)
• Looping constructions with floating point numbers. (Lab session on Newton-Raphson method. Comparison of
efficiency with bisection method.)
• Representations of continuous objects on a computer through discretisation. (Lab session on plotting and graphs
demonstrating “pixelation” of the output.)
• Representation of colors via the “color circle” where mathematics, physics and biology meet. (Lab session
on changing colors of images.)
• Solving linear equations on a computer—floating point vs Diophantine. (Lab session on row-reduction of
matrices with pivoting (integer pivoting and real number pivoting).)
• Pseudo-random number generation. Tests of random-ness. (Lab session where students are asked to
write/generate their own sequence of “random” numbers and apply tests of random-ness to them.)
• Numerical methods for integration. Simplex, Quadrature, Monte-Carlo. (Lab session to compare the results
of these methods.)
• Order and recursion with application to sorting. (Lab session on sorting using various methods.)

Allen B. Downey, Think Python: How to Think Like a Computer Scientist, 2nd Edition
Richard Peterson, Linux: The Complete Reference 6th edition, Tata McGraw (2008).
The online material available at http://docs.python.org/
I will not follow the exact syllabus.

My purpose of teaching this course is not to teach math or Numerical Methods, but to make you enjoy and love
coding. There are lot of Numerical courses you can do.
We will do most of them, but focus is more on learning the skill and love for coding.

One can’t learn how to do programming, one can just experience and feel.

"I can only show you the door, you're the one that has to walk through it" – Morpheus (The Matrix)
What I expect you to learn or take away from this course ?

Get familiar with Linux system :


Basic commands and appreciate the power of the command terminal

Learn about the BASH or at least get introduced to it.


a powerful tool to do small daily jobs

Python : Learn about its basic, its common libraries, plotting tools.

Some Numerical Methods


Grading Scheme for IDC 101

Component Marks
Attendance (lab) 10
Lab Reports 30
End Sem Lab Exam 30
End Sem Exam 30

Lab (Session1) Lab (Session2) Lab (Session3)


Thursday 9:00 Monday 14:00 Tuesday 9:00

Lecture Tuesday 15:00 @ LH6


Linux
Linux is a free and open-source software that operates on its own operating system. The term ‘Linux’ stands for GNU +
Linux. Initially developed by Linus Torvalds, it was created alongside the source code of Unix.

Most of the operating system which run on the Desktop and laptop are:

❖ Microsoft Windows : 72%


❖ macOS : 15%
❖ Linux : 4%
❖ chromeOS : 3% (also based on Linux kernel)
❖ Unknown : 6%

Kernel : computer program at the core of a computer’s OS and generally has complete control over everything in
the system.
The kernel is also responsible for preventing and mitigating conflicts between different processes.
On most systems, the kernel is one of the first programs loaded on startup or bootloader.
It handles the rest of startup as well as memory, peripherals, input/output requests from software, translating
the work into instructions from CPU.
Type of Linux Operating System
Debian based : empahsizes free software. It supports many hardware platforms. Debian and distributions based on it use .deb package
format and dpkg package anager and its frontends.
Ubuntu, Knoppix, Kali Linux, Mint, PureOS, BOSS, Puppy Linux, Rapberry pi OS

Pacman-based : primarily developed and used by Arch Linux and its derivative. Default installation is minimal base system, configured
by user to only add what is purposely required.
Garuda Linux, Manjaro, SteamOS, BlackArch

RPM based
Red Hat Linux and SUSE Linux were original major distributions that used .rpm files format, which today is used in several package
management system. Both of these were later divided into commercial and community-supported distributions.
RHEL, Fedora, Fermi Linux LTS, Scientific Linux, CentOS, SUSE Linux Enterprise,

Gentoo Based: Distributions based on Gentoo use the Portage package management system with emerge or one of the alternative
package managers.
ChromiumOS, ChromeOS, Sabayon

Slackware based: Slackware is a highly customizable distribution that stresses ease of maintenance and reliability over cutting-edge
software and automated tools.
Absolute Linux, KateOS, VectorLinux, Slax

Android based: mobile operatinf system bought and developed by Google., based on google modified linux kernel.
Android-x86, Fore OS, GrapheseOS
https://en.wikipedia.org/wiki/List_of_Linux_distributions
"Choice. The problem is choice" – Neo (The Matrix Reloaded)
"Choice is an illusion created between those with power and those
without" – Merovingian (The Matrix Reloaded)

“Choice is an illusion created between those with coding skill and


those without” – Coder (The World is Reloaded with Matrix)
https://kde.org/plasma-desktop/
KDE vs GNOME desktop https://www.gnome.org/
Two of the most popular desktop environments in the Linux
Feature KDE GNOME
Full form K Desktop Environment. GNU Network Object Model
Early days Environment
Common Desktop
Environment. Both environments have
Design Traditional desktop like Modern, minimalistic like their strengths, and the
Windows Mac choice is mostly your
Performance Efficient, Lightweight Is resource-intensive personal preference.
Default application KDE Application suite GNOME Application Suite
(Dolphin, Konsole) (Files, Terminal)
Customization Extensive customization Limited Customization
Desktop effects Advanced effects and Subtle animation, less focus
animations on effects
Usability Best for power user and Best for new user and
people who play with system people who just want to
work with simplicity
GNOME
Is Linux different ?
It is similar to any other OS.

You have input and output similar hardware.

GUI (Graphical User Interface) is almost same. Not much different.

Somethings work very well in Linux and some not.

Mostly the graphics or creative related stuff (specially working with Adobe, Windows PowerPoint, sheet). As
expected the market or business related software are optimized for these platforms. But these days, one can
also install them on Linux and unleash their potential.

Some machine only has driver for Windows or Mac because of the agreement between the companies.
However, this is now changing. More companies are making drivers easily available for the Linux.

Is Linux safe ?
Safe as long as you know what you are doing and not downloading or visiting fishy sites.

There is recipe to be safe by computer expert


If you have a system, Don’t turn it ON.
If you turn it ON, Don’t put on NET.
If you on NET, then no one can keep you safe.
You are only safe till you are not valuable to be hacked.
The Terminal

*I am running Ubuntu on
Windows using App
Command
https://www.digitalocean.com/community/tutorials/linux-commands
Instruction given to system to do particular action.

If you want to read about the Linux commands, use “man”

man -> Allow you to access the manual pages of the Linux command

Try

man man
if you want to exit, type q. Please read/follow the instructions provided by the computer

uname
uname -a
We provide option for the command with “–a”

Try now “man uname”

Play with all the options and see


Try the following commands
“whoami”
“ls”
“pwd”

In linux or even in other OS:


You don’t need GUI or mouse to click and do things.

One can simply just use keyboard and make computer do most of
the work.

The day you started using terminal a lot and start hating the GUI.
You would be able to do things without even using mouse.
That day you reach Nirvana in coding and will become NEO

"I don't like the idea that I’m not in control of my life" –
Neo (The Matrix)

“I don’t like the idea that I’m not in control of my PC”


– Coding enthusiast (The World Named Matrix)
Commands you will need in this course or other place.

“ cd ” → change directory

cd directory1/directory2

“pwd” → present working directory

“mkdir” → make directory

mkdir directoryNew

“mv” → Move or rename files in Linux

“cp” → Similar usage as mv but copying files in linux

“rm” → Delete files or directories .. The most powerful command of the system.
Use this command careful.
The most powerful is “rm –rf” Avoid using it as much as possible
Programming Language

Any one of the following:


C++ : Classic, faster, only downside is one need separate plotting tool.
Python : Almost every library and function easily available. Matplotlib

Level required for the course:


No experience
Two secrets for coding I was told by a computer teacher:
If you know for, if, arrays, input, output, compiling, commenting, .....
you are ready to code.
K.I.S.S. Keep it Simple & Stupid
What I prefer for the course (of course flexibility is there):
If possible, use Linux (Ubuntu LTS, Fedora, Centos, OpenSUSE, ....)
I started with Fedora and now use Ubuntu LTS (due to most of the (non-)commercially available software tailored for Ubuntu LTS).
If windows system && sufficient RAM/memory use Oracle VirtualBox to run Mint Linux (Xfce)

If your system has not much space, there are lot of linux which can simply boot from pendrive (but try to save the work/code
everytime)
Most lighter Linux I have used is puppy linux (it can even run on old systems without any problem) even support 32 bit with 256 RAM and CP
600Hz processor
I want you to use a simple editor like vi, emacs (I prefer emacs) to edit/write a code.
Compile the code and print.
Before starting to code, I want everyone to make a proper flow chart
Some Tips to be better coder

1) Always Write detailed comments on your code. This will help you in long run.
2) Catalogue and make better directories. Arrange the code and work in workspace.
3) Always think of using less memory and think that computer has limited memory.
4) If code is working, don’t touch it.
5) If need to modify the code. Make a copy of that code with version and date. Then
start working on that code. There is a strong chance that you may either make the
code buddy or the code might not work. Always doubt your coding skill.
6) Introduce only those features which are required. Don’t over do or don’t under do
the coding.
7) Always keep your code simple. Follow “K.I.S.S. – Keep it Simple and Stupid”
8) Never introduce the variables which are not required in the code.
9) Test your code for multiple case scenarios.
10)Always assume that computer don’t know anything.
Question: When I will become expert in coding.
By the time you learn one language or think you are expert.
The world will move to another new language because of some cool features and a new generation
pushing/believing it to be cool.

FORTRAN
Used to have indentation
C++
Brackets (who the hell need indentation, blocks, brackets are the new cool)
Python
Indentation (who the hell need ugly brackets, blocks and indentation is the new cool)

But the one things which remain same in every coding language is
Logics
And
Bugs.

But for now


Python and C++ are going to stay.
Also, if you use Linux, I suggest to learn ‘bash or shell scripting’ [will give you taste in the end].
You can unleash the power of terminal.
Computer programming language
Code or syntax which is used to make processors do a specific/required task

Machine Language
▪ Referred to as machine code which is set of binary digits 0 and 1.
▪ These binary digits are understood and read by a computer system and interpret it easily.
▪ It is a native language as it can be directly understood by the central processing unit (CPU).

Assembly Language
▪ Low-level language for microprocessors and many other programmable devices.
▪ The assembly language is also considered as second-generation language.
▪ It is mostly famous for writing an operating system and also in writing different desktop applications.
▪ The operations carried out by programmers using assembly language are memory management, registry access,
and clock cycle operations.
▪ The drawback of assembly language is the code cannot be reused and the language is not so easy to understand

High Level Language


▪ High-level language is easy to understand and can be written easily as the programs written are user-friendly.
▪ The other advantage of code written in a high-level language is the code is independent of a computer system
which means the code can be transferred to other machines.
▪ The high-level of language uses the concept of abstraction and also focus on programming language rather than
focusing on computer hardware components like register utilization or memory utilization.
Other High Level programming

If you are more interested to build customized electronic boards, where signal processing and fitting has to be done:
FPGAs programming is crucial.
These days FPGAs even contain integrated processors which is a system in itself.
For that one need to use VHDL or Verilog programming.
Add two 8-bit numbers
https://www.javatpoint.com/programming-in-8085

http://computerscience.chemeketa.edu/cs160Reader/Programmin
gLanguages/Assembly.html

Assembly language

High level
language
https://www.geeksforgeeks.org/cpp-add-numbers/
How to represent numbers

You are well aware that numbers can be represented in various form

Decimals : base 10 : daily use (0,1,2,3,4,5,6,7,8,9)

Binary : base 2 : Computers (0,1)

Octal : base 8 : Yuki and Pamean languages, as speakers count using spaces between their fingers
(0,1,2,3,4,5,6,7,10).
It became widely used in computing systems as UNIVAC 1050, PDP-8, ICL 1900 an dIBM mainframes employed 6-bit,
12-bit, 24-bit or 36-bit words.
Each Octal digit represents three binary digits. So, 2,4,8 or 12 digits could concisely display an entire machine word.

Hexadecimal: base 16 : Ancient Chinese. Used widely by computer system designers and programmers because they
provide human-friendly representation of binary-coded values.
Each hexadecimal digit represents four bits ( nibble or nybble, which is half a byte)
Representation of numbers on computer
103 102 101 100 10−1 10−2 10−3

5 3 0 1 . 4 7 9
5 × 103 +3 × 102 +0 × 101 +1 × 100 +4 × 10−1 +7 × 10−2 +9 × 10−3 = 5301.479

The base(radix) of a number system determines the number of distinct values that can be used to
represent any arbitrary number. The decimal number is said to be of base 10.
23 22 21 20 2−1 2−2 2−3
Binary fraction
1 0 0 1 . 1 0 1

1 × 23 +0 × 22 +0 × 21 +1 × 20 +1 × 2−1 +1 × 2−2 +1 × 2−3


1 × 8 +0 × 4 +0 × 2 +1 × 1 +1 × 0.5+1 × 0.25+1 × 0.125 = 9.625

Position of a digit in a number is important. Certain weight is assigned to each position of a digit in a number.
Right most position of digit in a number has the lowest weightage and is called Least Significant Digit (LSD).
The digit in the extreme left position has maximum weightage and is thus called Most Significant Digit (MSD).
For a binary number, the bit (0 or 1) on the right most position is called the Least Significant bit (LSB) and the bit on the
extreme left position is called the Most Significant bit (MSB).

You might also like