Skip to content

Instantly share code, notes, and snippets.

View certik's full-sized avatar

Ondřej Čertík certik

View GitHub Profile
@certik
certik / gist:996213
Created May 27, 2011 21:26
sqrt(a**2+b**2) using Newton method and integers
def prep2(a, b):
x = a**2 + b**2
r = x/2
residual = r**2 - x
r_old = r+1
while 1:
r -= residual/(2*r)
residual = r**2 - x
if r == r_old:
break
@certik
certik / gist:1001505
Created May 31, 2011 23:45
U N study rmax=50, rmin=1e-7, a=2.7e6
1000 -2.5658418384904369e+04
2000 -2.5658417920167172e+04
3000 -2.5658417895063809e+04
4000 -2.5658417890822853e+04
5000 -2.5658417889660028e+04
6000 -2.5658417889242643e+04
7000 -2.5658417889067179e+04
8000 -2.5658417888976146e+04
9000 -2.5658417888932374e+04
10000 -2.5658417888905260e+04
@certik
certik / fparser
Created June 8, 2011 00:58
Generate .pxd from Fortran sources
#! /usr/bin/env python
import os
import sys
from optparse import OptionParser
import re
def main():
parser = OptionParser(usage="[options] filename")
# parser.add_option("-n", "--no-upload",
>>> JxKet(1,-1).rewrite("Jz")
⎽⎽⎽
❘1,-1⟩ ╲╱ 2 ⋅❘1,0⟩ ❘1,1⟩
────── - ─────────── + ─────
2 2 2
>>> JxKet(1,0).rewrite("Jz")
⎽⎽⎽ ⎽⎽⎽
╲╱ 2 ⋅❘1,-1⟩ ╲╱ 2 ⋅❘1,1⟩
──────────── - ───────────
2 2
$ bin/test sympy/physics/quantum/tests/test_spin.py
============================= test process starts ==============================
executable: /usr/bin/python (2.7.1-final-0)
ground types: python
sympy/physics/quantum/tests/test_spin.py[7] .EE..f. [FAIL]
________________________________________________________________________________
____________ sympy/physics/quantum/tests/test_spin.py:test_rewrite _____________
File "/home/ondrej/repos/sympy/sympy/physics/quantum/tests/test_spin.py", line 25, in test_rewrite
@certik
certik / README.md
Created July 20, 2011 22:12
C vs Fortran benchmark

On my machine, the timings are:

Fortran:

$ time ./a.out 
   249999999500000000

real	0m0.510s
user	0m0.510s
sys	0m0.000s
// Compile with:
// gcc -O3 -march=native -ffast-math -funroll-loops b.c
#include "stdio.h"
long sumit(long n)
{
long i = 0, s = 0;
while (i < n) {
s += i;
i++;
// Compile with:
// gcc -O3 -march=native -ffast-math -funroll-loops b.c
#include "stdio.h"
long sumit(long n)
{
long i = 0, s = 0;
while (i < n) {
s += i;
i++;
-789.592041565 6765
-619.368664942 4305
-476.262965938 6875
-326.011401127 4975
-198.674933407 4415
-195.044210313 2125
-152.770505228 825
-152.749919571 1985
-151.315548035 55
-144.85136202 8445
program array
implicit none
integer, allocatable :: a(:)
call bill2(100000000, a);
print *, bill(a)
contains
subroutine bill2(n, a)