Skip to content

Commit 88de441

Browse files
committed
merge again
2 parents 21fb80b + 283187f commit 88de441

13 files changed

+464
-148
lines changed

.gitignore

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Cargo.lock
22
target/
3-
flake.lock
4-
flake.nix
3+
#flake.lock
4+
#flake.nix
55
.envrc
6-
.direnv/
6+
.direnv/# Devenv
7+
.devenv*
8+
devenv.local.nix
9+
10+
# direnv
11+
.direnv
12+
13+
# pre-commit
14+
.pre-commit-config.yaml

Cargo.toml

+18-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ inherits = "dev"
2121
opt-level = 3
2222

2323
[lib]
24-
crate-type = ["lib"]
24+
crate-type = ["lib", "cdylib"]
2525
name = "symbolica"
2626

2727
[features]
@@ -32,25 +32,28 @@ faster_alloc = ["tikv-jemallocator"]
3232
# sort functions based on an argument-by-argument comparison
3333
full_fn_cmp = []
3434
mathematica_api = ["wolfram-library-link"]
35-
python_api = ["pyo3", "bincode"]
35+
python_api = ["pyo3"]
3636
# do not create a Python module but allow other crates to do so
3737
python_no_module = ["python_api"]
3838
# build a module that is independent of the specific Python version
3939
python_abi3 = ["pyo3/abi3", "pyo3/abi3-py37"]
4040
tracing_only_warnings = ["tracing/release_max_level_warn"]
41+
# bincode = ["dep:bincode"]
4142

4243
[dependencies.pyo3]
4344
features = ["extension-module", "abi3", "py-clone"]
4445
optional = true
4546
version = "0.23"
4647

4748
[dev-dependencies]
48-
tracing-subscriber = {version = "0.3.18", features = ["env-filter"]}
49+
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
4950

5051
[dependencies]
5152
ahash = "0.8.7"
5253
append-only-vec = "0.1"
53-
bincode = {version = "1.3", optional = true}
54+
bincode = { git = "https://github.com/branchseer/bincode", branch = "decode_context", features = [
55+
"serde",
56+
] }
5457
brotli = "5.0"
5558
byteorder = "1.5"
5659
bytes = "1.5"
@@ -63,11 +66,19 @@ rand_xoshiro = "0.6"
6366
rayon = "1.8"
6467
rug = "=1.25.0"
6568
self_cell = "1.0"
66-
serde = {version = "1.0", features = ["derive"]}
69+
serde = { version = "1.0", features = ["derive"] }
6770
smallvec = "1.13"
6871
smartstring = "1.0"
69-
tikv-jemallocator = {version = "0.5.4", optional = true}
72+
tikv-jemallocator = { version = "0.5.4", optional = true }
7073
tinyjson = "2.5"
7174
tracing = "0.1"
7275
wide = "0.7"
73-
wolfram-library-link = {version = "0.2.9", optional = true}
76+
wolfram-library-link = { version = "0.2.9", optional = true }
77+
78+
79+
[build-dependencies]
80+
pyo3-build-config = "*"
81+
82+
83+
[patch.crates-io]
84+
bincode = { git = "https://github.com/branchseer/bincode", branch = "decode_context" }

Readme.md

+3-120
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,6 @@
1-
<h1 align="center">
2-
<br>
3-
<picture>
4-
<source media="(prefers-color-scheme: dark)" srcset="https://symbolica.io/logo_dark.svg">
5-
<source media="(prefers-color-scheme: light)" srcset="https://symbolica.io/logo.svg">
6-
<img src="https://symbolica.io/logo.svg" alt="logo" width="200">
7-
</picture>
8-
<br>
9-
</h1>
101

11-
<p align="center">
12-
<a href="https://symbolica.io"><img alt="Symbolica website" src="https://img.shields.io/static/v1?label=symbolica&message=website&color=orange&style=flat-square"></a>
13-
<a href="https://reform.zulipchat.com"><img alt="Zulip Chat" src="https://img.shields.io/static/v1?label=zulip&message=discussions&color=blue&style=flat-square"></a>
14-
<a href="https://github.com/benruijl/symbolica"><img alt="Symbolica website" src="https://img.shields.io/static/v1?label=github&message=development&color=green&style=flat-square&logo=github"></a>
15-
<a href="https://app.codecov.io/gh/benruijl/symbolica"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/benruijl/symbolica?token=N43MATK5XJ&style=flat-square"></a>
16-
</p>
2+
# <h1 align="center"> Disclaimer </h1>
173

