next up previous contents
Next: 4.3 DOCFOR Up: 4.2 SRC2TEX Previous: 4.2 SRC2TEX

Example:

A Mathematica program documented in a src2latex-compliant manner is depicted in Table 5.

 

% {\bf sqrt\_mat.red}

% {\null For a given $2\times2$ matrix $\,A\ge0\,$, we shall prove that
% $$
% \sqrt{A}={1\over\sqrt{2\sqrt{ac-b^2}+a+c}}
% \pmatrix{
% \sqrt{ac-b^2}+a & b \cr
% b & \sqrt{ac-b^2}+c \cr}
% $$}
%

on div;

% {\null For a given matrix
% $
% A=\pmatrix{ a & b \cr b & c \cr}
% $
% ,\ we shall find a matrix
% $
% X=\pmatrix{ x & y \cr y & z \cr}
% $
% satisfying $A=X^2$.}
%

mat_a:=mat((a,b),(b,c));
mat_x:=mat((x,y),(y,z));

% {\null The equation
% $\,A=X^2\,$ is translated into algebraic equations
% $$
% x^2+y^2=a,\ y(x+z)=b,\ y^2+z^2=c \leqno(1)
% $$}
%

mat_xx:=mat_x*mat_x;

% {\null (1) is equivalent to
% $$
% x=\sqrt{a-y^2},
%	\ y\bigl(\sqrt{a-y^2}+\sqrt{c-y^2}\,\bigr)=b,
%	\ z=\sqrt{c-y^2} \leqno(2)
% $$
% We put
% $$
% f(y)=\sqrt{a-y^2},
% \ g(y)=y\bigl(\sqrt{a-y^2}+\sqrt{c-y^2}\,\bigr)-b,
% \ h(y)=\sqrt{c-y^2} \leqno(3)
% $$}
%

func_f:=rhs(first(solve(mat_xx(1,1)=a,x)));
func_h:=rhs(first(solve(mat_xx(2,2)=c,z)));
func_g:=sub({x=func_f,z=func_h},mat_xx(1,2))-b;

% {\null We define a function $\,g_1(w)\,$ by
% $$
% g_1(w)=g(y)\;{\sqrt{a-y^2}-\sqrt{c-y^2}\over y}\;\Bigg|_{y=1/w}
%	=-b\sqrt{aw^2-1}+b\sqrt{cw^2-1}+a-c \leqno(4)
% $$}
%

func_g1:=sub(y=1/w,func_g*(sqrt(a-y^2)-sqrt(c-y^2))/y);

 
Table 5: An example of a Mathematica program documented in a src2latex compliant manner. The full flexibility of LaTeXis available, although in a very unstructured way.

src2tex and src2latex were built in particular for the needs of the Japanese to including Kanji characters into software documentation. Since the DAO cannot take advantage of that feature, what remains is a very simple system to put TeX and LaTeX\ documentation into code. This is not sufficient for the DAO's needs -- since there are certain prescribed conventions in the softare standard for documenting code.



Will Sawyer
Fri Mar 6 18:02:18 EST 1998