Skip to content

Instantly share code, notes, and snippets.

@hacklex
hacklex / MinimalApplyLemmaBugReproduction.fst
Created April 6, 2025 16:25
Calling lemma via apply_lemma fails in manual case (line 115)
module MinimalApplyLemmaBugReproduction
open FStar.Tactics.V2
open FStar.List
open FStar.List.Tot
noeq type setoid_monoid (a: Type) = {
eq: a -> a -> Type;
op: a -> a -> a;
id: a;
@hacklex
hacklex / SimpleAlgebraTactics.fst
Created March 30, 2025 14:21
Simple tactic to prove associativity in setoid monoids
module SimpleAlgebraTactics
open FStar.Tactics.V2
open FStar.List
open FStar.List.Tot
noeq type setoid_monoid (a: Type) = {
eq: a -> a -> Type; (* Equivalence relation *)
op: a -> a -> a;
id: a; (* Identity element *)
@hacklex
hacklex / AssociativityTest.fst
Created March 28, 2025 10:07
Tactic example featuring associativity lemma application
module TacSandbox
open FStar.Tactics.V2
open FStar.List
open FStar.List.Tot
noeq type setoid_monoid (a: Type) (eq: a -> a -> Type) = {
op: a -> a -> a;
(* Equivalence relation properties *)
@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!