Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'

This commit is contained in:
ruv
2026-02-28 14:39:40 -05:00
7854 changed files with 3522914 additions and 0 deletions

562
vendor/ruvector/examples/prime-radiant/wasm/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,562 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "async-trait"
version = "0.1.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "autocfg"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "bumpalo"
version = "3.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
[[package]]
name = "cast"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
version = "1.2.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "755d2fce177175ffca841e9a06afdb2c4ab0f593d53b4dee48147dfaade85932"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "either"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "find-msvc-tools"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db"
[[package]]
name = "futures-core"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-task"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
[[package]]
name = "futures-util"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi",
"wasm-bindgen",
]
[[package]]
name = "itoa"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "js-sys"
version = "0.3.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"
dependencies = [
"once_cell",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.180"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]]
name = "libm"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "memchr"
version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]]
name = "minicov"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4869b6a491569605d66d3952bcdf03df789e5b536e5f0cf7758a7f08a55ae24d"
dependencies = [
"cc",
"walkdir",
]
[[package]]
name = "nu-ansi-term"
version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
"libm",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "oorandom"
version = "11.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"
[[package]]
name = "pin-project-lite"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "prime-radiant-advanced-wasm"
version = "0.1.0"
dependencies = [
"console_error_panic_hook",
"getrandom",
"js-sys",
"rayon",
"serde",
"serde-wasm-bindgen",
"serde_json",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-rayon",
"wasm-bindgen-test",
"web-sys",
]
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f"
dependencies = [
"either",
"rayon-core",
"wasm_sync",
]
[[package]]
name = "rayon-core"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
"wasm_sync",
]
[[package]]
name = "rustversion"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde-wasm-bindgen"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"
dependencies = [
"js-sys",
"serde",
"wasm-bindgen",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "slab"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"
[[package]]
name = "syn"
version = "2.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasm-bindgen"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"
dependencies = [
"cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f"
dependencies = [
"cfg-if",
"futures-util",
"js-sys",
"once_cell",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-rayon"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a16c60a56c81e4dc3b9c43d76ba5633e1c0278211d59a9cb07d61b6cd1c6583"
dependencies = [
"crossbeam-channel",
"js-sys",
"rayon",
"wasm-bindgen",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"
dependencies = [
"unicode-ident",
]
[[package]]
name = "wasm-bindgen-test"
version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45649196a53b0b7a15101d845d44d2dda7374fc1b5b5e2bbf58b7577ff4b346d"
dependencies = [
"async-trait",
"cast",
"js-sys",
"libm",
"minicov",
"nu-ansi-term",
"num-traits",
"oorandom",
"serde",
"serde_json",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
"wasm-bindgen-test-shared",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f579cdd0123ac74b94e1a4a72bd963cf30ebac343f2df347da0b8df24cdebed2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "wasm-bindgen-test-shared"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8145dd1593bf0fb137dbfa85b8be79ec560a447298955877804640e40c2d6ea"
[[package]]
name = "wasm_sync"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff360cade7fec41ff0e9d2cda57fe58258c5f16def0e21302394659e6bbb0ea"
dependencies = [
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "web-sys"
version = "0.3.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "winapi-util"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "zmij"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"

View File

@@ -0,0 +1,66 @@
[package]
name = "prime-radiant-advanced-wasm"
version = "0.1.0"
edition = "2021"
authors = ["Prime-Radiant Team"]
license = "MIT OR Apache-2.0"
description = "WASM bindings for Prime-Radiant Advanced Math modules"
repository = "https://github.com/ruvnet/ruvector"
keywords = ["wasm", "category-theory", "homotopy-type-theory", "spectral-analysis", "causal-inference"]
categories = ["wasm", "mathematics", "science"]
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
# Enable parallel computation in web workers
parallel = ["rayon", "wasm-bindgen-rayon"]
[dependencies]
# WASM bindings
wasm-bindgen = "0.2"
js-sys = "0.3"
web-sys = { version = "0.3", features = [
"console",
"Performance",
"Window",
] }
# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde-wasm-bindgen = "0.6"
# Random number generation for WASM
getrandom = { version = "0.2", features = ["js"] }
# Error handling in WASM
console_error_panic_hook = { version = "0.1", optional = true }
# Async support
wasm-bindgen-futures = "0.4"
# Local prime-radiant module
# Note: In production, use: prime-radiant = { path = ".." }
# For now we implement the engines directly
# Optional parallel support
rayon = { version = "1.10", optional = true }
wasm-bindgen-rayon = { version = "1.2", optional = true }
[dev-dependencies]
wasm-bindgen-test = "0.3"
[profile.release]
# Optimize for small binary size
opt-level = "s"
lto = true
codegen-units = 1
panic = "abort"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-Os", "--enable-mutable-globals"]
# Exclude from parent workspace
[workspace]

View File

@@ -0,0 +1,446 @@
/**
* Prime-Radiant Advanced WASM - JavaScript/TypeScript API Example
*
* This example demonstrates usage of all 6 mathematical engines:
* - CohomologyEngine: Sheaf cohomology computations
* - CategoryEngine: Functorial retrieval and topos operations
* - HoTTEngine: Type checking and path operations
* - SpectralEngine: Eigenvalue computation and Cheeger bounds
* - CausalEngine: Causal inference and interventions
* - QuantumEngine: Topological invariants and quantum simulation
*/
import init, {
CohomologyEngine,
SpectralEngine,
CausalEngine,
QuantumEngine,
CategoryEngine,
HoTTEngine,
getVersion,
initModule,
type SheafGraph,
type SheafNode,
type SheafEdge,
type Graph,
type CausalModel,
type QuantumState,
type Complex,
type Category,
type CatObject,
type Morphism,
type HoTTType,
type HoTTTerm,
type HoTTPath,
} from './prime_radiant_advanced_wasm';
// ============================================================================
// Initialization
// ============================================================================
async function main() {
// Initialize WASM module
await init();
initModule();
console.log(`Prime-Radiant Advanced WASM v${getVersion()}`);
console.log('='.repeat(50));
// Run all examples
await cohomologyExample();
await spectralExample();
await causalExample();
await quantumExample();
await categoryExample();
await hottExample();
console.log('\nAll examples completed successfully!');
}
// ============================================================================
// Cohomology Engine Example
// ============================================================================
async function cohomologyExample() {
console.log('\n--- Cohomology Engine Example ---');
const cohomology = new CohomologyEngine();
// Create a belief graph with consistent sections
const consistentGraph: SheafGraph = {
nodes: [
{ id: 0, label: 'Belief A', section: [1.0, 0.5], weight: 1.0 },
{ id: 1, label: 'Belief B', section: [1.0, 0.5], weight: 1.0 },
{ id: 2, label: 'Belief C', section: [1.0, 0.5], weight: 1.0 },
],
edges: [
{
source: 0,
target: 1,
restriction_map: [1.0, 0.0, 0.0, 1.0], // Identity map
source_dim: 2,
target_dim: 2,
},
{
source: 1,
target: 2,
restriction_map: [1.0, 0.0, 0.0, 1.0],
source_dim: 2,
target_dim: 2,
},
],
};
// Compute cohomology
const result = cohomology.computeCohomology(consistentGraph);
console.log('Cohomology of consistent graph:');
console.log(` H^0 dimension: ${result.h0_dim}`);
console.log(` H^1 dimension: ${result.h1_dim}`);
console.log(` Euler characteristic: ${result.euler_characteristic}`);
console.log(` Is consistent: ${result.is_consistent}`);
// Create an inconsistent graph
const inconsistentGraph: SheafGraph = {
nodes: [
{ id: 0, label: 'Belief A', section: [1.0, 0.0], weight: 1.0 },
{ id: 1, label: 'Belief B', section: [0.0, 1.0], weight: 1.0 }, // Different!
],
edges: [
{
source: 0,
target: 1,
restriction_map: [1.0, 0.0, 0.0, 1.0],
source_dim: 2,
target_dim: 2,
},
],
};
// Detect obstructions
const obstructions = cohomology.detectObstructions(inconsistentGraph);
console.log(`\nDetected ${obstructions.length} obstruction(s):`);
for (const obs of obstructions) {
console.log(` ${obs.description}`);
}
// Compute consistency energy
const energy = cohomology.consistencyEnergy(inconsistentGraph);
console.log(` Consistency energy: ${energy.toFixed(6)}`);
}
// ============================================================================
// Spectral Engine Example
// ============================================================================
async function spectralExample() {
console.log('\n--- Spectral Engine Example ---');
const spectral = new SpectralEngine();
// Create a path graph: 0 -- 1 -- 2 -- 3 -- 4
const pathGraph: Graph = {
n: 5,
edges: [
[0, 1, 1.0],
[1, 2, 1.0],
[2, 3, 1.0],
[3, 4, 1.0],
],
};
// Compute Cheeger bounds
const cheeger = spectral.computeCheegerBounds(pathGraph);
console.log('Cheeger bounds for path graph:');
console.log(` Lower bound: ${cheeger.lower_bound.toFixed(6)}`);
console.log(` Upper bound: ${cheeger.upper_bound.toFixed(6)}`);
console.log(` Fiedler value (λ₂): ${cheeger.fiedler_value.toFixed(6)}`);
// Compute spectral gap
const gap = spectral.computeSpectralGap(pathGraph);
console.log(`\nSpectral gap analysis:`);
console.log(` λ₁ = ${gap.lambda_1.toFixed(6)}`);
console.log(` λ₂ = ${gap.lambda_2.toFixed(6)}`);
console.log(` Gap = ${gap.gap.toFixed(6)}`);
console.log(` Ratio = ${gap.ratio.toFixed(6)}`);
// Predict minimum cut
const prediction = spectral.predictMinCut(pathGraph);
console.log(`\nMin-cut prediction:`);
console.log(` Predicted cut: ${prediction.predicted_cut.toFixed(6)}`);
console.log(` Confidence: ${(prediction.confidence * 100).toFixed(1)}%`);
console.log(` Cut nodes: [${prediction.cut_nodes.join(', ')}]`);
// Create a barbell graph (two cliques connected by single edge)
const barbellGraph: Graph = {
n: 6,
edges: [
// First clique
[0, 1, 1.0], [0, 2, 1.0], [1, 2, 1.0],
// Second clique
[3, 4, 1.0], [3, 5, 1.0], [4, 5, 1.0],
// Bridge
[2, 3, 1.0],
],
};
const barbellGap = spectral.computeSpectralGap(barbellGraph);
console.log(`\nBarbell graph spectral gap: ${barbellGap.gap.toFixed(6)}`);
console.log('(Small gap indicates bottleneck structure)');
}
// ============================================================================
// Causal Engine Example
// ============================================================================
async function causalExample() {
console.log('\n--- Causal Engine Example ---');
const causal = new CausalEngine();
// Build a causal model: Age -> Income, Education -> Income, Income -> Savings
const model: CausalModel = {
variables: [
{ name: 'Age', var_type: 'continuous' },
{ name: 'Education', var_type: 'discrete' },
{ name: 'Income', var_type: 'continuous' },
{ name: 'Savings', var_type: 'continuous' },
],
edges: [
{ from: 'Age', to: 'Income' },
{ from: 'Education', to: 'Income' },
{ from: 'Income', to: 'Savings' },
],
};
// Check if valid DAG
const isValid = causal.isValidDag(model);
console.log(`Model is valid DAG: ${isValid}`);
// Get topological order
const order = causal.topologicalOrder(model);
console.log(`Topological order: ${order.join(' -> ')}`);
// Check d-separation
const dSep = causal.checkDSeparation(model, 'Age', 'Savings', ['Income']);
console.log(`\nD-separation test:`);
console.log(` Age ⊥ Savings | Income: ${dSep.d_separated}`);
const dSep2 = causal.checkDSeparation(model, 'Age', 'Savings', []);
console.log(` Age ⊥ Savings | ∅: ${dSep2.d_separated}`);
// Find confounders
const confounders = causal.findConfounders(model, 'Education', 'Savings');
console.log(`\nConfounders between Education and Savings: [${confounders.join(', ')}]`);
// Compute causal effect
const effect = causal.computeCausalEffect(model, 'Income', 'Savings', 10000);
console.log(`\nCausal effect of do(Income = 10000) on Savings:`);
console.log(` Effect: ${effect.causal_effect}`);
console.log(` Affected variables: [${effect.affected_variables.join(', ')}]`);
}
// ============================================================================
// Quantum Engine Example
// ============================================================================
async function quantumExample() {
console.log('\n--- Quantum Engine Example ---');
const quantum = new QuantumEngine();
// Create GHZ state (maximally entangled)
const ghz = quantum.createGHZState(3);
console.log(`GHZ state (3 qubits):`);
console.log(` Dimension: ${ghz.dimension}`);
console.log(` |000⟩ amplitude: ${ghz.amplitudes[0].re.toFixed(4)}`);
console.log(` |111⟩ amplitude: ${ghz.amplitudes[7].re.toFixed(4)}`);
// Create W state
const w = quantum.createWState(3);
console.log(`\nW state (3 qubits):`);
console.log(` |001⟩ amplitude: ${w.amplitudes[1].re.toFixed(4)}`);
console.log(` |010⟩ amplitude: ${w.amplitudes[2].re.toFixed(4)}`);
console.log(` |100⟩ amplitude: ${w.amplitudes[4].re.toFixed(4)}`);
// Compute fidelity between states
const fidelity = quantum.computeFidelity(ghz, w);
console.log(`\nFidelity between GHZ and W states:`);
console.log(` Fidelity: ${fidelity.fidelity.toFixed(6)}`);
console.log(` Trace distance: ${fidelity.trace_distance.toFixed(6)}`);
// Compute entanglement entropy
const entropy = quantum.computeEntanglementEntropy(ghz, 1);
console.log(`\nEntanglement entropy of GHZ (split at qubit 1): ${entropy.toFixed(6)}`);
// Compute topological invariants of a simplicial complex
// Triangle: vertices {0,1,2}, edges {01,12,02}, face {012}
const simplices = [
[0], [1], [2], // 0-simplices (vertices)
[0, 1], [1, 2], [0, 2], // 1-simplices (edges)
[0, 1, 2], // 2-simplex (face)
];
const invariants = quantum.computeTopologicalInvariants(simplices);
console.log(`\nTopological invariants of filled triangle:`);
console.log(` Euler characteristic: ${invariants.euler_characteristic}`);
console.log(` Is connected: ${invariants.is_connected}`);
// Apply Hadamard gate
const hadamard: Complex[][] = [
[{ re: 1 / Math.sqrt(2), im: 0 }, { re: 1 / Math.sqrt(2), im: 0 }],
[{ re: 1 / Math.sqrt(2), im: 0 }, { re: -1 / Math.sqrt(2), im: 0 }],
];
const ground: QuantumState = {
amplitudes: [{ re: 1, im: 0 }, { re: 0, im: 0 }],
dimension: 2,
};
const result = quantum.applyGate(ground, hadamard, 0);
console.log(`\nHadamard on |0⟩:`);
console.log(` |0⟩ amplitude: ${result.amplitudes[0].re.toFixed(4)}`);
console.log(` |1⟩ amplitude: ${result.amplitudes[1].re.toFixed(4)}`);
}
// ============================================================================
// Category Engine Example
// ============================================================================
async function categoryExample() {
console.log('\n--- Category Engine Example ---');
const category = new CategoryEngine();
// Create a simple category with vector spaces
const vecCategory: Category = {
name: 'Vect',
objects: [
{ id: 'R2', dimension: 2, data: [1.0, 0.0] },
{ id: 'R3', dimension: 3, data: [1.0, 0.0, 0.0] },
],
morphisms: [],
};
// Create morphisms (linear maps)
const projection: Morphism = {
source: 'R3',
target: 'R2',
matrix: [1, 0, 0, 0, 1, 0], // Project to first two coordinates
source_dim: 3,
target_dim: 2,
};
const embedding: Morphism = {
source: 'R2',
target: 'R3',
matrix: [1, 0, 0, 1, 0, 0], // Embed in first two coordinates
source_dim: 2,
target_dim: 3,
};
// Apply morphism
const data = [1.0, 2.0, 3.0];
const projected = category.applyMorphism(projection, data);
console.log(`Projection of [${data.join(', ')}]: [${projected.map(x => x.toFixed(2)).join(', ')}]`);
// Compose morphisms (embedding then projection = identity)
const composed = category.composeMorphisms(embedding, projection);
console.log(`\nComposed morphism (P ∘ E):`);
console.log(` Source: ${composed.source}`);
console.log(` Target: ${composed.target}`);
console.log(` Matrix: [${composed.matrix.map(x => x.toFixed(2)).join(', ')}]`);
// Verify category laws
vecCategory.morphisms.push(projection);
const lawsValid = category.verifyCategoryLaws(vecCategory);
console.log(`\nCategory laws verified: ${lawsValid}`);
// Functorial retrieval
const docsCategory: Category = {
name: 'Docs',
objects: [
{ id: 'doc1', dimension: 3, data: [1.0, 0.0, 0.0] },
{ id: 'doc2', dimension: 3, data: [0.9, 0.1, 0.0] },
{ id: 'doc3', dimension: 3, data: [0.0, 1.0, 0.0] },
{ id: 'doc4', dimension: 3, data: [0.0, 0.0, 1.0] },
],
morphisms: [],
};
const query = [1.0, 0.0, 0.0];
const results = category.functorialRetrieve(docsCategory, query, 2);
console.log(`\nFunctorial retrieval for query [${query.join(', ')}]:`);
for (const r of results) {
console.log(` ${r.object_id}: similarity = ${r.similarity.toFixed(4)}`);
}
}
// ============================================================================
// HoTT Engine Example
// ============================================================================
async function hottExample() {
console.log('\n--- HoTT Engine Example ---');
const hott = new HoTTEngine();
// Create terms
const star: HoTTTerm = { kind: 'star', children: [] };
const zero: HoTTTerm = { kind: 'zero', children: [] };
const one: HoTTTerm = { kind: 'succ', children: [zero] };
const pair: HoTTTerm = { kind: 'pair', children: [zero, star] };
// Infer types
console.log('Type inference:');
const starType = hott.inferType(star);
console.log(` ★ : ${starType.inferred_type?.kind}`);
const zeroType = hott.inferType(zero);
console.log(` 0 : ${zeroType.inferred_type?.kind}`);
const oneType = hott.inferType(one);
console.log(` S(0) : ${oneType.inferred_type?.kind}`);
const pairType = hott.inferType(pair);
console.log(` (0, ★) : ${pairType.inferred_type?.name}`);
// Type checking
const natType: HoTTType = { name: 'Nat', level: 0, kind: 'nat', params: [] };
const checkResult = hott.typeCheck(zero, natType);
console.log(`\nType checking 0 : Nat: ${checkResult.is_valid}`);
const boolType: HoTTType = { name: 'Bool', level: 0, kind: 'bool', params: [] };
const checkResult2 = hott.typeCheck(zero, boolType);
console.log(`Type checking 0 : Bool: ${checkResult2.is_valid}`);
if (checkResult2.error) {
console.log(` Error: ${checkResult2.error}`);
}
// Path operations
const refl = hott.createReflPath(natType, zero);
console.log(`\nReflexivity path: refl(0) : 0 = 0`);
// Compose paths
const composed = hott.composePaths(refl, refl);
if (composed.is_valid) {
console.log('Path composition: refl ∙ refl is valid');
}
// Invert path
const inverted = hott.invertPath(refl);
if (inverted.is_valid) {
console.log('Path inversion: refl⁻¹ is valid');
}
// Check type equivalence
const nat1: HoTTType = { name: 'Nat', level: 0, kind: 'nat', params: [] };
const nat2: HoTTType = { name: 'Nat', level: 0, kind: 'nat', params: [] };
const equiv = hott.checkTypeEquivalence(nat1, nat2);
console.log(`\nType equivalence Nat ≃ Nat: ${equiv}`);
}
// ============================================================================
// Run Examples
// ============================================================================
main().catch(console.error);

View File

@@ -0,0 +1,326 @@
/* tslint:disable */
/* eslint-disable */
/**
* Category theory engine
*/
export class CategoryEngine {
free(): void;
[Symbol.dispose](): void;
/**
* Apply morphism to an object
*/
applyMorphism(morphism_js: any, data_js: any): any;
/**
* Compose two morphisms
*/
composeMorphisms(f_js: any, g_js: any): any;
/**
* Functorial retrieval: find similar objects
*/
functorialRetrieve(category_js: any, query_js: any, k: number): any;
/**
* Create a new category engine
*/
constructor();
/**
* Verify categorical laws
*/
verifyCategoryLaws(category_js: any): boolean;
/**
* Check if functor preserves composition
*/
verifyFunctoriality(functor_js: any, source_cat_js: any): boolean;
}
/**
* Causal inference engine
*/
export class CausalEngine {
free(): void;
[Symbol.dispose](): void;
/**
* Check d-separation between two variables
*/
checkDSeparation(model_js: any, x: string, y: string, conditioning_js: any): any;
/**
* Compute causal effect via do-operator
*/
computeCausalEffect(model_js: any, treatment: string, outcome: string, treatment_value: number): any;
/**
* Find all confounders between two variables
*/
findConfounders(model_js: any, treatment: string, outcome: string): any;
/**
* Check if model is a valid DAG
*/
isValidDag(model_js: any): boolean;
/**
* Create a new causal engine
*/
constructor();
/**
* Get topological order of variables
*/
topologicalOrder(model_js: any): any;
}
/**
* Sheaf cohomology computation engine
*/
export class CohomologyEngine {
free(): void;
[Symbol.dispose](): void;
/**
* Compute cohomology groups of a sheaf graph
*/
computeCohomology(graph_js: any): any;
/**
* Compute global sections (H^0)
*/
computeGlobalSections(graph_js: any): any;
/**
* Compute consistency energy
*/
consistencyEnergy(graph_js: any): number;
/**
* Detect all obstructions to global consistency
*/
detectObstructions(graph_js: any): any;
/**
* Create a new cohomology engine
*/
constructor();
/**
* Create with custom tolerance
*/
static withTolerance(tolerance: number): CohomologyEngine;
}
/**
* HoTT type checking and path operations engine
*/
export class HoTTEngine {
free(): void;
[Symbol.dispose](): void;
/**
* Check type equivalence (univalence-related)
*/
checkTypeEquivalence(type1_js: any, type2_js: any): boolean;
/**
* Compose two paths
*/
composePaths(path1_js: any, path2_js: any): any;
/**
* Create reflexivity path
*/
createReflPath(type_js: any, point_js: any): any;
/**
* Infer type of a term
*/
inferType(term_js: any): any;
/**
* Invert a path
*/
invertPath(path_js: any): any;
/**
* Create a new HoTT engine
*/
constructor();
/**
* Type check a term
*/
typeCheck(term_js: any, expected_type_js: any): any;
/**
* Create with strict mode
*/
static withStrictMode(strict: boolean): HoTTEngine;
}
/**
* Quantum computing and topological analysis engine
*/
export class QuantumEngine {
free(): void;
[Symbol.dispose](): void;
/**
* Simulate quantum circuit evolution
*/
applyGate(state_js: any, gate_js: any, target_qubit: number): any;
/**
* Compute entanglement entropy
*/
computeEntanglementEntropy(state_js: any, subsystem_size: number): number;
/**
* Compute quantum state fidelity
*/
computeFidelity(state1_js: any, state2_js: any): any;
/**
* Compute topological invariants of a simplicial complex
*/
computeTopologicalInvariants(simplices_js: any): any;
/**
* Create a GHZ state
*/
createGHZState(num_qubits: number): any;
/**
* Create a W state
*/
createWState(num_qubits: number): any;
/**
* Create a new quantum engine
*/
constructor();
}
/**
* Spectral analysis engine
*/
export class SpectralEngine {
free(): void;
[Symbol.dispose](): void;
/**
* Compute the algebraic connectivity (Fiedler value)
*/
algebraicConnectivity(graph_js: any): number;
/**
* Compute Cheeger bounds for a graph
*/
computeCheegerBounds(graph_js: any): any;
/**
* Compute eigenvalues of the graph Laplacian
*/
computeEigenvalues(graph_js: any): any;
/**
* Compute Fiedler vector
*/
computeFiedlerVector(graph_js: any): any;
/**
* Compute spectral gap
*/
computeSpectralGap(graph_js: any): any;
/**
* Create a new spectral engine
*/
constructor();
/**
* Predict minimum cut
*/
predictMinCut(graph_js: any): any;
/**
* Create with configuration
*/
static withConfig(num_eigenvalues: number, tolerance: number, max_iterations: number): SpectralEngine;
}
/**
* JavaScript-friendly error type
*/
export class WasmError {
private constructor();
free(): void;
[Symbol.dispose](): void;
readonly code: string;
readonly message: string;
}
/**
* Get library version
*/
export function getVersion(): string;
/**
* Initialize the WASM module
*/
export function initModule(): void;
export function start(): void;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_categoryengine_free: (a: number, b: number) => void;
readonly __wbg_hottengine_free: (a: number, b: number) => void;
readonly __wbg_spectralengine_free: (a: number, b: number) => void;
readonly __wbg_wasmerror_free: (a: number, b: number) => void;
readonly categoryengine_applyMorphism: (a: number, b: any, c: any) => [number, number, number];
readonly categoryengine_composeMorphisms: (a: number, b: any, c: any) => [number, number, number];
readonly categoryengine_functorialRetrieve: (a: number, b: any, c: any, d: number) => [number, number, number];
readonly categoryengine_new: () => number;
readonly categoryengine_verifyCategoryLaws: (a: number, b: any) => [number, number, number];
readonly categoryengine_verifyFunctoriality: (a: number, b: any, c: any) => [number, number, number];
readonly causalengine_checkDSeparation: (a: number, b: any, c: number, d: number, e: number, f: number, g: any) => [number, number, number];
readonly causalengine_computeCausalEffect: (a: number, b: any, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
readonly causalengine_findConfounders: (a: number, b: any, c: number, d: number, e: number, f: number) => [number, number, number];
readonly causalengine_isValidDag: (a: number, b: any) => [number, number, number];
readonly causalengine_topologicalOrder: (a: number, b: any) => [number, number, number];
readonly cohomologyengine_computeCohomology: (a: number, b: any) => [number, number, number];
readonly cohomologyengine_computeGlobalSections: (a: number, b: any) => [number, number, number];
readonly cohomologyengine_consistencyEnergy: (a: number, b: any) => [number, number, number];
readonly cohomologyengine_detectObstructions: (a: number, b: any) => [number, number, number];
readonly cohomologyengine_withTolerance: (a: number) => number;
readonly getVersion: () => [number, number];
readonly hottengine_checkTypeEquivalence: (a: number, b: any, c: any) => [number, number, number];
readonly hottengine_composePaths: (a: number, b: any, c: any) => [number, number, number];
readonly hottengine_createReflPath: (a: number, b: any, c: any) => [number, number, number];
readonly hottengine_inferType: (a: number, b: any) => [number, number, number];
readonly hottengine_invertPath: (a: number, b: any) => [number, number, number];
readonly hottengine_new: () => number;
readonly hottengine_typeCheck: (a: number, b: any, c: any) => [number, number, number];
readonly hottengine_withStrictMode: (a: number) => number;
readonly initModule: () => [number, number];
readonly quantumengine_applyGate: (a: number, b: any, c: any, d: number) => [number, number, number];
readonly quantumengine_computeEntanglementEntropy: (a: number, b: any, c: number) => [number, number, number];
readonly quantumengine_computeFidelity: (a: number, b: any, c: any) => [number, number, number];
readonly quantumengine_computeTopologicalInvariants: (a: number, b: any) => [number, number, number];
readonly quantumengine_createGHZState: (a: number, b: number) => [number, number, number];
readonly quantumengine_createWState: (a: number, b: number) => [number, number, number];
readonly spectralengine_algebraicConnectivity: (a: number, b: any) => [number, number, number];
readonly spectralengine_computeCheegerBounds: (a: number, b: any) => [number, number, number];
readonly spectralengine_computeEigenvalues: (a: number, b: any) => [number, number, number];
readonly spectralengine_computeFiedlerVector: (a: number, b: any) => [number, number, number];
readonly spectralengine_computeSpectralGap: (a: number, b: any) => [number, number, number];
readonly spectralengine_new: () => number;
readonly spectralengine_predictMinCut: (a: number, b: any) => [number, number, number];
readonly spectralengine_withConfig: (a: number, b: number, c: number) => number;
readonly start: () => void;
readonly wasmerror_code: (a: number) => [number, number];
readonly wasmerror_message: (a: number) => [number, number];
readonly causalengine_new: () => number;
readonly cohomologyengine_new: () => number;
readonly quantumengine_new: () => number;
readonly __wbg_causalengine_free: (a: number, b: number) => void;
readonly __wbg_cohomologyengine_free: (a: number, b: number) => void;
readonly __wbg_quantumengine_free: (a: number, b: number) => void;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __externref_table_alloc: () => number;
readonly __wbindgen_externrefs: WebAssembly.Table;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
readonly __externref_table_dealloc: (a: number) => void;
readonly __wbindgen_start: () => void;
}
export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
*
* @returns {InitOutput}
*/
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;

File diff suppressed because it is too large Load Diff