Skip to content

Instantly share code, notes, and snippets.

Craig Gidney Strilanc

Block or report user

Report or block Strilanc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Strilanc /
Created May 9, 2019
Simulates samples that Shor's algorithm would generate, in order to estimate how often factoring succeeds.
from typing import Optional, List, Dict, Callable, Any
from collections import defaultdict
import fractions
import math
import random
import sys
import matplotlib.pyplot as plt
Strilanc /
Created Mar 22, 2019
Code to search for numbers with large persistence of multiplication. Finds the largest known ones in under a second.
def persistence(n):
t = 0
while n >= 10:
t += 1
n2 = 1
for d in str(n):
n2 *= int(d)
n = n2
return t
Strilanc /
Last active Oct 4, 2016
For the record, the algorithm works just fine on this problem. Here's a simple python script that sets up the transfer matrix and finds the eigenvalues/eigenvectors:
from itertools import *
import string
from numpy import *
from scipy import *
from scipy.linalg import *
#Script for setting up transfer matrix describing the evolution of diagonal
#elements of the density matrix given a list of three variable clauses.
#The Transfer matrix maps the vector of state populations (diagonal elements of
Strilanc /
Created Aug 31, 2016
Renders colorful density plots of the roots of polynomials with coefficients drawn from a small set of sets.
import numpy as np
import cv2
import itertools
import math
import cmath
w = h = 1024
deg = 11
# The root phases to sample frame, and the color that goes with each.
Strilanc /
Created Nov 1, 2015
A python 3 program that print the operation matrix for a CROT operation from the paper at . The printed operation is just a controlled quarter-turn around the Y axis.
# -*- coding: utf-8 -*-
import numpy as np
import math
import cmath
np.set_printoptions(precision=2, suppress=True)
qubit_count = 2
σx = np.mat([[0, 1], [1, 0]])
σy = np.mat([[0, -1j], [1j, 0]])
σz = np.mat([[1, 0], [0, -1]])
Strilanc /
Created Jun 9, 2015
Hacky python code to build n-bit reversible increment gates out of O(n) Toffoli gates and one ancilla bit.
# coding=utf-8
import math
import itertools
def evaluate_circuit(gates, initial_bits=None):
:param gates: [( [controls], [targets] )]
:param initial_bits: set(on_bits)
Strilanc /
Last active Mar 5, 2016
Various usefully arranged unicode characters


π θ Ψ φ ε ∞
⊕ · ⊗ ∫ ± ∂ √ ∛ ∜
〈 〉 ⟨ ⟩ °
≈ ≤ ≥ ∝
⅟ ½ ⅓ ¼ ⅕ ⅙ ⅐ ⅛ ⅑ ⅒
    ⅔   ⅖
Strilanc / BitsPredicateEquivalence
Created Nov 12, 2014
Determines whether two Predicate<Predicate<Integer>>s are equivalent. Really.
View BitsPredicateEquivalence
// An infinite bit-string.
public interface Bits {
// requires n >= 0
boolean bit(int n);
// Determines the equivalence of predicates over infinite-bit-strings.
// Requires that the given predicates halt for all inputs.
public final class BitsPredicateEquivalence extends Equivalence<Predicate<Bits>> {
Strilanc / FakeTimeBasedScheduler
Created Jan 3, 2014
A test fake for a reactive cocoa scheduler, allowing manual advancement of time.
View FakeTimeBasedScheduler
// FakeScheduler.h
#import "ReactiveCocoa.h"
@interface FakeScheduler : RACScheduler
-(instancetype) init;
-(void) advanceTimeBy:(NSTimeInterval)duration;
-(NSDate*) date;
-(NSDate*) dateAtTimeZero;
View gist:7634770
Imports Tinker.Pickling
Namespace WC3
Public NotInheritable Class GameServer
Inherits DisposableWithTask
Private Shared ReadOnly InitialConnectionTimeout As TimeSpan = 5.Seconds
Private ReadOnly inQueue As CallQueue = MakeTaskedCallQueue
Private ReadOnly outQueue As CallQueue = MakeTaskedCallQueue
You can’t perform that action at this time.