Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Avhz RustQuant Mathematical Sequences

From Leeroopedia


Knowledge Sources
Domains Mathematics, Numerical_Methods
Last Updated 2026-02-07 21:00 GMT

Overview

Mathematical sequence generation utilities providing R-style functions for creating arithmetic sequences, repetitions, linearly spaced vectors, logarithmically spaced vectors, and cumulative sums.

Description

Mathematical Sequences in RustQuant implements the Sequence trait, which provides a set of generic functions for generating and transforming numerical sequences. The trait is inspired by R's seq, rep, and related functions, and is implemented generically for any type satisfying Num + PartialOrd + Copy + FromPrimitive + ToPrimitive.

The trait defines five methods:

  • seq(start, end, step) generates an arithmetic sequence from start to end (inclusive) with the given step size. For example, f64::seq(0.0, 1.0, 0.1) produces [0.0, 0.1, 0.2, ..., 1.0].
  • rep(x, n) repeats the value x a total of n times, returning a vector.
  • linspace(start, end, n) generates n linearly spaced values between start and end (inclusive). The step size is computed as (end - start) / (n - 1).
  • logspace(start, end, n) is intended to generate n logarithmically spaced values between start and end. This method is currently unimplemented (todo!()).
  • cumsum(v) computes the cumulative sum of a slice, producing a vector where each element is the running total up to that index.

The implementation uses a blanket impl so that all compatible numeric types (including f32, f64, i32, i64, u32, u64, usize) automatically gain these methods as associated functions.

Usage

Use these utilities when constructing grids for numerical methods (e.g., finite difference grids), generating time steps for simulations, creating evenly spaced evaluation points for curve plotting, or performing running total calculations. The generic implementation ensures the same interface works across all numeric types.

Theoretical Basis

An arithmetic sequence with start a, step d, and n terms is:

ak=a+kd,k=0,1,2,

For linearly spaced points between a and b with n elements:

xk=a+kban1,k=0,1,,n1

The cumulative sum of a sequence {v1,v2,,vn} is:

Sk=i=1kvi

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment