Skip to content

Instantly share code, notes, and snippets.

@gagern
gagern / findduplicate.sh
Created August 26, 2015 12:11
Find two dependency atoms referring to the same package
#!/bin/bash
# Find two dependency atoms referring to the same package
# See https://github.com/cschwan/sage-on-gentoo/pull/371
shopt -s extglob
inherit() { :; }
replace_all_version_separators() { :; }
delete_version_separator() { :; }
@gagern
gagern / code.sage
Created February 21, 2014 14:47
Area of intersection between two circles in the hyperbolic plane
# See http://math.stackexchange.com/q/684834/35416 for details
var('a b x y r d')
var('R1', latex_name='R')
var('R2', latex_name="R'")
# The following two antiderivatives were found by Wolfram Alpha
upperArc(x) = -(b*arctan((b*x)/(sqrt(b^2-r^2)*sqrt(r^2-x^2))))/sqrt(b^2-r^2)+(b*arctan(x/sqrt(b^2-r^2)))/sqrt(b^2-r^2)+arctan(x/sqrt(r^2-x^2))
lowerArc(x) = (-sqrt(b^2-r^2)*arctan(x/sqrt(r^2-x^2))+b*arctan((b*x)/(sqrt(b^2-r^2)*sqrt(r^2-x^2)))+b*arctan(x/sqrt(b^2-r^2)))/sqrt(b^2-r^2)
y1 = cosh(R1)
r1 = sinh(R1)
y2 = (cosh(d)+sinh(d))*cosh(R2)
@gagern
gagern / Computation.sage
Last active August 29, 2015 13:56
Sage trouble related to a MSE question about ellipses
# This is an attempt to obtain numeric results for
# http://math.stackexchange.com/q/688861/35416
# but the computation is smbolic since I'll want a derivative later on
a = var('a', latex_name='\\alpha', domain='positive')
b = var('b', latex_name='\\beta', domain='positive')
a0 = RDF(0.14778)
b0 = RDF(0.77656)
SRmu.<mu> = SR[]
farpoint1 = vector([1, b, 0])
@gagern
gagern / exact_code.sage
Last active August 29, 2015 13:56
Minimum eccentricity of ellipses around another ellipse
# Exact computation to solve http://math.stackexchange.com/q/688861/35416,
# heavily inspired by https://groups.google.com/d/msg/sci.math/LYtIdRhk2ac/mQtEBcgCjZkJ
def printPoly(name, poly):
print(name + ":")
print(poly.denominator()*poly)
print("")
# a and b are the alpha and beta from http://math.stackexchange.com/a/698656/35416.
# We use approximate values to choose the right alternatives in some situations.
@gagern
gagern / eclp.py
Created April 23, 2014 08:02
Print ECL data structures in GDB
from __future__ import with_statement
import gdb
class EclUtil(object):
def __init__(self, *args, **kwargs):
super(EclUtil, self).__init__(*args, **kwargs)
self.cl_object = gdb.lookup_type("cl_object").strip_typedefs()
self.cl_objectp = self.cl_object.pointer()
@gagern
gagern / mmap.diff
Created May 2, 2014 20:21
Python using mmap vs. read
fstat(3, {st_mode=S_IFREG|0644, st_size=164, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
+lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=164, ...}) = 0
-dup(3) = 4
-mmap(NULL, 164, PROT_READ, MAP_SHARED, 3, 0) = 0x...
-open("so23434490out.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 5
-fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
-ioctl(5, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x...) = -1 ENOTTY (Inappropriate ioctl for device)
-fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
@gagern
gagern / mx779275.txt
Created May 3, 2014 08:52
Finding singularities for Math SE 779275
sage: # http://math.stackexchange.com/a/779318/35416
sage: P1.<x,y,z,w> = QQ[]
sage: p = x^3+y^3+z^3+w*x*y*z
sage: px, py, pz = [P1(p.polynomial(v).differentiate()) for v in [x, y, z]]
sage: px
y*z*w + 3*x^2
sage: pxy = px.resultant(py, x)
sage: pxz = px.resultant(pz, x)
sage: pxyz = pxy.resultant(pxz, y)
sage: f = pxyz.factor()
def rotmat(a, t=(0,0,1), l=False):
# Rotate by a degrees, then shift origin to point t.
# If l=True then transform lines not points.
x, y, z = t
q = QQ(a/360)
w = QQbar.zeta(q.denominator())^(q.numerator())
c = AA(z*w.real())
s = AA(z*w.imag())
m = matrix(AA, [[c, -s, x], [s, c, y], [0, 0, z]])
if l:
@gagern
gagern / terms.txt
Created December 8, 2014 14:39
Math SE 1055320
# Terms for http://math.stackexchange.com/a/1057500/35416
+ 16 z1^2 u2^2 ar^4
+ 32 z1^2 u2 v2 ar^4
+ 16 z1^2 v2^2 ar^4
+ 32 z1^2 u2^2 ar^2 ai^2
+ 64 z1^2 u2 v2 ar^2 ai^2
+ 32 z1^2 v2^2 ar^2 ai^2
+ 16 z1^2 u2^2 ai^4
+ 32 z1^2 u2 v2 ai^4
@gagern
gagern / InaccessibleSymbols.js
Last active August 29, 2015 14:24
Identifying inaccessible symbols for KaTeX
var fs = require("fs");
var symbols = require("./src/symbols");
var todo = 0;
var files = fs.readdirSync("static/fonts");
files.forEach(function(file) {
if (file.substr(file.length - 4) !== ".ttx")
return;
++todo;
fs.readFile("static/fonts/" + file, "utf-8", doTTX.bind(null, file));