Semantic Preserving Bijective Mappings of Mathematical Formulae between Document Preparation Systems and Computer Algebra Systems

📝 Abstract
Document preparation systems like LaTeX offer the ability to render mathematical expressions as one would write these on paper. Using LaTeX, LaTeXML, and tools generated for use in the National Institute of Standards (NIST) Digital Library of Mathematical Functions, semantically enhanced mathematical LaTeX markup (semantic LaTeX) is achieved by using a semantic macro set. Computer algebra systems (CAS) such as Maple and Mathematica use alternative markup to represent mathematical expressions. By taking advantage of Youssef’s Part-of-Math tagger and CAS internal representations, we develop algorithms to translate mathematical expressions represented in semantic LaTeX to corresponding CAS representations and vice versa. We have also developed tools for translating the entire Wolfram Encoding Continued Fraction Knowledge and University of Antwerp Continued Fractions for Special Functions datasets, for use in the NIST Digital Repository of Mathematical Formulae. The overall goal of these efforts is to provide semantically enriched standard conforming MathML representations to the public for formulae in digital mathematics libraries. These representations include presentation MathML, content MathML, generic LaTeX, semantic LaTeX, and now CAS representations as well.
💡 Analysis
Document preparation systems like LaTeX offer the ability to render mathematical expressions as one would write these on paper. Using LaTeX, LaTeXML, and tools generated for use in the National Institute of Standards (NIST) Digital Library of Mathematical Functions, semantically enhanced mathematical LaTeX markup (semantic LaTeX) is achieved by using a semantic macro set. Computer algebra systems (CAS) such as Maple and Mathematica use alternative markup to represent mathematical expressions. By taking advantage of Youssef’s Part-of-Math tagger and CAS internal representations, we develop algorithms to translate mathematical expressions represented in semantic LaTeX to corresponding CAS representations and vice versa. We have also developed tools for translating the entire Wolfram Encoding Continued Fraction Knowledge and University of Antwerp Continued Fractions for Special Functions datasets, for use in the NIST Digital Repository of Mathematical Formulae. The overall goal of these efforts is to provide semantically enriched standard conforming MathML representations to the public for formulae in digital mathematics libraries. These representations include presentation MathML, content MathML, generic LaTeX, semantic LaTeX, and now CAS representations as well.
📄 Content
문서 작성 시스템 중 LaTeX와 같은 시스템은 수학식을 종이에 적듯이 화면에 그대로 렌더링할 수 있는 기능을 제공합니다. LaTeX를 이용하면 수학식의 시각적 표현뿐만 아니라, 수식의 의미론적 구조까지도 기술할 수 있는데, 이를 위해서는 semantic LaTeX라 불리는 의미론적으로 강화된 LaTeX 마크업이 필요합니다. 의미론적 LaTeX은 일반적인 LaTeX 명령어에 추가적인 의미 정보를 담은 매크로 집합을 적용함으로써 구현됩니다. 이러한 매크로 집합은 수식의 연산자, 피연산자, 함수, 그리고 그들 사이의 관계를 명시적으로 표시하도록 설계되었습니다.
국립표준기술연구소(NIST)에서 운영하는 **Digital Library of Mathematical Functions (DLMF)**는 방대한 수학 함수와 그 특성을 디지털 형태로 제공하는 저장소이며, 여기서는 LaTeX와 LaTeXML을 활용해 수식 데이터를 표준화된 형태로 변환합니다. LaTeXML은 LaTeX 소스를 XML 기반의 MathML로 변환해 주는 도구로, 특히 Presentation MathML과 Content MathML을 동시에 생성함으로써 인간이 읽기 쉬운 형태와 기계가 해석하기 쉬운 형태를 모두 제공할 수 있습니다.
한편, Maple, Mathematica와 같은 **Computer Algebra System (CAS)**은 자체적인 내부 표현 방식을 사용하여 수학식을 다룹니다. CAS 내부 표현은 일반적으로 트리 구조의 추상 구문 트리(AST) 형태이며, 이는 수식의 연산 순서와 변수 바인딩 정보를 정확히 보존합니다. 따라서 CAS와 LaTeX 사이에 의미를 보존하면서 변환하는 작업은 단순한 문자열 치환을 넘어, 두 시스템이 공유하는 의미론적 모델을 매핑하는 복잡한 과정이 요구됩니다.
이러한 변환 문제를 해결하기 위해 우리는 Youssef의 Part‑of‑Math 태거와 각 CAS가 제공하는 내부 표현 API를 활용했습니다. Part‑of‑Math 태거는 텍스트 내에서 수학식이 차지하는 영역을 자동으로 식별하고, 해당 영역에 대한 메타데이터(예: 수식 종류, 사용된 기호, 구문 트리 등)를 부착합니다. 이 메타데이터를 기반으로 우리는 다음과 같은 두 가지 주요 알고리즘을 설계했습니다.
Semantic LaTeX → CAS 표현 변환 알고리즘
- 입력으로 제공된 의미론적 LaTeX 코드를 파싱하여 의미 매크로를 추출합니다.
- 추출된 매크로와 일반 LaTeX 토큰을 결합해 중간 표현인 MathML(Presentation + Content)로 변환합니다.
- 생성된 Content MathML을 CAS가 이해할 수 있는 OpenMath 혹은 직접적인 AST 형태로 매핑합니다.
- 마지막 단계에서는 매핑된 AST를 해당 CAS의 함수 호출 형태(예:
Maple: int(f(x), x)혹은Mathematica: Integrate[f[x], x])로 변환합니다.
CAS 표현 → Semantic LaTeX 변환 알고리즘
- CAS 내부에서 제공하는 AST 혹은 OpenMath 객체를 받아들여, 각 노드에 대응되는 의미 매크로 사전을 조회합니다.
- 매크로 사전은 연산자, 함수, 특수 기호 등에 대한 LaTeX 정의와 그 의미론적 태그를 포함합니다.
- 노드 순회를 통해 트리를 재구성하고, 재구성된 트리를 기반으로 의미 매크로를 삽입한 LaTeX 문자열을 생성합니다.
- 최종적으로 생성된 LaTeX 문자열은 기존의 semantic LaTeX 규격에 맞게 포맷팅되어, 인간이 읽기에도, 기계가 재해석하기에도 적합한 형태가 됩니다.
이 두 알고리즘을 실제 데이터에 적용해 본 결과, 우리는 Wolfram Encoding Continued Fraction Knowledge와 University of Antwerp Continued Fractions for Special Functions라는 두 대규모 데이터셋을 성공적으로 변환할 수 있었습니다. 첫 번째 데이터셋은 Wolfram Research에서 제공하는 연속분수(continued fraction) 표현을 포함하고 있으며, 두 번째 데이터셋은 안트워프 대학교에서 수집한 특수 함수에 대한 연속분수 전개식을 담고 있습니다. 두 데이터셋 모두 원본은 각각 Wolfram 언어의 내부 표현 혹은 전통적인 LaTeX 형태로 저장되어 있었으나, 우리의 변환 파이프라인을 거치면서 semantic LaTeX, Presentation MathML, Content MathML, 그리고 CAS 전용 표현까지 모두 포함하는 다중 포맷 형태로 재구성되었습니다.
이러한 변환 작업은 단순히 포맷을 바꾸는 수준을 넘어, 의미론적 일관성을 유지한다는 점에서 큰 의미를 가집니다. 예를 들어, 연속분수의 경우 분자와 분모가 무한히 반복되는 구조를 갖는데, 이 구조를 LaTeX에서는 \cfrac{...}{...}와 같은 매크로로 표현하지만, CAS에서는 재귀적인 함수 호출 형태로 모델링됩니다. 우리의 알고리즘은 이러한 재귀 구조를 정확히 인식하고, 양쪽 포맷 모두에서 동일한 수학적 의미를 보존하도록 설계되었습니다.
이제 우리는 변환된 결과물을 NIST Digital Repository of Mathematical Formulae에 업로드하여, 전 세계 연구자들이 자유롭게 접근하고 활용할 수 있도록 하고 있습니다. 이 저장소는 다음과 같은 5가지 표준 포맷을 모두 제공함으로써, 다양한 사용 시나리오를 지원합니다.
- Presentation MathML: 화면에 수식을 시각적으로 표시하기 위한 포맷.
- Content MathML: 수식의 의미론적 구조를 기술하여 기계가 연산을 수행할 수 있게 함.
- Generic LaTeX: 전통적인 LaTeX 소스 코드 형태, 대부분의 논문 및 교재에서 사용.
- Semantic LaTeX: 의미 매크로가 삽입된 확장형 LaTeX, 인간과 기계 모두가 의미를 파악 가능.
- CAS 표현: Maple, Mathematica 등 각 CAS가 내부적으로 사용하는 구문 트리 혹은 함수 호출 형태.
궁극적인 목표는 디지털 수학 도서관에 수록된 모든 수식이 이러한 풍부한 메타데이터와 다중 포맷을 통해 표준화된 MathML 형태로 제공되는 것입니다. 이를 통해 연구자는 웹 브라우저에서 바로 수식을 시각화하고, 동시에 해당 수식을 CAS에 직접 입력하여 계산을 수행하거나, 의미론적 검색 엔진을 이용해 관련 수식을 찾아볼 수 있게 됩니다.
요약하면, 우리는 LaTeX 기반의 의미론적 마크업과 CAS 내부 표현 사이의 양방향 변환을 가능하게 하는 알고리즘을 구현했으며, 이를 실제 대규모 연속분수 데이터셋에 적용하여 NIST 디지털 저장소에 통합했습니다. 앞으로는 이 파이프라인을 확장하여 더 다양한 수학 분야(예: 특수 함수, 군론, 위상수학 등)의 데이터셋에도 적용하고, 자동화된 검증 절차와 사용자 친화적인 인터페이스를 제공함으로써, 전 세계 수학 커뮤니티가 보다 효율적으로 디지털 수학 지식을 공유하고 활용할 수 있도록 기여하고자 합니다.