Skip to content

Instantly share code, notes, and snippets.

@kenoss
Last active December 21, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenoss/6384624 to your computer and use it in GitHub Desktop.
Save kenoss/6384624 to your computer and use it in GitHub Desktop.
TeXで対角成分のみの行列を簡単に書く
; -*- coding: euc-jp -*-
; こういうコードを TeX で書きたい. (TeX に移植するので Lisp としては少し不自然.)
(use srfi-1)
(use srfi-11)
(use srfi-13)
(define (diagmatrix ufill lfill diagonals)
(define (dots? str)
(rxmatch #/^ *(\.\.\.|\\dots)$/ str))
(define (mask-with e b replacement)
(if b
replacement
e))
(define (make-row d i b right-cdots left-cdots mask right-line left-line right-dots-line left-dots-line)
(let-values (((left-mask r) (split-at mask i)))
(let1 right-mask (cdr r)
(if b
`(,@(map (cut mask-with <> <> "") left-dots-line left-mask)
"\\ddots"
,@(map (cut mask-with <> <> "") right-dots-line right-mask))
`(,@(map (cut mask-with <> <> left-cdots) left-line left-mask)
,d
,@(map (cut mask-with <> <> right-cdots) right-line right-mask))))))
(let* ((r (if (string-null? ufill)
'("" . "")
'("\\cdots" . "\\vdots")))
(right-cdots (car r))
(right-vdots (cdr r))
(l (if (string-null? lfill)
'("" . "")
'("\\cdots" . "\\vdots")))
(left-cdots (car l))
(left-vdots (cdr l))
(mask (map dots? diagonals))
(size (length diagonals))
(indice (iota size 0 1))
(right-line (make-list size ufill))
(left-line (make-list size lfill))
(right-dots-line (make-list size right-vdots))
(left-dots-line (make-list size left-vdots))
; row は実際には行列が入る
(row (map (cut make-row <> <> <>
right-cdots left-cdots mask right-line left-line right-dots-line left-dots-line)
diagonals indice mask)))
row))
(diagmatrix "*" "0" '("A" "B" "..." "D"))
; => (("A" #0="*" #1="\\cdots" #0#)
; (#2="0" "B" #1# #0#)
; (#3="\\vdots" #3# "\\ddots" "\\vdots")
; (#2# #2# "\\cdots" "D"))
; 見難いが, (2,4)-成分と(4,2)-成分が空になっている
(format "~s" (diagmatrix "0" "0" '("a_1" "..." "a_i" "..." "a_n")))
; => "((a_1 \\cdots 0 \\cdots 0)\
; (\\vdots \\ddots \\vdots \\vdots)\
; (0 \\cdots a_i \\cdots 0)\
; (\\vdots \\vdots \\ddots \\vdots)\
; (0 \\cdots 0 \\cdots a_n))"
(diagmatrix "0" "0" '("a_1" "..." "a_i" "..." "a_n"))
; => (("a_1" #0="\\cdots" #1="0" #0# #1#)
; (#2="\\vdots" #3="\\ddots" #4="\\vdots" "" #4#)
; (#5="0" #6="\\cdots" "a_i" #0# #1#)
; (#2# "" #2# #3# #4#) (#5# #6# #5# #6# "a_n"))
% -*- coding: euc-jp -*-
\documentclass[10pt,draft]{amsart}
\usepackage{amsmath,amssymb}
%\usepackage{kmathmacro}
\usepackage{mwmlist}
\makeatletter
\newcount\mwm@@counter
\newif\if@mwm
\def\mwm@is@true#1{#1}
\let\mwm@true\@mwmtrue
\let\mwm@false\@mwmfalse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\diagmatrix{% [ufill,lfill] CSL ;
% Diagonal matrix whose diagonal elements are CSL, upper triangle filled with ufill,
% lower with lfill. In CSL, the strings "..." and "\dots" following spaces have special meaning.
% Matrix elements of rows and columns <dots> exist are replaced with appropriate dots
% as the element see how many <dots> in the diagonal. For example, if an element sees
% <dots> vertically and no <dots> horizontally, it is replaced with \cdots .
\begingroup
% \def\mwm@dm@@upper@filling{}%
% \def\mwm@dm@@lower@filling{}%
\@ifnextchar[ \mwm@dm@bite@bracket {\mwm@dm@bite@bracket[,]}%
}
\def\mwm@dm@bite@bracket[#1]{%
\mwm@dm@bite@bracket@aux#1,\@nil
\mwm@dm@main
}
\def\mwm@dm@bite@bracket@aux#1,#2\@nil{%
\def\@tempa{#2}%
\ifx\@tempa\@empty
\def\mwm@dm@@upper@filling{#1}%
\def\mwm@dm@@lower@filling{#1}%
\else
\mwm@dm@bite@bracket@aux@two#1,#2\@nil
\fi
}
\def\mwm@dm@bite@bracket@aux@two#1,#2,\@nil{%
\def\mwm@dm@@upper@filling{#1}%
\def\mwm@dm@@lower@filling{#2}%
}
\def\mwm@dm@main#1;{%
\let\mwm@dm@@ddots\ddots
\ifx\mwm@dm@@upper@filling\@empty
\let\mwm@dm@@right@cdots\relax
\let\mwm@dm@@right@vdots\relax
\else
\let\mwm@dm@@right@cdots\cdots
\let\mwm@dm@@right@vdots\vdots
\fi
\ifx\mwm@dm@@lower@filling\@empty
\let\mwm@dm@@left@cdots\relax
\let\mwm@dm@@left@vdots\relax
\else
\let\mwm@dm@@left@cdots\cdots
\let\mwm@dm@@left@vdots\vdots
\fi
\mwml@set@list@from@csl\mwm@dm@@diagonals{#1}%
\mwm@dm@make@mask% make a mask, contained in \mwm@dm@@mask
\mwml@set@length\mwm@dm@@size\mwm@dm@@diagonals
% note that the below is incompatible with index of row of matrix
\mwml@set@iota\mwm@dm@@iota\mwm@dm@@size{0}{1}%
\mwml@set@make@list\mwm@dm@@right@line\mwm@dm@@size\mwm@dm@@upper@filling
\mwml@set@make@list\mwm@dm@@left@line\mwm@dm@@size\mwm@dm@@lower@filling
\mwml@set@make@list\mwm@dm@@left@dots@line\mwm@dm@@size{\mwm@dm@@left@vdots}%
\mwml@set@make@list\mwm@dm@@right@dots@line\mwm@dm@@size{\mwm@dm@@right@vdots}%
% A variable \mwm@dm@@row is used to return value by \mwm@dm@make@row .
\mwml@set@map@three\mwm@dm@@row\mwm@dm@make@row\mwm@dm@@diagonals\mwm@dm@@iota\mwm@dm@@mask
% But now it contains the matrix we wanted.
\mwml@output@matrix@with@pmatrix\mwm@dm@@row
\endgroup
}
\def\mwm@dm@make@mask{%
\mwml@set@map\@tempa\mwm@dm@make@mask@aux\mwm@dm@@diagonals
\let\mwm@dm@@mask\@tempa
}
\def\mwm@dm@make@mask@aux#1{%
\mwm@dm@is@dots{#1}%
\if@mwm \def\@tempa{\mwm@true}\else \def\@tempa{\mwm@false}\fi
}
\def\mwm@dm@is@dots#1{%
\@mwmfalse
\mwm@dm@is@dots@a#1...\@nil
\mwm@dm@is@dots@b#1\dots\@nil
}
\def\mwm@dm@is@dots@a#1...#2\@nil{%
\def\@tempa{#2}%
\ifx\@tempa\@empty \else \@mwmtrue \fi
}
\def\mwm@dm@is@dots@b#1\dots#2\@nil{%
\def\@tempa{#2}%
\ifx\@tempa\@empty \else \@mwmtrue \fi
}
\def\mwm@dm@make@row#1#2#3{% elem -> index -> boolian -> nothing, row in \mwm@dm@@row
% \mwm@dm@@row will be `(,@\mwm@dm@@left@row ,\@tempb ,@\mwm@dm@@right@row)
\mwml@set@take@nth@drop\mwm@dm@@left@mask\@tempa\mwm@dm@@right@mask\mwm@dm@@mask{#2}%
\mwm@is@true{#3}\if@mwm% if #1 is dots
\mwml@set@map@two\@tempa\mwm@dm@mask@empty@aux\mwm@dm@@left@dots@line\mwm@dm@@left@mask
\let\mwm@dm@@left@row\@tempa
\mwml@set@map@two\@tempa\mwm@dm@mask@empty@aux\mwm@dm@@right@dots@line\mwm@dm@@right@mask
\let\mwm@dm@@right@row\@tempa
\def\@tempb{\mwm@dm@@ddots}%
\else% if #1 is not dots
\mwml@set@map@two\@tempa\mwm@dm@mask@left@aux\mwm@dm@@left@line\mwm@dm@@left@mask
\let\mwm@dm@@left@row\@tempa
\mwml@set@map@two\@tempa\mwm@dm@mask@right@aux\mwm@dm@@right@line\mwm@dm@@right@mask
\let\mwm@dm@@right@row\@tempa
\def\@tempb{#1}%
\fi
\mwm@exnr\mwml@push\@tempb\mwm@dm@@right@row
\mwml@set@append\mwm@dm@@row\mwm@dm@@left@row\mwm@dm@@right@row
}
\def\mwm@dm@mask@left@aux#1#2{%
\mwm@is@true{#2}\if@mwm
\def\@tempa{\mwm@dm@@left@cdots}%
\else
\def\@tempa{#1}%
\fi
}
\def\mwm@dm@mask@right@aux#1#2{%
\mwm@is@true{#2}\if@mwm
\def\@tempa{\mwm@dm@@right@cdots}%
\else
\def\@tempa{#1}%
\fi
}
\def\mwm@dm@mask@empty@aux#1#2{%
\mwm@is@true{#2}\if@mwm
\def\@tempa{}%
\else
\def\@tempa{#1}%
\fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\fbox{test diagmatrix}
\[
\diagmatrix A,B,C,D ;
\]
\[
\diagmatrix A,B,...,D ;
\]
\[
\diagmatrix[0] A,B,...,D ;
\]
\[
\diagmatrix[0,] A,B,...,D ;
\]
\[
\diagmatrix[,0] A,B,...,D ;
\]
\[
\diagmatrix[*,0] A, B, ..., D ;
\]
\[
\diagmatrix[*,0] a_1, a_2, ..., a_i, ..., a_{n-1}, a_n ;
\]
% test for non-robust elements
% \[
% \diagmatrix[{\map from X to Y ;},\chi]
% {\H_{Gal}^1(\aGal_K, A)}, {\H_{et}^1(X_\Kbar, \Ql)}, ..., {\Hom_{cont}(G, A)} ;
% \]
\end{document}
\makeatother
% -*- coding: euc-jp -*-
%%% mwmu -- utilities for mwmath
%\def\mwm@exr#1#2{%
% \expandafter#1\expandafter{#2}%
%}
%\def\mwm@enr#1#2{%
% #1{#2}%
%}
%\def\mwm@exxr#1#2#3{%
% \def\mwm@er@aux##1{\mwm@exr{#1}{#2}{##1}}%
% \mwm@exr\mwm@er@aux{#3}%
%}
%\def\mwm@exnr#1#2#3{%
% \mwm@exr{#1}{#2}{#3}%
%}
%\def\mwm@enxr#1#2#3{%
% \def\mwm@er@aux##1{#1{#2}{##1}}%
% \mwm@exr\mwm@er@aux{#3}%
%}
%\def\mwm@ennr#1#2#3{%
% #1{#2}{#3}%
%}
%\def\mwm@exxxr#1#2#3#4{%
% \def\mwm@er@aux##1{\mwm@exxr{#1}{#2}{#3}{##1}}%
% \mwm@exr\mwm@er@aux{#4}%
%}
%\def\mwm@exxnr#1#2#3#4{%
% \mwm@exxr{#1}{#2}{#3}{#4}%
%}
%\def\mwm@exnxr#1#2#3#4{%
% \def\mwm@er@aux##1{\mwm@exnr{#1}{#2}{#3}{##1}}%
% \mwm@exr\mwm@er@aux{#4}%
%}
%\def\mwm@exnnr#1#2#3#4{%
% \mwm@exnr{#1}{#2}{#3}{#4}%
%}
%\def\mwm@enxxr#1#2#3#4{%
% \def\mwm@er@aux##1{\mwm@enxr{#1}{#2}{#3}{##1}}%
% \mwm@exr\mwm@er@aux{#4}%
%}
%\def\mwm@enxnr#1#2#3#4{%
% \mwm@enxr{#1}{#2}{#3}{#4}%
%}
%\def\mwm@ennxr#1#2#3#4{%
% \def\mwm@er@aux##1{#1{#2}{#3}{##1}}%
% \mwm@exr\mwm@er@aux{#4}%
%}
%\def\mwm@ennnr#1#2#3#4{%
% #1{#2}{#3}{#4}%
%}
\def\mwm@exr#1#2{%
\expandafter#1\expandafter{#2}%
}
\let\mwm@enr\relax
\def\mwm@exxr#1#2#3{%
\def\mwm@er@aux##1{\mwm@exr#1{#2}{##1}}%
\mwm@exr\mwm@er@aux{#3}%
}
\let\mwm@exnr\mwm@exr
\def\mwm@enxr#1#2#3{%
\def\mwm@er@aux##1{#1{#2}{##1}}%
\mwm@exr\mwm@er@aux{#3}%
}
\let\mwm@ennr\relax
\def\mwm@exxxr#1#2#3#4{%
\def\mwm@er@aux##1{\mwm@exxr#1{#2}{#3}{##1}}%
\mwm@exr\mwm@er@aux{#4}%
}
\let\mwm@exxnr\mwm@exxr
\def\mwm@exnxr#1#2#3#4{%
\def\mwm@er@aux##1{\mwm@exnr#1{#2}{#3}{##1}}%
\mwm@exr\mwm@er@aux{#4}%
}
\let\mwm@exnnr\mwm@exr
\def\mwm@enxxr#1#2#3#4{%
\def\mwm@er@aux##1{\mwm@enxr#1{#2}{#3}{##1}}%
\mwm@exr\mwm@er@aux{#4}%
}
\let\mwm@enxnr\mwm@enxr
\def\mwm@ennxr#1#2#3#4{%
\def\mwm@er@aux##1{#1{#2}{#3}{##1}}%
\mwm@exr\mwm@er@aux{#4}%
}
\let\mwm@ennnr\relax
\def\mwm@exxxxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@exxxr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@exxxnr\mwm@exxxr
\def\mwm@exxnxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@exxnr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@exxnnr\mwm@exxr
\def\mwm@exnxxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@exnxr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@exnxnr\mwm@exnxr
\def\mwm@exnnxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@exnnr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@exnnnr\mwm@exr
\def\mwm@enxxxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@enxxr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@enxxnr\mwm@enxxr
\def\mwm@enxnxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@enxnr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@enxnnr\mwm@enxr
\def\mwm@ennxxr#1#2#3#4#5{%
\def\mwm@er@aux##1{\mwm@ennxr#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@ennxnr\mwm@ennxr
\def\mwm@ennnxr#1#2#3#4#5{%
\def\mwm@er@aux##1{#1{#2}{#3}{#4}{##1}}%
\mwm@exr\mwm@er@aux{#5}%
}
\let\mwm@ennnnr\relax
\def\mwm@in@group@with@nonlocal#1#2#3{% :: cs -> cs -> block -> nothing
\begingroup
#3%
\global\let\mwm@in@group@with@nonlocal@@a#1%
\endgroup
\let#2\mwm@in@group@with@nonlocal@@a
}
\def\mwm@in@group@with@nonlocal@two#1#2#3#4#5{% :: cs -> cs -> cs -> cs -> block -> nothing
\begingroup
#5%
\global\let\mwm@in@group@with@nonlocal@@a#1%
\global\let\mwm@in@group@with@nonlocal@@b#3%
\endgroup
\let#2\mwm@in@group@with@nonlocal@@a
\let#4\mwm@in@group@with@nonlocal@@b
}
\def\mwm@in@group@with@nonlocal@three#1#2#3#4#5#6#7{% :: cs -> cs -> cs -> cs -> cs -> cs -> block -> nothing
\begingroup
#7%
\global\let\mwm@in@group@with@nonlocal@@a#1%
\global\let\mwm@in@group@with@nonlocal@@b#3%
\global\let\mwm@in@group@with@nonlocal@@c#5%
\endgroup
\let#2\mwm@in@group@with@nonlocal@@a
\let#4\mwm@in@group@with@nonlocal@@b
\let#6\mwm@in@group@with@nonlocal@@c
}
\def\mwm@in@group@with@nonlocal@@a{}
\def\mwm@in@group@with@nonlocal@@b{}
\def\mwm@in@group@with@nonlocal@@c{}
\def\mwm@endgroup@with@nonlocal#1#2{% :: cs -> cs -> nothing
\global\let\mwm@in@group@with@nonlocal@@a#1%
\endgroup
\let#2\mwm@in@group@with@nonlocal@@a
}
%%% mwmlist -- List processing library for mwmath
\newcount\mwml@@counter
\newcount\mwml@@countera
\newif\if@mwml
%\def\mwml@false{\@mwml@false}
%% Local variables
\def\mwml@tempa{}
\def\mwml@tempb{}
\def\mwml@tempc{}
\def\mwml@tempd{}
%% Non-local variables
\def\mwml@tempflasque{}
%% Temporary local variables for arguments
% One may only use these variables to contain arguments, e.g. #1, to avoid overwritting them,
% which causes a problem in the case that one of arguments is a control sequence like \mwml@tempa .
% It is not allowed to pass these variables as control sequence. Expand them.
\def\mwml@arga{}
\def\mwml@argb{}
\def\mwml@argc{}
\def\mwml@argd{}
%% Data constructers
% LIST := \mwml@NULL | \mwml@CONS{ELEM}{LIST}
% ELEM := anything
\def\mwml@CONS#1#2{}
\def\mwml@NULL{}
%%% Logic
% implemented: is@true is@false not and or not@and not@or
\def\mwml@is@true#1{% :: boolian -> nothing
\mwml@not{\mwml@is@false{#1}}%
}
\def\mwml@is@false#1{% :: boolian -> nothing
\ifx#1\mwml@false
\@mwmltrue
\else
\@mwmlfalse
\fi
}
\def\mwml@not#1{% (not #1)
#1%
\if@mwml
\@mwmlfalse
\else
\@mwmltrue
\fi
}
\def\mwml@and#1#2{% (and #1 #2)
#1%
\if@mwml
#2%
\else
\@mwmlfalse
\fi
}
\def\mwml@or#1#2{% (or #1 #2)
#1%
\if@mwml
\else
#2%
\fi
}
\def\mwml@not@and#1#2{% (not (and #1 #2))
\mwml@not{\mwml@and{#1}{#2}}%
}
\def\mwml@not@or#1#2{% (not (or #1 #2))
\mwml@not{\mwml@or{#1}{#2}}%
}
%%% Auxiliary macro
\def\mwml@with@freezed@list#1{%
\let\mwml@CONS@before\mwml@CONS
\let\mwml@NULL@before\mwml@NULL
\let\mwml@CONS\relax
\let\mwml@NULL\relax
#1%
\let\mwml@CONS\mwml@CONS@before
\let\mwml@NULL\mwml@NULL@before
}
%%% Fundamentals
% \mwml@set@null \mwml@set@copy \mwml@apply
\def\mwml@set@null#1{%
\def#1{\mwml@NULL}%
}
\def\mwml@set@copy#1#2{%
% Bind copy of #2 to #1
\mwm@in@group@with@nonlocal#1#1{%
\mwml@with@freezed@list{%
\toks2\expandafter{#2}%
\edef#1{\the\toks2}%
}%
}%
}
\def\mwml@apply#1#2{% :: proc -> [a] -> nothing, apply proc to [a]
\mwml@set@fold\mwml@tempflasque\mwml@apply@kons{}{#2}%
\expandafter#1\mwml@tempflasque
}
\def\mwml@apply@kons#1#2{%
\toks1{#1}%
\toks2{{#2}}%
\edef\mwml@tempflasque{\the\toks1 \the\toks2}%
}
%%% Auxiliary macnros with side effect
\def\mwml@push#1#2{%
\mwml@set@cons#2{#1}{#2}%
}
\def\mwml@drop@one#1{%
\mwml@set@cdr#1#1%
}
%%% Constructors
% implemented: cons make-list iota
% \def\mwml@set@cons#1#2#3{%
% % Bind cons of #2 and #3 to #1
% \mwml@with@freezed@list{%
% \edef#1{\mwml@CONS{#2}{#3}}%
% }%
% }
\def\mwml@set@cons#1#2#3{%
% Bind cons of #2 and #3 to #1
\mwm@in@group@with@nonlocal#1#1{%
\mwml@with@freezed@list{%
\toks2{#2}%
\toks3\expandafter{#3}%
\edef#1{\mwml@CONS{\the\toks2}{\the\toks3}}%
}%
}%
}
\def\mwml@set@make@list#1#2#3{% :: cs -> length -> a -> nothing, [a] in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@@counter=#2
\mwml@set@copy\mwml@argc{#3}%
\mwml@set@null\mwml@tempa
\ifnum\mwml@@counter>0
\loop
\mwm@exnr\mwml@push\mwml@argc\mwml@tempa
\advance \mwml@@counter by -1
\ifnum\mwml@@counter>0 \repeat
\fi
}%
}
\def\mwml@set@iota#1#2#3#4{% :: cs -> count -> start -> step -> nothing, [a] in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@@counter=#2\relax% count
\mwml@@countera=#3\relax% start
\mwml@set@null\mwml@tempa
\ifnum\mwml@@counter>0
\loop
\mwm@exnr\mwml@push{\the\mwml@@countera}\mwml@tempa
\advance \mwml@@counter by -1
\advance \mwml@@countera by #4
\ifnum\mwml@@counter>0 \repeat
\fi
\mwml@reverse\mwml@tempa
}%
}
%%% Predicates
% implemented: is-null eq-nth test-nth
\def\mwml@is@null#1{%
\let\mwml@NULL@before\mwml@NULL
\let\mwml@CONS@before\mwml@CONS
\let\mwml@NULL\@mwmltrue
\let\mwml@CONS\mwml@is@null@cons
#1%
\let\mwml@NULL\mwml@NULL@before
\let\mwml@CONS\mwml@CONS@before
}
\def\mwml@is@null@cons#1#2{%
\@mwmlfalse
}
\def\mwml@eq@nth#1#2#3{% :: a -> i -> [a] -> nothing
\mwml@set@list@ref\mwml@tempflasque{#3}{#2}%
\def\@tempa{#1}%
\ifx\@tempa\mwml@tempflasque
\@mwmltrue
\else
\@mwmlfalse
\fi
}
\def\mwml@test@nth#1#2#3{% :: (a -> nothing, predicate) -> i -> [a] -> nothing
\mwml@set@list@ref\@tempa{#3}{#2}%
#1\@tempa
}
%%% Selectors
% implemented: car cdr cadr caddr cadddr list-ref
% take drop split-at
% take/nth/drop
% \def\mwml@set@car#1#2{%
% % Bind car of #2 to #1
% \begingroup
% \def\mwml@CONS##1##2{\def#1{##1}}%
% \let\mwml@NULL\undefined
% #2%
% % \mwm@endgroup@with@nonlocal#1#1
% \global\let\mwml@result#1
% \endgroup
% \let#1\mwml@result
% }
% \def\mwml@set@cdr#1#2{%
% % Bind cdr of #2 to #1
% \begingroup
% \def\mwml@CONS##1##2{\def#1{##2}}%
% \let\mwml@NULL\undefined
% #2%
% \global\let\mwml@result#1
% \endgroup
% \let#1\mwml@result
% }
\def\mwml@set@car#1#2{%
% Bind car of #2 to #1
\mwm@in@group@with@nonlocal#1#1{%
\def\mwml@CONS##1##2{\def#1{##1}}%
\let\mwml@NULL\undefined
#2%
}%
}
\def\mwml@set@cdr#1#2{%
% Bind cdr of #2 to #1
\mwm@in@group@with@nonlocal#1#1{%
\def\mwml@CONS##1##2{\def#1{##2}}%
\let\mwml@NULL\undefined
#2%
}%
}
\def\mwml@set@cadr#1#2{\mwml@set@list@ref{#1}{#2}{1}}
\def\mwml@set@caddr#1#2{\mwml@set@list@ref{#1}{#2}{2}}
\def\mwml@set@cadddr#1#2{\mwml@set@list@ref{#1}{#2}{3}}
\def\mwml@set@list@ref#1#2#3{% :: cs -> [a] -> i -> a
% imported from srfi-1
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@@counter=#3
\let\mwml@NULL\undefined
\let\mwml@CONS\mwml@set@list@ref@cons
#2%
}%
}
\def\mwml@set@list@ref@cons#1#2{%
% \ifnum\mwml@@counter=0
% \def\mwml@tempa{#1}%
% \let\mwml@CONS\@gobbletwo
% \let\mwml@NULL\relax
% \else
% \advance \mwml@@counter by -1
% \fi
% #2%
\ifnum\mwml@@counter=0
\def\mwml@tempa{#1}%
\else
\advance \mwml@@counter by -1
#2%
\fi
}
\def\mwml@set@take#1#2#3{% cs -> [a] -> index -> nothing, [a] in cs
\mwm@in@group@with@nonlocal#1#1{%
\mwml@set@split@at#1\mwm@devnull{#2}{#3}%
}%
}
\def\mwml@set@drop#1#2#3{% cs -> [a] -> index -> nothing
\mwm@in@group@with@nonlocal#1#1{%
\mwml@set@split@at\mwm@devnull#1{#2}{#3}%
}%
}
\def\mwml@set@split@at#1#2#3#4{%
% :: cs-take -> cs-drop -> [a] -> index -> nothing, [a] in cs-take, [a] in cs-drop
% return (take x i), (drop x i)
\mwm@in@group@with@nonlocal@two\mwml@tempa#1\mwml@tempb#2{%
\mwml@set@copy\mwml@argc{#3}%
\mwml@set@null\mwml@tempa
\mwml@@counter=0
\mwml@@countera=#4
\ifnum\mwml@@countera=0
\let\mwml@tempb\mwml@argc
\else
\let\mwml@NULL\undefined
\let\mwml@CONS\mwml@set@split@at@cons
\mwml@argc
\fi
\mwml@reverse\mwml@tempa
}%
}
\def\mwml@set@split@at@cons#1#2{%
\mwml@push{#1}\mwml@tempa
\advance \mwml@@counter by 1
\ifnum\mwml@@counter=\mwml@@countera
\def\mwml@tempb{#2}%
\else
#2%
\fi
}
\def\mwml@set@take@nth@drop#1#2#3#4#5{% :: cs-take -> cs-nth -> cs-drop -> [a] -> index -> nothing,
% [a] in cs-take, a in cs-nth, [a] in cs-drop
% return (take x i), (nth i x), (drop x (+ i 1))
\mwm@in@group@with@nonlocal@three\mwml@tempa#1#2#2#3#3{%
\mwm@ennxnr\mwml@set@split@at\mwml@tempa\mwml@tempb{#4}{#5}%
\mwml@set@car#2\mwml@tempb
\mwml@set@cdr#3\mwml@tempb
}%
}
%%% Selectors with side effect
% Do not use them, they often causes bugs.
\def\mwml@car#1{%
\mwml@set@car\mwml@tempa{#1}%
\mwml@tempa
}
\def\mwml@cadr#1{\mwml@list@ref{#1}{1}}
\def\mwml@caddr#1{\mwml@list@ref{#1}{2}}
\def\mwml@cadddr#1{\mwml@list@ref{#1}{3}}
\def\mwml@list@ref#1#2{% :: [a] -> i -> a
\mwml@set@list@ref\mwml@tempa{#1}{#2}%
\mwml@tempa
}
\def\mwml@nth#1#2{% :: i -> [a] -> a
\mwml@set@list@ref\mwml@tempa{#2}{#1}%
\mwml@tempa
}
%%% Miscellaneous: length, append, concatenate, reverse, zip & count
% implemented: length, append, concatenate reverse, append-reverse, zip (2,3)
% \def\mwml@set@length#1#2{% cs -> [a] -> nothing, length in cs
% \mwm@in@group@with@nonlocal\mwml@tempa#1{%
% \mwml@set@fold\mwml@tempa\mwml@set@length@kons{0}{#2}%
% }%
% }
% \def\mwml@set@length@kons#1#2{%
% \mwml@@counter=#1
% \advance \mwml@@counter by 1
% \edef\mwml@tempa{\the\mwml@@counter}%
% }
\def\mwml@set@length#1#2{% cs -> [a] -> nothing, length in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@fold\mwml@tempa\mwml@set@length@kons{0}{#2}%
}%
}
\def\mwml@set@length@kons#1#2{%
\mwml@@counter=#1
\advance \mwml@@counter by 1
\edef\mwml@tempa{\the\mwml@@counter}%
}
\def\mwml@set@length@counter#1#2{% counter -> [a] -> nothing, length in counter
\mwm@in@group@with@nonlocal\mwml@tempa\mwml@tempflasque{%
\mwml@set@length\mwml@tempa{#2}%
}
#1=\mwml@tempflasque
}
\def\mwml@set@append#1#2#3{% :: cs -> [a] -> [a] -> nothing, [a] in cs
\mwm@in@group@with@nonlocal#1#1{%
% \mwml@set@reverse#1{#2}%
% \mwml@set@append@reverse#1#1{#3}%
\mwml@set@reverse\mwml@append@@lis{#2}%
\mwm@enxnr\mwml@set@append@reverse#1\mwml@append@@lis{#3}%
}%
}
\def\mwml@set@append@reverse#1#2#3{% :: cs -> [a] -> [a] -> nothing, [a] in cs
% (append (reverse #1) #2)
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@copy\mwml@argb{#2}%
\mwml@set@copy\mwml@tempa{#3}%
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@set@append@reverse@cons
\mwml@argb
}%
}
\def\mwml@set@append@reverse@cons#1#2{%
\mwml@push{#1}\mwml@tempa
#2%
}
\def\mwml@set@concatenate#1#2{% :: cs -> [[a]] -> nothing, [a] in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@reverse\mwml@tempb{#2}%
\mwml@set@fold\mwml@tempa\mwml@set@concatenate@kons\mwml@NULL\mwml@tempb
}%
}
\def\mwml@set@concatenate@kons#1#2{%
\mwml@set@append\mwml@tempa{#2}{#1}%
}
\def\mwml@reverse#1{%
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@reverse\mwml@tempa{#1}%
}%
}
\def\mwml@set@reverse#1#2{% :: cs -> [a] -> nothing, [a] in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@copy\mwml@argb{#2}%
\mwml@set@null\mwml@tempa
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@set@reverse@cons
\mwml@argb
}%
}
\def\mwml@set@reverse@cons#1#2{%
\mwml@push{#1}\mwml@tempa
#2%
}
\def\mwml@set@zip@two#1#2#3{% :: cs -> [a] -> [b] -> nothing, [(a,b)] in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
% \mwml@set@copy\mwml@tempb{#2}%
% \mwml@set@copy\mwml@tempc{#3}%
% \mwml@set@null\mwml@tempa
% \let\mwml@NULL\relax
% \let\mwml@CONS\mwml@set@zip@two@cons
% \mwml@tempb
% \mwml@reverse\mwml@tempa
\mwml@set@copy\mwml@argb{#2}%
\mwml@set@copy\mwml@argc{#3}%
\mwml@set@null\mwml@tempa
\mwml@set@copy\mwml@tempb\mwml@argb
\mwml@set@copy\mwml@tempc\mwml@argc
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@set@zip@two@cons
\mwml@tempb
\mwml@reverse\mwml@tempa
}%
}
\def\mwml@set@zip@two@cons#1#2{%
\mwml@is@null\mwml@tempb \if@mwml \else
\mwml@is@null\mwml@tempc \if@mwml \else
\mwml@set@car\@tempb\mwml@tempb
\mwml@drop@one\mwml@tempb
\mwml@set@car\@tempc\mwml@tempc
\mwml@drop@one\mwml@tempc
\mwml@set@null\@tempa
\mwm@exnr\mwml@push\@tempc\@tempa
\mwm@exnr\mwml@push\@tempb\@tempa
\mwm@exnr\mwml@push\@tempa\mwml@tempa% (push `(,\@tempb ,\@tempc) \mwml@tempa)
% I think the below null check is not necessarily needed, but the rack causes an error. Hum...
% \def\@tempa{#2}%
% \mwml@is@null\@tempa \if@mwml
% \else
#2%
% \fi
\fi\fi
}
\def\mwml@set@zip@three#1#2#3#4{% :: cs -> [a] -> [b] -> [c] -> nothing, [(a,b,c)] in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
% \mwml@set@copy\mwml@tempb{#2}%
% \mwml@set@copy\mwml@tempc{#3}%
% \mwml@set@copy\mwml@tempd{#4}%
% \mwml@set@null\mwml@tempa
% \let\mwml@NULL\relax
% \let\mwml@CONS\mwml@set@zip@three@cons
% \mwml@tempb
% \mwml@reverse\mwml@tempa
\mwml@set@copy\mwml@argb{#2}%
\mwml@set@copy\mwml@argc{#3}%
\mwml@set@copy\mwml@argd{#4}%
\mwml@set@null\mwml@tempa
\mwml@set@copy\mwml@tempb\mwml@argb
\mwml@set@copy\mwml@tempc\mwml@argc
\mwml@set@copy\mwml@tempd\mwml@argd
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@set@zip@three@cons
\mwml@tempb
\mwml@reverse\mwml@tempa
}%
}
\def\mwml@set@zip@three@cons#1#2{%
\mwml@is@null\mwml@tempb \if@mwml \else
\mwml@is@null\mwml@tempc \if@mwml \else
\mwml@is@null\mwml@tempd \if@mwml \else
\mwml@set@car\@tempb\mwml@tempb
\mwml@drop@one\mwml@tempb
\mwml@set@car\@tempc\mwml@tempc
\mwml@drop@one\mwml@tempc
\mwml@set@car\@tempd\mwml@tempd
\mwml@drop@one\mwml@tempd
\mwml@set@null\@tempa
\mwm@exnr\mwml@push\@tempd\@tempa
\mwm@exnr\mwml@push\@tempc\@tempa
\mwm@exnr\mwml@push\@tempb\@tempa
\mwm@exnr\mwml@push\@tempa\mwml@tempa% (push `(,\@tempb ,\@tempc ,\@tempd) \mwml@tempa)
% see the comment in \mwml@set@zip@two@cons
% \def\@tempa{#2}%
% \mwml@is@null\@tempa \if@mwml
% \else
#2%
% \fi
\fi\fi\fi
}
%%% Fold, unfold & map
% implemented: fold map
% \def\mwml@set@fold{\mwml@set@fold@cont\relax}
% \def\mwml@set@fold@cont#1#2#3#4#5{% :: cont -> cs -> (a -> b -> a) -> a -> [b] -> a
% % #3 have to return value in cs
% % #1: cont (continuation)
% % #2: cs (control sequence used in #3 to return value)
% % #3: a -> b -> a
% % #4: a (accumulator)
% % #5: [b]
% \mwm@in@group@with@nonlocal#2#2{%
% \def\mwml@fold@kons##1##2{%
% \mwm@exnr#3{#2}{##1}%
% ##2%
% }%
% \let\mwml@NULL\relax
% \let\mwml@CONS\mwml@fold@kons
% \def#2{#4}%
% #5%
% }%
% }
\def\mwml@set@fold#1#2#3#4{% :: cs -> (a -> b -> nothing, a in cs) -> a -> [b] -> nothing, a in cs
% #2 have to return value in #1
% Note that this macro is imported from Haskell (foldl), not from Scheme.
% Take care of the order of arguments of #2.
% #1: cs (control sequence used in #3 to return value)
% #2: a -> b -> a
% #3: a (accumulator)
% #4: [b]
\mwm@in@group@with@nonlocal#1#1{%
\def\mwml@fold@kons##1##2{%
\mwm@exnr#2{#1}{##1}%
##2%
}%
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@fold@kons
\mwml@set@copy\mwml@argd{#4}%
\def#1{#3}%
\mwml@argd
}%
}
\def\mwml@set@map#1#2#3{% :: cs -> (a -> nothing, b in cs) -> [a] -> nothing, [b] in cs
\mwm@in@group@with@nonlocal\mwml@map@@res#1{%
\def\mwml@set@map@kons##1##2{%
#2{##2}%
\mwm@enxnr\mwml@set@cons\mwml@map@@res#1{##1}%
}%
\mwml@set@fold\mwml@map@@res\mwml@set@map@kons\mwml@NULL{#3}%
\mwml@reverse\mwml@map@@res
}%
}
\def\mwml@set@map@two#1#2#3#4{%
% :: cs -> (a -> b -> nothing, c in cs) -> [a] -> [b] -> nothing, [c] in cs
\mwm@in@group@with@nonlocal#1#1{%
\def\mwml@map@proc##1{%
\mwml@apply#2{##1}%
}%
\mwml@set@zip@two#1{#3}{#4}%
\mwm@ennxr\mwml@set@map#1\mwml@map@proc{#1}%
}%
}
\def\mwml@set@map@three#1#2#3#4#5{%
% :: cs -> (a -> b -> c -> nothing, d in cs) -> [a] -> [b] -> [c] -> nothing, [d] in cs
\mwm@in@group@with@nonlocal#1#1{%
\def\mwml@map@proc##1{%
\mwml@apply#2{##1}%
}%
\mwml@set@zip@three#1{#3}{#4}{#5}%
\mwm@ennxr\mwml@set@map#1\mwml@map@proc{#1}%
}%
}
%%% Filtering & partitioning
% implemented: filter
% TODO: delete
\def\mwml@filter#1#2{%
\mwml@set@filter\mwml@tempa{#1}{#2}%
\let#2\mwml@tempa
}
\def\mwml@set@filter#1#2#3{% :: cs -> (a -> nothing, predicate) -> [a] -> nothing, [a] in cs
% \begingroup
% \mwml@set@null\mwml@tempa
% \let\mwml@NULL\relax
% \let\mwml@CONS\mwml@set@filter@cons
% \let\mwml@temp@pred#2%
% #3%
% \mwml@set@reverse\mwml@@result\mwml@tempa
% \global\let\mwml@@result\mwml@@result
% \endgroup
% \let#1\mwml@@result
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\let\mwml@temp@pred#2%
\mwml@set@copy\mwml@argc{#3}%
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@set@filter@cons
\mwml@set@null\mwml@tempa
\mwml@argc
\mwml@reverse\mwml@tempa
}%
}
\def\mwml@set@filter@cons#1#2{%
\mwml@temp@pred{#1}%
\if@mwml
\mwml@push{#1}\mwml@tempa
\else
\fi
#2%
}
%%% Searching
% implemented: memq
\def\mwml@memq#1#2{% :: a -> [a] -> nothing
\let\mwml@NULL\@mwmlfalse
\let\mwml@CONS\mwml@memq@cons
\mwml@set@copy\mwml@argb{#2}%
\def\mwml@tempa{#1}%
\mwml@argb
}
\def\mwml@memq@cons#1#2{%
\def\@tempa{#1}%
\ifx\@tempa\mwml@tempa
\@mwmltrue
\else
#2%
\fi
}
%%% Conversion
\def\mwml@csl@from@list#1{%
\begingroup
\mwml@set@csl@from@list\mwml@tempa{#1}%
\mwml@tempa
\endgroup
}
\def\mwml@set@csl@from@list#1#2{% :: cs -> [a] -> nothing, CSL in cs
% Convert a list #2 to csl #1
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@copy\mwml@argb{#2}%
\let\mwml@NULL\relax
\let\mwml@CONS\mwml@set@csl@from@list@loop@first
\mwml@argb
}%
}
\def\mwml@set@csl@from@list@loop@first#1#2{%
\toks1{{#1}}%
\edef\mwml@tempa{\the\toks1}%
\let\mwml@CONS\mwml@set@csl@from@list@loop
#2%
}
\def\mwml@set@csl@from@list@loop#1#2{%
\toks0\expandafter{\mwml@tempa}%
\toks1{{#1}}%
\edef\mwml@tempa{\the\toks0,\the\toks1}%
#2%
}
\def\mwml@list@from@csl#1{%
\begingroup
\mwml@set@list@from@csl\mwml@tempa{#1}%
\mwml@tempa
\endgroup
}
\def\mwml@set@list@from@csl#1#2{% :: cs -> CSL -> nothing, [a] in cs
% Convert a CSL #2 to list #1
% One can't use \mwml@tempa for #2. Expand it.
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
\mwml@set@null\mwml@tempa
\def\mwml@argb{#2}%
\ifx\mwml@argb\@empty
\else
\mwml@set@list@from@csl@loop#2,\@nil
\fi
\mwml@reverse\mwml@tempa
}%
}
\def\mwml@set@list@from@csl@loop#1,#2\@nil{%
\mwml@push{#1}\mwml@tempa
\def\@tempa{#2}%
\ifx\@tempa\@empty
\let\@next\@gobble
\else
\let\@next\mwml@set@list@from@csl@loop
\fi
\@next#2\@nil
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\mwml@set@make@matrix#1#2#3#4{% :: cs -> row -> column -> a -> nothing, [[a]] in cs
\mwm@in@group@with@nonlocal\mwml@tempb#1{%
\def\mwml@proc##1{%
\def\mwml@tempb{#4}%
}%
\mwml@set@empty@matrix\mwml@tempa{#2}{#3}%
\mwml@set@map@matrix\mwml@tempb\mwml@proc\mwml@tempa
}%
}
\def\mwml@set@empty@matrix#1#2#3{% :: cs -> row -> column -> nothing, [[a]] in cs
\begingroup
\def\mwml@proc{%
\mwml@set@make@list\mwml@tempa{#3}{}%
}%
\mwml@set@make@list\mwml@tempa{#2}{}%
\mwm@ennxr\mwml@set@map\mwml@tempa\mwml@proc\mwml@tempa
\global\let\mwml@result\mwml@tempa
\endgroup
\let#1\mwml@result
}
\def\mwml@set@map@matrix#1#2#3{% :: cs -> (a -> b) -> [[a]] -> nothing, [[b]] in cs
% (a -> b) returns value with cs
\begingroup
\def\mwml@map@matrix@proc##1{%
\mwml@set@map#1#2{##1}%
}%
\mwm@ennxr\mwml@set@map#1\mwml@map@matrix@proc{#3}%
\global\let\mwml@result#1
\endgroup
\let#1\mwml@result
}
%% output
\def\mwml@output@matrix@with@pmatrix#1{% :: [[a]] -> output
\begingroup
\mwml@set@make@matrix@contents\mwml@tempa{#1}%
\begin{pmatrix}
\mwml@tempa
\end{pmatrix}
\endgroup
}
\def\mwml@set@make@matrix@contents#1#2{% :: cs -> [[a]] -> nothing, matrix contents in cs
\mwm@in@group@with@nonlocal\mwml@tempa#1{%
% consider the case that #2 = \mwml@tempa
% \mwml@set@car\mwml@tempa{#2}%
% \mwm@exr\mwml@matrix@join@with@tab\mwml@tempa
% \mwml@set@cdr\mwml@tempb{#2}%
\mwml@set@copy\mwml@tempb{#2}%
\mwml@set@car\mwml@tempa\mwml@tempb
\mwm@exr\mwml@matrix@join@with@tab\mwml@tempa
\mwml@drop@one\mwml@tempb
\mwm@ennxxr\mwml@set@fold\mwml@tempa\mwml@matrix@join@with@newline\mwml@tempa\mwml@tempb
}%
}
\def\mwml@matrix@join@with@newline#1#2{%
\toks0{\\}%
\toks1{#1}%
\mwml@matrix@join@with@tab{#2}%
\toks2\expandafter{\mwml@tempa}%
\edef\mwml@tempa{\the\toks1 \the\toks0 \the\toks2}%
}
\def\mwml@matrix@join@with@tab#1{% :: [a] -> value in \mwml@tempa
% (string-join lis " & ")
\mwm@in@group@with@nonlocal\mwml@tempa\mwml@tempa{%
\mwml@set@car\mwml@tempa{#1}%
\mwml@set@cdr\mwml@tempb{#1}%
\mwm@ennxnr\mwml@set@fold\mwml@tempa\mwml@matrix@join@with@tab@aux\mwml@tempa\mwml@tempb
}%
}
\def\mwml@matrix@join@with@tab@aux#1#2{%
\toks1{#1}%
\toks2{#2}%
\def\mwml@tempa{#1 & #2}%
}
%\def\datum{1: #1, 2: #2, 11: ##1, 22: ##2}\show\datum
% -*- coding: euc-jp -*-
%\documentclass[10pt,draft]{jsarticle}
\documentclass[10pt,draft]{amsart}
%\usepackage{amsmath,amssymb}
\usepackage{kmathmacro}
\usepackage{mwmlist}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%===========================================
%
%\fbox{test exr}
%
%\def\@tempa{A}
%\def\@tempb{B}
%\def\@tempc{C}
%\def\@tempd{D}
%\def\testA#1{%
% \def\datum{TEST A :: 1: #1}
% \show\datum
%}
%\def\testB#1#2{%
% \def\datum{TEST B :: 1: #1, 2: #2}
% \show\datum
%}
%\def\testC#1#2#3{%
% \def\datum{TEST C :: 1: #1, 2: #2, 3: #3}
% \show\datum
%}
%\def\testD#1#2#3#4{%
% \def\datum{TEST D :: 1: #1, 2: #2, 3: #3, 4: #4}
% \show\datum
%}
%
%\mwm@exr\testA\@tempa
%\mwm@enr\testA\@tempa
%
%\mwm@exxr\testB\@tempa\@tempb
%\mwm@exnr\testB\@tempa\@tempb
%\mwm@enxr\testB\@tempa\@tempb
%\mwm@ennr\testB\@tempa\@tempb
%
%\mwm@exxxr\testC\@tempa\@tempb\@tempc
%\mwm@exxnr\testC\@tempa\@tempb\@tempc
%\mwm@exnxr\testC\@tempa\@tempb\@tempc
%\mwm@exnnr\testC\@tempa\@tempb\@tempc
%\mwm@enxxr\testC\@tempa\@tempb\@tempc
%\mwm@enxnr\testC\@tempa\@tempb\@tempc
%\mwm@ennxr\testC\@tempa\@tempb\@tempc
%\mwm@ennnr\testC\@tempa\@tempb\@tempc
%
%\mwm@exxxxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exxxnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exxnxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exxnnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exnxxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exnxnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exnnxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@exnnnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@enxxxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@enxxnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@enxnxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@enxnnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@ennxxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@ennxnr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@ennnxr\testD\@tempa\@tempb\@tempc\@tempd
%\mwm@ennnnr\testD\@tempa\@tempb\@tempc\@tempd
%
%===========================================
===========================================
\fbox{test car, cadr, list-ref}
\def\listA{%
\mwml@CONS{A}{\mwml@CONS{B}{\mwml@CONS{C}{\mwml@CONS{D}{\mwml@NULL}}}}}
listA = (A, B, C, D)
car of listA is \mwml@car\listA \par
cadr of listA is \mwml@cadr\listA \par
caddr of listA is \mwml@caddr\listA \par
cadddr of listA is \mwml@cadddr\listA \par
(list-ref listA 0) \mwml@list@ref\listA{0} ,
(list-ref listA 1) \mwml@list@ref\listA{1} ,\par
(list-ref listA 2) \mwml@list@ref\listA{2} ,
(list-ref listA 3) \mwml@list@ref\listA{3} ,
\mwml@drop@one\listA
dropped
(list-ref listA 0) \mwml@list@ref\listA{0} ,
(list-ref listA 1) \mwml@list@ref\listA{1} ,
===========================================
\fbox{test convert list to csl}
\def\listA{\mwml@CONS{A}{\mwml@CONS{B}{\mwml@CONS{C}\mwml@NULL}}}
first \mwml@list@ref\listA{0} ,
second \mwml@list@ref\listA{1} ,
third \mwml@list@ref\listA{2}
(\mwml@csl@from@list\listA)
===========================================
\fbox{test cons and push}
\def\listA{\mwml@CONS{A}{\mwml@CONS{B}{\mwml@CONS{C}\mwml@NULL}}}
(\mwml@csl@from@list\listA)
\mwml@set@cons\listB{consed}\listA
(\mwml@csl@from@list\listB)
\mwml@push{pushed}\listA
\mwml@push{more}\listA
(\mwml@csl@from@list\listA)
===========================================
\fbox{test reverse}
\def\listA{\mwml@CONS{A}{\mwml@CONS{B}{\mwml@CONS{C}\mwml@NULL}}}
listA
(\mwml@csl@from@list\listA)
reversed
\mwml@set@reverse\listB\listA
(\mwml@csl@from@list\listB)
reversed
\mwml@reverse\listA
(\mwml@csl@from@list\listA)
===========================================
\fbox{test convert csl to list}
\mwml@set@list@from@csl\listA{A,B,C,DE}
(A, B, C, DE) = (\mwml@csl@from@list\listA)
===========================================
\fbox{test append}
\mwml@set@list@from@csl\listA{A,B,C}
\mwml@set@list@from@csl\listB{1,2,3}
\mwml@set@list@from@csl\listD{}
%\mwml@set@null\listD
listA (\mwml@csl@from@list\listA),
listB (\mwml@csl@from@list\listB),
listD (\mwml@csl@from@list\listD)
(\mwml@csl@from@list\listD)
(append-reverse listA listB) =
\mwml@set@append@reverse\listC\listA\listB
(C, B, A, 1, 2, 3) = (\mwml@csl@from@list\listC)
(append listA listB) =
\mwml@set@append\listC\listA\listB
(A, B, C, 1, 2, 3) = (\mwml@csl@from@list\listC)
(append listA listD) =
\mwml@set@append\listC\listA\listD
(A, B, C) = (\mwml@csl@from@list\listC)
(append listD listB) =
\mwml@set@append\listC\listD\listB
(1, 2, 3) = (\mwml@csl@from@list\listC)
===========================================
\fbox{test fold}
\def\mwml@fold@reverse#1{%
\mwml@set@null\mwml@tempa
\mwml@set@fold\mwml@tempa\mwml@fold@reverse@kons{}{#1}%
(\mwm@exr\mwml@csl@from@list\mwml@tempa)%
}
\def\mwml@fold@reverse@kons#1#2{%
\mwml@push{#2}\mwml@tempa
}
\mwml@set@list@from@csl\listA{A,B,C}
\mwml@fold@reverse\listA
===========================================
\fbox{test iota, make-list, map}
\mwml@set@iota\listA{5}{0}{1}
(iota 5 0 1) = (\mwml@csl@from@list\listA)
\mwml@set@iota\listA{5}{10}{2}
(iota 5 10 2) = (\mwml@csl@from@list\listA)
\mwml@set@iota\listA{0}{0}{1}
(iota 0 0 1) = (\mwml@csl@from@list\listA)
\mwml@set@make@list\listA{5}{0}
(make-list 5 0) = (\mwml@csl@from@list\listA)
\mwml@set@make@list\listA{0}{0}
(make-list 0 0) = (\mwml@csl@from@list\listA)
\mwml@set@iota\listA{5}{0}{1}
\def\mwml@map@test#1{%
\mwml@set@map\mwml@tempa\mwml@map@test@aux{#1}%
\mwm@exr\mwml@csl@from@list{\mwml@tempa}%
}
\def\mwml@map@test@aux#1{\edef\mwml@tempa{(#1)}}
(\mwml@map@test\listA)
===========================================
\newpage
\fbox{factorial}
\def\mwml@fact#1{%
\mwml@set@iota\mwml@tempb{#1}{1}{1}%
\mwml@set@fold\@tempa\mwml@mul{1}\mwml@tempb
}
\def\mwml@mul#1#2{%
\mwml@set@make@list\mwml@tempb{#1}{#2}%
\mwml@set@fold\@tempa\mwml@add{0}\mwml@tempb
}
\def\mwml@add#1#2{%
\mwml@@counter=#1
\advance \mwml@@counter by #2
\edef\@tempa{\the\mwml@@counter}%
}
\mwml@add{2}{3}
$2 + 3 = \@tempa$
\mwml@mul{2}{3}
$2 \times 3 = \@tempa$
\mwml@fact{5}
$5! = \@tempa$
\mwml@set@iota\listA{7}{1}{1}%
\mwml@set@map\@tempa\mwml@fact\listA
(map fact (iota 7 1 1)) = (\mwml@csl@from@list\@tempa)
===========================================
\fbox{test logic}
(not t) =
\mwml@not{\@mwmltrue}
\if@mwml TRUE \else FALSE \fi
(not f) =
\mwml@not{\@mwmlfalse}
\if@mwml TRUE \else FALSE \fi
\def\logictest#1#2{%
#1{t}{t} =
#2{\@mwmltrue}{\@mwmltrue}
\if@mwml TRUE \else FALSE \fi
#1{t}{f} =
#2{\@mwmltrue}{\@mwmlfalse}
\if@mwml TRUE \else FALSE \fi
#1{f}{t} =
#2{\@mwmlfalse}{\@mwmltrue}
\if@mwml TRUE \else FALSE \fi
#1{f}{f} =
#2{\@mwmlfalse}{\@mwmlfalse}
\if@mwml TRUE \else FALSE \fi
}
\def\logictestand#1#2{(and #1 #2)}%
\logictest\logictestand\mwml@and
\def\logictestor#1#2{(or #1 #2)}%
\logictest\logictestor\mwml@or
\def\logictestnotand#1#2{(not (and #1 #2))}%
\logictest\logictestnotand\mwml@not@and
\def\logictestnotor#1#2{(not (or #1 #2))}%
\logictest\logictestnotor\mwml@not@or
false is false?
\mwml@is@false\mwml@false
\if@mwml TRUE \else FALSE \fi
A is false?
\mwml@is@false{A}
\if@mwml TRUE \else FALSE \fi
false is true?
\mwml@is@true\mwml@false
\if@mwml TRUE \else FALSE \fi
A is true?
\mwml@is@true{A}
\if@mwml TRUE \else FALSE \fi
===========================================
\fbox{test if}
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
\mwml@set@null\listB
listB = (\mwml@csl@from@list\listB)
\mwml@is@null\listA
(null? listA) = \if@mwml TRUE \else FALSE \fi
\mwml@is@null\listB
(null? listB) = \if@mwml TRUE \else FALSE \fi
===========================================
\fbox{test if}
\def\mwml@even@p#1{%
\ifodd#1
\@mwmlfalse
\else
\@mwmltrue
\fi
}
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
(eq A (nth 0 listA)) =
\mwml@eq@nth{A}{0}\listA
\if@mwml TRUE \else FALSE \fi
(eq A (nth 1 listA)) =
\mwml@eq@nth{A}{1}\listA
\if@mwml TRUE \else FALSE \fi
(memq A listA) =
\mwml@memq{A}\listA
\if@mwml TRUE \else FALSE \fi
(memq C listA) =
\mwml@memq{C}\listA
\if@mwml TRUE \else FALSE \fi
(memq 1 listA) =
\mwml@memq{1}\listA
\if@mwml TRUE \else FALSE \fi
\mwml@set@list@from@csl\listA{0,1,2}
listA = (\mwml@csl@from@list\listA)
(even? (nth 0 listA)) =
\mwml@test@nth\mwml@even@p{0}\listA
\if@mwml TRUE \else FALSE \fi
(even? (nth 1 listA)) =
\mwml@test@nth\mwml@even@p{1}\listA
\if@mwml TRUE \else FALSE \fi
===========================================
\fbox{test filter}
\mwml@set@iota\listA{5}{0}{1}
listA = (\mwml@csl@from@list\listA)
(filter even? listA) =
\mwml@filter\mwml@even@p\listA
(\mwml@csl@from@list\listA)
===========================================
\fbox{}
===========================================
\fbox{}
===========================================
\fbox{}
===========================================
\fbox{}
==========================================
\fbox{test matrix}
\mwml@set@empty@matrix\listA 2 2
%\show\listA
\def\insA#1{\def\@tempa{A}}
\mwml@set@map@matrix\@tempa\insA\listA
%\show\@tempa
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
\mwml@set@map\@tempa\insA\listA
%\show\@tempa
\mwml@set@make@matrix\matrixA{2}{2}{B}
%\show\matrixA
===========================================
\fbox{}
%\mwml@set@list@from@csl\listA{A,B,C}
%listA = (\mwml@csl@from@list\listA)
%
%\mwml@matrix@convert@line\listA
%\show\mwml@tempa
%
\mwml@set@make@matrix\matrixA{2}{2}{B}
%\show\matrixA
\def\matrixA{%
\mwml@CONS {\mwml@CONS {A}{\mwml@CONS {B}{\mwml@NULL }}}%
{\mwml@CONS {\mwml@CONS {C}{\mwml@CONS {D}{\mwml@NULL }}}%
{\mwml@NULL }}}%
%\show\matrixA
%\mwml@set@make@matrix@contents\mwml@tempa\matrixA
%\show\mwml@tempa
\[
\mwml@output@matrix@with@pmatrix\matrixA
\]
% \let\mwml@tempa\matrixA
% \[
% \mwml@output@matrix@with@pmatrix\mwml@tempa
% \]
% \[
% \mwm@exr\mwml@output@matrix@with@pmatrix\mwml@tempa
% \]
Does it look like the following?
\[
\begin{pmatrix}
A & B \\
C & D
\end{pmatrix}
\]
===========================================
\fbox{test apply}
\def\testapply#1#2{1 #1 2 #2 done}
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
\mwml@apply\relax\listA
%\show\mwml@tempflasque
\mwml@apply\testapply\listA
===========================================
\fbox{test zip}
\def\testzip#1{%
\mwml@set@csl@from@list\@tempa{#1}%
\edef\@tempa{(\@tempa)}%
}
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
\mwml@set@list@from@csl\listB{1,2,3,4,5}
listB = (\mwml@csl@from@list\listB)
\mwml@set@list@from@csl\listC{a,b,c}
listC = (\mwml@csl@from@list\listC)
% \mwml@set@list@from@csl\listA{A,C}
% listA = (\mwml@csl@from@list\listA)
% \mwml@set@list@from@csl\listB{B,D}
% listB = (\mwml@csl@from@list\listB)
\mwml@set@zip@two\mwml@tempa\listA\listB
%\show\mwml@tempa
% \[
% \mwml@output@matrix@with@pmatrix\mwml@tempa
% \]
\mwml@set@map\@tempa\testzip\mwml@tempa
%\show\@tempa
\testzip\@tempa
%\show\@tempa
\@tempa
\[
\mwml@output@matrix@with@pmatrix\mwml@tempa
\]
\mwml@set@zip@two\mwml@tempa\listB\listA
%\show\@tempa
\mwml@set@map\@tempa\testzip\mwml@tempa
\testzip\@tempa
\@tempa
\mwml@set@csl@from@list\@tempa\listA
%\show\@tempa
(\@tempa)
\mwml@set@zip@three\mwml@tempa\listA\listB\listC
\mwml@set@map\@tempa\testzip\mwml@tempa
%\show\@tempa
\testzip\@tempa
%\show\@tempa
\@tempa
\mwml@set@zip@three\mwml@tempa\listB\listC\listA
\mwml@set@map\@tempa\testzip\mwml@tempa
\testzip\@tempa
\@tempa
\mwml@set@zip@three\mwml@tempa\listC\listA\listB
\mwml@set@map\@tempa\testzip\mwml@tempa
\testzip\@tempa
\@tempa
\def\testmaptwo#1#2{%
\def\@tempa{(#1 + #2)}%
}
\def\testmapthree#1#2#3{%
\def\@tempa{(#1 + #2 - #3)}%
}
\mwml@set@map@two\@tempa\testmaptwo\listA\listB
(\mwml@csl@from@list\@tempa)
\mwml@set@map@three\@tempa\testmapthree\listA\listB\listC
(\mwml@csl@from@list\@tempa)
===========================================
\fbox{test length}
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
\mwml@set@list@from@csl\listB{1,2,3,4,5}
listB = (\mwml@csl@from@list\listB)
(length listA) =
\mwml@set@length\@tempa\listA
\@tempa
(length listB) =
\mwml@set@length\@tempa\listB
\@tempa
\mwml@set@length@counter\mwml@@counter\listA
(length listA) = \the\mwml@@counter
===========================================
\fbox{test take drop}
\mwml@set@list@from@csl\listA{A,B,C,D,E}
listA = (\mwml@csl@from@list\listA)
\mwml@set@split@at\@tempa\@tempb\listA{2}
(split-at 2 listA) = ((\mwml@csl@from@list\@tempa), (\mwml@csl@from@list\@tempb))
\mwml@set@split@at\@tempa\@tempb\listA{0}
(split-at 0 listA) = ((\mwml@csl@from@list\@tempa), (\mwml@csl@from@list\@tempb))
\mwml@set@split@at\@tempa\@tempb\listA{5}
(split-at 5 listA) = ((\mwml@csl@from@list\@tempa), (\mwml@csl@from@list\@tempb))
% expect error
% \mwml@set@split@at\@tempa\@tempb\listA{6}
% (split-at 6 listA) = ((\mwml@csl@from@list\@tempa), (\mwml@csl@from@list\@tempb))
\mwml@set@take@nth@drop\@tempa\@tempb\@tempc\listA{2}
(take/nth/drop 2 listA) = ((\mwml@csl@from@list\@tempa), \@tempb, (\mwml@csl@from@list\@tempc))
\mwml@set@take@nth@drop\@tempa\@tempb\@tempc\listA{0}
(take/nth/drop 0 listA) = ((\mwml@csl@from@list\@tempa), \@tempb, (\mwml@csl@from@list\@tempc))
\mwml@set@take@nth@drop\@tempa\@tempb\@tempc\listA{4}
(take/nth/drop 4 listA) = ((\mwml@csl@from@list\@tempa), \@tempb, (\mwml@csl@from@list\@tempc))
% expect error
% (take/nth/drop 5 listA) =
% \mwml@set@take@nth@drop\@tempa\@tempb\@tempc\listA{5}
% ((\mwml@csl@from@list\@tempa), \@tempb, (\mwml@csl@from@list\@tempc))
\mwml@set@take\@tempa\listA{2}
(take 2 listA) = (\mwml@csl@from@list\@tempa)
\mwml@set@take\@tempa\listA{0}
(take 0 listA) = (\mwml@csl@from@list\@tempa)
\mwml@set@take\@tempa\listA{5}
(take 5 listA) = (\mwml@csl@from@list\@tempa)
\mwml@set@drop\@tempa\listA{2}
(drop 2 listA) = (\mwml@csl@from@list\@tempa)
\mwml@set@drop\@tempa\listA{0}
(drop 0 listA) = (\mwml@csl@from@list\@tempa)
\mwml@set@drop\@tempa\listA{5}
(drop 5 listA) = (\mwml@csl@from@list\@tempa)
===========================================
\fbox{test treating non-robust command}
\def\A{\greedysubscript{A}}
\def\listA{\mwml@CONS{A}{\mwml@CONS{B}{\mwml@CONS{C}\mwml@NULL}}}
\def\listAh{\mwml@CONS{\H_{Gal}^1(\aGal_K, A)}{\mwml@CONS{\H_{et}^1(X_\kbar, \Ql)}{\mwml@CONS{\A_0_L}\mwml@NULL}}}
\def\listAm{\mwml@CONS{\map f from X to Y ;}{\mwml@CONS{B}{\mwml@CONS{C}\mwml@NULL}}}
\mwml@set@cons\listB{Z}\listA
%\show\listB
\mwml@set@cons\listB{\H_{Gal}^1(\aGal_K, A)}\listAh
%\show\listB
\mwml@set@cons\listB{Z}\listAm
%\show\listB
\mwml@set@car\@tempa\listA
%\show\@tempa
\mwml@set@car\@tempa\listAh
%\show\@tempa
$\@tempa$
\mwml@set@car\@tempa\listAm
%\show\@tempa
$\@tempa$
\mwml@set@cdr\listB\listA
(cdr listA) = (\mwml@csl@from@list\listB)
\mwml@set@cdr\listB\listAh
(cdr listAh) = $(\mwml@csl@from@list\listB)$
\mwml@set@cdr\listB\listAm
(cdr listAm) = (\mwml@csl@from@list\listB)
(list-ref listAh 0) $\mwml@list@ref\listAh{0}$,
(list-ref listAh 1) $\mwml@list@ref\listAh{1}$ ,\par
(list-ref listAh 2) $\mwml@list@ref\listAh{2}$ ,
\mwml@set@cons\listB{\Hom_{cont}(G, A)}\listAh
\mwml@set@cons\listB{consed}\listB
$(\mwml@csl@from@list\listB)$
\mwml@push{pushed}\listB
\mwml@push{more}\listB
\mwml@push{\map g from Y to Z ;}\listB
$(\mwml@csl@from@list\listB)$
\mwml@set@copy\listB\listAh
$(\mwml@csl@from@list\listB)$
listAh
$(\mwml@csl@from@list\listAh)$
reversed
\mwml@set@reverse\listB\listA
$(\mwml@csl@from@list\listB)$
reversed
\mwml@set@reverse\listB\listAh
$(\mwml@csl@from@list\listB)$
% reversed
% \mwml@reverse\listAh
% $(\mwml@csl@from@list\listAh)$
\mwml@set@list@from@csl\listB{A,B,{\map f from X to Y ;},{\H_{Gal}^1(\aGal_K, A)}}
(A, B, C, DE) = $(\mwml@csl@from@list\listB)$
\def\outinmath#1{$(\mwml@csl@from@list#1)$}
\mwml@set@null\listD
listD = (\mwml@csl@from@list\listD)
\mwml@set@append@reverse\listB\listAh\listAm
(append-reverse listAh listAm) = \outinmath\listB
\mwml@set@append\listB\listAh\listAm
(append listAh listAm) = \outinmath\listB
\mwml@set@append\listB\listAh\listD
(append listAh listD) = \outinmath\listB
$(\mwml@csl@from@list\listB)$
(append listD listAh) =
\mwml@set@append\listB\listD\listAh
(append listD listAh) = \outinmath\listB
\mwml@set@make@list\listB{5}{\H_{Gal}^1(\aGal_K, A)}
(make-list 5 H1) = \outinmath\listB
\def\mwml@map@test#1{%
\mwml@set@map\mwml@tempa\mwml@map@test@aux{#1}%
}
\def\mwml@map@test@aux#1{\edef\mwml@tempa{(#1)}}
\outinmath\listA
\mwml@map@test\listA
(\mwm@exr\mwml@csl@from@list{\mwml@tempa})
% \mwm@enxr\mwml@set@csl@from@list\listB{\mwml@tempa}%
% \show\listB
% \mwml@set@list@from@csl\listB{A,B,C}%
% \mwml@set@csl@from@list\listB\listB
% \show\listB
\mwml@is@null\listAh
(null? listAh) = \if@mwml TRUE \else FALSE \fi
\mwml@set@null\listB
\mwml@is@null\listB
(null? listB) = \if@mwml TRUE \else FALSE \fi
===========================================
\fbox{test apply}
\def\testapply#1#2{1 #1 2 #2 done}
$\mwml@apply\testapply\listAh$
===========================================
\fbox{test zip}
\def\testzip#1{%
\mwml@set@csl@from@list\@tempa{#1}%
% \edef\@tempa{(\@tempa)}%
\toks0\expandafter{\@tempa}%
\edef\@tempa{(\the\toks0)}%
}
\mwml@set@list@from@csl\listA{A,B,C}
listA = (\mwml@csl@from@list\listA)
\mwml@set@list@from@csl\listB{1,2,3,4,5}
listB = (\mwml@csl@from@list\listB)
\mwml@set@list@from@csl\listC{a,b,c}
listC = (\mwml@csl@from@list\listC)
\mwml@set@zip@two\mwml@tempa\listAh\listB
%\mwml@set@zip@two\mwml@tempa\listB\listA
%\show\mwml@tempa
\[
\mwml@output@matrix@with@pmatrix\mwml@tempa
\]
\mwml@set@map\@tempa\testzip\mwml@tempa
\outinmath\@tempa
\mwml@set@zip@three\mwml@tempa\listAh\listB\listC
\mwml@set@map\@tempa\testzip\mwml@tempa
\outinmath\@tempa
\def\testmaptwo#1#2{%
\def\@tempa{(#1 + #2)}%
}
\def\testmapthree#1#2#3{%
\def\@tempa{(#1 + #2 - #3)}%
}
\mwml@set@map@two\@tempa\testmaptwo\listAh\listB
\outinmath\@tempa
\mwml@set@map@three\@tempa\testmapthree\listAh\listB\listC
\outinmath\@tempa
%===========================================
%
%\fbox{}
%
%%\mwml@set@list@from@csl\listA{A,B,C}
%%listA = (\mwml@csl@from@list\listA)
%%
%%\mwml@matrix@convert@line\listA
%%\show\mwml@tempa
%%
%%\mwml@set@make@matrix\matrixA{2}{2}{B}
%%\show\matrixA
%
%\def\matrixA{%
% \mwml@CONS {\mwml@CONS {A}{\mwml@CONS {B}{\mwml@NULL }}}%
% {\mwml@CONS {\mwml@CONS {C}{\mwml@CONS {D}{\mwml@NULL }}}%
% {\mwml@NULL }}}%
%%\show\matrixA
%
%
%%\mwml@set@make@matrix@contents\mwml@tempa\matrixA
%%\show\mwml@tempa
%
%\[
% \mwml@output@matrix@with@pmatrix\matrixA
%\]
%% \let\mwml@tempa\matrixA
%% \[
%% \mwml@output@matrix@with@pmatrix\mwml@tempa
%% \]
%% \[
%% \mwm@exr\mwml@output@matrix@with@pmatrix\mwml@tempa
%% \]
%
%Does it look like the following?
%\[
% \begin{pmatrix}
% A & B \\
% C & D
% \end{pmatrix}
%\]
\let\@tempa\relax
\def\matrixA{%
\mwml@CONS {\mwml@CONS {A}{\mwml@CONS {B}{\mwml@NULL }}}%
{\mwml@CONS {\mwml@CONS {C}{\mwml@CONS {D}{\mwml@NULL }}}%
{\mwml@NULL }}}%
\mwml@set@concatenate\@tempa\matrixA
(A, B, C, D) = (\mwml@csl@from@list\@tempa)
\end{document}
\makeatother
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment