From 7337c282459ce6b26c03a8fb920fe7632372b862 Mon Sep 17 00:00:00 2001 From: lcnbr Date: Tue, 22 Oct 2024 09:08:03 +0200 Subject: [PATCH] feat(rust): :sparkles: new spenso structure format and symbolica 0.13, all rust tests pass --- .zed/settings.json | 4 +- .zed/tasks.json | 49 +- Cargo.lock | 137 +++--- Cargo.toml | 4 +- bin/build_dependencies.sh | 2 +- src/graph.rs | 97 ++-- src/model.rs | 265 +++++------ src/momentum.rs | 48 +- src/numerator.rs | 420 +++++++++++------- ...numerator__tests__Single color string.snap | 4 +- src/numerator/tests.rs | 21 +- src/numerator/ufo.rs | 243 ++++++++++ src/tests_from_pytest.rs | 2 +- src/utils.rs | 61 ++- 14 files changed, 848 insertions(+), 509 deletions(-) create mode 100644 src/numerator/ufo.rs diff --git a/.zed/settings.json b/.zed/settings.json index 1fe00c87..dbe5e1d8 100644 --- a/.zed/settings.json +++ b/.zed/settings.json @@ -23,7 +23,7 @@ } }, "cargo": { - "features": "all" + // "features": "all" }, "diagnostics": { "experimental": { @@ -35,7 +35,7 @@ "checkOnSave": true, "check": { "onSave": true, - "features": ["all"] + "features": [] } } } diff --git a/.zed/tasks.json b/.zed/tasks.json index 76f196b8..427ba702 100644 --- a/.zed/tasks.json +++ b/.zed/tasks.json @@ -1,40 +1,17 @@ -// Static tasks configuration. -// -// Example: - [ { - "label": "Example task", - "command": "for i in {1..5}; do echo \"Hello $i/5\"; sleep 1; done", - //"args": [], - // Env overrides for the command, will be appended to the terminal's environment from the settings. - "env": { "foo": "bar" }, - // Current working directory to spawn the command into, defaults to current project root. - //"cwd": "/path/to/working/directory", - // Whether to use a new terminal tab or reuse the existing one to spawn the process, defaults to `false`. - "use_new_terminal": false, - // Whether to allow multiple instances of the same task to be run, or rather wait for the existing ones to finish, defaults to `false`. - "allow_concurrent_runs": false, - // What to do with the terminal pane and tab, after the command was started: - // * `always` — always show the terminal pane, add and focus the corresponding task's tab in it (default) - // * `never` — avoid changing current terminal pane focus, but still add/reuse the task's tab there - "reveal": "always", - // What to do with the terminal pane and tab, after the command had finished: - // * `never` — Do nothing when the command finishes (default) - // * `always` — always hide the terminal tab, hide the pane also if it was the last tab in it - // * `on_success` — hide the terminal tab on task success only, otherwise behaves similar to `always` - "hide": "never", - // Which shell to use when running a task inside the terminal. - // May take 3 values: - // 1. (default) Use the system's default terminal configuration in /etc/passwd - // "shell": "system" - // 2. A program: - // "shell": { - // "program": "sh" - // } - // 3. A program with arguments: - "shell": { - "program": "bash" - } + "label": "Run Rust tests", + "command": "cargo test -p gammalooprs $env.ZED_SYMBOL --no-default-features --lib -- --nocapture", + "tags": ["rust-test"] + }, + { + "label": "Run Rust mod tests", + "command": "cargo test -p $env.ZED_CUSTOM_RUST_PACKAGE $env.ZED_SYMBOL --no-default-features", + "tags": ["rust-mod-test"] + }, + { + "label": "Run Rust main function", + "command": "cargo run -p $env.ZED_CUSTOM_RUST_PACKAGE --bin $env.ZED_CUSTOM_RUST_BIN_NAME --no-default-features", + "tags": ["rust-main"] } ] diff --git a/Cargo.lock b/Cargo.lock index 2c78ce8d..74c95b8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,18 +166,18 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95" dependencies = [ "backtrace", ] [[package]] name = "append-only-vec" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb8633986ce6db557d8a568b0b874d840db9946e589a3de4cf84fb02130745f" +checksum = "7992085ec035cfe96992dd31bfd495a2ebd31969bb95f624471cb6c0b349e571" [[package]] name = "approx" @@ -323,9 +323,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" +checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" [[package]] name = "byteorder" @@ -335,9 +335,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cast" @@ -347,9 +347,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.28" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ "shlex", ] @@ -423,18 +423,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.19" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.19" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstyle", "clap_lex", @@ -582,7 +582,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.5.19", + "clap 4.5.20", "criterion-plot", "is-terminal", "itertools 0.10.5", @@ -695,7 +695,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -717,7 +717,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -737,7 +737,7 @@ checksum = "4e018fccbeeb50ff26562ece792ed06659b9c2dae79ece77c4456bb10d9bf79b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -791,7 +791,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -804,7 +804,7 @@ dependencies = [ "proc-macro2", "quote", "rustc-hash", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -844,7 +844,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -856,7 +856,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1001,7 +1001,7 @@ dependencies = [ "petgraph", "pprof", "pyo3", - "pyo3-build-config 0.21.2", + "pyo3-build-config 0.22.5", "pyo3-log", "rand", "rayon", @@ -1064,7 +1064,7 @@ checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1310,9 +1310,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -1325,9 +1325,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libloading" @@ -1496,7 +1496,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1842,9 +1842,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] @@ -1880,9 +1880,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.3" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e61cef80755fe9e46bb8a0b8f20752ca7676dcc07a5277d8b7768c6172e529b3" +checksum = "bc38c5feeb496c8321091edf3d63e9a6829eab4b863b4a6a65f26f3e9cc6b179" dependencies = [ "once_cell", "target-lexicon", @@ -1918,7 +1918,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1931,7 +1931,7 @@ dependencies = [ "proc-macro2", "pyo3-build-config 0.21.2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2188,29 +2188,29 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.211" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "1ac55e59090389fb9f0dd9e0f3c09615afed1d19094284d0b200441f13550793" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.211" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "54be4f245ce16bc58d57ef2716271d0d4519e0f6defa147f6e081005bcb278ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -2226,7 +2226,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2262,7 +2262,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2350,11 +2350,12 @@ dependencies = [ [[package]] name = "spenso" version = "0.2.0" -source = "git+https://github.com/alphal00p/spenso?branch=master#ab137ba842b64e7eb43bea2a74274a4a4b064d77" +source = "git+https://github.com/alphal00p/spenso?branch=master#6288d81b95bc642e663f584d0626ffbd92820990" dependencies = [ "ahash", "ambassador", "anyhow", + "append-only-vec", "approx", "bitvec", "const_format", @@ -2370,6 +2371,7 @@ dependencies = [ "indexmap 2.6.0", "log", "num 0.4.3", + "once_cell", "rand", "rand_xoshiro", "ref-ops", @@ -2456,7 +2458,7 @@ dependencies = [ [[package]] name = "symbolica" -version = "0.12.1" +version = "0.13.0" dependencies = [ "ahash", "append-only-vec", @@ -2467,7 +2469,6 @@ dependencies = [ "dyn-clone", "libloading", "once_cell", - "pyo3-build-config 0.22.3", "rand", "rand_xoshiro", "rayon", @@ -2494,9 +2495,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" dependencies = [ "proc-macro2", "quote", @@ -2584,7 +2585,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2662,7 +2663,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2727,9 +2728,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "getrandom", "serde", @@ -2780,9 +2781,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", "once_cell", @@ -2791,24 +2792,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2816,28 +2817,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", @@ -3068,5 +3069,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] diff --git a/Cargo.toml b/Cargo.toml index 62237ce3..b20bac55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ criterion = { version = "0.5", features = ["html_reports"] } [dependencies] # These will be patched -symbolica = { version = "0.12.1" } +symbolica = { version = "0.13" } spenso = { version = "0.2.0", features = ["shadowing"] } momtrop = { git = "https://github.com/alphal00p/momtrop", features = ["log"] } @@ -130,5 +130,5 @@ fail-on-warnings = [] [patch.crates-io] symbolica = { path = "./python/gammaloop/dependencies/symbolica" } -spenso = { git = "https://github.com/alphal00p/spenso", branch = "master" } # spenso = { path = "../../alphal00p/spenso" } +spenso = { git = "https://github.com/alphal00p/spenso", branch = "master" } diff --git a/bin/build_dependencies.sh b/bin/build_dependencies.sh index a49f69c5..eef335b6 100755 --- a/bin/build_dependencies.sh +++ b/bin/build_dependencies.sh @@ -1,6 +1,6 @@ cd ./python/gammaloop #export CMD_TO_ACCESS_SYMBOLICA="${CMD_TO_ACCESS_SYMBOLICA:-git clone https://github.com/alphal00p/symbolica}" export CMD_TO_ACCESS_SYMBOLICA="${CMD_TO_ACCESS_SYMBOLICA:-git clone -b main https://github.com/benruijl/symbolica}" -export SYMBOLICA_REVISION_HASH="${SYMBOLICA_REVISION_HASH:-v0.12.1}" +export SYMBOLICA_REVISION_HASH="${SYMBOLICA_REVISION_HASH:-v0.13.0}" export SYMBOLICA_BUILD_PROFILE="${SYMBOLICA_BUILD_PROFILE:-release}" ./bin/build_dependencies.sh "$@" diff --git a/src/graph.rs b/src/graph.rs index 864d33b5..b1e9e6af 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -12,6 +12,7 @@ use crate::{ model::{self, ColorStructure, EdgeSlots, Model, Particle, VertexSlots}, momentum::{FourMomentum, Polarization, Rotation, SignOrZero, Signature, ThreeMomentum}, numerator::{ + ufo::{preprocess_ufo_color_wrapped, preprocess_ufo_spin_wrapped, UFO}, AppliedFeynmanRule, AtomStructure, ContractionSettings, Evaluate, Evaluators, ExtraInfo, GammaAlgebraMode, Numerator, NumeratorState, NumeratorStateError, PythonState, RepeatingIteratorTensorOrScalar, TypedNumeratorState, UnInit, @@ -45,12 +46,15 @@ use spenso::{ contraction::{IsZero, RefZero}, data::{DataTensor, DenseTensor, GetTensorData, SetTensorData, SparseTensor}, scalar::Scalar, + shadowing::{Shadowable, ETS}, structure::{ - AbstractIndex, CastStructure, HasStructure, Lorentz, NamedStructure, ScalarTensor, - Shadowable, ToSymbolic, VecStructure, COLORADJ, COLORANTIFUND, COLORANTISEXT, COLORFUND, - COLORSEXT, EUCLIDEAN, + abstract_index::AbstractIndex, + representation::{ + BaseRepName, ColorAdjoint, ColorFundamental, ColorSextet, Euclidean, Minkowski, + }, + slot::{DualSlotTo, IsAbstractSlot}, + CastStructure, HasStructure, NamedStructure, ScalarTensor, ToSymbolic, VecStructure, }, - ufo::{preprocess_ufo_color_wrapped, preprocess_ufo_spin_wrapped}, }; use uuid::Uuid; @@ -69,13 +73,13 @@ use std::{ use symbolica::{ atom::{Atom, Symbol}, domains::{float::NumericalFloatLike, rational::Rational}, + fun, id::{Pattern, Replacement}, state::State, + symb, }; //use symbolica::{atom::Symbol,state::State}; -use constcat::concat; - #[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq)] pub enum EdgeType { #[serde(rename = "in")] @@ -265,15 +269,17 @@ impl HasVertexInfo for InteractionVertexInfo { .map(|ls| { let mut atom = ls.structure.clone(); + println!("in vertex{atom}"); + for (i, e) in edges.iter().enumerate() { let momentum_in_pattern = Pattern::parse(&format!("P(x_,{})", i + 1)).unwrap(); let momentum_out_pattern = if e < &0 { - Pattern::parse(&format!("-Q({},aind(lord(4,indexid(x_))))", -e)) + Pattern::parse(&format!("-Q({},mink(4,x_))", -e)) .unwrap() .into() //TODO flip based on flow } else { - Pattern::parse(&format!("Q({},aind(loru(4,indexid(x_))))", e)) + Pattern::parse(&format!("Q({},mink(4,x_))", e)) .unwrap() .into() //TODO flip based on flow }; @@ -286,7 +292,8 @@ impl HasVertexInfo for InteractionVertexInfo { ); } - atom = preprocess_ufo_spin_wrapped(atom, true); + atom = preprocess_ufo_spin_wrapped(atom); + println!("preprocessed vertex{atom}"); for (i, _) in edges.iter().enumerate() { let replacements = vertex_slots[i].replacements(i + 1); @@ -298,7 +305,7 @@ impl HasVertexInfo for InteractionVertexInfo { atom = atom.replace_all_multiple(&reps); } - + println!("out vertex{atom}"); atom }) .collect_vec(); @@ -311,50 +318,40 @@ impl HasVertexInfo for InteractionVertexInfo { .map(|cs| { let n_dummies = ColorStructure::number_of_dummies_in_atom(cs.as_view()); let mut atom = cs.clone(); - //a is adjoint index, i is fundamental index, ia is antifundamental index, s is sextet ,sa is antisextet atom = preprocess_ufo_color_wrapped(atom); - //T(1,2,3) Fundamental representation matrix (T a1 )ı ̄3 i2 - // f(1,2,3) Antisymmetric structure constant f a1a2a3 - // d(1,2,3) Symmetric structure constant da1 a2 a3 - // Epsilon(1,2,3) Fundamental Levi-Civita tensor εi1 i2 i3 EpsilonBar(1,2,3) Antifundamental Levi-Civita tensor εı ̄1 ı ̄2 ı ̄3 - // T6(1,2,3) Sextet representation matrix (T a1 6 ) ̄ α3 α2 - // K6(1,2,3) Sextet Clebsch-Gordan coefficient (K6)ı ̄2 ı ̄3 α1 K6Bar(1,2,3) Antisextet Clebsch-Gordan coefficient (K6) ̄ α1 i2i3 - - // First process kronkers, with respect to spin: let spins: Vec = self.vertex_rule.particles.iter().map(|s| s.color).collect(); for (i, s) in spins.iter().enumerate() { - let id1 = Pattern::parse(&format!("Identity({},x_)", i + 1)).unwrap(); - - let id2 = Pattern::parse(&format!("id(aind(x_,{}))", i + 1)).unwrap(); + let id1 = fun!(UFO.identity, Atom::new_num((i + 1) as i32), symb!("x_")) + .into_pattern(); + let id2 = + fun!(ETS.id, symb!("x_"), Atom::new_num((i + 1) as i32)).into_pattern(); let ind = match s { - 1 => concat!(EUCLIDEAN, "(1,"), - 3 => concat!(COLORFUND, "(3,"), - -3 => concat!(COLORANTIFUND, "(3,"), - 6 => concat!(COLORSEXT, "(6,"), - -6 => concat!(COLORANTISEXT, "(6,"), - 8 => concat!(COLORADJ, "(8,"), + 1 => Euclidean::slot(1, i + 1).to_symbolic_wrapped(), + 3 => ColorFundamental::slot(3, i + 1).to_symbolic_wrapped(), + -3 => ColorFundamental::slot(3, i + 1) + .dual() + .to_symbolic_wrapped(), + 6 => ColorSextet::slot(6, i + 1).to_symbolic_wrapped(), + -6 => ColorSextet::slot(6, i + 1).dual().to_symbolic_wrapped(), + 8 => ColorAdjoint::slot(8, i + 1).to_symbolic_wrapped(), i => panic!("Color {i}not supported "), }; atom = id1.replace_all( atom.as_view(), - &Pattern::parse(&format!("id(aind({}indexid({})),x_))", ind, i + 1)) - .unwrap() - .into(), + &fun!(ETS.id, ind, symb!("x_")).into_pattern().into(), None, None, ); atom = id2.replace_all( atom.as_view(), - &Pattern::parse(&format!("id(aind(x_,{}indexid({}))))", ind, i + 1)) - .unwrap() - .into(), + &fun!(ETS.id, symb!("x_"), ind).into_pattern().into(), None, None, ); @@ -548,14 +545,14 @@ impl Edge { // State::get_symbol(format!("Q{num}")) // } - pub fn in_slot(&self, graph: &BareGraph) -> EdgeSlots { + pub fn in_slot(&self, graph: &BareGraph) -> EdgeSlots { let local_pos_in_sink_vertex = graph.vertices[self.vertices[0]].get_local_edge_position(self, graph); graph.vertex_slots[self.vertices[0]][local_pos_in_sink_vertex].dual() } - pub fn out_slot(&self, graph: &BareGraph) -> EdgeSlots { + pub fn out_slot(&self, graph: &BareGraph) -> EdgeSlots { let local_pos_in_sink_vertex = graph.vertices[self.vertices[1]].get_local_edge_position(self, graph); @@ -576,22 +573,25 @@ impl Edge { match self.edge_type { EdgeType::Incoming => { let [lorentz, spin, color] = in_slots.dual().kroneker(&out_slots); - // println!("Incoming color: {}", color); + println!("Incoming color: {}", color); [lorentz * spin, color] } EdgeType::Outgoing => { let [lorentz, spin, color] = out_slots.dual().kroneker(&in_slots); // println!("Outgoing color: {}", color); + println!("Outgoing color: {}", color); [lorentz * spin, color] } EdgeType::Virtual => { let mut atom = self.propagator.numerator.clone(); + println!("in prop:{atom}"); + let pfun = Pattern::parse("P(x_)").unwrap(); if self.particle.is_antiparticle() { atom = pfun.replace_all( atom.as_view(), - &Pattern::parse(&format!("-Q({},aind(loru(4,x_)))", num)) + &Pattern::parse(&format!("-Q({},mink(4,x_))", num)) .unwrap() .into(), None, @@ -600,7 +600,7 @@ impl Edge { } else { atom = pfun.replace_all( atom.as_view(), - &Pattern::parse(&format!("Q({},aind(loru(4,x_)))", num)) + &Pattern::parse(&format!("Q({},mink(4,x_))", num)) .unwrap() .into(), None, @@ -614,7 +614,7 @@ impl Edge { atom = pslashfun.replace_all( atom.as_view(), &Pattern::parse(&format!( - "-Q({},aind(lord(4,{})))*Gamma({},i_,j_)", + "-Q({},mink(4,{}))*Gamma({},i_,j_)", num, pindex_num, pindex_num )) .unwrap() @@ -626,7 +626,7 @@ impl Edge { atom = pslashfun.replace_all( atom.as_view(), &Pattern::parse(&format!( - "Q({},aind(lord(4,{})))*Gamma({},i_,j_)", + "Q({},mink(4,{}))*Gamma({},i_,j_)", num, pindex_num, pindex_num )) .unwrap() @@ -636,7 +636,7 @@ impl Edge { ); } - atom = preprocess_ufo_spin_wrapped(atom, false); + atom = preprocess_ufo_spin_wrapped(atom); let (replacements_in, mut replacements_out) = if self.particle.is_antiparticle() { (in_slots.replacements(2), out_slots.replacements(1)) @@ -662,10 +662,15 @@ impl Edge { .map(|(pat, rhs)| Replacement::new(pat, rhs)) .collect(); - [ + let out = [ atom.replace_all_multiple(&reps), color_atom.replace_all_multiple(&reps), - ] + ]; + + println!("out prop:{}", out[0]); + println!("out color:{}", out[1]); + + out } } } @@ -755,7 +760,7 @@ impl Vertex { .into_iter() .reduce(|acc, tensor| acc.contract(&tensor).unwrap()) .unwrap() - .get(&[]) + .get_owned(&[]) .unwrap() .clone(); @@ -933,7 +938,7 @@ pub struct Shifts { } impl BareGraph { - pub fn external_slots(&self) -> Vec> { + pub fn external_slots(&self) -> Vec> { self.vertices .iter() .enumerate() diff --git a/src/model.rs b/src/model.rs index 995cfbbc..19804cd6 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,5 +1,6 @@ use crate::graph::Shifts; use crate::momentum::{FourMomentum, Helicity, Polarization}; +use crate::numerator::ufo::UFO; use crate::utils::{self, FloatLike, F}; use ahash::{AHashMap, RandomState}; @@ -11,15 +12,26 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; use serde_yaml::Error; use smartstring::{LazyCompact, SmartString}; -use spenso::parametric::{ExpandedCoefficent, TensorCoefficient}; +use spenso::parametric::ExpandedCoefficent; +use spenso::structure::representation::Minkowski; use spenso::structure::{ - AbstractIndex, Dimension, Euclidean, ExpandedIndex, FlatIndex, VecStructure, CONCRETEIND, + abstract_index::AbstractIndex, concrete_index::CONCRETEIND, representation::Euclidean, + VecStructure, }; +use spenso::structure::{TensorStructure, ToSymbolic}; use spenso::{ contraction::IsZero, structure::{ - BaseRepName, Bispinor, ColorAdjoint, ColorFundamental, ColorSextet, Dual, DualSlotTo, - IsAbstractSlot, Lorentz, PhysReps, RepName, Representation, Slot, ABSTRACTIND, + representation::Lorentz, + representation::PhysReps, + representation::RepName, + representation::Representation, + representation::{ + BaseRepName, Bispinor, ColorAdjoint, ColorFundamental, ColorSextet, Dual, + }, + slot::DualSlotTo, + slot::IsAbstractSlot, + slot::Slot, }, }; use std::fmt::{Display, Formatter}; @@ -35,9 +47,10 @@ use std::sync::Arc; use std::{collections::HashMap, fs::File}; use symbolica::atom::{Atom, AtomView, FunctionBuilder, Symbol}; +use crate::utils::GS; use spenso::complex::Complex; +use spenso::shadowing::ETS; use symbolica::domains::float::NumericalFloatLike; - use symbolica::fun; use symbolica::printer::{AtomPrinter, PrintOptions}; use symbolica::state::State; @@ -185,7 +198,7 @@ pub struct VertexRule { } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct VertexSlots { - edge_slots: Vec>>, + edge_slots: Vec>, pub coupling_indices: Option<[Slot; 2]>, //None for external vertices pub internal_dummy: DummyIndices, } @@ -227,14 +240,14 @@ impl std::fmt::Display for VertexSlots { } impl Index for VertexSlots { - type Output = EdgeSlots>; + type Output = EdgeSlots; fn index(&self, index: usize) -> &Self::Output { &self.edge_slots[index] } } -impl From>> for VertexSlots { - fn from(value: EdgeSlots>) -> Self { +impl From> for VertexSlots { + fn from(value: EdgeSlots) -> Self { VertexSlots { edge_slots: vec![value], coupling_indices: None, @@ -308,8 +321,8 @@ impl VertexRule { let j_dim = self.couplings[0].len(); let coupling_indices = Some([ - Euclidean::new_slot_selfless(i_dim, coupling_shift), - Euclidean::new_slot_selfless(j_dim, coupling_shift + 1), + Euclidean::slot(i_dim, coupling_shift), + Euclidean::slot(j_dim, coupling_shift + 1), ]); ( @@ -597,11 +610,25 @@ pub struct InOutIndex { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct EdgeSlots { - lorentz: Vec>, + pub lorentz: Vec>, spin: Vec>, pub color: Vec>, } +impl From> for VecStructure { + fn from(value: EdgeSlots) -> Self { + VecStructure { + structure: value + .lorentz + .into_iter() + .map(|x| x.into()) + .chain(value.spin.into_iter().map(|x| x.into())) + .chain(value.color.into_iter().map(|x| x.into())) + .collect(), + } + } +} + impl Display for EdgeSlots { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "Lorentz: ")?; @@ -661,55 +688,6 @@ where [lorentz, spin, color] } - pub fn expanded_index(&self, flat_index: FlatIndex) -> Result { - let mut indices = vec![]; - let mut index: usize = flat_index.into(); - for &stride in &self.strides_row_major()? { - indices.push(index / stride); - index %= stride; - } - if usize::from(flat_index) < self.size() { - Ok(indices.into()) - } else { - Err(eyre!("Index {flat_index} out of bounds")) - } - } - - fn order(&self) -> usize { - self.color.len() + self.lorentz.len() + self.spin.len() - } - - fn shape(&self) -> Vec { - let mut dims = vec![]; - dims.extend(self.lorentz.iter().map(|s| s.dim())); - dims.extend(self.spin.iter().map(|s| s.dim())); - dims.extend(self.color.iter().map(|s| s.dim())); - dims - } - - fn strides_row_major(&self) -> Result> { - let mut strides = vec![1; self.order()]; - if self.order() == 0 { - return Ok(strides); - } - - for i in (0..self.order() - 1).rev() { - strides[i] = strides[i + 1] * usize::try_from(self.shape()[i + 1])?; - } - - Ok(strides) - } - pub fn to_dense_labels(&self, index_to_atom: impl Fn(&Self, FlatIndex) -> T) -> Vec - where - Self: Sized, - T: TensorCoefficient, - { - let mut data = vec![]; - for index in 0..self.size() { - data.push(index_to_atom(self, index.into()).to_atom().unwrap()); - } - data - } pub fn size(&self) -> usize { if self.spin.is_empty() && self.lorentz.is_empty() && self.color.is_empty() { 0 @@ -747,64 +725,60 @@ where } } pub fn replacements(&self, id: usize) -> Vec<(Pattern, PatternOrMap)> { - let rhs_lor = LorRep::new_slot_selfless(4, id) - .to_symbolic_wrapped() - .into_pattern(); + let rhs_lor = LorRep::slot(4, id).to_symbolic_wrapped().into_pattern(); - let rhs_spin = Bispinor::new_slot_selfless(4, id); + let rhs_spin = Bispinor::slot(4, id); let rhs_spin = rhs_spin.to_symbolic_wrapped().into_pattern(); let mut reps = vec![]; for l in &self.lorentz { - reps.push((rhs_lor.clone(), l.to_symbolic().into_pattern().into())); + reps.push((rhs_lor.clone(), l.to_atom().into_pattern().into())); } for s in &self.spin { - reps.push((rhs_spin.clone(), s.to_symbolic().into_pattern().into())); + reps.push((rhs_spin.clone(), s.to_atom().into_pattern().into())); } for c in &self.color { let mut rhs_color = *c; rhs_color.aind = id.into(); + println!("rhs color pattern :{}", rhs_color.to_symbolic_wrapped()); let rhs_color = rhs_color.to_symbolic_wrapped().into_pattern(); - - reps.push((rhs_color.clone(), c.to_symbolic().into_pattern().into())); + reps.push((rhs_color.clone(), c.to_atom().into_pattern().into())); } reps } - pub fn to_aind_atom(&self) -> Atom { - let mut builder = FunctionBuilder::new(State::get_symbol(ABSTRACTIND)); - + pub fn complete_fn_builder(&self, mut fn_builder: FunctionBuilder) -> Atom { for l in &self.lorentz { - builder = builder.add_arg(l.to_symbolic().as_view()); + fn_builder = fn_builder.add_arg(l.to_atom().as_view()); } for s in &self.spin { - builder = builder.add_arg(s.to_symbolic().as_view()); + fn_builder = fn_builder.add_arg(s.to_atom().as_view()); } for c in &self.color { - builder = builder.add_arg(c.to_symbolic().as_view()); + fn_builder = fn_builder.add_arg(c.to_atom().as_view()); } - builder.finish() + fn_builder.finish() } pub fn to_cind_atom(&self) -> Atom { let mut builder = FunctionBuilder::new(State::get_symbol(CONCRETEIND)); for l in &self.lorentz { - builder = builder.add_arg(l.to_symbolic().as_view()); + builder = builder.add_arg(l.to_atom().as_view()); } for s in &self.spin { - builder = builder.add_arg(s.to_symbolic().as_view()); + builder = builder.add_arg(s.to_atom().as_view()); } for c in &self.color { - builder = builder.add_arg(c.to_symbolic().as_view()); + builder = builder.add_arg(c.to_atom().as_view()); } builder.finish() @@ -821,7 +795,7 @@ impl Particle { } fn lorentz_slots(&self, shift: usize) -> (Vec>, usize) { - let fourd_lor = LR::new_dimed_rep_selfless(4); + let fourd_lor = LR::rep(4); match self.spin { 3 => (vec![Representation::new_slot(&fourd_lor, shift)], shift + 1), @@ -830,7 +804,7 @@ impl Particle { } fn spin_slots(&self, shift: usize) -> (Vec>, usize) { - let fourd_bis: Representation<_> = Bispinor::new_dimed_rep_selfless(4); + let fourd_bis: Representation<_> = Bispinor::rep(4); match self.spin { 2 => (vec![fourd_bis.new_slot(shift)], shift + 1), @@ -840,11 +814,11 @@ impl Particle { fn color_slots(&self, shift: usize) -> (Vec>, usize) { let rep: Representation = match self.color { - 3 => ColorFundamental::new_dimed_rep_selfless(3).cast(), - -3 => Dual::::new_dimed_rep_selfless(3).cast(), - 6 => ColorSextet::new_dimed_rep_selfless(6).cast(), - -6 => Dual::::new_dimed_rep_selfless(6).cast(), - 8 => ColorAdjoint::new_dimed_rep_selfless(8).cast(), + 3 => ColorFundamental::rep(3).cast(), + -3 => Dual::::rep(3).cast(), + 6 => ColorSextet::rep(6).cast(), + -6 => Dual::::rep(6).cast(), + 8 => ColorAdjoint::rep(8).cast(), _ => return (vec![], shift), }; @@ -891,31 +865,18 @@ impl Particle { } } - pub fn incoming_polarization_atom(&self, edge_slots: &EdgeSlots, num: usize) -> Atom { + pub fn incoming_polarization_atom( + &self, + edge_slots: &EdgeSlots, + num: usize, + ) -> Atom { let mut colorless = edge_slots.clone(); colorless.color = vec![]; - match self.spin { - 1 => Atom::parse("1").unwrap(), - 2 => { - if self.pdg_code > 0 { - let mut u = FunctionBuilder::new(State::get_symbol("u")); - u = u.add_arg(&Atom::new_num(num as i64)); - u = u.add_arg(&colorless.to_aind_atom()); - u.finish() - } else { - let mut vbar = FunctionBuilder::new(State::get_symbol("vbar")); - vbar = vbar.add_arg(&Atom::new_num(num as i64)); - vbar = vbar.add_arg(&colorless.to_aind_atom()); - vbar.finish() - } - } - 3 => { - let mut e = FunctionBuilder::new(State::get_symbol("ϵ")); - e = e.add_arg(&Atom::new_num(num as i64)); - e = e.add_arg(&colorless.to_aind_atom()); - e.finish() - } - _ => panic!("higher spin not supported"), //Atom::parse("1").unwrap(), + if let Some(name) = self.in_pol_symbol() { + colorless + .complete_fn_builder(FunctionBuilder::new(name).add_arg(&Atom::new_num(num as i64))) + } else { + Atom::new_num(1) } } @@ -923,12 +884,12 @@ impl Particle { match self.spin { 2 => { if self.pdg_code > 0 { - Some(State::get_symbol("u")) + Some(GS.u) } else { - Some(State::get_symbol("vbar")) + Some(GS.vbar) } } - 3 => Some(State::get_symbol("ϵ")), + 3 => Some(GS.epsilon), _ => None, } } @@ -937,42 +898,57 @@ impl Particle { match self.spin { 2 => { if self.pdg_code > 0 { - Some(State::get_symbol("ubar")) + Some(GS.ubar) } else { - Some(State::get_symbol("v")) + Some(GS.v) } } - 3 => Some(State::get_symbol("ϵbar")), + 3 => Some(GS.epsilonbar), _ => None, } } pub fn incoming_polarization_atom_concrete( &self, - edge_slots: &EdgeSlots, + edge_slots: &EdgeSlots, num: usize, ) -> Vec { let mut colorless = edge_slots.clone(); colorless.color = vec![]; - colorless.to_dense_labels(|v, i| ExpandedCoefficent:: { - index: v.expanded_index(i).unwrap(), - name: self.in_pol_symbol(), - args: Some(num), - }) + if let Some(name) = self.in_pol_symbol() { + VecStructure::from(colorless) + .to_dense_labeled(|v, i| ExpandedCoefficent:: { + index: v.co_expanded_index(i).unwrap(), + name: Some(name), + args: Some(num), + }) + .unwrap() + .data + } else { + vec![] + } } pub fn outgoing_polarization_atom_concrete( &self, - edge_slots: &EdgeSlots, + edge_slots: &EdgeSlots, num: usize, ) -> Vec { let mut colorless = edge_slots.clone(); colorless.color = vec![]; - colorless.to_dense_labels(|v, i| ExpandedCoefficent:: { - index: v.expanded_index(i).unwrap(), - name: self.out_pol_symbol(), - args: Some(num), - }) + + if let Some(name) = self.out_pol_symbol() { + VecStructure::from(colorless) + .to_dense_labeled(|v, i| ExpandedCoefficent:: { + index: v.co_expanded_index(i).unwrap(), + name: Some(name), + args: Some(num), + }) + .unwrap() + .data + } else { + vec![] + } } pub fn incoming_polarization_match( @@ -1065,31 +1041,18 @@ impl Particle { } } - pub fn outgoing_polarization_atom(&self, edge_slots: &EdgeSlots, num: usize) -> Atom { + pub fn outgoing_polarization_atom( + &self, + edge_slots: &EdgeSlots, + num: usize, + ) -> Atom { let mut colorless = edge_slots.clone(); colorless.color = vec![]; - match self.spin { - 1 => Atom::parse("1").unwrap(), - 2 => { - if self.pdg_code > 0 { - let mut ubar = FunctionBuilder::new(State::get_symbol("ubar")); - ubar = ubar.add_arg(&Atom::new_num(num as i64)); - ubar = ubar.add_arg(&colorless.to_aind_atom()); - ubar.finish() - } else { - let mut v = FunctionBuilder::new(State::get_symbol("v")); - v = v.add_arg(&Atom::new_num(num as i64)); - v = v.add_arg(&colorless.to_aind_atom()); - v.finish() - } - } - 3 => { - let mut ebar = FunctionBuilder::new(State::get_symbol("ϵbar")); - ebar = ebar.add_arg(&Atom::new_num(num as i64)); - ebar = ebar.add_arg(&colorless.to_aind_atom()); - ebar.finish() - } - _ => Atom::parse("1").unwrap(), + if let Some(name) = self.out_pol_symbol() { + colorless + .complete_fn_builder(FunctionBuilder::new(name).add_arg(&Atom::new_num(num as i64))) + } else { + Atom::new_num(1) } } @@ -1784,6 +1747,8 @@ impl Model { } pub fn from_serializable_model(serializable_model: SerializableModel) -> Model { + UFO.t; + ETS.id; let mut model: Model = Model::default(); model.name = serializable_model.name; model.restriction = serializable_model.restriction; diff --git a/src/momentum.rs b/src/momentum.rs index 2fecf495..40d3f2b8 100644 --- a/src/momentum.rs +++ b/src/momentum.rs @@ -15,11 +15,14 @@ use spenso::{ data::{DataIterator, DataTensor, DenseTensor, HasTensorData, SetTensorData, SparseTensor}, iterators::IteratableTensor, parametric::{EvalTensor, FlatCoefficent, MixedTensor, ParamOrConcrete}, + shadowing::Shadowable, structure::{ - AbstractIndex, BaseRepName, Bispinor, CastStructure, Dual, DualSlotTo, Euclidean, - IndexLess, Lorentz, NamedStructure, NoArgs, PhysReps, RepName, Shadowable, Slot, - TensorStructure, ToSymbolic, VecStructure, + abstract_index::AbstractIndex, + representation::{BaseRepName, Bispinor, Euclidean, Minkowski, PhysReps, RepName}, + slot::{DualSlotTo, Slot}, + CastStructure, IndexLess, NamedStructure, TensorStructure, ToSymbolic, VecStructure, }, + symbolica_utils::NoArgs, upgrading_arithmetic::FallibleAdd, }; use symbolica::{ @@ -1267,7 +1270,7 @@ impl Polarization { } pub fn lorentz(value: [T; 4]) -> Self { - let structure = IndexLess::new(vec![Lorentz::new_dimed_rep_selfless(4).cast()]); + let structure = IndexLess::new(vec![Minkowski::rep(4).cast()]); Polarization { tensor: DenseTensor { data: value.to_vec(), @@ -1278,7 +1281,7 @@ impl Polarization { } pub fn bispinor_u(value: [T; 4]) -> Self { - let structure = IndexLess::new(vec![Bispinor::new_dimed_rep_selfless(4).cast()]); + let structure = IndexLess::new(vec![Bispinor::rep(4).cast()]); Polarization { tensor: DenseTensor { @@ -1290,7 +1293,7 @@ impl Polarization { } pub fn bispinor_v(value: [T; 4]) -> Self { - let structure = IndexLess::new(vec![Bispinor::new_dimed_rep_selfless(4).cast()]); + let structure = IndexLess::new(vec![Bispinor::rep(4).cast()]); Polarization { tensor: DenseTensor { @@ -1554,7 +1557,8 @@ impl FourMomentum { where T: Clone, { - let structure = VecStructure::from_iter([PhysReps::new_slot(Lorentz {}.into(), 4, index)]); + let structure = + VecStructure::from_iter([PhysReps::new_slot(Minkowski {}.into(), 4, index)]); DenseTensor::from_data( vec![ self.temporal.value, @@ -1576,8 +1580,9 @@ impl FourMomentum { where T: Clone, { - let structure = VecStructure::from_iter([PhysReps::new_slot(Lorentz {}.into(), 4, index)]) - .to_named(name, Some(num)); + let structure = + VecStructure::from_iter([PhysReps::new_slot(Minkowski {}.into(), 4, index)]) + .to_named(name, Some(num)); DenseTensor::from_data( vec![ self.temporal.value, @@ -2351,7 +2356,8 @@ impl FourMomentum { where T: Clone + Into + Exponent, { - let structure = VecStructure::from_iter([PhysReps::new_slot(Lorentz {}.into(), 4, index)]); + let structure = + VecStructure::from_iter([PhysReps::new_slot(Minkowski {}.into(), 4, index)]); let energy = self .temporal .value @@ -2573,9 +2579,9 @@ impl Rotation { } } pub fn new(method: RotationMethod) -> Self { - let mu = Lorentz::new_slot_selfless(4, 1); + let mu = Minkowski::slot(4, 1); - let al = Lorentz::new_slot_selfless(4, 3); + let al = Minkowski::slot(4, 3); let mud = mu.dual(); let shadow: NamedStructure = @@ -2604,9 +2610,9 @@ impl Rotation { .unwrap() .linearize(Some(1)); - let i = Bispinor::new_slot_selfless(4, 1); + let i = Bispinor::slot(4, 1); - let j = Bispinor::new_slot_selfless(4, 3); + let j = Bispinor::slot(4, 3); let shadow: NamedStructure = VecStructure::from_iter([i.cast::()]).to_named("u".to_string(), None); @@ -2641,8 +2647,8 @@ impl Rotation { impl RotationMethod { pub fn generator(&self, i: AbstractIndex, j: AbstractIndex) -> DataTensor { let structure = VecStructure::from_iter([ - PhysReps::new_slot(Lorentz {}.into(), 4, i), - PhysReps::new_slot(Lorentz {}.into(), 4, j), + PhysReps::new_slot(Minkowski {}.into(), 4, i), + PhysReps::new_slot(Minkowski {}.into(), 4, j), ]); let zero = 0.; match self { @@ -2685,8 +2691,8 @@ impl RotationMethod { pub fn lorentz_tensor( &self, - i: Slot>, - j: Slot, + i: Slot, + j: Slot, ) -> DataTensor { let structure = VecStructure::from_iter([i.cast::(), j.cast()]); @@ -2978,7 +2984,7 @@ mod tests { arithmetic::ScalarMul, contraction::Contract, iterators::IteratableTensor, - structure::{DualSlotTo, TensorStructure}, + structure::{slot::DualSlotTo, TensorStructure}, ufo, upgrading_arithmetic::{FallibleAdd, FallibleSub}, }; @@ -3502,9 +3508,9 @@ mod tests { #[test] fn omega() { - let mu = PhysReps::new_slot(Lorentz {}.into(), 4, 0); + let mu = PhysReps::new_slot(Minkowski {}.into(), 4, 0); - let nu = PhysReps::new_slot(Lorentz {}.into(), 4, 1); + let nu = PhysReps::new_slot(Minkowski {}.into(), 4, 1); let mud = mu.dual(); diff --git a/src/numerator.rs b/src/numerator.rs index 73ed7994..ee250a3b 100644 --- a/src/numerator.rs +++ b/src/numerator.rs @@ -33,23 +33,35 @@ use spenso::data::DataTensor; use spenso::network::Levels; use spenso::parametric::{ - EvalTensor, EvalTensorSet, LinearizedEvalTensorSet, ParamTensorSet, SerializableAtom, + EvalTensor, EvalTensorSet, LinearizedEvalTensorSet, ParamTensorSet, SerializableCompiledEvaluator, TensorSet, }; -use spenso::structure::{HasStructure, ScalarTensor, SerializableSymbol, SmartShadowStructure}; +use spenso::shadowing::ETS; +use spenso::structure::representation::{BaseRepName, ColorAdjoint, ColorFundamental}; +use spenso::structure::{HasStructure, ScalarTensor, SmartShadowStructure}; +use spenso::symbolica_utils::SerializableAtom; +use spenso::symbolica_utils::SerializableSymbol; use spenso::{ complex::Complex, network::TensorNetwork, parametric::{ParamTensor, PatternReplacement}, - structure::{Lorentz, NamedStructure, PhysReps, RepName, Shadowable, TensorStructure}, + shadowing::Shadowable, + structure::{ + representation::{Lorentz, PhysReps, RepName}, + NamedStructure, TensorStructure, + }, }; +use crate::numerator::ufo::UFO; use symbolica::atom::AtomView; use symbolica::evaluate::ExpressionEvaluator; use symbolica::id::{Condition, Match, MatchSettings, PatternOrMap}; + use symbolica::{ atom::{Atom, FunctionBuilder}, + fun, state::State, + symb, }; use symbolica::{ domains::{float::NumericalFloatLike, rational::Rational}, @@ -57,6 +69,7 @@ use symbolica::{ id::{Pattern, Replacement}, }; +pub mod ufo; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NumeratorSettings { pub eval_settings: NumeratorEvaluatorOptions, @@ -488,6 +501,8 @@ pub struct UnInit; impl Default for UnInit { fn default() -> Self { + UFO.f; + ETS.gamma; UnInit } } @@ -615,7 +630,9 @@ impl Numerator { impl Default for Numerator { fn default() -> Self { - Numerator { state: UnInit } + Numerator { + state: UnInit::default(), + } } } @@ -796,14 +813,26 @@ impl Numerator { fn color_simplify_global_impl(mut expression: SerializableAtom) -> SerializableAtom { ColorSimplified::isolate_color(&mut expression); + println!("{}", expression); let (mut coefs, rem) = expression.0.coefficient_list(State::get_symbol("color")); let mut atom = Atom::new_num(0); for (key, coef) in coefs.iter_mut() { - let color_simplified = ColorSimplified::color_symplify_impl(key.clone().into()) - .0 - .factor(); + if let AtomView::Fun(f) = key.as_view() { + let mut key = Atom::new(); + + key.set_from_view(&f.iter().next().unwrap()); - atom = atom + coef.factor() * color_simplified; + println!("{key}"); + let color_simplified = ColorSimplified::color_symplify_impl(key.clone().into()) + .0 + .factor(); + + println!("{coef}"); + + atom = atom + coef.factor() * color_simplified; + } else { + panic!("not a color fun"); + } // println!("coef {i}:{}\n", coef.factor()); } atom = atom + rem; @@ -1008,20 +1037,20 @@ impl ColorSimplified { expression.0 = &expression.0 * color_fn; let replacements = vec![ ( - Pattern::parse("f_(x___,aind(y___,cof(i__),z___))*color(a___)").unwrap(), - Pattern::parse("color(a___*f_(x___,aind(y___,cof(i__),z___)))") + Pattern::parse("f_(x___,cof(3,i_),z___)*color(a___)").unwrap(), + Pattern::parse("color(a___*f_(x___,cof(3,i_),z___))") .unwrap() .into(), ), ( - Pattern::parse("f_(x___,aind(y___,coaf(i__),z___))*color(a___)").unwrap(), - Pattern::parse("color(a___*f_(x___,aind(y___,coaf(i__),z___)))") + Pattern::parse("f_(x___,dind(cof(3,i_)),z___)*color(a___)").unwrap(), + Pattern::parse("color(a___*f_(x___,dind(cof(3,i_)),z___))") .unwrap() .into(), ), ( - Pattern::parse("f_(x___,aind(y___,coad(i__),z___))*color(a___)").unwrap(), - Pattern::parse("color(a___*f_(x___,aind(y___,coad(i__),z___)))") + Pattern::parse("f_(x___,coad(i__),z___)*color(a___)").unwrap(), + Pattern::parse("color(a___*f_(x___,coad(i__),z___))") .unwrap() .into(), ), @@ -1061,46 +1090,137 @@ impl ColorSimplified { } pub fn color_symplify_impl(mut expression: SerializableAtom) -> SerializableAtom { - let replacements = vec![ - (Pattern::parse("color(a___)").unwrap(),Pattern::parse("a___").unwrap().into()), - (Pattern::parse("f_(x___,aind(y___,cof(i__),z___))*id(aind(coaf(i__),cof(j__)))").unwrap(),Pattern::parse("f_(x___,aind(y___,cof(j__),z___))").unwrap().into()), - (Pattern::parse("f_(x___,aind(y___,cof(j__),z___))*id(aind(cof(i__),coaf(j__)))").unwrap(),Pattern::parse("f_(x___,aind(y___,cof(i__),z___))").unwrap().into()), - (Pattern::parse("f_(x___,aind(y___,coaf(i__),z___))*id(aind(cof(j__),coaf(i__)))").unwrap(),Pattern::parse("f_(x___,aind(y___,coaf(j__),z___))").unwrap().into()), - (Pattern::parse("f_(x___,aind(y___,coaf(i__),z___))*id(aind(coaf(j__),cof(i__)))").unwrap(),Pattern::parse("f_(x___,aind(y___,coaf(j__),z___))").unwrap().into()), - (Pattern::parse("f_(x___,aind(y___,coad(i__),z___))*id(aind(coad(j__),coad(i__)))").unwrap(),Pattern::parse("f_(x___,aind(y___,coad(j__),z___))").unwrap().into()), + let f_ = symb!("f_"); + let cof = ColorFundamental::rep(3); + let coaf = ColorFundamental::rep(3).dual(); + let coad = ColorAdjoint::rep(8); + let a___ = Atom::new_var(symb!("a___")); + let a_ = Atom::new_var(symb!("a_")); + let b_ = Atom::new_var(symb!("b_")); + let c___ = Atom::new_var(symb!("c___")); + let c_ = Atom::new_var(symb!("c_")); + let d_ = Atom::new_var(symb!("d_")); + let e_ = Atom::new_var(symb!("e_")); + let i_ = Atom::new_var(symb!("i_")); + let i = symb!("i"); + let j = symb!("j"); + let k = symb!("k"); + + let tr = Atom::new_var(symb!("TR")); + let nc = Atom::new_var(symb!("Nc")); + let reps = vec![ ( - Pattern::parse("id(aind(coaf(3,a_),cof(3,a_)))").unwrap(), - Pattern::parse("Nc").unwrap().into(), + fun!(f_, a___, cof.pattern(&b_), c___) + * fun!(ETS.id, coaf.pattern(&b_), cof.pattern(&c_)), + fun!(f_, a___, cof.pattern(&c_), c___), ), + // ( + // fun!(f_, a___, cof.pattern(&c_), c___) + // * fun!(ETS.id, cof.pattern(&b_), coaf.pattern(&c_)), + // fun!(f_, a___, cof.pattern(&b_), c___), + // ), ( - Pattern::parse("id(aind(cof(3,a_),coaf(3,a_)))").unwrap(), - Pattern::parse("Nc").unwrap().into(), + fun!(f_, a___, coaf.pattern(&b_), c___) + * fun!(ETS.id, cof.pattern(&b_), coaf.pattern(&c_)), + fun!(f_, a___, coaf.pattern(&c_), c___), ), + // ( + // fun!(f_, a___, coaf.pattern(&c_), c___) + // * fun!(ETS.id, coaf.pattern(&b_), cof.pattern(&c_)), + // fun!(f_, a___, coaf.pattern(&b_), c___), + // ), ( - Pattern::parse("id(aind(coad(8,a_),coad(8,a_)))").unwrap(), - Pattern::parse("Nc*Nc -1").unwrap().into(), + fun!(f_, a___, coad.pattern(&b_), c___) + * fun!(ETS.id, coad.pattern(&b_), coad.pattern(&a_)), + fun!(f_, a___, coad.pattern(&a_), c___), ), ( - Pattern::parse("T(aind(coad(8,b_),cof(3,a_),coaf(3,a_)))").unwrap(), - Pattern::parse("0").unwrap().into(), + fun!(f_, a___, coad.pattern(&a_), c___) + * fun!(ETS.id, coad.pattern(&b_), coad.pattern(&a_)), + fun!(f_, a___, coad.pattern(&b_), c___), ), ( - Pattern::parse("T(aind(coad(8,c_),cof(3,a_),coaf(3,b_)))T(aind(coad(8,d_),cof(3,b_),coaf(3,a_)))").unwrap(), - Pattern::parse("TR* id(aind(coad(8,c_),coad(8,d_)))").unwrap().into(), + fun!(ETS.id, coaf.pattern(&a_), cof.pattern(&a_)), + nc.clone(), ), ( - Pattern::parse("T(aind(coad(8,g_),cof(3,a_),coaf(3,b_)))*T(aind(coad(8,g_),cof(3,c_),coaf(3,d_)))").unwrap(), - Pattern::parse("TR* (id(aind(cof(3,a_),coaf(3,d_)))* id(aind(cof(3,c_),coaf(3,b_)))-1/Nc id(aind(cof(3,a_),coaf(3,b_)))* id(aind(cof(3,c_),coaf(3,d_))))").unwrap().into(), + fun!(ETS.id, cof.pattern(&a_), coaf.pattern(&a_)), + nc.clone(), ), ( - Pattern::parse("T(aind(coad(8,g_),cof(3,a_),coaf(3,b_)))*T(aind(coad(8,e_),cof(3,b_),coaf(3,c_)))*T(aind(coad(8,g_),cof(3,c_),coaf(3,d_)))").unwrap(), - Pattern::parse("-TR/Nc T(aind(coad(8,e_),cof(3,a_),coaf(3,d_)))").unwrap().into(), + fun!(ETS.id, coad.pattern(&a_), coad.pattern(&a_)), + (&nc * &nc) - 1, ), ( - Pattern::parse("f(aind(coad(8,a_),coad(8,b_),coad(8,c_)))").unwrap(), - Pattern::parse("1/TR *(T(aind(coad(8,a_),cof(3,i(a_,b_,c_)),coaf(3,j(a_,b_,c_))))*T(aind(coad(8,b_),cof(3,j(a_,b_,c_)),coaf(3,k(a_,b_,c_))))*T(aind(coad(8,c_),cof(3,k(a_,b_,c_)),coaf(3,i(a_,b_,c_))))-T(aind(coad(8,a_),cof(3,j(a_,b_,c_)),coaf(3,k(a_,b_,c_))))*T(aind(coad(8,b_),cof(3,i(a_,b_,c_)),coaf(3,j(a_,b_,c_))))*T(aind(coad(8,c_),cof(3,k(a_,b_,c_)),coaf(3,i(a_,b_,c_)))))").unwrap().into(), - ) + fun!(UFO.t, a_, cof.pattern(&b_), coaf.pattern(&b_)), + Atom::new_num(0), + ), + ( + fun!(UFO.t, a_, cof.pattern(&c_), coaf.pattern(&e_)) + * fun!(UFO.t, b_, cof.pattern(&e_), coaf.pattern(&c_)), + &tr * fun!(ETS.id, a_, b_), + ), + ( + fun!(UFO.t, &e_, a_, b_) * fun!(UFO.t, &e_, c_, d_), + &tr * (fun!(ETS.id, a_, d_) * fun!(ETS.id, c_, b_) + - (fun!(ETS.id, a_, b_) * fun!(ETS.id, c_, d_) / &nc)), + ), + ( + fun!(UFO.t, i_, a_, coaf.pattern(&b_)) + * fun!(UFO.t, e_, cof.pattern(&b_), coaf.pattern(&c_)) + * fun!(UFO.t, i_, cof.pattern(&c_), d_), + -(&tr / &nc) * fun!(UFO.t, e_, a_, d_), + ), + ( + fun!( + UFO.f, + coad.pattern(&a_), + coad.pattern(&b_), + coad.pattern(&c_) + ), + (fun!( + UFO.t, + coad.pattern(&a_), + cof.pattern(&fun!(i, a_, b_, c_)), + coaf.pattern(&fun!(j, a_, b_, c_)) + ) * fun!( + UFO.t, + coad.pattern(&b_), + cof.pattern(&fun!(j, a_, b_, c_)), + coaf.pattern(&fun!(k, a_, b_, c_)) + ) * fun!( + UFO.t, + coad.pattern(&c_), + cof.pattern(&fun!(k, a_, b_, c_)), + coaf.pattern(&fun!(i, a_, b_, c_)) + ) - fun!( + UFO.t, + coad.pattern(&a_), + cof.pattern(&fun!(j, a_, b_, c_)), + coaf.pattern(&fun!(k, a_, b_, c_)) + ) * fun!( + UFO.t, + coad.pattern(&b_), + cof.pattern(&fun!(i, a_, b_, c_)), + coaf.pattern(&fun!(j, a_, b_, c_)) + ) * fun!( + UFO.t, + coad.pattern(&c_), + cof.pattern(&fun!(k, a_, b_, c_)), + coaf.pattern(&fun!(i, a_, b_, c_)) + )) / &tr, + ), ]; + + for (a, b) in &reps { + println!("{a}->{b}"); + } + + let replacements: Vec<(Pattern, PatternOrMap)> = reps + .into_iter() + .map(|(a, b)| (a.into_pattern(), b.into_pattern().into())) + .collect(); + let settings = MatchSettings { rhs_cache_size: 0, ..Default::default() @@ -1220,8 +1340,8 @@ impl GammaSimplified { pub fn gamma_symplify_impl(mut expr: SerializableAtom) -> SerializableAtom { expr.0 = expr.0.expand(); let pats = [( - Pattern::parse("id(aind(a_,b_))*t_(aind(d___,b_,c___))").unwrap(), - Pattern::parse("t_(aind(d___,a_,c___))").unwrap().into(), + Pattern::parse("id(a_,b_)*t_(d___,b_,c___)").unwrap(), + Pattern::parse("t_(d___,a_,c___)").unwrap().into(), )]; let reps: Vec = pats @@ -1231,57 +1351,46 @@ impl GammaSimplified { expr.replace_repeat_multiple(&reps); let pats = vec![ ( - Pattern::parse("ProjP(aind(a_,b_))").unwrap(), - Pattern::parse("1/2*id(aind(a_,b_))-1/2*gamma5(aind(a_,b_))") + Pattern::parse("ProjP(a_,b_)").unwrap(), + Pattern::parse("1/2*id(a_,b_)-1/2*gamma5(a_,b_)") .unwrap() .into(), ), ( - Pattern::parse("ProjM(aind(a_,b_))").unwrap(), - Pattern::parse("1/2*id(aind(a_,b_))+1/2*gamma5(aind(a_,b_))") + Pattern::parse("ProjM(a_,b_)").unwrap(), + Pattern::parse("1/2*id(a_,b_)+1/2*gamma5(a_,b_)") .unwrap() .into(), ), ( - Pattern::parse("id(aind(a_,b_))*f_(c___,aind(d___,b_,e___))").unwrap(), - Pattern::parse("f_(c___,aind(d___,a_,e___))") - .unwrap() - .into(), + Pattern::parse("id(a_,b_)*f_(d___,b_,e___)").unwrap(), + Pattern::parse("f_(c___,a_,e___)").unwrap().into(), ), + // ( + // Pattern::parse("id(aind(a_,b_))*f_(c___,aind(d___,a_,e___))").unwrap(), + // Pattern::parse("f_(c___,aind(d___,b_,e___))") + // .unwrap() + // .into(), + // ), ( - Pattern::parse("id(aind(a_,b_))*f_(c___,aind(d___,a_,e___))").unwrap(), - Pattern::parse("f_(c___,aind(d___,b_,e___))") - .unwrap() - .into(), + Pattern::parse("γ(a_,b_,c_)*γ(d_,c_,e_)").unwrap(), + Pattern::parse("gamma_chain(a_,d_,b_,e_)").unwrap().into(), ), ( - Pattern::parse("γ(aind(a_,b_,c_))*γ(aind(d_,c_,e_))").unwrap(), - Pattern::parse("gamma_chain(aind(a_,d_,b_,e_))") - .unwrap() - .into(), + Pattern::parse("gamma_chain(a__,b_,c_)*gamma_chain(d__,c_,e_)").unwrap(), + Pattern::parse("gamma_chain(a__,d__,b_,e_)").unwrap().into(), ), ( - Pattern::parse("gamma_chain(aind(a__,b_,c_))*gamma_chain(aind(d__,c_,e_))") - .unwrap(), - Pattern::parse("gamma_chain(aind(a__,d__,b_,e_))") - .unwrap() - .into(), + Pattern::parse("γ(a_,b_,c_)*gamma_chain(d__,c_,e_)").unwrap(), + Pattern::parse("gamma_chain(a_,d__,b_,e_)").unwrap().into(), ), ( - Pattern::parse("γ(aind(a_,b_,c_))*gamma_chain(aind(d__,c_,e_))").unwrap(), - Pattern::parse("gamma_chain(aind(a_,d__,b_,e_))") - .unwrap() - .into(), - ), - ( - Pattern::parse("gamma_chain(aind(a__,b_,c_))*γ(aind(d_,c_,e_))").unwrap(), - Pattern::parse("gamma_chain(aind(a__,d_,b_,e_))") - .unwrap() - .into(), + Pattern::parse("gamma_chain(a__,b_,c_)*γ(d_,c_,e_)").unwrap(), + Pattern::parse("gamma_chain(a__,d_,b_,e_)").unwrap().into(), ), ( - Pattern::parse("gamma_chain(aind(a__,b_,b_))").unwrap(), - Pattern::parse("gamma_trace(aind(a__))").unwrap().into(), + Pattern::parse("gamma_chain(a__,b_,b_)").unwrap(), + Pattern::parse("gamma_trace(a__)").unwrap().into(), ), ]; let reps: Vec = pats @@ -1305,18 +1414,14 @@ impl GammaSimplified { for (_, v) in a.match_stack { match v { Match::Single(s) => { - match s { - AtomView::Fun(f) => { - let a = f.get_nargs(); - if a > max_nargs { - max_nargs = a; - } - } - _ => { - panic!("should be a function") - } + if max_nargs < 1 { + max_nargs = 1; + } + } + Match::Multiple(s, v) => { + if max_nargs < v.len() { + max_nargs = v.len(); } - // print!("{}", s) } _ => panic!("should be a single match"), } @@ -1331,15 +1436,10 @@ impl GammaSimplified { // sum((-1)**(k+1) * d(p_[0], p_[k]) * f(*p_[1:k], *p_[k+1:l]) for j in 1..n { - let gamma_chain_builder = - FunctionBuilder::new(State::get_symbol("gamma_trace")); - let mut gamma_chain_builder_slots = - FunctionBuilder::new(State::get_symbol("aind")); - - let metric_builder = FunctionBuilder::new(State::get_symbol("g")); + FunctionBuilder::new(State::get_symbol("gamma_trace")); - let metric_builder_slots = FunctionBuilder::new(State::get_symbol("aind")); + let metric_builder_slots = FunctionBuilder::new(State::get_symbol("Metric")); for k in 1..j { let mu = Atom::parse(&format!("a{}_", k)).unwrap(); @@ -1351,21 +1451,14 @@ impl GammaSimplified { gamma_chain_builder_slots = gamma_chain_builder_slots.add_arg(&mu); } - let metric = metric_builder - .add_arg( - &metric_builder_slots - .add_args(&[ - &Atom::parse(&format!("a{}_", 0)).unwrap(), - &Atom::parse(&format!("a{}_", j)).unwrap(), - ]) - .finish(), - ) + let metric = metric_builder_slots + .add_args(&[ + &Atom::parse(&format!("a{}_", 0)).unwrap(), + &Atom::parse(&format!("a{}_", j)).unwrap(), + ]) .finish(); - let gamma = &gamma_chain_builder - .add_arg(&gamma_chain_builder_slots.finish()) - .finish() - * &metric; + let gamma = gamma_chain_builder_slots.finish() * &metric; if j % 2 == 0 { sum = &sum - γ @@ -1374,93 +1467,89 @@ impl GammaSimplified { } } - let gamma_chain_builder = FunctionBuilder::new(State::get_symbol("gamma_trace")); - let mut gamma_chain_builder_slots = FunctionBuilder::new(State::get_symbol("aind")); + let mut gamma_chain_builder_slots = + FunctionBuilder::new(State::get_symbol("gamma_trace")); for k in 0..n { let mu = Atom::parse(&format!("a{}_", k)).unwrap(); gamma_chain_builder_slots = gamma_chain_builder_slots.add_arg(&mu); } - let a = gamma_chain_builder - .add_arg(&gamma_chain_builder_slots.finish()) - .finish(); + let a = gamma_chain_builder_slots.finish(); reps.push((a.into_pattern(), sum.into_pattern().into())); } else { - let gamma_chain_builder = FunctionBuilder::new(State::get_symbol("gamma_trace")); - let mut gamma_chain_builder_slots = FunctionBuilder::new(State::get_symbol("aind")); + let mut gamma_chain_builder_slots = + FunctionBuilder::new(State::get_symbol("gamma_trace")); for k in 0..n { let mu = Atom::parse(&format!("a{}_", k)).unwrap(); gamma_chain_builder_slots = gamma_chain_builder_slots.add_arg(&mu); } - let a = gamma_chain_builder - .add_arg(&gamma_chain_builder_slots.finish()) - .finish(); + let a = gamma_chain_builder_slots.finish(); // println!("{}", a); reps.push((a.into_pattern(), Atom::new_num(0).into_pattern().into())); } } reps.push(( - Pattern::parse("gamma_trace(aind())").unwrap(), + Pattern::parse("gamma_trace()").unwrap(), Pattern::parse("4").unwrap().into(), )); // Dd reps.push(( - Pattern::parse("f_(i_,aind(loru(a__)))*g(aind(lord(a__),lord(b__)))").unwrap(), - Pattern::parse("f_(i_,aind(lord(b__)))").unwrap().into(), + Pattern::parse("f_(i_,a_)*Metric(a_,b_)").unwrap(), + Pattern::parse("f_(i_,b_)").unwrap().into(), )); // Du + // reps.push(( + // Pattern::parse("f_(i_,a_)*Metric(a_,b_)").unwrap(), + // Pattern::parse("f_(i_,b_)").unwrap().into(), + // )); reps.push(( - Pattern::parse("f_(i_,aind(loru(a__)))*g(aind(lord(a__),loru(b__)))").unwrap(), - Pattern::parse("f_(i_,aind(loru(b__)))").unwrap().into(), - )); - reps.push(( - Pattern::parse("f_(i_,aind(loru(a__)))*id(aind(lord(a__),loru(b__)))").unwrap(), - Pattern::parse("f_(i_,aind(loru(b__)))").unwrap().into(), + Pattern::parse("f_(i_,a_)*id(a_,b_)").unwrap(), + Pattern::parse("f_(i_,b_)").unwrap().into(), )); // Uu - reps.push(( - Pattern::parse("f_(i_,aind(lord(a__)))*g(aind(loru(a__),loru(b__)))").unwrap(), - Pattern::parse("f_(i_,aind(loru(b__)))").unwrap().into(), - )); - // Ud - reps.push(( - Pattern::parse("f_(i_,aind(lord(a__)))*g(aind(loru(a__),lord(b__)))").unwrap(), - Pattern::parse("f_(i_,aind(lord(b__)))").unwrap().into(), - )); - reps.push(( - Pattern::parse("f_(i_,aind(lord(a__)))*id(aind(loru(a__),lord(b__)))").unwrap(), - Pattern::parse("f_(i_,aind(lord(b__)))").unwrap().into(), - )); - // dD - reps.push(( - Pattern::parse("f_(i_,aind(loru(a__)))*g(aind(lord(b__),lord(a__)))").unwrap(), - Pattern::parse("f_(i_,aind(lord(b__)))").unwrap().into(), - )); - // uD - reps.push(( - Pattern::parse("f_(i_,aind(loru(a__)))*g(aind(loru(b__),lord(a__)))").unwrap(), - Pattern::parse("f_(i_,aind(loru(b__)))").unwrap().into(), - )); - reps.push(( - Pattern::parse("f_(i_,aind(loru(a__)))*id(aind(loru(b__),lord(a__)))").unwrap(), - Pattern::parse("f_(i_,aind(loru(b__)))").unwrap().into(), - )); - // uU - reps.push(( - Pattern::parse("f_(i_,aind(lord(a__)))*g(aind(loru(b__),loru(a__)))").unwrap(), - Pattern::parse("f_(i_,aind(loru(b__)))").unwrap().into(), - )); + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*g(mink(a__),mink(b__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // // Ud + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*g(mink(a__),mink(b__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*id(mink(a__),mink(b__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // // dD + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*g(mink(b__),mink(a__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // // uD + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*g(mink(b__),mink(a__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*id(mink(b__),mink(a__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // // uU + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*g(mink(b__),mink(a__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); // dU - reps.push(( - Pattern::parse("f_(i_,aind(lord(a__)))*g(aind(lord(b__),loru(a__)))").unwrap(), - Pattern::parse("f_(i_,aind(lord(b__)))").unwrap().into(), - )); - reps.push(( - Pattern::parse("f_(i_,aind(lord(a__)))*id(aind(lord(b__),loru(a__)))").unwrap(), - Pattern::parse("f_(i_,aind(lord(b__)))").unwrap().into(), - )); + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*g(mink(b__),mink(a__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); + // reps.push(( + // Pattern::parse("f_(i_,mink(a__)))*id(mink(b__),mink(a__)))").unwrap(), + // Pattern::parse("f_(i_,mink(b__)))").unwrap().into(), + // )); let reps = reps .iter() @@ -1469,7 +1558,6 @@ impl GammaSimplified { expr.replace_repeat_multiple(&reps); expr.0 = expr.0.expand(); expr.replace_repeat_multiple(&reps); - expr } @@ -1848,6 +1936,10 @@ impl Contracted { let quad_values = param_values.iter().map(|c| c.map(|f| f.higher())).collect(); + // for p in params.iter() { + // println!("Param: {}", p); + // } + (params, param_values, quad_values, model_params_start) } } diff --git a/src/numerator/snapshots/_gammaloop__numerator__tests__Single color string.snap b/src/numerator/snapshots/_gammaloop__numerator__tests__Single color string.snap index 8a1bf990..372e211b 100644 --- a/src/numerator/snapshots/_gammaloop__numerator__tests__Single color string.snap +++ b/src/numerator/snapshots/_gammaloop__numerator__tests__Single color string.snap @@ -1,5 +1,5 @@ --- source: src/numerator/tests.rs -expression: "Numerator::default().from_global(Atom::parse(\"f(aind(coad(8,1),coad(8,11),coad(8,21)))*f(aind(coad(8,21),coad(8,2),coad(8,12)))*f(aind(coad(8,3),coad(8,12),coad(8,22)))*f(aind(coad(8,22),coad(8,4),coad(8,13)))*f(aind(coad(8,5),coad(8,13),coad(8,23)))*f(aind(coad(8,23),coad(8,6),coad(8,14)))*f(aind(coad(8,7),coad(8,14),coad(8,24)))*f(aind(coad(8,24),coad(8,8),coad(8,11)))*f(aind(coad(8,1),coad(8,2),coad(8,3)))*f(aind(coad(8,4),coad(8,5),coad(8,6)))*id(aind(coad(8,7),coad(8,8)))\").unwrap(),\nNone).color_simplify().export()" +expression: "Numerator::default().from_global(Atom::parse(\"f(coad(8,1),coad(8,11),coad(8,21))*f(coad(8,21),coad(8,2),coad(8,12))*f(coad(8,3),coad(8,12),coad(8,22))*f(coad(8,22),coad(8,4),coad(8,13))*f(coad(8,5),coad(8,13),coad(8,23))*f(coad(8,23),coad(8,6),coad(8,14))*f(coad(8,7),coad(8,14),coad(8,24))*f(coad(8,24),coad(8,8),coad(8,11))*f(coad(8,1),coad(8,2),coad(8,3))*f(coad(8,4),coad(8,5),coad(8,6))*id(coad(8,7),coad(8,8))\").unwrap(),\nNone).color_simplify().export()" --- -8*Nc^5*TR^5*(Nc-1)*(Nc+1) +8*TR^5*Nc^5*(Nc-1)*(Nc+1) diff --git a/src/numerator/tests.rs b/src/numerator/tests.rs index e87c24f0..221a06f8 100644 --- a/src/numerator/tests.rs +++ b/src/numerator/tests.rs @@ -45,7 +45,7 @@ fn hairy_glue_box() { println!("{i}:{}", s); } - let color = graph.derived_data.unwrap().numerator.from_graph(&graph.bare_graph,Some(&GlobalPrefactor{color:Atom::parse("f(aind(coad(8,1),coad(8,2),coad(8,3)))*f(aind(coad(8,4),coad(8,5),coad(8,6)))*id(aind(coad(8,7),coad(8,0)))").unwrap(),colorless:Atom::new_num(1)})).color_simplify().state.color.to_dense().map_data(|a|a.to_string()); + let color = graph.derived_data.unwrap().numerator.from_graph(&graph.bare_graph,Some(&GlobalPrefactor{color:Atom::parse("f(aind(coad(8,1),coad(8,2),coad(8,3)))*f(aind(coad(8,4),coad(8,5),coad(8,6)))*id(aind(coad(8,7),coad(8,0)))").unwrap(),colorless:Atom::new_num(1)})).color_simplify().state.color.to_bare_dense().map_data(|a|a.to_string()); insta::assert_ron_snapshot!(color); } @@ -119,7 +119,7 @@ fn trees() { println!("{i}:{}", s); } export_settings.numerator_settings.global_prefactor = Some(GlobalPrefactor { - color: Atom::parse("id(aind(cof(3,2),coaf(3,0)))/Nc").unwrap(), + color: Atom::parse("id(cof(3,2),dind(cof(3,0)))/Nc").unwrap(), colorless: Atom::new_num(1), }); @@ -189,7 +189,7 @@ fn tree_ta_ta_1() { let mut test_export_settings = test_export_settings(); test_export_settings.numerator_settings.global_prefactor = Some(GlobalPrefactor { - color: Atom::parse("id(aind(coaf(3,0),cof(3,2)))/Nc").unwrap(), + color: Atom::parse("id(dind(cof(3,0)),cof(3,2))/Nc").unwrap(), colorless: Atom::new_num(1), }); @@ -404,7 +404,7 @@ fn tree_h_ttxaah_1() { // } let mut test_export_settings = test_export_settings(); test_export_settings.numerator_settings.global_prefactor = Some(GlobalPrefactor { - color: Atom::parse("id(aind(cof(3,1),coaf(3,2)))/Nc").unwrap(), + color: Atom::parse("id(cof(3,1),dind(cof(3,2)))/Nc").unwrap(), colorless: Atom::new_num(1), }); @@ -456,7 +456,7 @@ fn tree_hh_ttxaa_1() { } let mut test_export_settings = test_export_settings(); test_export_settings.numerator_settings.global_prefactor = Some(GlobalPrefactor { - color: Atom::parse("id(aind(cof(3,2),coaf(3,3)))/Nc").unwrap(), + color: Atom::parse("id(cof(3,2),dind(cof(3,3)))/Nc").unwrap(), colorless: Atom::new_num(1), }); @@ -625,15 +625,16 @@ fn load_tree(tree_name: &str, amp_num: usize) -> (Model, Amplitude, Path #[test] fn tree_h_ttxaah_0() { let _ = env_logger::builder().is_test(true).try_init(); - let expr = Atom::parse("-8/3*𝑖*ee^2*vev*lam*yt*(MT*id(aind(bis(4,3),bis(4,4)))+Q(6,aind(lord(4,5)))*γ(aind(loru(4,5),bis(4,3),bis(4,4))))*(MT*id(aind(bis(4,5),bis(4,6)))+Q(7,aind(lord(4,11)))*γ(aind(loru(4,11),bis(4,5),bis(4,6))))*(ProjM(aind(bis(4,7),bis(4,6)))+ProjP(aind(bis(4,7),bis(4,6))))*sqrt(2)^-1*id(aind(coaf(3,5),cof(3,6)))*id(aind(coaf(3,6),cof(3,7)))*id(aind(coaf(3,7),cof(3,8)))*id(aind(coaf(3,8),cof(3,9)))*id(aind(coaf(3,9),cof(3,10)))*γ(aind(lord(4,2),bis(4,3),bis(4,2)))*γ(aind(lord(4,3),bis(4,5),bis(4,4)))*ubar(1,aind(bis(4,2)))*v(2,aind(bis(4,7)))*ϵbar(3,aind(loru(4,2)))*ϵbar(4,aind(loru(4,3)))").unwrap(); + + let num = Numerator::default(); + let expr = Atom::parse("-8/3*𝑖*ee^2*vev*lam*yt*(MT*id(bis(4,3),bis(4,4))+Q(6,mink(4,5))*γ(mink(4,5),bis(4,3),bis(4,4)))*(MT*id(bis(4,5),bis(4,6))+Q(7,mink(4,11))*γ(mink(4,11),bis(4,5),bis(4,6)))*(ProjM(bis(4,7),bis(4,6))+ProjP(bis(4,7),bis(4,6)))*sqrt(2)^-1*id(dind(cof(3,5)),cof(3,6))*id(dind(cof(3,6)),cof(3,7))*id(dind(cof(3,7)),cof(3,8))*id(dind(cof(3,8)),cof(3,9))*id(dind(cof(3,9)),cof(3,10))*γ(mink(4,2),bis(4,3),bis(4,2))*γ(mink(4,3),bis(4,5),bis(4,4))*ubar(1,bis(4,2))*v(2,bis(4,7))*ϵbar(3,mink(4,2))*ϵbar(4,mink(4,3))").unwrap(); let prefactor = GlobalPrefactor { - color: Atom::parse("id(aind(cof(3,5),coaf(3,10)))").unwrap(), + color: Atom::parse("id(cof(3,5),dind(cof(3,10)))").unwrap(), colorless: Atom::new_num(1), }; - Numerator::default() - .from_global(expr, Some(&prefactor)) + num.from_global(expr, Some(&prefactor)) .color_simplify() // .color_project() // .gamma_symplify() @@ -645,5 +646,5 @@ fn tree_h_ttxaah_0() { #[test] fn color() { - insta::assert_snapshot!("Single color string",Numerator::default().from_global(Atom::parse("f(aind(coad(8,1),coad(8,11),coad(8,21)))*f(aind(coad(8,21),coad(8,2),coad(8,12)))*f(aind(coad(8,3),coad(8,12),coad(8,22)))*f(aind(coad(8,22),coad(8,4),coad(8,13)))*f(aind(coad(8,5),coad(8,13),coad(8,23)))*f(aind(coad(8,23),coad(8,6),coad(8,14)))*f(aind(coad(8,7),coad(8,14),coad(8,24)))*f(aind(coad(8,24),coad(8,8),coad(8,11)))*f(aind(coad(8,1),coad(8,2),coad(8,3)))*f(aind(coad(8,4),coad(8,5),coad(8,6)))*id(aind(coad(8,7),coad(8,8)))").unwrap(), None).color_simplify().export()); + insta::assert_snapshot!("Single color string",Numerator::default().from_global(Atom::parse("f(coad(8,1),coad(8,11),coad(8,21))*f(coad(8,21),coad(8,2),coad(8,12))*f(coad(8,3),coad(8,12),coad(8,22))*f(coad(8,22),coad(8,4),coad(8,13))*f(coad(8,5),coad(8,13),coad(8,23))*f(coad(8,23),coad(8,6),coad(8,14))*f(coad(8,7),coad(8,14),coad(8,24))*f(coad(8,24),coad(8,8),coad(8,11))*f(coad(8,1),coad(8,2),coad(8,3))*f(coad(8,4),coad(8,5),coad(8,6))*id(coad(8,7),coad(8,8))").unwrap(), None).color_simplify().export()); } diff --git a/src/numerator/ufo.rs b/src/numerator/ufo.rs new file mode 100644 index 00000000..794ec76c --- /dev/null +++ b/src/numerator/ufo.rs @@ -0,0 +1,243 @@ +use std::sync::LazyLock; + +use spenso::shadowing::ETS; +use spenso::structure::representation::{ + BaseRepName, Bispinor, ColorAdjoint, ColorFundamental, ColorSextet, Minkowski, +}; +use symbolica::id::MatchSettings; +use symbolica::state::FunctionAttribute; +use symbolica::{ + atom::{Atom, Symbol}, + fun, + id::{Pattern, PatternOrMap, Replacement}, + state::State, + symb, +}; + +#[allow(dead_code)] +pub struct UFOSymbols { + pub identity: Symbol, + pub identityl: Symbol, + pub gamma: Symbol, + pub gamma5: Symbol, + pub projm: Symbol, + pub projp: Symbol, + pub sigma: Symbol, + pub charge_conj: Symbol, + pub metric: Symbol, + pub momentum: Symbol, + pub levicivita: Symbol, + pub t: Symbol, + pub f: Symbol, + pub d: Symbol, + pub antilevicivita: Symbol, + pub t6: Symbol, + pub k6: Symbol, + pub k6bar: Symbol, + pub pslash: Symbol, +} + +#[allow(dead_code)] +pub static UFO: LazyLock = LazyLock::new(|| UFOSymbols { + identity: symb!("Identity"), + identityl: symb!("IdentityL"), + gamma: symb!("Gamma"), + gamma5: symb!("Gamma5"), + projm: symb!("ProjM"), + projp: symb!("ProjP"), + sigma: symb!("Sigma"), + charge_conj: symb!("C"), + metric: State::get_symbol_with_attributes("Metric", &[FunctionAttribute::Symmetric]).unwrap(), + momentum: symb!("P"), + levicivita: symb!("Epsilon"), + t: symb!("T"), + f: State::get_symbol_with_attributes("f", &[FunctionAttribute::Antisymmetric]).unwrap(), + d: symb!("d"), + antilevicivita: symb!("EpsilonBar"), + t6: symb!("T6"), + k6: symb!("K6"), + k6bar: symb!("K6Bar"), + pslash: symb!("PSlash"), +}); + +pub fn preprocess_ufo_color_wrapped(atom: Atom) -> Atom { + let a_ = symb!("a_"); + let b_ = symb!("b_"); + let c_ = symb!("c_"); + + let coad = ColorAdjoint::rep(8); + let cof = ColorFundamental::rep(3); + let coaf = ColorFundamental::rep(3).dual(); + let cos = ColorSextet::rep(6); + let coas = ColorSextet::rep(6).dual(); + + let reps = vec![ + ( + fun!(UFO.t, a_, b_, c_), + fun!( + UFO.t, + coad.to_pattern_wrapped(a_), + cof.to_pattern_wrapped(b_), + coaf.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.f, a_, b_, c_), + fun!( + UFO.f, + coad.to_pattern_wrapped(a_), + coad.to_pattern_wrapped(b_), + coad.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.d, a_, b_, c_), + fun!( + UFO.d, + coad.to_pattern_wrapped(a_), + coad.to_pattern_wrapped(b_), + coad.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.levicivita, a_, b_, c_), + fun!( + UFO.levicivita, + cof.to_pattern_wrapped(a_), + cof.to_pattern_wrapped(b_), + cof.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.antilevicivita, a_, b_, c_), + fun!( + UFO.levicivita, + coaf.to_pattern_wrapped(a_), + coaf.to_pattern_wrapped(b_), + coaf.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.t6, a_, b_, c_), + fun!( + UFO.t6, + coad.to_pattern_wrapped(a_), + cos.to_pattern_wrapped(b_), + coas.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.k6, a_, b_, c_), + fun!( + UFO.k6, + coaf.to_pattern_wrapped(a_), + coaf.to_pattern_wrapped(b_), + cos.to_pattern_wrapped(c_) + ), + ), + ( + fun!(UFO.k6bar, a_, b_, c_), + fun!( + UFO.k6bar, + coas.to_pattern_wrapped(a_), + cof.to_pattern_wrapped(b_), + cof.to_pattern_wrapped(c_) + ), + ), + ]; + + let reps: Vec<(Pattern, PatternOrMap)> = reps + .into_iter() + .map(|(a, b)| (a.into_pattern(), b.into_pattern().into())) + .collect(); + + let reps: Vec<_> = reps.iter().map(|(a, b)| Replacement::new(a, b)).collect(); + + atom.replace_all_multiple(&reps) +} +pub fn preprocess_ufo_spin_wrapped(atom: Atom) -> Atom { + let a_ = symb!("a_"); + let b_ = symb!("b_"); + let c_ = symb!("c_"); + let d_ = symb!("d_"); + let wa_ = fun!(symb!("indexid"), Atom::new_var(symb!("a_"))); + let wb_ = fun!(symb!("indexid"), Atom::new_var(symb!("b_"))); + let wc_ = fun!(symb!("indexid"), Atom::new_var(symb!("c_"))); + let wd_ = fun!(symb!("indexid"), Atom::new_var(symb!("d_"))); + + let bis = Bispinor::rep(4); + let mink = Minkowski::rep(4); + + let reps = vec![ + ( + fun!(UFO.identity, a_, b_), + fun!(ETS.id, bis.pattern(&wa_), bis.pattern(&wb_)), + ), + ( + fun!(UFO.identityl, a_, b_), + fun!(ETS.id, mink.pattern(&wa_), mink.pattern(&wb_)), + ), + ( + fun!(UFO.gamma, a_, b_, c_), + fun!( + ETS.gamma, + mink.pattern(&wa_), + bis.pattern(&wb_), + bis.pattern(&wc_) + ), + ), + ( + fun!(UFO.gamma5, a_, b_), + fun!(ETS.gamma5, bis.pattern(&wa_), bis.pattern(&wb_)), + ), + ( + fun!(UFO.projm, a_, b_), + fun!(ETS.proj_m, bis.pattern(&wa_), bis.pattern(&wb_)), + ), + ( + fun!(UFO.projp, a_, b_), + fun!(ETS.proj_p, bis.pattern(&wa_), bis.pattern(&wb_)), + ), + ( + fun!(UFO.sigma, a_, b_, c_, d_), + fun!( + ETS.sigma, + mink.pattern(&wa_), + mink.pattern(&wb_), + bis.pattern(&wc_), + bis.pattern(&wd_) + ), + ), + ( + fun!(UFO.charge_conj, a_, b_), + fun!(UFO.charge_conj, bis.pattern(&wa_), bis.pattern(&wb_)), + ), + ( + fun!(UFO.metric, a_, b_), + fun!(ETS.metric, mink.pattern(&wa_), mink.pattern(&wb_)), + ), + ]; + + let reps: Vec<(Pattern, PatternOrMap)> = reps + .into_iter() + .map(|(a, b)| (a.into_pattern(), b.into_pattern().into())) + .collect(); + + let settings = MatchSettings { + rhs_cache_size: 0, + ..Default::default() + }; + let reps: Vec<_> = reps + .iter() + .map(|(a, b)| Replacement::new(a, b).with_settings(&settings)) + .collect(); + + atom.replace_all_multiple(&reps) +} + +#[cfg(test)] +pub mod test { + + #[test] + fn ufo_spin_processing() {} +} diff --git a/src/tests_from_pytest.rs b/src/tests_from_pytest.rs index a444c9c9..d6cb5879 100644 --- a/src/tests_from_pytest.rs +++ b/src/tests_from_pytest.rs @@ -51,7 +51,7 @@ use rayon::vec; use serde::{self, Deserialize, Serialize}; use spenso::complex::{Complex, SymbolicaComplex}; use spenso::network::TensorNetwork; -use spenso::structure::{IsAbstractSlot, Lorentz, RepName}; +use spenso::structure::{representation::Lorentz, representation::RepName, slot::IsAbstractSlot}; use statrs::function::evaluate; use std::collections::HashMap; use std::f32::consts::E; diff --git a/src/utils.rs b/src/utils.rs index 755edfb1..c9c0f5b9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,16 +19,19 @@ use spenso::{ contraction::{RefOne, RefZero}, upgrading_arithmetic::TrySmallestUpgrade, }; +use symbolica::atom::Symbol; use symbolica::domains::float::{ ConstructibleFloat, NumericalFloatLike, RealNumberLike, SingleFloat, }; use symbolica::domains::integer::Integer; use symbolica::evaluate::CompiledEvaluatorFloat; +use symbolica::symb; use statrs::function::gamma::{gamma, gamma_lr, gamma_ur}; use std::cmp::{Ord, Ordering}; use std::fmt::{Debug, Display}; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign}; +use std::sync::LazyLock; use std::time::Duration; use symbolica::domains::float::Real; use symbolica::domains::rational::Rational; @@ -477,6 +480,10 @@ impl RealNumberLike for VarFloat { self.float.to_f64() } + fn round_to_nearest_integer(&self) -> Integer { + self.float.clone().round().to_integer().unwrap().into() + } + fn to_usize_clamped(&self) -> usize { self.float .to_integer() @@ -487,6 +494,25 @@ impl RealNumberLike for VarFloat { } impl Real for VarFloat { + #[inline(always)] + fn pi(&self) -> Self { + Float::with_val(N, rug::float::Constant::Pi).into() + } + + #[inline(always)] + fn e(&self) -> Self { + self.one().exp() + } + + #[inline(always)] + fn euler(&self) -> Self { + Float::with_val(N, rug::float::Constant::Euler).into() + } + + #[inline(always)] + fn phi(&self) -> Self { + (self.one() + self.from_i64(5).sqrt()) / Self::from_f64(2.) + } fn atan2(&self, x: &Self) -> Self { self.float.clone().atan2(&x.float).into() } @@ -801,6 +827,7 @@ impl RealNumberLike for F { to self.0{ fn to_usize_clamped(&self)->usize; fn to_f64(&self)->f64; + fn round_to_nearest_integer(&self)->Integer; } } } @@ -957,6 +984,10 @@ impl Real for F { delegate! { #[into] to self.0{ + fn e(&self)->Self; + fn phi(&self)->Self; + fn euler(&self)->Self; + fn pi(&self)->Self; fn sqrt(&self) -> Self; fn log(&self) -> Self; fn exp(&self) -> Self; @@ -2978,13 +3009,13 @@ pub fn inv_3x3_sig_matrix(mat: [[isize; 3]; 3]) -> [[isize; 3]; 3] { pub fn print_banner() { info!( "\n{}{}\n", - r" _ - | | - __ _ __ _ _ __ ___ _ __ ___ __ _| | ___ ___ _ __ - / _` |/ _` | '_ ` _ \| '_ ` _ \ / _` | | / _ \ / _ \| '_ \ + r" _ + | | + __ _ __ _ _ __ ___ _ __ ___ __ _| | ___ ___ _ __ + / _` |/ _` | '_ ` _ \| '_ ` _ \ / _` | | / _ \ / _ \| '_ \ | (_| | (_| | | | | | | | | | | | (_| | |___| (_) | (_) | |_) | - \__, |\__,_|_| |_| |_|_| |_| |_|\__,_|______\___/ \___/| .__/ - __/ | | | + \__, |\__,_|_| |_| |_|_| |_| |_|\__,_|______\___/ \___/| .__/ + __/ | | | " .to_string() .bold() @@ -3113,6 +3144,24 @@ fn complex_compare() { ltd.approx_eq_res(&cff, &F(0.00000001)).unwrap(); } +pub struct GammaloopSymbols { + pub ubar: Symbol, + pub vbar: Symbol, + pub v: Symbol, + pub u: Symbol, + pub epsilon: Symbol, + pub epsilonbar: Symbol, +} + +pub static GS: LazyLock = LazyLock::new(|| GammaloopSymbols { + ubar: symb!("ubar"), + vbar: symb!("vbar"), + v: symb!("v"), + u: symb!("u"), + epsilon: symb!("ϵ"), + epsilonbar: symb!("ϵbar"), +}); + /// Checks if two lists are permutations of eachother, and establish a map between indices pub fn is_permutation(left: &[T], right: &[T]) -> Option { if left.len() != right.len() {