rathureqpy 0.3.0
Manipulating lists, basic mathematical functions and LaTeX-like writing
License: MIT
Keywords: lists, math, matrix, stacks, queues

# Rathureqpy - A Python Utility Library

Rathureqpy is a Python library that provides a set of useful functions for a variety of tasks including list manipulation, mathematical operations, logical operations, statistical measures, and more.

## Installation

You can install Rathureqpy by running:

``bash
pip install rathureqpy
``

## Features

### List Operations

- **zero(number)**: Returns a list of zeros with the specified length.

- **prod(L, a)**: Returns a new list with each element of `L` multiplied by `a`.

- **addl(*args)**: Adds corresponding elements from multiple lists of equal length.

- **linespace(start, end, step)**: Generates a list of evenly spaced values between `start` and `end` with a given `step`.

- **array(start, end, n)**: Generates an array of `n` evenly spaced values between `start` and `end`.

- **uni(*lists)**: Flattens multiple lists into a single list.

- **uniwd(*lists)**: Flattens multiple lists into a single list and removes duplicates.

- **inter(*lists)**: Returns the intersection of multiple lists.

- **uniq(L)**: Returns a list with unique elements from `L`.

- **moy(L)**: Returns the mean of a list `L`.

- **sum_int(start, end)**: Returns the sum of integers between `start` and `end`.

- **randl(min, max, n)**: Generates a list of `n` random integers between `min` and `max`.

- **shuffle_list(L)**: Returns a shuffled version of `L`.

- **filtrer(L, condition)**: Filters `L` based on a condition.

- **chunk(L, n)**: Splits `L` into chunks of size `n`.

- **partition(L, condition)**: Partitions `L` into two lists based on a condition.


### Logical Operations

- **binr(n)**: Converts an integer `n` to its binary representation as a string.

- **change_base(value, inp_base, out_base)**: Converts `value` from `inp_base` to `out_base`.

- **divisor_list(n)**: Returns a list of divisors of `n`.

- **dicho(start, end, f, eps)**: Performs binary search to find the root of the function `f` in the interval `[start, end]` with an error tolerance `eps`.

- **size(point_A, point_B)**: Calculates the distance between two points `A` and `B` in a 2D space.

### Constants

- **pi**: Returns the constant `\u03C0`.

- **e**: Returns the constant `e`.

- **tau**: Returns the constant `\u03C4` (2\u03C0).

### Mathematical Operations

- **abs(x)**: Returns the absolute value of `x`.

- **cos(x)**: Returns the cosine of `x`.

- **sin(x)**: Returns the sine of `x`.

- **log(x, base=e())**: Returns the logarithm of `x` to the specified `base`.

- **exp(x)**: Returns the exponential of `x`.

- **sqrt(x)**: Returns the square root of `x`.

- **facto(n)**: Returns the factorial of `n`.

- **floor(x)**: Returns the largest integer less than or equal to `x`.

- **ceil(x)**: Returns the smallest integer greater than or equal to `x`.

- **rint(x)**: Returns the integer closest to `x` (rounding halfway cases away from zero).

- **gcd(a, b)**: Returns the greatest common divisor of `a` and `b`.

- **lcm(a, b)**: Returns the least common multiple of `a` and `b`.

- **is_prime(n)**: Checks if `n` is a prime number.

- **integ(f, a, b, N)** : Calculates the integral of `f` from `a` to `b` using the trapezoidal rule, with a sign adjustment if `a > b`

### Statistical Measures

- **variance(L)**: Returns the variance of the list `L`.

- **ecart_type(L)**: Returns the standard deviation of the list `L`.

- **mediane(L)**: Returns the median of the list `L`.

- **decomp(n)**: Returns the prime factorization of `n` as a list of tuples.

- **list_prime(n)**: Returns a list of all prime numbers up to `n`.

- **pascal_row(n)**: Returns the `n`-th row of Pascal's Triangle.


### Matrix