18-
# Symbolica ⊆ Modern Computer Algebra
4+
This fork of the symbolica code is not meant to be used outside of the context of the [γLoop](https://github.com/alphal00p/gammaloop) project as it contains custom modifications that may not be suitable for a generic use.
195

20-
Symbolica is a blazing fast computer algebra system for Python and Rust, born of a need to push the boundaries of computations in science and enterprise.
21-
Check out the live [Jupyter Notebook demo](https://colab.research.google.com/drive/1VAtND2kddgBwNt1Tjsai8vnbVIbgg-7D?usp=sharing)!
22-
23-
For documentation and more, see [symbolica.io](https://symbolica.io).
24-
25-
26-
27-
## Quick Example
28-
29-
Symbolica allows you to build and manipulate mathematical expressions, for example from a Jupyter Notebook:
30-
31-
<picture>
32-
<source media="(prefers-color-scheme: dark)" srcset="https://symbolica.io/resources/demo.dark.svg">
33-
<source media="(prefers-color-scheme: light)" srcset="https://symbolica.io/resources/demo.light.svg">
34-
<img width="600" alt="A demo of Symbolica" src="https://symbolica.io/resources/demo.light.svg">
35-
</picture>
36-
37-
You are able to perform these operations from the comfort of a programming language that you (probably) already know, by using Symbolica's bindings to Python and Rust:
38-
39-
<picture>
40-
<source media="(prefers-color-scheme: dark)" srcset="https://symbolica.io/resources/completion.png">
41-
<source media="(prefers-color-scheme: light)" srcset="https://symbolica.io/resources/completion_light.png">
42-
<img width="600" alt="A demo of Symbolica" src="https://symbolica.io/resources/completion.png">
43-
</picture>
44-
45-
# Installation
46-
47-
Visit the [Get Started](https://symbolica.io/docs/get_started.html) page for detailed installation instructions.
48-
49-
## Python
50-
51-
Symbolica can be installed for Python >3.5 using `pip`:
52-
53-
```sh
54-
pip install symbolica
55-
```
56-
57-
## Rust
58-
59-
If you want to use Symbolica as a library in Rust, simply include it in the `Cargo.toml`:
60-
61-
```toml
62-
[dependencies]
63-
symbolica = "0.14"
64-
```
65-
66-
# Examples
67-
68-
Below we list some examples of the features of Symbolica. Check the [guide](https://symbolica.io/docs/) for a complete overview.
69-
70-
### Pattern matching
71-
72-
Variables ending with a `_` are wildcards that match to any subexpression.
73-
In the following example we try to match the pattern `f(w1_,w2_)`:
74-
75-
```python
76-
from symbolica import *
77-
x, y, w1_, w2_, f = S('x','y','w1_','w2_', 'f')
78-
e = f(3,x)*y**2+5
79-
r = e.replace_all(f(w1_,w2_), f(w1_ - 1, w2_**2))
80-
print(r)
81-
```
82-
which yields `y^2*f(2,x^2)+5`.
83-
84-
### Solving a linear system
85-
86-
Solve a linear system in `x` and `y` with a parameter `c`:
87-
88-
```python
89-
from symbolica import *
90-
91-
x, y, c, f = S('x', 'y', 'c', 'f')
92-
93-
x_r, y_r = Expression.solve_linear_system(
94-
[f(c)*x + y + c, y + c**2], [x, y])
95-
print('x =', x_r, ', y =', y_r)
96-
```
97-
which yields `x = (-c+c^2)*f(c)^-1` and `y = -c^2`.
98-
99-
### Series expansion
100-
101-
Perform a series expansion in `x`:
102-
103-
```python
104-
from symbolica import *
105-
e = E('exp(5+x)/(1-x)').series(S('x'), 0, 3)
106-
107-
print(e)
108-
```
109-
which yields `(exp(5))+(2*exp(5))*x+(5/2*exp(5))*x^2+(8/3*exp(5))*x^3+𝒪(x^4)`.
110-
111-
### Rational arithmetic
112-
113-
Symbolica is world-class in rational arithmetic, outperforming Mathematica, Maple, Form, Fermat, and other computer algebra packages. Simply convert an expression to a rational polynomial:
114-
```python
115-
from symbolica import *
116-
p = E('(x*y^2*5+5)^2/(2*x+5)+(x+4)/(6*x^2+1)').to_rational_polynomial()
117-
print(p)
118-
```
119-
which yields `(45+13*x+50*x*y^2+152*x^2+25*x^2*y^4+300*x^3*y^2+150*x^4*y^4)/(5+2*x+30*x^2+12*x^3)`.
120-
121-
## Development
122-
123-
Follow the development and discussions on [Zulip](https://reform.zulipchat.com)!
6+
Make sure to instead use the original codebase available [here](https://github.com/benruijl/symbolica).

build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use std::process::Command;
22
fn main() {
3+
if cfg!(target_os = "macos") {
4+
pyo3_build_config::add_extension_module_link_args();
5+
println!("cargo:rustc-link-lib=gcc_s");
6+
}
37
let output = Command::new("git")
48
.args(["describe", "--tags"])
59
.output()

flake.nix

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
description = "Description for the project";
3+
4+
inputs = {
5+
devenv-root = {
6+
url = "file+file:///dev/null";
7+
flake = false;
8+
};
9+
flake-parts.url = "github:hercules-ci/flake-parts";
10+
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
11+
devenv.url = "github:cachix/devenv";
12+
nix2container.url = "github:nlewo/nix2container";
13+
nix2container.inputs.nixpkgs.follows = "nixpkgs";
14+
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
15+
};
16+
17+
nixConfig = {
18+
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
19+
extra-substituters = "https://devenv.cachix.org";
20+
};
21+
22+
outputs = inputs@{ flake-parts, devenv-root, ... }:
23+
flake-parts.lib.mkFlake { inherit inputs; } {
24+
imports = [
25+
inputs.devenv.flakeModule
26+
];
27+
systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
28+
29+
perSystem = { config, self', inputs', pkgs, system, ... }: {
30+
# Per-system attributes can be defined here. The self' and inputs'
31+
# module parameters provide easy access to attributes of the same
32+
# system.
33+
34+
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
35+
packages.default = pkgs.hello;
36+
37+
devenv.shells.default = {
38+
devenv.root =
39+
let
40+
devenvRootFileContent = builtins.readFile devenv-root.outPath;
41+
in
42+
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
43+
44+
name = "my-project";
45+
46+
imports = [
47+
# This is just like the imports in devenv.nix.
48+
# See https://devenv.sh/guides/using-with-flake-parts/#import-a-devenv-module
49+
# ./devenv-foo.nix
50+
];
51+
52+
# https://devenv.sh/reference/options/
53+
# packages = [ config.packages.default ];
54+
55+
56+
packages = [config.packages.default
57+
pkgs.gnum4
58+
pkgs.gmp
59+
pkgs.mpfr
60+
pkgs.gnumake
61+
pkgs.diffutils
62+
pkgs.glibc
63+
];
64+
65+
languages.rust.enable = true;
66+
languages.cplusplus.enable = true;
67+
68+
69+
processes.hello.exec = "hello";
70+
};
71+
72+
};
73+
flake = {
74+
# The usual flake attributes can be defined here, including system-
75+
# agnostic ones like nixosModule and system-enumerating ones, although
76+
# those are more easily expressed in perSystem.
77+
78+
};
79+
};
80+
}

src/api/python.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11167,7 +11167,7 @@ impl PythonNumericalIntegrator {
1116711167
/// Use `export_grid` to export the grid.
1116811168
#[classmethod]
1116911169
fn import_grid(_cls: &Bound<'_, PyType>, grid: &[u8]) -> PyResult<Self> {
11170-
let grid = bincode::deserialize(grid)
11170+
let (grid, _) = bincode::decode_from_slice(grid, bincode::config::standard())
1117111171
.map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))?;
1117211172

1117311173
Ok(PythonNumericalIntegrator { grid })
@@ -11176,7 +11176,7 @@ impl PythonNumericalIntegrator {
1117611176
/// Export the grid, so that it can be sent to another thread or machine.
1117711177
/// Use `import_grid` to load the grid.
1117811178
fn export_grid<'p>(&self, py: Python<'p>) -> PyResult<Bound<'p, PyBytes>> {
11179-
bincode::serialize(&self.grid)
11179+
bincode::encode_to_vec(&self.grid, bincode::config::standard())
1118011180
.map(|a| PyBytes::new(py, &a))
1118111181
.map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))
1118211182
}

src/atom.rs

+46
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod coefficient;
4343
mod core;
4444
pub mod representation;
4545

46+
use bincode::{de::read::Reader, enc::write::Writer, Decode, Encode};
4647
use representation::InlineVar;
4748
use smartstring::{LazyCompact, SmartString};
4849

@@ -63,6 +64,7 @@ pub use self::representation::{
6364
};
6465
use self::representation::{FunView, RawAtom};
6566

67+
6668
/// A function that is called after normalization of the arguments.
6769
/// If the input, the first argument, is normalized, the function should return `false`.
6870
/// Otherwise, the function must return `true` and set the second argument to the normalized value.
@@ -97,6 +99,7 @@ pub enum FunctionAttribute {
9799
Linear,
98100
}
99101

102+
use std::result;
100103
/// A symbol, for example the name of a variable or the name of a function,
101104
/// together with its properties.
102105
///
@@ -124,6 +127,49 @@ pub struct Symbol {
124127
is_linear: bool,
125128
}
126129

130+
impl<__Context> ::bincode::Decode<__Context> for Symbol {
131+
fn decode<__D: ::bincode::de::Decoder<Context = __Context>>(
132+
decoder: &mut __D,
133+
) -> Result<Self, ::bincode::error::DecodeError> {
134+
Ok(Self {
135+
id: ::bincode::Decode::decode(decoder)?,
136+
wildcard_level: ::bincode::Decode::decode(decoder)?,
137+
is_symmetric: ::bincode::Decode::decode(decoder)?,
138+
is_antisymmetric: ::bincode::Decode::decode(decoder)?,
139+
is_cyclesymmetric: ::bincode::Decode::decode(decoder)?,
140+
is_linear: ::bincode::Decode::decode(decoder)?,
141+
})
142+
}
143+
}
144+
impl<'__de, __Context> ::bincode::BorrowDecode<'__de, __Context> for Symbol {
145+
fn borrow_decode<__D: ::bincode::de::BorrowDecoder<'__de, Context = __Context>>(
146+
decoder: &mut __D,
147+
) -> Result<Self, ::bincode::error::DecodeError> {
148+
Ok(Self {
149+
id: ::bincode::BorrowDecode::<'_, __Context>::borrow_decode(decoder)?,
150+
wildcard_level: ::bincode::BorrowDecode::<'_, __Context>::borrow_decode(decoder)?,
151+
is_symmetric: ::bincode::BorrowDecode::<'_, __Context>::borrow_decode(decoder)?,
152+
is_antisymmetric: ::bincode::BorrowDecode::<'_, __Context>::borrow_decode(decoder)?,
153+
is_cyclesymmetric: ::bincode::BorrowDecode::<'_, __Context>::borrow_decode(decoder)?,
154+
is_linear: ::bincode::BorrowDecode::<'_, __Context>::borrow_decode(decoder)?,
155+
})
156+
}
157+
}
158+
159+
impl ::bincode::Encode for Symbol {
160+
fn encode<__E: ::bincode::enc::Encoder>(
161+
&self,
162+
encoder: &mut __E,
163+
) -> Result<(), ::bincode::error::EncodeError> {
164+
::bincode::Encode::encode(&self.id, encoder)?;
165+
::bincode::Encode::encode(&self.wildcard_level, encoder)?;
166+
::bincode::Encode::encode(&self.is_symmetric, encoder)?;
167+
::bincode::Encode::encode(&self.is_antisymmetric, encoder)?;
168+
::bincode::Encode::encode(&self.is_cyclesymmetric, encoder)?;
169+
::bincode::Encode::encode(&self.is_linear, encoder)?;
170+
Ok(())
171+
}
172+
}
127173
impl std::fmt::Debug for Symbol {
128174
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129175
f.write_fmt(format_args!("{}", self.id))?;

0 commit comments

Comments
 (0)