Skip to content

Instantly share code, notes, and snippets.

View lovely-error's full-sized avatar
😆
Don't forget that you will die some day

Enigma Lav lovely-error

😆
Don't forget that you will die some day
View GitHub Profile
@lovely-error
lovely-error / quot.lean
Last active September 17, 2024 19:41
Injectivity of quotient constructor would lead to proof of false
def zmod : Nat -> Type | n => Quot (fun a b => a % n = b % n)
theorem prop_true_or_false : (p:Prop) -> p = False ∨ p = True := by
exact fun p => Or.symm (Classical.propComplete p)
theorem quot_ctor_inj : Quot.mk f a = Quot.mk f b -> a = b := by
intro k
-- injection k
admit
@lovely-error
lovely-error / dyn.rs
Created October 29, 2024 14:07
(Almost) How to desugar dynsized values in rust
#![feature(ptr_metadata)]
// use libc; // 0.2.159
use std::alloc::Layout;
use std::ptr::copy_nonoverlapping;
use std::mem::forget;
use std::ptr::metadata;
use std::ptr::DynMetadata;
fn main() {
@lovely-error
lovely-error / cond.c
Last active December 4, 2024 05:59
The only way to suppress speculation on branches??
#include <stdio.h>
#include <stdbool.h>
void lmao (bool cond) {
void* jmp_addr ;
__asm__ goto volatile (
"mov %[true_label], %[jmp_addr]\n\t"
"mov %[false_label], %%rbx\n\t"
"test %[cond], %[cond]\n\t"
"cmovz %%rbx, %[jmp_addr]\n\t"
@lovely-error
lovely-error / mod-arith.lean
Created December 5, 2024 12:25
my arch-nemesis atm
import Batteries
def NModB251CC8 := Vector (Fin 251) 4
def MAX_VAL := (250 * 251^0) + (250 * 251^1) + (250 * (251 ^ 2)) + (250 * (251 ^ 3))
def NModSC := Fin (MAX_VAL + 1)
def from_NModB251CC8_to_Nat : NModB251CC8 -> Nat | i => (i.zipWithIndex.map (fun ⟨ a , i ⟩ => a * ((251:Nat) ^ i))).foldl Nat.add 0
example : from_NModB251CC8_to_Nat (Vector.mk #[250,250,250,250] (by decide)) < MAX_VAL + 1 := by trivial
@lovely-error
lovely-error / deanoyify.rs
Created December 5, 2024 12:32
deanoyify rust
#![feature(decl_macro)]
macro d($ptr:expr) { unsafe { *$ptr } }
macro p($val:expr) { &raw mut $val }
macro pc($val:expr) { &raw const $val }
@lovely-error
lovely-error / no_rec_2_rec.lean
Created January 25, 2025 06:57
some random stuff
import Mathlib
example (p1: (V:Rat) = I * R)(vnz: Not (V = 0))(rnz: Not (R = 0)) : R = (I * R ^ 2) / V := by
let target := p1
let s1 : V = I * R <-> V / V = I * R / V := by
exact (iff_true_right (congrFun (congrArg HDiv.hDiv p1) V)).mpr p1
rw [s1] at target
let v_on_v_one: V / V = 1 := by
exact (div_eq_one_iff_eq vnz).mpr rfl
rw [v_on_v_one] at target
@lovely-error
lovely-error / tp.rs
Last active February 16, 2025 00:57
tagged ptr
use core::marker::PhantomData;
use core::mem::ManuallyDrop;
#[repr(C)] #[derive(Copy, Clone)]
union TaggedPtr64Repr<T> {
num: u64,
tag: ManuallyDrop<T>,
}
@lovely-error
lovely-error / test.sv
Created February 7, 2025 10:28
blinkin it the right way
module REG (CLK, WE, D, O);
parameter BITWIDTH = 1;
parameter [BITWIDTH-1:0] INIT = '0;
input CLK;
input WE;
input [BITWIDTH-1:0] D;
output [BITWIDTH-1:0] O;
@lovely-error
lovely-error / tedium.lean
Last active February 16, 2025 17:47
Basic algebra in lean
import Mathlib
import Lean.Meta
macro "rwi" pat:term "=>" new:term ":=" prf:term : tactic =>
`(tactic| rewrite [let _eq : $pat = $new := $prf ; _eq ])
macro "rwi" pat:term "=>" new:term "at" loc:Lean.Parser.Tactic.locationHyp ":=" prf:term : tactic =>
`(tactic| rewrite [let _eq : $pat = $new := $prf ; _eq ] at $loc)
def wmap : Type _ -> Type _ -> Type _ | A, B => @Subtype (Prod (A -> B) (B -> A)) fun ⟨ f , h ⟩ => ∀ i, h (f i) = i