Skip to content

Instantly share code, notes, and snippets.

View Nikolaj-K's full-sized avatar
💭
I'm combinating Why's.

Nikolaj Kuntner Nikolaj-K

💭
I'm combinating Why's.
  • DLR Germany, IST Austria, Infineon, ...
  • Vienna
View GitHub Profile
@Nikolaj-K
Nikolaj-K / rational_approximation_to_real.py
Last active March 7, 2024 23:21
Computing a series of good rational approximations to reals using interval shrinking and the mediant. This relates to the Farey sequence.
"""
Code also discussed in the video
https://youtu.be/icrXmYHnU9E
Related:
https://en.wikipedia.org/wiki/Mediant_(mathematics)
"""
from fractions import Fraction
@Nikolaj-K
Nikolaj-K / gradient_descent.py
Last active August 17, 2019 11:31
A gradient descent implementation for one-dimensional problems.
import time
from virtual_machine import VirtualMachine, approx_rational
def make_update_step(gradient, step_size):
def update_step(state):
g = state['g']
state['prev_g'] = g
@Nikolaj-K
Nikolaj-K / derivative_of_polynomials.py
Created August 21, 2019 23:00
Implementing polynomials as arrays, evaluating them and taking their derivatives.
class VirtualMachine:
def __init__(self, update_step, max_num_updates=0, halting_condition=lambda state: False):
self.update_step = update_step
self.halting_condition = halting_condition
self.max_num_updates = max_num_updates
self.num_updates = 0
def run(self, state):
@Nikolaj-K
Nikolaj-K / gaussian_elimination.py
Last active August 27, 2019 17:18
Gaussian elimination akin to the verion on rosettacode.org
# This is a modified version of the python implementation found on
# https://rosettacode.org/wiki/Gaussian_elimination#Python
#
# NOTE: I observe the rosettacode code has a bug for other dimensions of B than in the example (some index error)
import copy
from fractions import Fraction
def gauss_rosettacode(a, b):
@Nikolaj-K
Nikolaj-K / constructive_lem.py
Created September 3, 2019 20:02
Proving the law of excluded middle (LEM), constructively.
"""
https://en.wikipedia.org/wiki/Modus_ponens
https://en.wikipedia.org/wiki/De_Morgan%27s_laws
https://en.wikipedia.org/wiki/Double-negation_translation
https://en.wikipedia.org/wiki/Brouwer%E2%80%93Heyting%E2%80%93Kolmogorov_interpretation
https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence
https://en.wikipedia.org/wiki/Exponential_object
https://en.wikipedia.org/wiki/Constructive_analysis
"""
@Nikolaj-K
Nikolaj-K / vm_gradient_descent.py
Created September 9, 2019 15:18
The gradient descent routine from the Wikipedia page, but with our VM.
"""
Implementation discussed here:
https://youtu.be/mkQ1G6OAuMA
class VirtualMachine:
def __init__(self, update_step, max_num_updates=0, halting_condition=lambda state: False):
self.update_step = update_step
self.max_num_updates = max_num_updates
self.halting_condition = halting_condition
@Nikolaj-K
Nikolaj-K / bit_level_SHA256.py
Last active May 6, 2024 07:14
A python script to perform sha2 in terms of if-statements and for-loops.
"""
Bit level SHA2.
Script to perform sha2 in terms of if-statements and for-loops. This runs 1 batch iteration
(i.e. about 50 bytes max input, but should be easy to extend to any size.)
No warranty.
Explanation video:
https://youtu.be/UziK-Hqzwi4
2019
@Nikolaj-K
Nikolaj-K / proof_of_Cantors_theorem.md
Last active November 13, 2019 17:29
We explicitly proof Cantors theorem

Those are the text used in the video

https://youtu.be/0Sl0bcXyTAo

trivial case

For any finite sets x, we have that |P(x)| > |x|. In particular |{{}}| = |P({})| > |{}|. This is, in terms of Neumann ordinals, 1 > 0. When we say "function" in this text, we always

@Nikolaj-K
Nikolaj-K / minus_one_over_twelve.tex
Last active October 6, 2019 22:55
The LaTeX file used in the -1/12 video.
% This is the LaTeX file with all the formulas shown in the video on the
% infamous -1/12 value in analytic number theory and other fields:
%
% https://youtu.be/az2WOnxsLhc
\newpage
$\lim_{q \to 1} n\, q^n = n$
\hspace{.5cm}