Skip to main content
QUICK REVIEW

[Paper Review] How to turn a scripting language into a domain specific language for computer algebra

Raphaël Jolly, Heinz Kredel|ArXiv.org|Nov 6, 2008
Model-Driven Software Engineering Techniques9 references3 citations
TL;DR

This paper proposes using modern scripting languages like Python, Ruby, Groovy, or Scala as interactive front-ends for Java-based computer algebra systems (CAS), enabling intuitive symbolic mathematics through operator overloading and dynamic symbol handling. The key finding is that all four languages can effectively serve as domain-specific languages (DSLs) for CAS with minimal implementation overhead, offering seamless Java library integration and expressive, paper-and-pencil-like mathematical notation.

ABSTRACT

We have developed two computer algebra systems, meditor [Jolly:2007] and JAS [Kredel:2006]. These CAS systems are available as Java libraries. For the use-case of interactively entering and manipulating mathematical expressions, there is a need of a scripting front-end for our libraries. Most other CAS invent and implement their own scripting interface for this purpose. We, however, do not want to reinvent the wheel and propose to use a contemporary scripting language with access to Java code. In this paper we discuss the requirements for a scripting language in computer algebra and check whether the languages Python, Ruby, Groovy and Scala meet these requirements. We conclude that, with minor problems, any of these languages is suitable for our purpose.

Motivation & Objective

  • Address the lack of interactive, user-friendly scripting interfaces for Java-based computer algebra systems (CAS).
  • Overcome the limitations of custom DSLs by reusing existing, mature scripting languages with strong Java interoperability.
  • Enable natural mathematical expression input and manipulation in a way that mirrors paper-and-pencil notation.
  • Evaluate and compare multiple modern scripting languages for their suitability in implementing a CAS front-end.
  • Establish a reusable framework for integrating symbolic computation libraries with high-level, interactive scripting environments.

Proposed method

  • Evaluate scripting languages (Python, Ruby, Groovy, Scala) for key CAS requirements: symbol definition, operator overloading, and extension of built-in types.
  • Implement a prototype using toy code to demonstrate symbol creation and arithmetic operator overriding in each language.
  • Leverage Java interop features to access existing Java-based CAS libraries (e.g., JAS, meditor) directly from scripting environments.
  • Explore multiple strategies for coercion and operator resolution: reverse method calls (Python), explicit coercion methods (Ruby), context-specific operator binding (Groovy), and implicit view-based conversions (Scala).
  • Design wrapper classes and factory methods to map string-based expressions to native algebraic types (e.g., PolynomialRing, Expression).
  • Assess trade-offs in performance, expressiveness, and maintainability across the four languages, focusing on minimal code changes for full functionality.

Experimental results

Research questions

  • RQ1Can modern scripting languages be effectively repurposed as domain-specific languages (DSLs) for interactive computer algebra?
  • RQ2What are the critical language features required for a scripting language to support intuitive symbolic mathematics in a CAS context?
  • RQ3How do different scripting languages (Python, Ruby, Groovy, Scala) support operator overloading and type coercion for algebraic expressions?
  • RQ4What are the performance and maintainability trade-offs when extending built-in types or implementing custom coercion mechanisms in these languages?
  • RQ5To what extent can existing Java-based CAS libraries be exposed through scripting front-ends without requiring major reimplementation?

Key findings

  • All four evaluated scripting languages—Python, Ruby, Groovy, and Scala—can effectively serve as front-ends for Java-based computer algebra systems with minimal effort.
  • Python supports the required functionality with the least complexity, primarily through reverse method overloading (e.g., __radd__, __rmul__) to enable seamless interaction between expressions and numbers.
  • Ruby enables coercion via explicit `coerce()` methods and can extend built-in classes, though this may incur performance costs.
  • Groovy requires context blocks for operator binding, which limits interactive use, and extending built-in types demands low-level reimplementation of operators.
  • Scala’s view bounds and implicit conversions provide a clean, scalable mechanism for coercion, making it highly suitable for complex algebraic type systems.
  • The study concludes that with minor implementation adjustments, any of the four languages can successfully transform into a usable DSL for computer algebra, enabling expressive, readable, and interactive symbolic computation.

Better researchstarts right now

From reading papers to final review, dramatically reduce your research time.

No credit card · Free plan available

This review was created by AI and reviewed by human editors.