DRAFT DOCUMENT

Contents

Value

A value is an expression that implies no further processing; a normal form, for example: we can use a numerical value to represent the age of a person.

Swift
1
2
#!/usr/bin/env swiftshell
let age = 23

Referentially Transparent

An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing a program’s behavior.

Predicate

Is any boolean valued function, typically returning either true or false.

1
2
3
4
func isEven(value: Int) -> Boolean
{
  return value % 2 == 0 ? true : false
}

Function

Defines a relation between a set of inputs and a set of outputs, more typically with a formula or algorithm.

Domain

The input to a function is called the domain

Codomain

The output from a function is called the codomain, what actually comes out of the function is the range

Pure Function

Is a function where each input is related to exactly one output. Inversely any function can be memoized is a Pure Function.

Morphism

Morphisms are basically functions, and in category theory are also called arrows.

Injective Function

Is also called a one-to-one function is a function that preserves distinctness.

  • A monomorphism is generally injective.
  • Every injective function can be reversed.
  • Never assigns the same codomain value to two different domain elements.
  • Never assigns the same value to two different domain elements.

If we consider the square function:

is not injective if x is both postive and negative. However it is injective if we limit the domain:

  • values greater than zero.

Surjective graph

Injective graph

Swift
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env swiftshell
import Foundation
let x = sqrt(16)
let y = pow(x, 2)
print("x = \(x), y = \(y)") // x = 4.0, y = 16.0

print(pow(-4, 3))
print(pow(4, 3))

print(sqrt(16))
print(sqrt(16))

Note: sqrt and pow are both injective functions, each being the inverse of the other.

Surjective Function

Is also called a one-to-many function having at least one or more match in the output.

Bijective Function

The combination of Injective and Surjective.

So there is a perfect “one-to-one correspondence” between the members of the sets.

(But don’t get that confused with the term “One-to-One” used to mean injective).

Injective, Surjective and Bijective

Injective, Surjective and Bijective tells us about how a function behaves.

Monomorphism

Monomorphisms are a categorical generalization of injective functions (also called “one-to-one functions”); in some categories the notions coincide, but monomorphisms are more general, as in the examples below.

Epimorphism

Isomorphism

Homomorphism

If we look at the above variable; it’s clear that age is 23, because of the assignment.

  • age is our variable
  • 23 is the value that we’ve assigned to this variable

Functor

Applicative Functor

Attention Xennox

This can be used as an example template; I have also placed a copy in the templates folder.

I am providing this example to hopefully make the delineation of the language parts a little easier. Also I provided a few markdown examples within the code blocks; you can find the full github markdown documentation at github.com

Here’s an example of two formatting code:

  • C#
  • C++

The following tags:

  • {::options parse_block_html="true"/}
  • {::options parse_block_html="false"/}
  • highlight C# linenos
  • endhighlight

… are important to separate the different parts precisely; basically which parts are markdown (format) parsed and which parts are kramdown (code) parsed, similarly the spacing before and after the html tags like <div class="C#">, <div class="codefunc-result">45<br>90</div> and </div>

Example C# heading

Text explanation preceding the code block

1
2
3
4
5
6
7
8
int total = 0;
internal int sum(int[] values)
{
  foreach (int value in values) {
    total += value;
  }
  return total;
}

C# Explanation after the code block

Ensure that all the text that explains the code is included in the code <div>, also make sure you left align everything you want to be parsed as markdown.

  • list item 1
  • list item 2
  • list item 3
table example
1234 apple
5678 pear
9012 banana

In-line code tags int _sum = 23; example

block quote example

C# Task List

  • [x] This is a complete item
  • [ ] This is an incomplete item

Example C++ heading

Text explanation preceding the code block

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <vector>

int _sum = 0;

int sum(const std::vector<int>& values) {
    
    for (std::vector<int>::const_iterator itr = values.begin(); itr < values.end(); ++itr)
        _sum += *itr;

    return _sum;
}

int main() {

    std::cout << sum(std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9}) << std::endl;
    std::cout << sum(std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9}) << std::endl;

    return 0;
}
45
90
84848

C++ Explanation after the code block

Ensure that all the text that explains the code is included in the code <div>, also make sure you left align everything you want to be parsed as markdown.

  • list item 1
  • list item 2
  • list item 3
table example
1234 apple
5678 pear
9012 banana

In-line code tags int _sum = 23; example

block quote example

C++ Task List

  • [x] This is a complete item
  • [ ] This is an incomplete item

Hope this helps to make it a little easier.

Ps. To add another language we only need to modify the post.html languages array; thereafter it will be automatically detected and accommodated in the posts. Currently the array looks like this:

  • var languages = ['C#', 'C++', 'Go', 'Haskell', 'Java', 'JavaScript', 'Perl', 'PHP', 'Python', 'Rails', 'Ruby', 'Swift', 'VB.Net'];
The Language Preference Javascript will probably move out of the post.html to a .js file during refactoring; I'll let you know when the location changes.

Normal Form

  • An object is in normal form if it cannot be rewritten any further.