- **mat(data)**: Creates a matrix from a list of lists `data`. All rows must have the same length.

    - **__getitem__(idx)**: Returns a row if `idx` is an integer, or a single element if `idx` is a tuple `(i,j)`.

    - **__setitem__(idx, value)**: Sets a row if `idx` is an integer, or a single element if `idx` is a tuple `(i,j)`.

    - **__len__()**: Returns the number of rows of the matrix.

    - **size**: Returns a tuple `(rows, columns)` representing the matrix size.

    - **__add__(other)**: Element-wise addition of two matrices of the same size.

    - **__radd__(other)**: Right-side addition (supports `sum()`).

    - **__sub__(other)**: Element-wise subtraction of two matrices of the same size.

    - **__mul__(other)**: Multiplies the matrix by a scalar or another matrix (matrix multiplication).

    - **__rmul__(other)**: Right-side multiplication.

    - **__truediv__(scalar)**: Divides the matrix by a scalar.

    - **__pow__(n)**: Raises a square matrix to a non-negative integer power.

    - **__neg__()**: Returns the negation of the matrix.

    - **__eq__(other)**: Returns `True` if two matrices are equal.

    - **__ne__(other)**: Returns `True` if two matrices are not equal.

    - **T**: Returns the transpose of the matrix.

    - **copy()**: Returns a copy of the matrix.

    - **trace**: Returns the trace of a square matrix.

    - **tolist()**: Returns the matrix as a list of lists.

    - **__iter__()**: Returns an iterator over the rows of the matrix.

    - **flatten(as_tuple=False)**: Returns all elements as a flat generator, or as a tuple if `as_tuple=True`.

    - **diag_mat()**: Returns a diagonal matrix with the same diagonal elements as the current square matrix.

    - **diag_vec(column=True)**: Returns the diagonal elements as a column vector (default) or row vector if `column=False`.

    - **replace(old_value, new_value)**: Replaces all occurrences of `old_value` with `new_value` in-place.

    - **replaced(old_value, new_value)**: Returns a new matrix with `old_value` replaced by `new_value`.

    - **map(f)**: Applies a function `f` to each element of the matrix and returns a new matrix.

    - **det()**: Returns the determinant of a square matrix.

    - **rank()**: Returns the rank of the matrix using Gaussian elimination.

    - **__repr__()**: Returns the official string representation of the matrix.

    - **__str__()**: Returns a readable string representation of the matrix.

- **zero(n, p)**: Returns a zero matrix of size `n x p`.

- **I(n)**: Returns an identity matrix of size `n x n`.

- **diagonal(values)**: Returns a diagonal matrix with the given sequence of `values`.

- **full(n, p=0, value=1)**: Returns a matrix of size `n x p` filled with `value`. If `p` is 0, creates a square matrix `n x n`.

- **random(n, p=0, low=-10, high=10)**: Returns a random integer matrix of size `n x p` (square if `p=0`) with entries in `[low, high]`.

### Stacks

- **stack(*args)**: Initialize the stack with optional initial values.

    - **is_empty**: Return `True` if the stack contains no elements.

    - **__len__()**: Return the number of elements in the stack.

    - **size**: Return the size of the stack (same as len()).

    - **__neg__()**: Return a new stack with all elements negated.

    - **__call__(*args)**: Push new elements onto the stack.

    - **pop(n=1)**: Pop and return `n` elements from the stack. Return a single element if `n==1`, otherwise return a new stack.

    - **__eq__(other)**: Return `True` if both stacks contain the same elements.

    - **__ne__(other)**: Return `True` if stacks are different.

    - **__add__(other)**: Add two stacks element-wise and return a new stack.

    - **__sub__(other)**: Subtract another stack element-wise and return a new stack.

    - **__mul__(value)**: Multiply all elements by a value and return a new stack.

    - **__rmul__(value)**: Right multiplication: `value * stack`

    - **__truediv__(scalar)**: Divide stack elements by a scalar and return a new stack.

    - **__floordiv__(scalar)**: Apply floor division to all elements and return a new stack.

    - **__contains__(value)**: Return `True` if a value is in the stack.

    - **copy()**: Return a shallow copy of the stack.

    - **reverse()**: Return a new stack with elements in reversed order.

    - **replace(old_value, new_value)**: Replace all occurrences of `old_value` with `new_value` in place.

    - **replaced(old_value, new_value)**: Return a new stack with `old_value` replaced by `new_value`.

    - **map(f)**: Apply a function to each element and return a new stack.

    - **sum()**: Return the sum of all elements in the stack.

    - **__repr__()**: Return the official string representation of the stack.

    - **__str__()**: Return a readable string representation of the stack.

