This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Answer to: https://twitter.com/1HaskellADay/status/875063542784958465 | |
# | |
# So the Initial Value Problem (IVP) you want to solve seems to be the following | |
# | |
# dy/dx = 3*exp(-x) - 0.4*y | |
# y(x_0) = y_0 with x_0 = 0 and y_0 = 5 | |
# | |
# You then ask: what is the value of y when x = 3? | |
# | |
# This can be computed using the Runge Kutta method by feeding it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quad42(f,a,b,tol; α=0.9, Θ=3.0) | |
x, val, h = a, 0, (b-a)/10 | |
xx, f₀ = [x], f(x) | |
err, evals = 0.0, 1 | |
while x < b | |
fₘ, f₁ = f(x+h/2), f(x+h) # effektive Stufenzahl 2 (2 f-Auswertungen pro Schritt) | |
evals += 2 | |
Q2 = h*(f₀+f₁)/2 # Trapezregel (Ordnung 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unistd.h> | |
#include <sys/mman.h> | |
#include <cstring> | |
#include <cstdarg> | |
#include <ctime> | |
class code_emiter { | |
public: | |
code_emiter(char* base) : base(base) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sort_inverse(p) | |
out = [ i for i in 1:length(p) ] | |
for i = 1:length(p) | |
out[p[i]] = i | |
end | |
out | |
end | |
# TODO: limit allocations to improve performance | |
# Reverse Cuthill McKee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fast_solve_sylvester(A, B, C) # 6 m^3 | |
n = size(A, 1) | |
R,U = schur(complex(A)) # m^3 | |
S,V = schur(complex(B)) # m^3 | |
M = U'*C*V | |
Y = zeros(n, n) | |
m = zeros(n) | |
for i = 1:n # 2 m^3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* TODO: use Random.State *) | |
open Random;; | |
open List;; | |
(* =========================================== General Utils = *) | |
let sign x = if x < 0 then -1 else 1;; | |
let truncate x l = sign x * min (abs x) l;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Good morning everyone, I'm currently learning ocaml for one of my CS class and needed to implement | |
an avl tree using ocaml. I thought that it would be interesting to go a step further and try | |
to verify the balance property of the avl tree using the type system. Here's the resulting code | |
annotated for people new to the ideas of type level programming :) | |
*) | |
(* the property we are going to try to verify is that at each node of our tree, the height difference between | |
the left and the right sub-trees is at most of 1. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The Nat type class is to be seen as a port of the Nat type to the type level. | |
-- | |
-- At value level, the usual Nat type only posseses two constructors by being defined as followed: | |
-- | |
-- data Nat = Z | S Nat | |
-- | |
-- Being then usable by pattern matching on the constructor as following: | |
-- | |
-- foo :: Nat -> ... | |
-- foo n = case n of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
A bunch of useful primitives when using PureScript to prove *things*. | |
Idea of using Leibniz equality comes from http://code.slipthrough.net/2016/08/10/approximating-gadts-in-purescript/ | |
-} | |
module Leibniz where | |
import Prelude ((<<<), ($)) | |
import Unsafe.Coerce (unsafeCoerce) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codegen; | |
import java.lang.reflect.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.function.Function; | |
public class ClassSerializer { | |
private String indentation; | |
private String newLine; |