Skip to content

Instantly share code, notes, and snippets.

(* 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`"];
@tueda
tueda / mmautil.m
Last active October 19, 2015 12:55
A collection of small utility functions for Mathematica programming. Also for compatibility issues. #mma
(*
* MemberAllQ[list, form] returns True if all elements of `list' matches `form',
* False otherwise.
*)
MemberAllQ[list_, form_] := Fold[(#1 && MatchQ[#2, form])&, True, list];
(*
* FreeAllQ[expr, forms] returns True if the given expression does not match to
* any of the given forms.
*)
GlobalFlag[name_String] := Module[{s},
s = "Global`" <> name;
If[NameQ[s],
TrueQ[Symbol[s]]
,
False
]
];
GlobalValue[name_String, default_:0] := Module[{s},
@tueda
tueda / copyd.sh
Last active October 19, 2015 12:54
copyd & pasted: change the working directory to one in the saved list. #bin
#!/bin/bash
# Usage: load this file as
# . copyd.sh
# which defines the following commands:
#
# copyd
# Copy the current directory on the top of the directory list.
# pasted
# Change the current directory to the first directory in the list.
(*
* 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 / 00_Makefile_LaTeX_README.md
Last active June 29, 2024 17:56
Makefile for LaTeX documents. #make #latex

This project is superceded by makefile4latex.

Makefile for LaTeX

This is a GNU Makefile for typesetting LaTeX documents. Expected to work with TeXLive on Linux (and similar systems, e.g., on Cygwin). Just download Makefile and put it in a directory that contains your LaTeX files. Running make will generate PDF files for you:

@tueda
tueda / JHEP-mod.bst
Last active April 26, 2018 08:41
A modified version of JHEP.bst. (superseded by https://gist.github.com/tueda/515c813ad4dc42d8558a20aef94a83c9)
% UT Physics bibliographic style, ver. 1.2.1 Based on:
%
%X IEEE Transactions bibliography style (29-Jan-88 version)
%X numeric labels, order-of-reference, IEEE abbreviations,
%X quotes around article titles, commas separate all fields
%X except after book titles and before "notes". Otherwise,
%X much like the "plain" family, from which this is adapted.
%X
%X History
%X 9/30/85 (HWT) Original version, by Howard Trickey.