[Ann] Symbolic Algebra package

I am happy to announce that I’ve finished a stable version of a new package / library. All started when I wanted a Calculator in Pharo, for which I needed a parser, and then I needed to store Mathematical expressions, and variables, and constants, and precedence and simplification and other hundred things. Eventually became a small Symbolic Algebra package. The name is Mathemagics. Has the ability to either build expressions manually with messages, or via a built-in parser. It can simplify an expression (such as x*x = x^2), supports Number-like methods, and even a bit of Calculus generating derivatives.

Parse via expression, simplify, sort terms, use symbols (pi => π)

  | fx |
  "Notice that constants like pi display a symbol (both input supported)"
  fx := MathExpression from: 'x*x - (pi * -1) + x*8/1'.
  fx simplify.                                                  "x^2 + 8·x + π"

Derivatives

  | fx dFx |
  fx := MathExpression from: 'x*x + ln(x)'.
  dFx:= fx derivativeFor: 'x'.                                  "2·x + 1/x"

Block generation

  "Expression to a Smalltalk BlockClosure"
  | fx x |
  "Math precedence means no parenthesis required"
  fx := MathExpression from: 'x + 3 * pi'.                      "x + π·3"

  "New method will generate code with Smalltalk precedence"
  fx asBlock                                                    "[ 😡 | x + (3 * Float pi) ]"

It comes a small footprint Parser, with a help on Pharo Help, and with the Calculator added to the menu. Here is the GitHub page for download. Please let me know your opinion. Has involved lots of hours, hope is useful to many.

https://github.com/grpistoia/Mathemagics

Parse via expression, simplify, sort terms, use symbols (pi => π)

  | fx |
  "Notice that constants like pi display a symbol (both input supported)"
  fx := MathExpression from: 'x*x - (pi * -1) + x*8/1'.
  fx simplify.                                                  "x^2 + 8·x + π"

Derivatives

  | fx dFx |
  fx := MathExpression from: 'x*x + ln(x)'.
  dFx:= fx derivativeFor: 'x'.                                  "2·x + 1/x"

Block generation

  "Expression to a Smalltalk BlockClosure"
  | fx x |
  "Math precedence means no parenthesis required"
  fx := MathExpression from: 'x + 3 * pi'.                      "x + π·3"

  "New method will generate code with Smalltalk precedence"
  fx asBlock                                                    "[ 😡 | x + (3 * Float pi) ]"

Gus on discord

%d bloggers like this: