mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-01-30 16:58:00 +00:00
Add a bunch of notes
Well, I forgot to add them into the VCS. Whoops... On the other hand, I'm also trying to make it suitable both for org-roam and neuron at the same time.
This commit is contained in:
parent
18ba375642
commit
d91cb3652a
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,3 +8,6 @@ tmp/
|
||||
*.pdf
|
||||
*.tex
|
||||
*.md
|
||||
|
||||
# Neuron exports
|
||||
.neuron
|
||||
|
@ -85,6 +85,8 @@ For example, say we have different functions for knowing the area of a shape.
|
||||
(define (hexagon-area r) (* (sqrt 3) 1.5 r r))
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
|
||||
This could pass as a decent code if each area function is distinct from each other.
|
||||
However, all of the given area functions involves squaring the given parameter (~r~).
|
||||
We can separate that step in a function like the following.
|
||||
@ -98,6 +100,8 @@ We can separate that step in a function like the following.
|
||||
(define hexagon (* (sqrt 3) 1.5))
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
|
||||
|
||||
|
||||
|
||||
@ -387,4 +391,187 @@ As for notating ~f~, ~g~, and ~h~ into mathematical definitions:
|
||||
|
||||
- ~f~ is $2n$.
|
||||
- ~g~ is $2^n$.
|
||||
- ~h~ is $2^{n}^{2}$.
|
||||
- ~h~ is $2^n^2$.
|
||||
|
||||
|
||||
** Exercise 1.30
|
||||
|
||||
#+begin_quote
|
||||
The ~sum~ procedure above generates a linear recursion.
|
||||
The procedure can be rewritten so that the sum is performed iteratively.
|
||||
Show how to do this by filling in the missing expressions in the following definition:
|
||||
#+end_quote
|
||||
|
||||
#+BEGIN_SRC racket :lang sicp
|
||||
(define (sum term a next b)
|
||||
(define (iter a result)
|
||||
(if (> a b)
|
||||
result
|
||||
(iter (next a) (+ result a))))
|
||||
(iter a 0))
|
||||
#+END_SRC
|
||||
|
||||
|
||||
** Exercise 1.31a
|
||||
|
||||
#+begin_quote
|
||||
The ~sum~ procedure is only the simplest of a vast number of similar abstractions that can be captured as higher-order procedures.
|
||||
Write an analogous procedure called ~product~ that returns the product of the values of a function at points over a given range.
|
||||
Show how to define ~factorial~ in terms of ~product~.
|
||||
Also use ~product~ to compute approximations to \pi using the formula.
|
||||
|
||||
\begin{equation*}
|
||||
\frac{\pi}{4} = \frac{2 \cdot 4 \cdot 4 \cdot 6 \cdot 6 \cdot 8 \cdots}{3 \cdot 3 \cdot 5 \cdot 5 \cdot 7 \cdot 7 \cdots}
|
||||
\end{equation*}
|
||||
#+end_quote
|
||||
|
||||
#+BEGIN_SRC racket :lang sicp
|
||||
(define (product term a next b)
|
||||
(if (> a b)
|
||||
term
|
||||
(product (* (next a) term) (+ a 1) next b)))
|
||||
|
||||
(define (factorial term)
|
||||
(product 1 1 (lambda (a) a) term))
|
||||
|
||||
(define (wallis_prod term)
|
||||
(* 4 (product 1 1
|
||||
(lambda (a) (*
|
||||
(/ (* 2 a) (+ (* 2 a) 1))
|
||||
(/ (+ (* 2 a) 2) (+ (* 2 a) 1))))
|
||||
term)))
|
||||
|
||||
(factorial 1) ; should return 1
|
||||
(factorial 5) ; should return 120
|
||||
(factorial 10) ; should return 3628800
|
||||
(factorial 20) ; should return 20!
|
||||
|
||||
; With larger values should return closer to the value of pi.
|
||||
(wallis_prod 1)
|
||||
(wallis_prod 5)
|
||||
(wallis_prod 10)
|
||||
(wallis_prod 20)
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: 1
|
||||
: 120
|
||||
: 3628800
|
||||
: 2432902008176640000
|
||||
: 32/9
|
||||
: 524288/160083
|
||||
: 274877906944/85530896451
|
||||
: 302231454903657293676544/95064880114531295493525
|
||||
|
||||
Notwithstanding related to solving the entire problem, I'll include note on how I was able to create a procedure for the Pi value computation since it gave me the hardest time.
|
||||
In order to start creating a procedure, I've simply observed the given formula with the induction that it can be separated into pairs like the following.
|
||||
(I also simply didn't observe that each pair is also an iteration of a function.)
|
||||
|
||||
\begin{equation*}
|
||||
\frac{\pi}{4} = \left(\frac{2}{3} \cdot \frac{4}{3} \right) \cdot \left(\frac{4}{5} \cdot \frac{6}{5} \right) \cdot \left(\frac{6}{7} \cdot \frac{8}{7} \right)
|
||||
\end{equation*}
|
||||
|
||||
We can then observed that it has a generalized pattern.
|
||||
Each iteration, in isolation, can be summarized as such.
|
||||
|
||||
\begin{equation*}
|
||||
\left(\frac{2n}{2n+1} \cdot \frac{2n+2}{2n+1}\right)
|
||||
\end{equation*}
|
||||
|
||||
With simple algebra, you can get the approximation of Pi by simply multiplying the equation with $4$.
|
||||
Here is the finalized equation to my solution.
|
||||
|
||||
\begin{equation*}
|
||||
f(j) \approx \pi \approx 4 \cdot \prod_{n=1}^j \left(\frac{2n}{2n+1} \cdot \frac{2n+2}{2n+1}\right)
|
||||
\end{equation*}
|
||||
|
||||
With larger values, the result would be closer to the value of \pi.
|
||||
|
||||
|
||||
** Exercise 1.31b
|
||||
|
||||
#+begin_quote
|
||||
If your ~product~ procedure generates a recursive process, write one that generates an iterative process.
|
||||
If it generates an iterative process, write one that generates a recursive process.
|
||||
#+end_quote
|
||||
|
||||
Based from my answer in Exercise 1.31a, we can simply see whether we have created an iterative or recursive process simply with the ~trace~ function.
|
||||
|
||||
#+BEGIN_SRC racket :lang racket
|
||||
(require racket/trace)
|
||||
(define (product total fn a b)
|
||||
(if (> a b)
|
||||
total
|
||||
(product (* total (fn a)) fn (+ a 1) b)))
|
||||
|
||||
(define (factorial term)
|
||||
(product 1 (lambda (a) a) 1 term))
|
||||
|
||||
(trace product)
|
||||
(factorial 5)
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: >(product 1 #<procedure:...v3/ob-PoMhn9.rkt:10:13> 1 5)
|
||||
: >(product 1 #<procedure:...v3/ob-PoMhn9.rkt:10:13> 2 5)
|
||||
: >(product 2 #<procedure:...v3/ob-PoMhn9.rkt:10:13> 3 5)
|
||||
: >(product 6 #<procedure:...v3/ob-PoMhn9.rkt:10:13> 4 5)
|
||||
: >(product 24 #<procedure:...v3/ob-PoMhn9.rkt:10:13> 5 5)
|
||||
: >(product 120 #<procedure:...v3/ob-PoMhn9.rkt:10:13> 6 5)
|
||||
: <120
|
||||
: 120
|
||||
|
||||
With our implementation, we can see it is an iterative process.
|
||||
The following code block is its recursive equivalent along with the stack trace for comprehension.
|
||||
|
||||
#+BEGIN_SRC racket :lang racket
|
||||
(require racket/trace)
|
||||
(define (product total fn a b)
|
||||
(if (> a b)
|
||||
1
|
||||
(* (fn a) (product total fn (+ a 1) b))))
|
||||
|
||||
(define (factorial term)
|
||||
(product 1 (lambda (a) a) 1 term))
|
||||
|
||||
(trace product)
|
||||
(factorial 5)
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
#+begin_example
|
||||
>(product 1 #<procedure:...v3/ob-lY382a.rkt:10:13> 1 5)
|
||||
> (product 1 #<procedure:...v3/ob-lY382a.rkt:10:13> 2 5)
|
||||
> >(product 1 #<procedure:...v3/ob-lY382a.rkt:10:13> 3 5)
|
||||
> > (product 1 #<procedure:...v3/ob-lY382a.rkt:10:13> 4 5)
|
||||
> > >(product 1 #<procedure:...v3/ob-lY382a.rkt:10:13> 5 5)
|
||||
> > > (product 1 #<procedure:...v3/ob-lY382a.rkt:10:13> 6 5)
|
||||
< < < 1
|
||||
< < <5
|
||||
< < 20
|
||||
< <60
|
||||
< 120
|
||||
<120
|
||||
120
|
||||
#+end_example
|
||||
|
||||
|
||||
** Exercise 1.32a
|
||||
|
||||
#+begin_quote
|
||||
Show that ~sum~ and ~product~ (exercise 1.31) are both special cases of a still more general notion called ~accumulate~ that combines a collection of terms, using some general accumulation function:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
(accumulate combiner null-value term a next b)
|
||||
#+END_EXAMPLE
|
||||
|
||||
~accumulate~ takes as arguments the same term and range specifications as sum and product, together with a combiner procedure (of two arguments) that specifies how the current term is to be combined with the accumulation of the preceding terms and a null-value that specifies what base value to use when the terms run out.
|
||||
Write ~accumulate~ and show how ~sum~ and ~product~ can both be defined as simple calls to ~accumulate~.
|
||||
#+end_quote
|
||||
|
||||
#+BEGIN_SRC racket :lang sicp
|
||||
(define (accumulate combiner null-value term a next b)
|
||||
(if (> a b)
|
||||
term
|
||||
(accumulate combiner null-value (combiner (next a) term) (next a) next b)))
|
||||
#+END_SRC
|
0
20200701231907-information_literacy.org → 2020-07-01-23-19-07.org
Normal file → Executable file
0
20200701231907-information_literacy.org → 2020-07-01-23-19-07.org
Normal file → Executable file
0
20200706034752-refer_to_advanced_resources_when_skill_building_for_a_solid_short_term_goal.org → 2020-07-06-03-47-52.org
Normal file → Executable file
0
20200706034752-refer_to_advanced_resources_when_skill_building_for_a_solid_short_term_goal.org → 2020-07-06-03-47-52.org
Normal file → Executable file
0
20200706235547-deliberate_practice.org → 2020-07-06-23-55-47.org
Normal file → Executable file
0
20200706235547-deliberate_practice.org → 2020-07-06-23-55-47.org
Normal file → Executable file
16
2020-07-10-23-30-27.org
Executable file
16
2020-07-10-23-30-27.org
Executable file
@ -0,0 +1,16 @@
|
||||
#+title: Endianness
|
||||
|
||||
|
||||
- Tags :: [[file:computational-processes.org][Computational processes]]
|
||||
|
||||
Endianness refers to how bits are read and this depends on the underlying hardware architecture.
|
||||
[fn:: You can enforce endianness in software but oftentimes, it is not a good idea.]
|
||||
|
||||
For example, given the following bit, 11010, this could be read as $(1\times2^{0}) + (1\times2^{1}) + (0\times2^{2}) + (1\times2^{3}) + (0\times2^{4})$ or $11$ with the first bit being the least significant also known as *little-endian*.
|
||||
On the other hand, this could also be read as $(0\times2^{0}) + (1\times2^{1}) + (0\times2^{2}) + (1\times2^{3}) + (1\times2^{4})$ or $26$ with the last bit being the least significant which we refer to as *big-endian*.
|
||||
[fn:: Endianness focuses on byte order, not bit order but it is best to give the simplest example.]
|
||||
|
||||
Endianness can have subtle effects on various things — e.g., using binary data formats like [[https://fits.gsfc.nasa.gov/][FITS]] and [[https://www.hdfgroup.org/solutions/hdf5][HDF]] — like having the wrong endianness.
|
||||
|
||||
To know the endianness of your machine, you can simply create a test number (preferably in binary) and check for the first few digits if it's little-endian — otherwise, it is big-endian.
|
||||
If you have Python installed, you can simply use [[https://docs.python.org/3/library/sys.html#sys.byteorder][~sys.byteorder~]] (e.g., ~python -c 'import sys; print(sys.byteorder)~).
|
8
2020-08-19-08-21-44.org
Executable file
8
2020-08-19-08-21-44.org
Executable file
@ -0,0 +1,8 @@
|
||||
#+title: GNU Guix
|
||||
|
||||
|
||||
[[https://guix.gnu.org/][GNU Guix]] is a package manager that follows the footsteps of Nix in furthering [[file:2020-09-19-08-31-48.org][Functional package management]].
|
||||
|
||||
- [[https://guix.gnu.org/cookbook/][GNU Guix cookbook]]
|
||||
- [[http://www.gnu.org/software/guix/blog/2018/a-packaging-tutorial-for-guix/][GNU Guix packaging tutorial]]
|
||||
- [[https://github.com/pmeiyu/guix-config][This GuixSD config by pmeiyu@github.com]]
|
5
2020-08-28-19-26-43.org
Normal file
5
2020-08-28-19-26-43.org
Normal file
@ -0,0 +1,5 @@
|
||||
#+title: Linux drivers
|
||||
|
||||
- [[https://everything-is-sheep.herokuapp.com/posts/on-developing-a-linux-driver=-][An overview from a student without prior experience]]
|
||||
- [[https://unix.stackexchange.com/questions/507687/graphic-tablet-veikk-pressure-sensitivity-on-linux][Creating a driver for a graphics tablet]] on Unix StackExchange
|
||||
- [[https://lwn.net/Kernel/LDD3/][The de-facto reference on creating Linux drivers]]
|
15
2020-09-04-16-07-47.org
Normal file
15
2020-09-04-16-07-47.org
Normal file
@ -0,0 +1,15 @@
|
||||
#+title: Nix package manager
|
||||
|
||||
|
||||
[[https://nixos.org/][Nix]] is a package manager that pioneered [[file:2020-09-19-08-31-48.org][Functional package management]] which addresses the criticisms of traditional Unix systems while making it as a specialized tool for [[file:reproducible-research.org][Reproducible research]].
|
||||
Holistically, Nix is made up of at least four components: the store, the language, the derivations, and the sandbox.
|
||||
|
||||
- The store is a immutable centralized location where all of the outputs are placed.
|
||||
- The derivations are essentially build instructions.
|
||||
- The language (also called as Nix but we'll refer to it as Nixlang) is a domain-specific language for creating derivations.
|
||||
- The build process can be locked in a sandbox, improving the reproducibility of a setup and lowering the attack surface for a malicious package.
|
||||
|
||||
Furthermore, it also offers one of the must-haves as a power user (in my opinion) which is declarative configuration.
|
||||
You can write the whole system configuration in a plain-text file giving you all of the little knobs and switches of the system.
|
||||
Even then, it also applies some abstraction if you don't want the full control which is an attractive option if you're looking for a quick setup.
|
||||
Finally, they are suitable to be used under a version control system like Git and Subversion giving more room for experimentation [fn:: As if the rollback feature for NixOS wasn't enough.] and control.
|
1
2020-09-04-19-57-06.org
Normal file
1
2020-09-04-19-57-06.org
Normal file
@ -0,0 +1 @@
|
||||
#+title: Functional programming
|
27
2020-09-19-08-31-48.org
Executable file
27
2020-09-19-08-31-48.org
Executable file
@ -0,0 +1,27 @@
|
||||
#+title: Functional package management
|
||||
|
||||
|
||||
Functional package management (FPM) is the next step forward [[https://edolstra.github.io/pubs/nixos-icfp2008-final.pdf][pioneered by Eelco Dolstra]] with [[https://nixos.org/][NixOS]] as the living implementation.
|
||||
[fn:: Eventually, it became the inspiration for other projects that focuses on reproducibility and security such as [[https://guix.gnu.org/][GNU Guix]] and [[https://silverblue.fedoraproject.org/][Fedora Silverblue]].]
|
||||
|
||||
The conceptual overview of it is similar to [[file:2020-09-04-19-57-06.org][Functional programming]] with how it views with data and functions (in this case, packages and build processes).
|
||||
|
||||
It views that packages are a unique result from combining different things: dependencies, build processes, versions, and more.
|
||||
If a dependency has updated its patch version or a build instruction has revised with one line of change, it will result in a "new" package as the output even if the package isn't any different.
|
||||
|
||||
Coming from a functional approach, it also features statelessness and immutability, making it a reliable toolkit for [[https://reproducible-builds.org/][reproducible builds]] (thus gaining a reach for [[file:reproducible-research.org][Reproducible research]]).
|
||||
|
||||
The problems that FPM attempts to solve come from the critique of the traditional package management which is still dominant as of today (2020-08-31).
|
||||
Here are some of the problems on a traditional Linux-based system:
|
||||
|
||||
- The statefulness of the entire system leads to similar situations on Windows' dependency hell problem.
|
||||
- Multiple versions of packages are hard to place side-by-side which is used by developers targetting stable versions while experimenting with the latest versions.
|
||||
- Destructive ongoing updates which consists of replacing the current version with the updated version while the update is going.
|
||||
- Traceability is almost non-existent with all of the statefulness of the system.
|
||||
|
||||
The functional approach with the unique output and immutable variables addresses the listed problems in some way.
|
||||
|
||||
- A package is built from an input resulting in a package on a unique immutable location, eliminating the statefulness in the process.
|
||||
- Since each revision results in a new location, the same package with different versions can be easily placed side-by-side.
|
||||
- With the way how packages built, the old system can be kept giving the possibility for the user to rollback to those previous versions.
|
||||
- The functional approach creates a guaranteed output, making it predictable (and traceable).
|
7
index.org
Normal file
7
index.org
Normal file
@ -0,0 +1,7 @@
|
||||
#+TITLE: Index
|
||||
|
||||
Hello!
|
||||
This is my public knowledge graph publicly available for the public.
|
||||
It is mostly intended for easy access for my notes in case I'm not in my computer along with sharing my findings with the rest of the world (and hopefully getting feedback on it).
|
||||
|
||||
If you want to view my notes in its raw form, you can look at the [[http://github.com/foo-dogsquared/wiki][Git repo]].
|
7
neuron.dhall
Normal file
7
neuron.dhall
Normal file
@ -0,0 +1,7 @@
|
||||
{ siteTitle = "foo-dogsquared's notes"
|
||||
, author = Some "Gabriel Arazas"
|
||||
, siteBaseUrl = Some "https://foo-dogsquared.github.io/wiki"
|
||||
, theme = "brown"
|
||||
, mathJaxSupport = True
|
||||
, formats = ["markdown", "org"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user