Saturday, May 9, 2020

operators syntax: macros instead of abstract syntax trees

Currently the JSON file has a set of named operators with the attributes "argument count", "latex", "scope". The "argument count" is a non-negative integer and the "scope" is a list with elements like real, complex, vector, matrix. integer.

What's missing is the AST structure that defines where the arguments go with respect to the operator. For example,
x + y
is valid while
x y +
is not.

Similarly,
cos x
is valid while
x cos
is not.

While I can state these concepts I don't know how to formalize the notation.
For example, a definite integral takes 4 arguments in a specific location:
int_x^y f(z) dz

I could express operators using a latex macro


\documentclass[12pt]{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage[dvipdfmx,colorlinks=true,pdfkeywords={physics derivation graph}]{hyperref}
\newcommand\addition[2]{ #1 + #2}
\newcommand\subtraction[2]{ #1 - #2}
\newcommand\divisionSameLine[2]{ #1 / #2 }
\newcommand\divisionFrac[2]{ \frac{ #1}{ #2} }
\newcommand\integralDefinite[4]{ \int_{ #1}^{ #2} #3 #4}
\newcommand\addXtobothsides[3]{Add $#1$ to both sides of Eq.~\ref{eq:#2}; yields Eq.~\ref{eq:#3}.}
\title{Lorentz transformation}
\date{\today}
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{9in}
\setlength{\oddsidemargin}{0in}
\setlength{\textwidth}{6.5in}
\begin{document}
\maketitle
\begin{abstract}
This is the abstract
\end{abstract}

\begin{equation}
\addition{a}{b}
\end{equation}

\begin{equation}
\divisionFrac{a}{b}
\end{equation}

\begin{equation}
\integralDefinite{a}{b}{f(x)}{dx}
\end{equation}

\end{document}

Compile to PDF using

latex runthis.tex 
latex runthis.tex 
dvipdfmx runme.dvi 

No comments:

Post a Comment