Tokenizing
Breaking up the program into a list of strings that are independent tokens.
e.g.
Lexing
Iterating over that list and converting the tokens into strong types.
e.g.
Breaking up the program into a list of strings that are independent tokens.
e.g.
int a = 5 → [int] [a] [=] [5]Lexing
Iterating over that list and converting the tokens into strong types.
e.g.
[int] [a] [=] [5] → [type] [identifier] [assignment] [integerLiteral]Parser is responsible for creating abstract syntax trees and logical validation of the code. The parser uses a stream of tokens.
“The beginning of wisdom is to call things by their proper name.”
— Chinese proverb
— Chinese proverb
Correctness
Correctness of an algorithm is asserted when it is said that the algorithm is correct with respect to a specification. Functional correctness refers to the input-output behaviour of the algorithm i.e., for each input it produces the expected output.
Partial versus Total correctness
An algorithm is partially correct if an answer is returned; it is totally correct if it terminates i.e., halts.
Halting problem
The problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running i.e., halt or continue to run forever.
#Alan_Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. A key part of the proof was a mathematical definition of a computer and program, which became known as a #Turing_machine; the halting problem is undecidable over Turing machines. It is one of the first examples of a decision problem.
Correctness of an algorithm is asserted when it is said that the algorithm is correct with respect to a specification. Functional correctness refers to the input-output behaviour of the algorithm i.e., for each input it produces the expected output.
Partial versus Total correctness
An algorithm is partially correct if an answer is returned; it is totally correct if it terminates i.e., halts.
Halting problem
The problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running i.e., halt or continue to run forever.
#Alan_Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. A key part of the proof was a mathematical definition of a computer and program, which became known as a #Turing_machine; the halting problem is undecidable over Turing machines. It is one of the first examples of a decision problem.
#Java
Collections
It was designed to meet three goals:
• its implementations for the fundamental collections had to be highly efficient.
• it had to allow different types of collections to work in a similar manner and with interoperability.
• it had to adapt a new collection easily.
Lists
Sets
Maps
Collections
It was designed to meet three goals:
• its implementations for the fundamental collections had to be highly efficient.
• it had to allow different types of collections to work in a similar manner and with interoperability.
• it had to adapt a new collection easily.
AbstractCollection: Implements most of the Collection interface.Lists
AbstractList: Extends AbstractCollection and implements most of the List interface.AbstractSequentialList: Extends AbstractList for use by a collection that uses sequential rather than random access of its elements.LinkedList: Implements a linked list by extending AbstractSequentialList.ArrayList: Implements a dynamic array by extending AbstractList.Sets
AbstractSet: Extends AbstractCollection and implements most of the Set interface.HashSet: Extends AbstractSet for use with a hash table.LinkedHashSet: Extends HashSet to allow insertion-order iterations.TreeSet: Implements a set stored in a tree. Extends AbstractSet.Maps
AbstractMap: Implements most of the Map interface.HashMap: Extends AbstractMap to use a hash table.TreeMap: Extends AbstractMap to use a tree.WeakHashMap: Extends AbstractMap to use a hash table with weak keys.LinkedHashMap: Extends HashMap to allow insertion-order iterations.IdentityHashMap: Extends AbstractMap and uses reference equality when comparing documents.#Java
LinkedList
1.
Inserts the specified element at the specified position index in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index > size()).
2.
Appends the specified element to the end of this list.
3.
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. Throws NullPointerException if the specified collection is null.
4.
Inserts all of the elements in the specified collection into this list, starting at the specified position. Throws NullPointerException if the specified collection is null.
5.
Inserts the given element at the beginning of this list.
6.
Appends the given element to the end of this list.
7.
Removes all of the elements from this list.
8.
Returns a shallow copy of this LinkedList.
9.
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
10.
Returns the element at the specified position in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
11.
Returns the first element in this list. Throws NoSuchElementException if this list is empty.
12.
Returns the last element in this list. Throws NoSuchElementException if this list is empty.
13.
Returns the index in this list of the first occurrence of the specified element, or -1 if the list does not contain this element.
14.
Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
15.
Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
16.
Removes the element at the specified position in this list. Throws NoSuchElementException if this list is empty.
17.
Removes the first occurrence of the specified element in this list. Throws NoSuchElementException if this list is empty. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
18.
Removes and returns the first element from this list. Throws NoSuchElementException if this list is empty.
19.
Removes and returns the last element from this list. Throws NoSuchElementException if this list is empty.
20.
Replaces the element at the specified position in this list with the specified element. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
21.
Returns the number of elements in this list.
22.
Returns an array containing all of the elements in this list in the correct order. Throws NullPointerException if the specified array is null.
23.
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
LinkedList
1.
void add(int index, Object element)Inserts the specified element at the specified position index in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index > size()).
2.
boolean add(Object o)Appends the specified element to the end of this list.
3.
boolean addAll(Collection c)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. Throws NullPointerException if the specified collection is null.
4.
boolean addAll(int index, Collection c)Inserts all of the elements in the specified collection into this list, starting at the specified position. Throws NullPointerException if the specified collection is null.
5.
void addFirst(Object o)Inserts the given element at the beginning of this list.
6.
void addLast(Object o)Appends the given element to the end of this list.
7.
void clear()Removes all of the elements from this list.
8.
Object clone()Returns a shallow copy of this LinkedList.
9.
boolean contains(Object o)Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
10.
Object get(int index)Returns the element at the specified position in this list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
11.
Object getFirst()Returns the first element in this list. Throws NoSuchElementException if this list is empty.
12.
Object getLast()Returns the last element in this list. Throws NoSuchElementException if this list is empty.
13.
int indexOf(Object o)Returns the index in this list of the first occurrence of the specified element, or -1 if the list does not contain this element.
14.
int lastIndexOf(Object o)Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
15.
ListIterator listIterator(int index)Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
16.
Object remove(int index)Removes the element at the specified position in this list. Throws NoSuchElementException if this list is empty.
17.
boolean remove(Object o)Removes the first occurrence of the specified element in this list. Throws NoSuchElementException if this list is empty. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
18.
Object removeFirst()Removes and returns the first element from this list. Throws NoSuchElementException if this list is empty.
19.
Object removeLast()Removes and returns the last element from this list. Throws NoSuchElementException if this list is empty.
20.
Object set(int index, Object element)Replaces the element at the specified position in this list with the specified element. Throws IndexOutOfBoundsException if the specified index is out of range (index < 0 || index >= size()).
21.
int size()Returns the number of elements in this list.
22.
Object[] toArray()Returns an array containing all of the elements in this list in the correct order. Throws NullPointerException if the specified array is null.
23.
Object[] toArray(Object[] a)Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
Pattern matching
- is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match has to either be or not be an exact match. The patterns have the form of either sequences or trees.
Sequence patterns, like strings, are often described using regular expressions and matched using techniques such as backtracking.
#regex
- is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match has to either be or not be an exact match. The patterns have the form of either sequences or trees.
Sequence patterns, like strings, are often described using regular expressions and matched using techniques such as backtracking.
#regex
GoTo
- is a statement that performs a one-way transfer of control to another point of code; in contrast to a function call which returns control.
Its use has declined significantly since the advent of structured programming in the 1960s. Structured programming languages like #Pascal introduced control structures such as: subroutines, loops and multiway branch for clarity and efficiency. These replace equivalent flows written using gotos and ifs.
Language support:
• #C
• #CSharp: also makes
• #Perl
• #PHP there was no native support for goto until version 5.3
• #Java:
• #Python: does not support it but there are several joke modules that provide it.
The structured program theorem proves that
- is a statement that performs a one-way transfer of control to another point of code; in contrast to a function call which returns control.
Its use has declined significantly since the advent of structured programming in the 1960s. Structured programming languages like #Pascal introduced control structures such as: subroutines, loops and multiway branch for clarity and efficiency. These replace equivalent flows written using gotos and ifs.
Language support:
• #C
• #CSharp: also makes
case and default statements labels, whose scope is the enclosing switch statement; goto case or goto default is often used to replace explicit "fall-through", which C# disallows.• #Perl
• #PHP there was no native support for goto until version 5.3
• #Java:
goto is a reserved word, but is unusable.• #Python: does not support it but there are several joke modules that provide it.
The structured program theorem proves that
goto is not necessary to write programs.Structured program theorem
- states that the three combinations of subprograms which are sequence, choice, and iteration are sufficient for any computation that can be performed by a #Turing_machine; however, additional variables may be needed.
• Sequence: Executing one subprogram, and then another subprogram.
• Choice: Executing one of two subprograms according to the value of a boolean expression.
• Iteration: Executing a subprogram as long as a boolean expression is true.
- states that the three combinations of subprograms which are sequence, choice, and iteration are sufficient for any computation that can be performed by a #Turing_machine; however, additional variables may be needed.
• Sequence: Executing one subprogram, and then another subprogram.
• Choice: Executing one of two subprograms according to the value of a boolean expression.
• Iteration: Executing a subprogram as long as a boolean expression is true.
Forwarded from Ali "AnotherTest" Mohammad Pur
You should try making something that makes you think "I'm a fucking genius"
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
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
Computer Science is no more about computers than astronomy is about telescopes.
~ #EdsgerDijkstra
~ #EdsgerDijkstra
“Trees sprout up just about everywhere in computer science.”
— #Donald_Knuth
— #Donald_Knuth
#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.
#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.
#mathematics #geometry
Plane curve
Parametric equation:
Examples:
• Straight line
As a function:
• Circle
• Parabola
• Ellipse
Tangent
The tangent line (or simply tangent) to a plane curve at a given point is the straight line that "just touches" the curve at that point.
The line through a pair of infinitely close points on the curve. — #Gottfried_Leibniz
A straight line is a tangent of a curve
Plane curve
Parametric equation:
(x, y) = (f(x), g(y))Examples:
• Straight line
(x, y) = (x0+a*t, y0+b*t)As a function:
y = m*x + c• Circle
(x, y) = (r*cos(t), r*sin(t))• Parabola
(x, y) = (t, t^2)• Ellipse
(x, y) = (a*cos(t), b*sin(t))Tangent
The tangent line (or simply tangent) to a plane curve at a given point is the straight line that "just touches" the curve at that point.
The line through a pair of infinitely close points on the curve. — #Gottfried_Leibniz
A straight line is a tangent of a curve
y = f(x) at x = c if the line passes through the point (c, f(c)) on the curve and has a slope of (derivative(f))(c).#mathematics #calculus
Derivative
The derivative of a function of a real variable measures the sensitivity to change of the function value (output value) with respect to a change in its argument (input value).
The derivative of a function of a single variable at a chosen input value, when it exists, is the slope of the tangent line to the graph of the function at that point.
The process of computing a derivative is called differentiation. The reverse process is called antidifferentiation. The fundamental theorem of calculus states that antidifferentiation is the same as integration.
Differentiable function
- is a function whose derivative exists at each point in its domain. Its graph has a non-vertical tangent line at each point in its domain, is relatively smooth, and does not contain breaks, bends, or cusps (when a curve suddenly starts to move backwards).
If f is differentiable at x0, then f must also be continuous at x0. In particular, any differentiable function must also be continuous at every point in its domain. The converse does not hold.
Continuous function
- is a function for which sufficiently small changes in the input result in arbitrarily small changes in the output. Otherwise it is discontinuous.
Definition: f is continuous at c if
The function itself is said to be continuous if it is continuous at every point.
Derivative
The derivative of a function of a real variable measures the sensitivity to change of the function value (output value) with respect to a change in its argument (input value).
The derivative of a function of a single variable at a chosen input value, when it exists, is the slope of the tangent line to the graph of the function at that point.
The process of computing a derivative is called differentiation. The reverse process is called antidifferentiation. The fundamental theorem of calculus states that antidifferentiation is the same as integration.
Differentiable function
- is a function whose derivative exists at each point in its domain. Its graph has a non-vertical tangent line at each point in its domain, is relatively smooth, and does not contain breaks, bends, or cusps (when a curve suddenly starts to move backwards).
If f is differentiable at x0, then f must also be continuous at x0. In particular, any differentiable function must also be continuous at every point in its domain. The converse does not hold.
Continuous function
- is a function for which sufficiently small changes in the input result in arbitrarily small changes in the output. Otherwise it is discontinuous.
Definition: f is continuous at c if
limit(f(x), x approaches c) == f(c).The function itself is said to be continuous if it is continuous at every point.