Hasty Briefsbeta

BQN "Macros" with •Decompose (2023)

2 days ago
  • #BQN
  • #Functional Programming
  • #Symbolic Differentiation
  • •Decompose is a BQN system function that breaks down compound functions, providing access to their syntax tree.
  • It only works with tacit functions and doesn't delay evaluation or handle invalid syntax.
  • The function returns a list where the first element is a code indicating the function's structure, followed by its components.
  • AST helper function recursively decomposes a function into its abstract syntax tree (AST) and can reassemble it back.
  • Example applications include alternate train semantics (e.g., transforming 3-trains into nested 2-trains) and symbolic differentiation.
  • Symbolic differentiation modifier (_d) can compute derivatives of functions, though it lacks simplification capabilities.
  • Newton's method implementation (_newton_) uses •Decompose for root finding, demonstrating practical utility.