Skip to content

Instantly share code, notes, and snippets.

@tueda
tueda / test1.frm
Last active August 28, 2015 16:36
#-
#include `NAME_' # time
Off stats;
CF num;
S ep,n1,...,n14;
L F1 =
+(n1)^3*(n4)^2*(n5)^11*(n6)^14*(n7)^6*(n8)^15*(n9)^12*(-
35184372088832)*(-1+n5)*(1+n9)*(5-11*n9+n9^2-13*n8+2*n8*n9+2*n8^2
-9*n7+3*n7*n9+3*n7*n8+2*n7^2+n6-14*n5+2*n5*n9+5*n5*n8+3*n5*n7+n5*
n6+2*n5^2-14*n4+5*n4*n9+7*n4*n8+6*n4*n7-2*n4*n6+5*n4*n5+6*n4^2+n3
@tueda
tueda / test-InternalSeries.m
Last active August 29, 2015 13:55
An experiment on System`Private`InternalSeries in Mathematica v5.1+.
(*
* Tested in v5.1, v5.2, v6.0.3, v7.0.1, v8.0.4 and v9.0.1.
* It is said that Wolfram changed the way how Series works between v5.0 and
* v5.1, but I don't have any working binaries of <= v5.0 for now.
*)
ExplicitFunc[x_] := 1/x^3 Log[1-x];
Series[ExplicitFunc[x], {x, 0, 3}] // Print;
Series[Log[1-x] ExplicitFunc[x], {x, 0, 3}] // Print;
@tueda
tueda / fun-SplitDigits.m
Created February 1, 2014 22:47
1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256...
(* https://news.ycombinator.com/item?id=7144616 *)
SplitDigits[x_, n_, m_] := Module[{a},
a = RealDigits[FractionalPart[N[x, n + 1]]];
a = Join[ConstantArray[0, -a[[2]]], a[[1]]];
a = Drop[a, -1];
a = ToString /@ a;
a = Partition[a, m];
a = (StringJoin @@ # &) /@ a;
a = ToExpression /@ a;
(* The following pattern matching freezes Mathematica v9.0.1 Linux x86-64. *)
MatchQ[{1}, {m_Integer..., ml_Integer /; ml != 0}]
(* The following is OK. *)
MatchQ[{1}, {_Integer..., ml_Integer /; ml != 0}]
@tueda
tueda / MyPackage.m
Last active August 29, 2015 13:56
A template for Mathematica packages.
BeginPackage["MyPackage`"];
Unprotect["MyPackage`*"];
ClearAll["MyPackage`*", "MyPackage`Private`*"];
(******************************************************************************)
MyAdd::usage = "MyAdd[a,b] returns a+b.";
Begin["`Private`"];
GlobalFlag[name_String] := Module[{s},
s = "Global`" <> name;
If[NameQ[s],
TrueQ[Symbol[s]]
,
False
]
];
GlobalValue[name_String, default_:0] := Module[{s},
(*
* Fast factoring out irrelevant factors.
*
* In a test environment, the first one takes about 50 seconds, while
* the second one takes < 0.01 seconds.
*)
Clear[NewIntegrate1];
Clear[NewIntegrate2];
NewIntegrate1[c_ f_., x_] := c NewIntegrate1[f, x] /;
#!/bin/sh
set -e
#sudo apt-get clean
kbytes=`df -P -k | grep /dev/sda1 | sed 's/ */ /g' | cut -d ' ' -f 4`
size=`expr $kbytes - 10`
file=tmp_zero$$
dd if=/dev/zero of=$file bs=1k count=$size
rm $file
@tueda
tueda / fibonacci.frm
Created April 24, 2014 11:56
Computing Fibonacci number in FORM.
* Procedures converting f(n) to the corresponding Fibonacci number:
* F(1) = 1, F(2) = 1, F(n+2) = F(n) + F(n+1).
S fibN,fibX1,fibX2;
CF fibF;
* A straightforward implementation using the downward recursion.
* It generates many terms exponentially and becomes very slow for large n.
*
#procedure Fibonacci1(f)
@tueda
tueda / jaxmanip.py
Created May 2, 2014 19:14
Manipuate JaxoDraw2 xml files.
#!/usr/bin/python
from xml.etree.ElementTree import *
from optparse import OptionParser
def get_xypoints(node):
xpoints = []
ypoints = []
for e in node.findall(".//void[@class='java.awt.Point'][@method='getField']"):
e_name = e.find("string")