Analogy-Making as a Core Primitive in the Software Engineering Toolbox

Matthew Sotoudeh, Aditya V. Thakur

TL;DR

This paper proposes viewing analogy-making as a fundamental primitive for software engineering (SE) tasks like program understanding, optimization, and API migration. They introduce SIFTER, a novel algorithm that uses a flexible triplet-structure representation to make analogies across diverse SE inputs, including code and documentation.

What Problem Does This Paper Address?

Software engineering tasks often involve understanding and manipulating complex code. Humans intuitively use analogies to tackle these problems – for example, understanding new code by relating it to familiar codebases or generalizing a fix from a few examples. However, existing computational approaches struggle to capture this analogical reasoning effectively, especially when dealing with the rich, multi-faceted nature of software (syntax, semantics, documentation, etc.). This paper aims to bridge this gap by proposing analogy-making as a core, computationally tractable primitive for SE.

Methods

The authors introduce SIFTER, an analogy-making algorithm built upon a novel triplet-structure representation. This structure is a flexible way to represent objects and relational facts, allowing for arbitrary arity and partial information. SIFTER operates by defining update rules that modify this triplet structure, either by inferring new facts (like "letter X is a successor of letter Y") or by building analogies. Analogies are represented as abstractions within the triplet structure, where concrete objects are mapped to abstract types. SIFTER's design is influenced by the Copycat algorithm but generalized to handle arbitrary relations and inputs, making it suitable for SE.

Datasets

Not discussed in the paper. The paper focuses on demonstrating the approach with illustrative examples rather than formal evaluation on large datasets.

Key Insights and Ideas

  • Analogy as a Universal SE Primitive: The core idea is that many SE problems, from understanding code to migrating APIs, can be reframed as analogy-making tasks. This offers a unifying perspective.
  • Triplet Structures for Flexibility: The novel triplet-structure representation is key. It allows SIFTER to handle diverse inputs (code, documentation, semantic information) and arbitrary relations, overcoming limitations of systems tied to specific representations like ASTs.
  • Abstraction for Analogy Representation: Representing analogies as abstractions within the triplet structure provides a clear and extensible mechanism for capturing correspondences.
  • Compositional Analogy Building: SIFTER can build analogies incrementally, using previously identified correspondences to infer new ones, mirroring how humans build understanding.
  • Handling "Slips" and Ambiguity: The framework is designed to handle nuances like "slips" (e.g., reversed order in strings) and to integrate semantic information, which is crucial for robust software analysis.

Key Results

The paper demonstrates SIFTER's capabilities through several examples:

  • Program Understanding: SIFTER can map functions and objects between different codebases (e.g., bash and fish shells), aiding comprehension.
  • Program Transformation Learning: SIFTER can learn to optimize code (e.g., replacing gemm_large with gemm_skinny) by generalizing from example code pairs, even incorporating semantic constraints.
  • API Migration: SIFTER can infer code changes needed for API migration by learning from example code pairs and documentation.

While no quantitative results are presented, the qualitative demonstrations show SIFTER's potential to automate complex SE tasks by leveraging analogical reasoning.

Limitations and Future Work

  • Heuristics for Analogy Strength: The paper acknowledges the need for better heuristics to guide the search for strong analogies and avoid false positives.
  • Computational Complexity: While optimizations are discussed, constraint satisfaction problems in triplet structures can still be NP-hard.
  • Integration with Other Engines: The authors envision SIFTER as a "glue" for various reasoning engines (logic-based, statistical, DNNs) and suggest future work on probabilistic triplet structures and a unified workspace.
  • Dynamic Granularity: Allowing the encoding of source code to change dynamically during the analogy process is a promising future direction.
  • Cognitive Models: Integrating SIFTER with cognitive architectures like LIDA and Global Workspace Theory is suggested for more sophisticated analogy-making.
  • Meta-Reasoning: Extending SIFTER to support meta-reasoning, where it can introspect on its own solving process, is a long-term goal.

Summary updated

Abstract

An analogy is an identification of structural similarities and correspondences between two objects. Computational models of analogy making have been studied extensively in the field of cognitive science to better understand high-level human cognition. For instance, Melanie Mitchell and Douglas Hofstadter sought to better understand high-level perception by developing the Copycat algorithm for completing analogies between letter sequences. In this paper, we argue that analogy making should be seen as a core primitive in software engineering. We motivate this argument by showing how complex software engineering problems such as program understanding and source-code transformation learning can be reduced to an instance of the analogy-making problem. We demonstrate this idea using Sifter, a new analogy-making algorithm suitable for software engineering applications that adapts and extends ideas from Copycat. In particular, Sifter reduces analogy-making to searching for a sequence of update rule applications. Sifter uses a novel representation for mathematical structures capable of effectively representing the wide variety of information embedded in software. We conclude by listing major areas of future work for Sifter and analogy-making in software engineering.
BibTeX
@inproceedings{sotoudeh2020analogy,
  author = {Matthew Sotoudeh and Aditya V. Thakur},
  title = {{Analogy-Making as a Core Primitive in the Software Engineering Toolbox}},
  booktitle = {Onward!},
  year = {2020},
  doi = {10.1145/3426428.3426918},
}
Figure