Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Bug report
description: Something works incorrectly or crashes
labels: [bug]
body:
- type: textarea
id: description
attributes:
label: Description
description: What happened, and what did you expect?
validations:
required: true
- type: input
id: version
attributes:
label: symcas version
description: Output of `cargo tree -i symcas` or the version in your Cargo.toml
validations:
required: true
- type: input
id: rust
attributes:
label: Rust version
description: Output of `rustc -V`
- type: dropdown
id: os
attributes:
label: OS
options: [Linux, macOS, Windows]
- type: textarea
id: repro
attributes:
label: Minimal reproduction
description: A self-contained code snippet that reproduces the issue
render: rust
validations:
required: true
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Feature request
description: Suggest new functionality or an improvement
labels: [enhancement]
body:
- type: textarea
id: problem
attributes:
label: Problem
description: What is missing or painful today?
validations:
required: true
- type: textarea
id: solution
attributes:
label: Proposed solution
description: What should symcas do instead?
validations:
required: true
12 changes: 12 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Summary

<!-- What does this PR change and why? -->

## Checklist

- [ ] Summary explains motivation and the change itself
- [ ] New/changed behavior is covered by tests (unit, doctest, or property tests)
- [ ] `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets --locked -- -D warnings`, and `cargo test --workspace --locked` pass locally
- [ ] No undocumented public API changes (doc comments updated)

Closes #<issue number, if any>
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
commit-message:
prefix: "chore(deps)"
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: "chore(deps)"
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 推送 v* 标签时自动创建 GitHub Release,变更日志由 GitHub 自动生成。
# 不含 crates.io 发布(需要 CARGO_REGISTRY_TOKEN secret,暂不引入)。
name: Release

on:
push:
tags: ["v*"]

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write

jobs:
github-release:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: 创建 GitHub Release(自动生成变更日志)
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" --generate-notes --verify-tag
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition = "2024"
rust-version = "1.85"
license = "MIT OR Apache-2.0"
repository = "https://github.com/cislunarspace/cas"
homepage = "https://github.com/cislunarspace/cas"
homepage = "https://docs.rs/symcas"
readme = "README.md"
categories = ["mathematics", "science"]
keywords = ["cas", "computer-algebra", "symbolic", "mathematics"]
Expand Down
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Fast, deterministic computer algebra system in Rust.

`symcas` provides a canonical expression arena with hash-consing, exact arithmetic over arbitrary precision rational numbers, ordered sparse multivariate polynomials, symbolic differentiation, series expansions, directed simplifications, roundtrip plain parsing, and LaTeX rendering.

**English** | [简体中文](README.zh-CN.md)

[![CI](https://github.com/cislunarspace/cas/actions/workflows/ci.yml/badge.svg)](https://github.com/cislunarspace/cas/actions/workflows/ci.yml)
[![Crates.io](https://img.shields.io/crates/v/symcas)](https://crates.io/crates/symcas)
[![Docs.rs](https://docs.rs/symcas/badge.svg)](https://docs.rs/symcas)
[![License](https://img.shields.io/crates/l/symcas)](#license)

## Contents

- [Key Features](#key-features)
- [Architecture](#architecture)
- [Quickstart](#quickstart)
- [Documentation](#documentation)
- [License](#license)

## Key Features

- **Canonical Construction & O(1) Equality**: Expressions are automatically normalized upon construction through flattening, term sorting, exact arithmetic folding, and like-term combination. Equivalent expressions within the same `Context` share an identical arena handle (`Expr::raw_id`).
Expand Down Expand Up @@ -32,11 +47,29 @@ Add `symcas` to your `Cargo.toml`:

```toml
[dependencies]
symcas = "0.1.0"
symcas = "0.1"
```

Requires Rust 1.85+ (enforced via `rust-version` in Cargo.toml).

### Basic Workflow

Every symcas session follows the same standard procedure:

1. **Create a `Context`**, the arena that owns every expression: `Context::new()`.
2. **Create atoms**: `ctx.sym("x")` for symbols, `ctx.int(2)` for integers, `ctx.int(1) / ctx.int(2)` for exact rationals; declare several symbols at once with `sym!(&ctx, x, y)`.
3. **Build or parse an expression**: combine atoms with `+`, `-`, `*`, `/`, `.pow(n)` and `ctx.call("sin", &[x.clone()])`, or read text with `symcas::parse(&ctx, "sin(x)^2")`. Construction canonicalizes immediately.
4. **Transform it**: `ctx.expand(&e)`, `ctx.simplify(&e)`, `ctx.diff(&e, &x)`, `ctx.taylor(&e, &x, 0, 4)`, `ctx.subst(&e, &[("x", v)])`, `ctx.cancel(&e)`, `ctx.factor(&e)`.
5. **Output the result**: `symcas::plain(&ctx, &e)` (roundtrip-safe machine format) or `symcas::latex(&ctx, &e)` (publication-ready).

Each example below applies this procedure to one scenario.

### 1. Expressions & Canonical Form

*Use this to tell whether two differently written formulas are the same math:*

$$ (x + y)^{2} = x^{2} + 2xy + y^{2} \qquad x + x = 2x $$

```rust
use symcas::prelude::*;

Expand All @@ -56,6 +89,10 @@ assert!(a == b);

### 2. Parsing & Roundtrip Guarantee

*Use this to normalize loosely written input into one deterministic canonical form:*

$$ x + x + \frac{1}{2}x \;\to\; \frac{5}{2}x $$

```rust
use symcas::prelude::*;

Expand All @@ -70,6 +107,10 @@ assert!(back == e);

### 3. Expansion, Simplification & Substitution

*Use this to verify hand-derived identities and declutter expressions:*

$$ (x + y)^{2} = x^{2} + y^{2} + 2xy \qquad \sin^{2}x + \cos^{2}x = 1 $$

```rust
use symcas::prelude::*;

Expand All @@ -93,6 +134,12 @@ assert_eq!(symcas::plain(&ctx, &sim), "1");

### 4. Differentiation & Taylor Expansion

*Use this to compute derivatives too tedious by hand and local series approximations:*

$$ \frac{\mathrm{d}}{\mathrm{d}x}\left(\sin(x)\,x^{2}\right) = 2x\sin(x) + x^{2}\cos(x) $$

$$ e^{x} = 1 + x + \frac{x^{2}}{2} + \frac{x^{3}}{6} + \frac{x^{4}}{24} + \cdots $$

```rust
use symcas::prelude::*;

Expand All @@ -112,6 +159,10 @@ assert_eq!(symcas::plain(&ctx, &s), "1 + x + 1/24*x^4 + 1/6*x^3 + 1/2*x^2");

### 5. Rational Reduction & Polynomial Operations

*Use this to cancel common factors in rational expressions and expose roots by factoring:*

$$ \frac{x^{2} - 1}{x - 1} = x + 1 \qquad x^{2} - 4 = (x - 2)(x + 2) $$

```rust
use symcas::prelude::*;

Expand All @@ -129,6 +180,12 @@ let factored = ctx.factor(&poly);
assert_eq!(symcas::plain(&ctx, &factored), "(-2 + x)*(2 + x)");
```

## Documentation

- [DESIGN.md](DESIGN.md): design document (Chinese), covering goals, decisions D1 to D6, and acceptance criteria
- [MATLAB-PARITY.md](MATLAB-PARITY.md): feature parity status against MATLAB Symbolic Math Toolbox
- API reference on [docs.rs](https://docs.rs/symcas)

## License

Licensed under either of:
Expand Down
Loading
Loading