ComputerScientist
174 subscribers
14 photos
3 files
206 links
▜ The Inventor

Stuff that inspire you to create.

See also: ▙ @LitMind
Download Telegram
#Programming_paradigms : Declarative versus Imperative

#Declarative
All about relations.

Does not state the order in which operations execute.

Focuses on what the program should accomplish without specifying how the program should achieve the result.
Expresses the logic of a computation without describing its control flow.

Common declarative languages include those of database query languages (e.g. #SQL, #XQuery), regular expressions (#Regex), logic programming, functional programming, and configuration management systems.

e.g. #Haskell, #Kanren (a dialect of #Scheme), #Prolog, #Wolfram_Language

#Imperative
Uses statements that change a program's state.
1. they state the order in which operations occur, with constructs that explicitly control that order

Allows side effects, in which state can be modified within one unit of code, and then read inside a different unit of code.

Imperative programming focuses on describing how a program operates.
an imperative program consists of commands for the computer to perform.
Many imperative programming languages (such as #Fortran, #BASIC, and #C) are abstractions of assembly language.
#Programming_paradigms : #Logic programming
Based on formal logic.
Any program is a set of sentences in logical form, expressing facts and rules about some problem domain.
Major logic programming language families include #Prolog, Answer set programming (#ASP) and #Datalog.

In all of these languages, rules are written in the form of clauses:
H if B1 and … and Bn.

H is called the head of the rule and B1, …, Bn is called the body.

Facts are rules that have no body.
#Programming_paradigms : #Functional programming

Seeks to use pure functions.

Pure functions:
• have no side effects
• return a value that depends only on their arguments. e.g. sin(x) will, for the same value of x, always return the same result.
• are easier to reason about and test.
• are more efficient. Once the function has been evaluated for an input, the result can be stored and referred to the next time the function of that input is needed, reducing the number of times the function is called. This is called #memoization.
• are less confusing to run in parallel (See #concurrent programming).

Using only pure functions complicates the otherwise simple task of IO since this appears to inherently require side effects.
#Programming_paradigms : #Array_programming (also vector or multidimensional)

Generalizes operations on scalars to apply transparently to vectors, matrices, and higher-dimensional arrays.

Is used in scientific and engineering settings.

e.g. APL, J, Fortran, #Ada, #MATLAB, #Perl Data Language (PDL) and the NumPy extension to #Python.

Vectorized operation
Operations applied at once to an entire set of values like arrays; regardless of whether it is executed on a vector processor or not.

Function rank
Analogous to tensor rank in mathematics
Functions that operate on data may be classified by the number of dimensions they act on.

• Ordinary multiplication, for example, is a scalar ranked function because it operates on zero-dimensional data (individual numbers).

• The cross product operation is an example of a vector rank function because it operates on vectors, not scalars.

• Matrix multiplication is an example of a 2-rank function, because it operates on 2-dimensional objects (matrices).

Collapse operators reduce the dimensionality of an input data array by one or more dimensions. For example, summing over elements collapses the input array by 1 dimension.
ComputerScientist
#Programming_paradigms : Declarative versus Imperative #Declarative All about relations. Does not state the order in which operations execute. Focuses on what the program should accomplish without specifying how the program should achieve the result. Expresses…
#Programming_paradigms
Expression versus Statement
An expression is a unit of #declarative programming.
A statement is a unit of #imperative programming.
An expression is evaluated whereas a statement is executed.

Expressions
A combination of values, variables and functions that return a value and have no side effects.

Expressions can contain functions and functions may have side effects. A side effect is a change to the abstract state of the running program that does not depend on the function input.

Functional programs do not have assignment statements therefore the value of a variable never changes once defined. An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. Evaluating a referentially transparent function gives the same value for same arguments. Such functions are called pure functions. Referentially transparent expressions allow #memoization.

Statements
Do not return results and are executed solely for their side effects.

Simple statements:
• assertion
• assignment
• goto
• return
• call

Compound statements: (may contain statements as components)
• block
• choice
• iteration
#Programming_paradigms
#Structured
Structured versus non-structured

Non-structured programming
• Historically the earliest programming paradigm capable of creating #Turing_complete algorithms.
• Uses unstructured control flow construct of GoTo which can lead to "spaghetti code" that is potentially difficult to follow and maintain.

Structured programming
• Aims at improving the clarity, quality, and development time.
• Uses structured control flow constructs of choice and repetition, block structures, and subroutines.

Elements
• Control structures: following the structured program theorem, all programs are seen as composed of control structures of sequence, choice, iteration.
• Blocks: enable groups of statements to be treated as one statement.
• Subroutines: are callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement.
• Recursion: a subroutines is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterations, recursions may be more efficient.
#programming_paradigms
Stream processing
- is a programming paradigm that simplifies parallelism by restricting the parallel computation that can be performed: programs may use multiple computational units, such as the floating point unit on a GPU or FPGA, without explicitly managing allocation, synchronization, or communication among those units. Given a sequence or "stream" of data, a series of kernel functions is applied to each element in that stream.

Kernel functions are usually pipelined, and optimal local on-chip memory reuse is attempted, in order to minimize the loss in bandwidth, accredited to external memory interaction. Uniform streaming, where one kernel function is applied to all elements in the stream, is typical. Since the kernel and stream abstractions expose data dependencies, compiler tools can fully automate and optimize on-chip management tasks. Stream processing hardware can use scoreboarding, for example, to initiate a direct memory access (DMA) when dependencies become known. The elimination of manual DMA management reduces software complexity, and an associated elimination for hardware cached I/O, reduces the data area expanse that has to be involved with service by specialized computational units such as ALUs.

Stream processing was explored within dataflow programming, during the 80s. An example is the language #SISAL.

Compute kernel a.k.a. Kernel function
- is a function compiled for high throughput accelerators, separate from but used by programs running on CPU. They roughly correspond to inner loops when implementing algorithms in traditional languages (though non-sequential), or to code passed to internal iterators. They may be specified by a separate programming language such as #OpenCL_C, or embedded directly in application code written in a high level language, as in the case of C++AMP.

#Stream_processing