- **zero(n)**: Return a stack filled with `n` zeros.

- **full(n, value)**: Return a stack filled with `n` copies of a given value.

- **random(n, low=-10, high=10)**: Return a stack of `n` random integers between `low` and `high`.

- **queue(*args)**: Initialize the queue with optional initial values

    - **is_empty()**: Return `True` if the queue contains no elements.
    
    - **__len__()**: Return the number of elements in the queue.
    
    - **size()**: Return the size of the queue (same as len()).
    
    - **__neg__()**: Return a new queue with all elements negated.
    
    - **__call__(*args)**: Push new elements into the queue.
    
    - **pop(n=1)**: Pop and return `n` elements from the queue. If `n==1`, return a single value; otherwise return a new queue.
    
    - **__eq__(other)**: Return `True` if both queues contain the same elements.
    
    - **__ne__(other)**: Return `True` if queues are different.
    
    - **__add__(other)**: Add two queues element-wise and return a new queue.
    
    - **__sub__(other)**: Subtract another queue element-wise and return a new queue.
    
    - **__mul__(value)**: Multiply all elements by a value and return a new queue.
    
    - **__rmul__(value)**: Right multiplication: `value * queue`.
    
    - **__truediv__(scalar)**: Divide queue elements by a scalar and return a new queue.
    
    - **__floordiv__(scalar)**: Apply floor division to all elements and return a new queue.
    
    - **__contains__(value)**: Return `True` if a value is in the queue.
    
    - **copy()**: Return a shallow copy of the queue.
    
    - **reverse()**: Return a new queue with elements in reversed order.
    
    - **replace(old_value, new_value)**: Replace all occurrences of `old_value` with `new_value` in place.
    
    - **replaced(old_value, new_value)**: Return a new queue with `old_value` replaced by `new_value`.
    
    - **map(f)**: Apply a function to each element and return a new queue.
    
    - **sum()**: Return the sum of all elements in the queue.
    
    - **__repr__()**: Return the official string representation of the queue.
    
    - **__str__()**: Return a readable string representation of the queue.

- **zero(n)**: Return a queue filled with `n` zeros.

- **full(n, value)**: Return a queue filled with `n` copies of a value.

- **random(n, low=-10, high=10)**: Return a queue of `n` random integers between `low` and `high`.

### Mathematical Language LaTeX-like

- **lat(expr)**: Converts a simple LaTeX-like string `expr` into Unicode math characters. Supports: exponents (`^`), indices (`_`), square roots (`sqrt(...)`), sums (`sum{...}^...`), products (`prod{...}^...`), integrals (`int`), and fractions (`frac{...}{...}`).

- **symbol(sym)**: Returns the Unicode math symbol corresponding to the LaTeX command `sym`. If the command is unknown, returns `[unknown: sym]`.

- **dot(text)**: Returns the input string `text` with a dot placed above each character.

- **vec(text)**: Returns the input string `text` with a bar placed above each character.

- **greek(expr)**: Converts the Greek letter name `expr` into its corresponding Unicode symbol. Returns an empty string if the name is not recognized.

- **italic(text)**: Converts the input string `text` to italic Unicode mathematical characters. Only English letters (a-z, A-Z) are transformed.

