JonjubNet.Mathematical 3.1.1

dotnet add package JonjubNet.Mathematical --version 3.1.1
                    
NuGet\Install-Package JonjubNet.Mathematical -Version 3.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JonjubNet.Mathematical" Version="3.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JonjubNet.Mathematical" Version="3.1.1" />
                    
Directory.Packages.props
<PackageReference Include="JonjubNet.Mathematical" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JonjubNet.Mathematical --version 3.1.1
                    
#r "nuget: JonjubNet.Mathematical, 3.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JonjubNet.Mathematical@3.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JonjubNet.Mathematical&version=3.1.1
                    
Install as a Cake Addin
#tool nuget:?package=JonjubNet.Mathematical&version=3.1.1
                    
Install as a Cake Tool

JonjubNet.Mathematical

Biblioteca matemática pura y reutilizable para aplicaciones .NET: aritmética escalar, potencias y funciones trigonométricas, álgebra lineal (vectores y matrices inmutables), cálculo numérico (derivadas, integrales, interpolación) y transformaciones de series numéricas (SMA, EMA, retornos, normalización, True Range).

Sin dependencias externas, sin estado, sin conocimiento de dominio (no conoce Binance, criptomonedas, estrategias ni bases de datos). Pensada para ser consumida desde JonjubNet.Statistical, el nuevo bot de trading de Jonjub, o cualquier otra aplicación .NET.

Versión 3.0.0 — latencia en nanosegundos

  • Funciones incrementales. Quien llama conserva el último valor (suma de la ventana, última EMA, último cierre) y el componente solo calcula: el costo depende de los valores nuevos, no de la historia. Un paso cuesta unos 5 ns; continuar la SMA con 1 valor nuevo, unos 13 ns. Producen los mismos bits que la serie completa.
  • Suma y producto punto en 16 carriles fijos (4 × Vector256). La ruta escalar reproduce el mismo orden: el resultado es idéntico con o sin SIMD, en cualquier procesador y para cualquier tipo de colección, y es más preciso que la suma secuencial. Los últimos decimales pueden diferir de 2.x.
  • Producto matriz × vector (Matrix.Multiply(Vector) y su versión con destino).
  • Cambios incompatibles: se retiran ScalarMath.Product (use CollectionMath.Product) y las sobrecargas Vector.Equals/Matrix.Equals con tolerancias (use ApproximatelyEquals).
// Arranque: serie completa una sola vez.
var sums = SeriesMath.WindowSum(history, 14);
double sum = sums[^1];
double ema = SeriesMath.ExponentialMovingAverage(history, 14)[^1];

// Cada vela nueva: O(1).
sum = SeriesMath.WindowSumStep(sum, entering: close, leaving: closeThatLeavesTheWindow);
ema = SeriesMath.ExponentialMovingAverageStep(ema, close, 14);

// Varias velas nuevas de una vez: O(velas nuevas), sin asignaciones.
sum = SeriesMath.SimpleMovingAverage(sum, lastWindow, newCloses, destination);

Refactorización 2.0.0

Vector.Equals y Matrix.Equals ahora comparan componentes exactamente (Double.Equals), para que Dictionary y HashSet tengan igualdad transitiva y hashes coherentes. Para comparar resultados numéricos con tolerancia use ApproximatelyEquals. Es un cambio de comportamiento respecto a 1.x; no se debe actualizar un consumidor sin revisar esos usos.

Se mantiene la inmutabilidad y no se limita ni trunca la cantidad de registros. SMA, EMA, retornos, normalización, True Range, acumulados e integral acumulada ofrecen sobrecargas con ReadOnlySpan<double> y Span<double> de destino para reutilizar memoria. Los destinos no deben solaparse con las entradas; la cola no utilizada queda intacta. No modifique las colecciones de entrada mientras se ejecuta una operación.

using JonjubNet.Mathematical.Core.Series;
using JonjubNet.Mathematical.Core.LinearAlgebra;

double[] values = [1, 2, 3, 4, 5];
double[] destination = new double[values.Length - 3 + 1];
SeriesMath.SimpleMovingAverage(values, 3, destination);

