Abstract
This paper discusses a Domain Specific Language (DSL) that has been developed to enable implementation of concepts of discrete mathematics. A library of data types and functions provides functionality which is frequently required by users. Covering the areas of Mathematical Logic, Set Theory, Functions, Graph Theory, Number Theory, Linear Algebra and Combinatorics, the language's syntax is close to the actual notation used in the specific fields.
Introduction
Discrete mathematics serves as the foundational language of computer science. However, implementing its abstract concepts in General Purpose Languages (GPLs) like C++, Java, or Python often introduces a significant "translation gap." Researchers and students must frequently convert elegant mathematical notation into verbose, state-heavy code, which can obscure the underlying logic and increase the likelihood of errors. To address this friction, this work introduces a Domain-Specific Language (DSL) designed to mirror mathematical jargon, allowing users to focus on problem-solving rather than low-level implementation details.
System Architecture and Methodology
The authors chose Haskell as the host language for the DSL due to its purely functional nature, which treats computation as the evaluation of mathematical functions. The system is implemented as a Preprocessed DSL, utilizing a custom syntactic preprocessor to bridge the gap between math-friendly syntax and executable code.
As shown in the workflow above, the process begins with a DSL program written in math-like syntax (e.g., using ==> for logical implication). The preprocessor translates this into standard Haskell code, which is then compiled by the Glasgow Haskell Compiler (GHC) alongside a specialized library of data structures. This approach allows for high-performance binaries while maintaining a high level of abstraction.
Core Features: Functional Parity and Laziness
Two key features of Haskell are leveraged to ensure the DSL behaves like mathematical theory:
- Functional Parity: Because data is immutable in a functional paradigm, an expression always yields the same result. This ensures that code behaves like a mathematical theorem rather than a shifting piece of memory.
- Lazy Evaluation: This allows for the definition of infinite sets, such as the set of all natural numbers (
[1..]). The system only calculates specific values as they are requested at runtime, preventing system crashes and enabling more natural mathematical modeling.
Implementation and Results
The DSL successfully implements seven core modules: Mathematical Logic, Set Theory, Functions, Graph Theory, Number Theory, Linear Algebra, and Combinatorics. The Graph Theory module, for instance, allows for the intuitive definition and manipulation of complex structures, including both directed and undirected graphs.
Beyond basic structures, the language has been used to implement real-world applications, including RSA encryption/decryption workflows, simultaneous linear equation solvers using matrix representations, and efficient generators for Mersenne primes. The system maintains a lightweight footprint, requiring only 128 MB of RAM and GHC version 7.0.4 or later, making it accessible for educational settings with older hardware.
Conclusion and Future Directions
While the current iteration covers a broad range of discrete mathematics, the authors acknowledge that fields such as Group Theory, Information Theory, and Topology remain for future development. Future work will also focus on refining syntax based on user feedback from students and educators to further minimize the learning curve associated with the Haskell ecosystem and compiler environment.
Summary updated