# Mathematica Migration Guide

This guide is for Mathematica / Wolfram Language users moving symbolic
calculation, notebook, and research-code workflows to Kalika.

Official source references used while preparing this guide:

- Wolfram `Integrate`:
  <https://reference.wolfram.com/language/ref/Integrate.html>
- Wolfram `Series`: <https://reference.wolfram.com/language/ref/Series.html>
- Wolfram `Solve`: <https://reference.wolfram.com/language/ref/Solve.html>

## Quick Mapping

| Mathematica                          | Kalika TypeScript                                          | Kalika Python                           | Notes                                                                                                                                |
| ------------------------------------ | ---------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `Simplify[expr]`                     | `sdk.simplify(expr)`                                       | `simplify(expr)`                        | Kalika returns a result wrapper in TypeScript and an expression facade in Python helpers.                                            |
| `FullSimplify[expr]`                 | `runEqualitySaturation(...)` with `createRewriteRule(...)` | Use TypeScript core for custom rewrites | Model expensive rewrite strategy explicitly rather than relying on one global simplifier.                                            |
| `D[expr, x]`                         | `sdk.differentiate(expr, "x")`                             | `diff(expr, x)`                         | Variables are strings in TypeScript and `Symbol` helpers in Python.                                                                  |
| `Integrate[expr, x]`                 | `sdk.integrate(expr, "x")`                                 | `integrate(expr, x)`                    | Definite and multidimensional integrations should be represented through domain/numerical packages until a direct SDK facade exists. |
| `N[expr]`                            | `sdk.evaluate(expr, values)`                               | `N(expr, values)`                       | Numeric evaluation is explicit and reports execution metadata.                                                                       |
| `Solve[eqn, x]`                      | `sdk.solve(eqn, "x")`                                      | `solve(eqn, x)`                         | Current SDK solve facade targets linear equations; use domain packages for structured systems.                                       |
| `Series[f, {x, a, n}]`               | `sdk.series(f, "x", a, n)`                                 | `series(f, x, a, n)`                    | For asymptotics, use `taylorAsymptoticExpansion`.                                                                                    |
| `Limit[f, x -> a]`                   | `sdk.limit(f, "x", a)`                                     | `limit(f, x, a)`                        | Limits return structured SDK result metadata.                                                                                        |
| `MatrixForm`, `Det`, `Inverse`, `Tr` | `sdk.matrix(...)` or `determinant(...)`                    | `client.matrix(...)`                    | Use `@kalika/algebra` for exact rational matrices.                                                                                   |
| `FactorInteger`, `PrimeQ`            | `factorInteger`, `isPrime`                                 | TypeScript domain package               | Number theory lives in `@kalika/number-theory`.                                                                                      |
| `TeXForm[expr]`                      | `serializeExprToLatex`, `renderLatexEquation`              | TypeScript domain package               | Use core serialization for expressions and typesetting for publication output.                                                       |

## Syntax and Notation

| Wolfram Pattern             | Kalika Pattern                                                                   |
| --------------------------- | -------------------------------------------------------------------------------- |
| `Head[args]` syntax         | TypeScript/Python function calls and expression strings.                         |
| Lists `{1, 2, 3}`           | JavaScript arrays or Python lists.                                               |
| Rules `x -> 2`              | Explicit substitution, rewrite rules, or SDK variable maps.                      |
| Global `$Assumptions`       | Pass assumptions through domain-specific options or proof contexts.              |
| Notebook-global definitions | Notebook cells, SDK clients, or plain module imports.                            |
| Implicit exact arithmetic   | Choose `@kalika/algebra` exact rationals or SDK numerical evaluation explicitly. |

## TypeScript Examples

```ts
import { createKalikaSdk } from '@kalika/sdk';
import { determinant, rationalMatrix } from '@kalika/algebra';

const sdk = await createKalikaSdk();

const derivative = sdk.differentiate('x^3 + 2*x', 'x');
const integral = sdk.integrate('sin(x)', 'x');
const series = sdk.series('exp(x)', 'x', 0, 5);
const numeric = sdk.evaluate('sin(x)^2 + y', { x: Math.PI / 2, y: 3 });

const exactMatrix = rationalMatrix([
  [1, 2],
  [3, 5],
]);
const det = determinant(exactMatrix);

console.log(
  derivative.result,
  integral.result,
  series.result,
  numeric.result,
  det
);
```

## Python Examples

```python
from kalika_sdk import N, KalikaClient, diff, integrate, series, solve, symbols

x = symbols("x")
client = KalikaClient()

print(diff(x**3 + 2 * x, x))
print(integrate("sin(x)", x))
print(series("exp(x)", x, 0, 5))
print(N("sin(x)^2 + y", {"x": 1.57079632679, "y": 3}))
print(solve("2*x + 4 = 10", x))
print(client.verify(client.diff("x^2", "x")))
```

## Migration Checklist

- Replace square-bracket Wolfram calls with SDK or domain-package calls.
- Convert replacement rules and assumptions into explicit request data.
- Audit every use of `FullSimplify`; decide whether SDK simplification, equality
  saturation, or a domain-specific identity is the right target.
- Separate exact algebra (`@kalika/algebra`) from numerical execution
  (`@kalika/sdk`, `@kalika/numerical`).
- Preserve publication output by replacing `TeXForm`/notebook export paths with
  `@kalika/core`, `@kalika/notebooks`, and `@kalika/typesetting`.
