Skip to content

Instantly share code, notes, and snippets.

@hacklex
hacklex / test.cs
Created September 14, 2024 01:04
test.cs
int size = 24;
(int aWins, int bWins, int draws, int indecisives) SequentialNonRandomTest()
{
int topBound = 1 << size;
int aWins = 0;
int bWins = 0;
int draws = 0;
int indecisives = 0;
for (int i = 0; i < topBound; i++)
@hacklex
hacklex / Colors.cs
Created July 13, 2024 20:40
C# Color Space Conversion Utilities
using System.Windows.Media;
using JetBrains.Annotations;
// ReSharper disable once CheckNamespace
namespace ZetaColorEditor.Colors;
[PublicAPI]
public interface IColor<out T> where T:IColor<T>
{
/// <summary>
@hacklex
hacklex / Histograms.txt
Created February 9, 2024 12:39
Heisenberg group over Z2, zero-point distances histograms
Order = 1
# 0 1 2
hist 1 3 4
Δ 1 1 -2
2C₂ᵏ 2 4 2
NoZ Δ 1 2 0
NoZHist 1 2 2 2 1
Order = 2
# 0 1 2 3 4
hist 1 5 12 12 2
@hacklex
hacklex / HeisenbergGroupDistanceHistogram.cs
Last active February 6, 2024 23:10
Heisenberg Group Distance Histogram
Console.OutputEncoding = System.Text.Encoding.UTF8;
const int Order = 6;
int basisSize = Order * 2;
var reachabilities = GetReachabilities(Enumerable.Range(0, basisSize).Select(i => 1ul << (i)).ToArray());
Console.WriteLine("Reachabilities dump: ");
WriteArray(reachabilities);
Console.WriteLine();
Console.WriteLine("Histogram:");
PrintHistogram(reachabilities);
@hacklex
hacklex / Program.cs
Created February 3, 2024 21:37
Permutation polynomial computation in C#
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Permutation: (0 1)");
Console.WriteLine("Permutation polynomial:");
Console.WriteLine(BytePolynomial.FromPermutation(new BitSwapPermutation(0, 1)));
Console.ReadKey();
@hacklex
hacklex / OpaqueExample.fst
Created December 18, 2023 16:06
FStar Opaques Example
module OpaqueExample
#set-options "--ifuel 0 --fuel 0 --z3rlimit 1"
type binary_op (a:Type) = a -> a -> a
type unary_op (a:Type) = a -> a
type predicate (a:Type) = a -> bool
type binary_relation (a: Type) = a -> a -> bool
[@@"opaque_to_smt"]
@hacklex
hacklex / Sheera.fst
Created October 3, 2023 16:10
Newer version of address shift properties
module Sheera
open FStar.Seq
open FStar.Seq.Base
open FStar.IntegerIntervals
open FStar.Mul
//Name Your Variables Properly!
@hacklex
hacklex / ShiftProperties.fst
Created September 30, 2023 09:26
Backward-forward shift is identity on applicable domain
module ShiftProperties
open FStar.Seq
open FStar.Seq.Base
open FStar.IntegerIntervals
open FStar.Mul
//Name Your Variables Properly!
@hacklex
hacklex / MemorySandbox.fst
Created July 7, 2023 17:36
Memory access helper lemmas
module MemorySandbox
open FStar.Mul
open FStar.Bytes
open FStar.Endianness
open FStar.Seq
open FStar.IntegerIntervals
type qword = UInt64.t
@hacklex
hacklex / MemorySandbox.fst
Created July 6, 2023 20:37
F* Memory read/write helpers
module MemorySandbox
open FStar.Mul
open FStar.Bytes
open FStar.Endianness
open FStar.Seq
open FStar.IntegerIntervals
type qword = UInt64.t