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 <cstdlib> | |
#include <iostream> | |
#include <chrono> | |
#include <random> | |
template <typename Fn> | |
void measure(Fn &&fn) { | |
auto before = std::chrono::system_clock::now(); | |
auto res = std::forward<Fn>(fn)(); | |
auto after = std::chrono::system_clock::now(); |
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
structure Z (modulus : Nat) : Type where | |
val : Fin modulus | |
deriving Repr | |
instance : Add (Z modulus) where | |
add x y := { val := x.val + y.val } | |
instance : Mul (Z modulus) where | |
mul x y := { val := x.val * y.val } |
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] | |
name = "idk" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
cranelift = "0.105.1" | |
cranelift-module = "0.105.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
template <typename T, size_t N> | |
struct mdspan { | |
T *data; | |
std::array<size_t, N> extents; | |
template <typename... OtherIndexTypes> | |
requires(std::is_convertible_v<OtherIndexTypes, size_t> && ...) && | |
(sizeof...(OtherIndexTypes) == N) | |
constexpr explicit mdspan(T *data, OtherIndexTypes... _extents) | |
: data(data), extents{} { |
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
#let template( | |
title: none, | |
font: "New Computer Modern", | |
authors: (), | |
date: none, | |
show-outline: false, | |
body | |
) = { | |
show link: text.with(blue) |
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
{-# LANGUAGE NumericUnderscores #-} | |
import Data.Int | |
modulus = 1_000_000_007 | |
-- M = Z / 1_000_000_007 Z | |
newtype M = M Int64 deriving (Eq, Ord) | |
-- Ext = M[x]/(x^2 - 5) |
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
use std::ops::{Add, Mul, Sub}; | |
/// Performs the extended euclidean algorithm | |
pub const fn xgcd(a: i64, b: i64) -> (i64, i64, i64) { | |
let (mut old_r, mut r) = (a, b); | |
let (mut old_s, mut s) = (1, 0); | |
let (mut old_t, mut t) = (0, 1); | |
while r != 0 { | |
let quotient = old_r / r; |
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
// Complex numbers are represented as pairs | |
#let re(x) = x.at(0) | |
#let im(x) = x.at(1) | |
#let cmul(x, y) = (re(x)*re(y) - im(x)*im(y), re(x)*im(y) + im(x)*re(y)) | |
#let cadd(x, y) = (re(x) + re(y), im(x) + im(y)) | |
#let csub(x, y) = (re(x) - re(y), im(x) - im(y)) | |
#let cscale(k, x) = (k * re(x), k * im(x)) | |
#let cis(phi) = (calc.cos(phi), calc.sin(phi)) | |
#let cshow(x) = [#re(x) + i #im(x)] |
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
#![feature(generators, generator_trait)] | |
use std::{ | |
cell::Cell, | |
future::Future, | |
ops::Generator, | |
pin::Pin, | |
rc::Rc, | |
task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, | |
}; |
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
#lang racket | |
(define (split x) | |
(match x | |
['() '(() . ())] | |
[(list-rest x y zs) | |
(match-let ([(cons xs ys) (split zs)]) | |
(cons | |
(cons x xs) | |
(cons y ys)))])) |
NewerOlder