Instantly share code, notes, and snippets.

# Craig GidneyStrilanc

• Sort options
Created May 9, 2019
Simulates samples that Shor's algorithm would generate, in order to estimate how often factoring succeeds.
View sim-factor.py
 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
Created Mar 22, 2019
Code to search for numbers with large persistence of multiplication. Finds the largest known ones in under a second.
View high_persistence_of_multiplication_search.py
 def persistence(n): t = 0 while n >= 10: t += 1 n2 = 1 for d in str(n): n2 *= int(d) n = n2 return t
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:
View zach-linear-3-sat.py
 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
Created Aug 31, 2016
Renders colorful density plots of the roots of polynomials with coefficients drawn from a small set of sets.
View polynomial-root-phase-diagram.py
 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.
Created Nov 1, 2015
A python 3 program that print the operation matrix for a CROT operation from the paper at http://arxiv.org/abs/1510.00409 . The printed operation is just a controlled quarter-turn around the Y axis.
View walters_bqp_np_CROT.py
 # -*- 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]])
Created Jun 9, 2015
Hacky python code to build n-bit reversible increment gates out of O(n) Toffoli gates and one ancilla bit.
View increment_to_linear_toffoli.py
 # coding=utf-8 import math import itertools def evaluate_circuit(gates, initial_bits=None): """ :param gates: [( [controls], [targets] )] :param initial_bits: set(on_bits)
Last active Mar 5, 2016
Various usefully arranged unicode characters
View Arranged_Box_Draw_Chars.md

# Math

``````π θ Ψ φ ε ∞
⊕ · ⊗ ∫ ± ∂ √ ∛ ∜
〈 〉 ⟨ ⟩ °
≈ ≤ ≥ ∝
⁰¹²³⁴⁵⁶⁷⁸⁹₀₁₂₃₄₅₆₇₈₉
⁺⁻⁼⁽⁾ⁱⁿ₊₋₌₍₎ₐₑₒₓₔₕₖₗₘₙₚₛₜ
⅟ ½ ⅓ ¼ ⅕ ⅙ ⅐ ⅛ ⅑ ⅒
⅔   ⅖
``````
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> {
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; -(NSTimeInterval)time; -(NSDate*) date; -(NSDate*) dateAtTimeZero;
Created Nov 25, 2013
A copy of the GameServer class source from Tinker. https://github.com/Strilanc/Tinker/blob/master/Warcraft3/Server/GameServer.vb
View gist:7634770