- **bold(text)**: Converts the input string `text` to bold Unicode mathematical characters. Only English letters (a-z, A-Z) are transformed.

- **mathbb(text)**: Converts the input string `text` to double-struck (blackboard bold) Unicode characters. Only English letters (a-z, A-Z) are transformed.

- **cursive(text)**: Converts the input string `text` to cursive (script) Unicode characters. Only English letters (a-z, A-Z) are transformed.


## Contribute and Bugs

If you encounter any bugs or would like to contribute to the project, feel free to open an issue or submit a pull request. Contributions are always welcome!

**email** : arthur.quersin@gmail.com

Made by Arthur Quersin


Change log 
==========

0.0.1 (26/01/2025)
-------------------
First release

0.0.2 (27/01/2025)
-------------------
Second release (stable)

0.0.3 (31/01/2025)
-------------------
Third release (stable, I hope)

0.0.4 (31/01/2025)
-------------------
Fourth release (stable, I hope 2)

0.0.5 (02/02/2025)
-------------------
Fith release, with a lot of new fonctions

0.1.2 (18/02/2025)
-------------------
A new release with, again, a lot of new and useful functions including :
    
    - subindex

    - pascal_row

    - list_prime
    
    - decomp
    
0.1.21 (24/03/2025)
-------------------
Fixing readme file

0.1.22 (24/03/2025)
-------------------
Fixing readme file

0.1.32 (29/04/2025)
-------------------
- Removed `apply()` because it duplicated functionality of `map()`

- Changed `rathureqpy.pi()`, `rathureqpy.e()`, and `rathureqpy.tau()` to `rathureqpy.pi`, `rathureqpy.e`, and `rathureqpy.tau` (variables instead of functions)

- Added `integ(f, a, b, N)` to calculate the integral using the trapezoidal rule, with sign adjustment if `a > b`

0.1.40 (12/06/2025)
-------------------
A new release with, again, a lot of new and useful functions for mathematical writing !
    
    - lat

    - symbol

    - dot

    - vec

    - greek

    - italic

    - bold

    - mathbb

    - cursive

0.1.41 (13/06/2025)
-------------------
Fixing `lat` (exponent and index) and adding `inf` to `symbol`

0.2.0 (18/09/2025)
-------------------
A new release with, the addition of Matrix!
    
    - mat

        - __getitem__

        - __setitem__

        - __len__

        - size
        
        - __add__
        
        - __radd__
        
        - __sub__
        
        - __mul__
        
        - __rmul__
        
        - __truediv__
        
        - __pow__
        
        - __neg__
        
        - __eq__
        
        - __ne__
        
        - T
        
        - copy
        
        - trace
        
        - tolist
        
        - __iter__
        
        - flatten
        
        - diag_mat
        
        - diag_vec
        
        - replace
        
        - replaced
        
        - map
        
        - det
        
        - rank
        
        - __repr__
        
        - __str__

    - zero

    - I

    - diagonal

    - full

    - random

0.3.0 (25/11/2025)
-------------------
A new release introducing the `stack` and `queue` classes with full functionality!
Updated the matrix methodsâ€™ type hints, replacing `int|float` with `Any`.

    - stack

        - __init__

        - is_empty

        - __len__

        - size

        - __neg__

        - __call__

        - pop

        - __eq__

        - __ne__

        - __add__

        - __sub__

        - __mul__

        - __rmul__

        - __truediv__

        - __floordiv__

        - __contains__

        - copy

        - reverse

        - replace

        - replaced

        - map

        - sum

        - __repr__

        - __str__

    - zero

    - full

    - random

    - queue

        - __init__

        - is_empty

        - __len__

        - size

        - __neg__

        - __call__

        - pop

        - __eq__

        - __ne__

        - __add__

        - __sub__

        - __mul__

        - __rmul__

        - __truediv__

        - __floordiv__

        - __contains__

        - copy

        - reverse

        - replace

        - replaced

        - map

        - sum

        - __repr__

        - __str__

    - zero

    - full

    - random