// Una factorización por matriz; reutilizable entre resoluciones y entre hilos,
// siempre con destinos independientes. Factorizar asigna; Solve sobre destino no.
var matrix = new Matrix(new double[,] { { 2, 1 }, { 1, 3 } });
ILinearSystemSolver solver = matrix.Factorize();
double[] rhs = [5, 10];
double[] solutionBuffer = new double[2];
solver.Solve(rhs, solutionBuffer);

Las operaciones no garantizan 50 µs para entradas arbitrarias. Consulte las mediciones, condiciones y límites en Refactorización y rendimiento.


Inicio rápido

Requisitos

Herramienta Versión mínima Verificar con
.NET SDK 10.0 dotnet --version

Instalar el paquete

dotnet add package JonjubNet.Mathematical

Ejemplo de uso

using JonjubNet.Mathematical.Core.Arithmetic;
using JonjubNet.Mathematical.Core.LinearAlgebra;
using JonjubNet.Mathematical.Core.Calculus;
using JonjubNet.Mathematical.Core.Series;

// Aritmética
var sum = ScalarMath.Add(2.0, 3.0);              // 5.0
var product = CollectionMath.Product(new[] { 1.0, 2.0, 3.0 }); // 6.0

// Álgebra lineal
var a = new Vector(new double[] { 1.0, 2.0, 3.0 });
var b = new Vector(new double[] { 4.0, 5.0, 6.0 });
var dot = a.Dot(b);                              // 32.0
var norm = a.Norm();

var matrix = new Matrix(new double[,] { { 2, 1 }, { 1, 3 } });
var solution = matrix.Solve(new Vector(new double[] { 5, 10 })); // x=1, y=3

// Cálculo numérico
var derivative = NumericalCalculus.DerivativeCentral(x => x * x, 2.0); // ≈ 4.0
var integral = NumericalCalculus.IntegrateTrapezoidal(
    new double[] { 0.0, 1.0 }, new double[] { 0.0, 1.0 });             // 0.5

// Series
var sma = SeriesMath.SimpleMovingAverage(new double[] { 1, 2, 3, 4, 5 }, period: 3);
var returns = SeriesMath.SimpleReturns(new double[] { 100, 110 });     // [0.10]

Catálogo de operaciones

Área Namespace Operaciones
Aritmética escalar JonjubNet.Mathematical.Core.Arithmetic (ScalarMath) suma, resta, multiplicación, división, módulo, abs, sign, min, max, clamp, suma segura, producto de colección
Colecciones JonjubNet.Mathematical.Core.Arithmetic (CollectionMath) sumatoria, productoria, suma/producto acumulado, promedio, producto punto, norma, distancia euclídea
Potencias JonjubNet.Mathematical.Core.Powers (PowerMath) potencia, raíz cuadrada/cúbica/n-ésima, exp, ln, log10, log en base arbitraria
Trigonometría JonjubNet.Mathematical.Core.Powers (TrigMath) seno, coseno, tangente, arco seno/coseno/tangente, grados↔radianes
Álgebra lineal JonjubNet.Mathematical.Core.LinearAlgebra (Vector, Matrix) suma, resta, escalar, producto punto, norma, normalización, distancia, transpuesta, determinante, inversa, resolución de sistemas lineales
Cálculo numérico JonjubNet.Mathematical.Core.Calculus (NumericalCalculus) derivada (central/adelante/atrás), integral (trapecio, trapecio acumulado, Simpson), interpolación lineal
Series JonjubNet.Mathematical.Core.Series (SeriesMath) ventana móvil, SMA, EMA, retornos simples/log, normalización min-max, True Range; formas incrementales O(1) por valor nuevo

Fuera de alcance (pertenece a JonjubNet.Statistical): varianza, desviación estándar, covarianza, Pearson, Spearman, percentiles, regresión, bootstrap, intervalos de confianza.


Tests

dotnet test JonjubNet.Mathematical.slnx --configuration Release

Documentación

Documento Descripción
Arquitectura Capas, principios y flujo de dependencias
ADRs Decisiones de arquitectura registradas
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.1 50 10/21/2026
1.0.2 141 9/11/2026