Skip to content

Instantly share code, notes, and snippets.

@etale
etale / adic.rb
Created November 1, 2009 10:45
an implementation of p-adic numbers
class Adic < Numeric
def initialize adic, precision, arg = 0, ord = 0
@adic, @precision = adic, precision
@modulus = adic ** precision
@int, @ord = if arg.zero?
[0, :infty]
else
while arg % adic == 0
arg /= adic
@etale
etale / alg.rb
Created November 24, 2009 09:28
module Algebraic
$radix ||= 10 # 2 <= $radix <= 36
$adic ||= 10**4 # 2 <= $adic
$delim ||= ',' # or '|', etc.
$type ||= :arch # or :adic
$prec ||= 44 # default precision
$term_order ||= :gr # or :lex
def scale; $adic ** $prec; end # default scale
def prec_2; (scale - 1).size 2; end # default precision in bits
def prec_calc; ($prec / $adic.log).ceil; end
@etale
etale / p-adic.html
Created December 7, 2009 02:43
a visualization of p-adic numbers
<html>
<head>
<title>p-adic</title>
<script type="text/javascript">
window.onload = function(){
var ctx = document.getElementById('z_p').getContext('2d')
var scale = 256
ctx.translate(512, 512)
ctx.scale(scale, scale)
ctx.lineWidth = 1/scale
@etale
etale / log.rb
Created October 15, 2010 14:17
log
class Real
def log
return if zero?
_ = self
return (- _).log if _ < zero
if _ > 2 or _ < unity
e = 0
e, _ = e + 1, _ / 2 while _ > 2
e, _ = e - 1, _ * 2 while _ < 1
_.log + e * 2.log
@etale
etale / kMGTPB.html
Created June 27, 2011 09:21
b, B, kB, MB, GB, TB and PB
<head>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js">
MathJax.Hub.Config({extensions:["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js","TeX/autobold.js"],jax:["input/TeX","output/HTML-CSS"],tex2jax:{inlineMath:[['$','$'],['\\(','\\)']],displayMath:[['$$','$$'],['\\[','\\]']],processEscapes:true}});
</script>
</head>
<body>
\begin{array}{rcrcrcrclcrcr}
& & & & \mathrm{b} &=& \log 2 &=& e^{ \log\log 2} &=& -0.3665\cdots\ \mathrm{X}&=& 0.6931\cdots\\
& & \mathrm{B} &=& 2^3 \ \mathrm{b} &=& 2^3 \log 2 &=& e^{3 \log 2 + \log\log 2} &=& 1.7129\cdots\ \mathrm{X}&=& 5.5451\cdots\\
\mathrm{kB} &=& 2^{10} \ \mathrm{B} &=& 2^{13} \ \mathrm{b} &=& 2^{13} \log 2 &=& e^{13 \log 2 + \log\log 2} &=& 8.6444\cdots\ \mathrm{X}&=& 5678.2617\cdots\\
@etale
etale / tropical.rb
Created October 4, 2011 05:48
an implementation of complex numbers with tropical flavor
# tropical.rb
# an implementation of complex numbers with tropical flavor
#
# self == e^{ord + 2 \pi i arg}
class Class
def get *args, &block
(new *args, &block).identity
end
end
@etale
etale / alg.rb
Last active September 27, 2015 17:47
an implementation of adeles
def not_implemented
puts "#{inspect} : #{self.class}"
raise NotImplementedError
end
$radix ||= 10 # 2 <= $radix <= 36
$adic ||= 10**4 # 2 <= $adic
$delim ||= ',' # or '|', etc.
$type ||= :arch # or :adic
$prec ||= 4 # default precision
@etale
etale / planck_clock.html
Last active December 21, 2015 00:28
simple demo for Planck clock
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<script>
var d = 99.6290 - Math.log(1e3), c, p = Date.parse, n = Date.now
onload = function() {
var t = location.hash.slice(1).split(',').filter(p).map(p)
t.push(n())
t.unshift(-13.772e9 * 365.25 * 24 * 3600 * 1e3)
@etale
etale / calc.html
Last active December 23, 2015 21:39
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta charset="UTF-8">
<title>Natural Calc</title>
<style>
body {
width: 100%;
position: fixed;
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta charset="UTF-8">
<title>Natural Calc</title>
<style>
html, body {
width: 100%;
height: 100%;