Skip to content

Instantly share code, notes, and snippets.

@tueda
tueda / bench.frm
Last active August 29, 2015 14:21
FORM benchmark: if((...) && (...) && ...) vs. if(...) if (...) ...
#-
#:smallsize 100M
#:termsinsmall 10M
#:largesize 500M
*--#[ time :
#define oldt "0.0"
#procedure resettime()
#redefine oldt "`time_'"
Block[{a = 10, ep = 10^-30},
NIntegrate[
I/(x - a + ep*I) - I/(x - a - ep*I), {x, -Infinity, a, Infinity},
WorkingPrecision -> 1000, PrecisionGoal -> 6]
]
@tueda
tueda / AppendPath.m
Last active October 19, 2015 12:51
Append a path to Mathematica $Path permanently. #mma
AppendPath::ver = "AppendPath requires Mathematica version 7 or later.";
If[$VersionNumber < 7,
(* We use FileExistsQ and FileNameJoin. *)
Message[AppendPath::ver];
Abort[];
];
AppendPath::usage = "AppendPath[path] appends the given path to $Path in \
Kernel/init.m.";
#-
Off stats;
CF pow,log;
CF pow1,log1;
S x,n
S uuu;
Auto S ttt;
#procedure simopt(F,t1,t2,type,file)
ps f -o user,pid,ppid,pgid,tty,time,command
@tueda
tueda / form.rb
Last active August 29, 2015 14:22
FORM Cookbook with some moderate extentions. Forked from https://github.com/tueda/homebrew-loops/blob/master/form.rb
require "formula"
class Form < Formula
homepage "http://www.nikhef.nl/~form/"
url "https://github.com/vermaseren/form/releases/download/v4.1-20131025/form-4.1.tar.gz"
sha1 "527005d082a823e260d77043be3c2539dcc6a72f"
head do
url "https://github.com/vermaseren/form.git"
depends_on "autoconf" => :build
/**
* @file shared_ptr.h
*
* A Boost/C++11-like shared pointer. Limitations are:
* - No custom allocator/deleter can be used.
* - No support for sharing ownership.
* - No support for other smart pointers, e.g., weak_ptr.
* - No support for multi-threaded access.
* - No helper functions, e.g., make_shared.
* - Defined in the global namespace.
TrapezoidalRule[expr_, {x_, x1_, x2_}, n_Integer] := Module[{h},
h = (x2 - x1) / (n - 1);
Sum[
Switch[i,
0, 1/2,
n - 1, 1/2,
_, 1
] * (expr /. x -> x1 + i * h) * h
, {i, 0, n - 1}]
] /; n >= 2;
#include <iostream>
using namespace std;
class C {
public:
explicit C(int i) {
cout << "create" << endl;
n_ = i;
}
ColorToHexString[expr_] := expr /.
c:Hue[_]|Hue[_, _, _]|CMYKColor[_, _, _, _]|GrayLevel[_] :>
ColorConvert[c, "RGB"] /.
RGBColor[r_, g_, b_] :>
"#" <> IntegerString[Clip[Round[r * 255], {0, 255}] * 256^2 +
Clip[Round[g * 255], {0, 255}] * 256 +
Clip[Round[b * 255], {0, 255}], 16, 6];