Skip to main content

Generate ranges of algebraic numbers — a Python port of the Wolfram Language AlgebraicRange resource function.

Project description

algebraic-range

Tests PyPI version Python License: MIT

Generate ranges of algebraic numbers.

Python port of the Wolfram resource function "AlgebraicRange" resource function.

Requires SymPy ≥ 1.12.

Overview

algebraic_range creates ranges made of algebraic numbers. This extends the basic concept of range() to include, besides rational numbers, also roots — always restricted to the real domain.

The first two arguments represent the bounds of the range (minimum and maximum values), while the optional third and fourth arguments (by default equal to 1 and 0) regulate the upper and lower bounds of the steps (differences between successive elements).

Usage

algebraic_range(x)                # Sqrt[Range[1, x²]]  for x ≥ 1
algebraic_range(x, y)             # Sqrt[Range[x², y²]]  for 0 ≤ x ≤ y
algebraic_range(x, y, s)          # step upper bound s,  0 < s ≤ y
algebraic_range(x, y, s, d)       # step lower bound d,  0 ≤ d ≤ s

Parameters

Parameter Default Description
r1 (required) Start of range (or single argument)
r2 None End of range
s None Step upper bound (negative → descending)
d 0 Step lower bound
root_order 2 int r → orders 2..r; [r] → only order r; [r1,r2,…] → listed orders
step_method "Outer" "Outer" or "Root"
farey_range False Use Farey-sequence–based rational multipliers
formula_complexity_threshold inf Discard elements above this complexity
algebraics_only True Reject transcendental inputs

Options

root_order

# Include square and cubic roots
algebraic_range(2, root_order=3)

# Only cubic roots
algebraic_range(2, root_order=[3])

# Cubic and fifth roots
algebraic_range(1, Rational(3, 2), root_order=[3, 5])

step_method

# "Root" method: Sqrt[Range[x², y², s²]]
algebraic_range(0, 3, Rational(1, 3), step_method="Root")

The default "Outer" method uses the outer product construction. The "Root" method is generally a superset.

farey_range

algebraic_range(0, 3, Rational(1, 3), farey_range=True)

Generalises FareyRange by combining algebraic ranges over all Farey-sequence steps.

formula_complexity_threshold

# Only keep simple expressions
algebraic_range(4, root_order=4, formula_complexity_threshold=8)

algebraics_only

from sympy import sqrt, E

# This raises NotAlgebraicError:
# algebraic_range(0, 5, sqrt(E))

# Allow transcendental step:
algebraic_range(0, 5, sqrt(E), algebraics_only=False)

Properties

  • Extends range(): set(range(x, y+1))set(algebraic_range(x, y))
  • Negative reflection: algebraic_range(-y, -x) = list(reversed([-v for v in algebraic_range(x, y)]))
  • All outputs are algebraic (when algebraics_only=True) and real
  • Sorted in ascending order (or descending for negative step)
  • No duplicates

See also

More details and examples can be found in the documentation for the original Wolfram Language resource function AlgebraicRange, contributed by the same author and vetted by the Wolfram Review Team.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algebraic_range-0.8.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algebraic_range-0.8.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file algebraic_range-0.8.0.tar.gz.

File metadata

  • Download URL: algebraic_range-0.8.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for algebraic_range-0.8.0.tar.gz
Algorithm Hash digest
SHA256 c443a222923e305e13e48b8b131203eb591373c2601a6bf46dc97bb9eda6444a
MD5 567d192d9f38029577ecd5cf4005050f
BLAKE2b-256 a9c7121abe59092234a84d93bd145c080a79dc1acb7431259367252771a0b32f

See more details on using hashes here.

File details

Details for the file algebraic_range-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for algebraic_range-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3fa292ec6c7fe55b80d3aa17cd25ff116a27f480d1283165469e7b805047876
MD5 832f43626374bc2fc7d3e9a896e2d14a
BLAKE2b-256 418e96058e7f88d620f3291ee497b56c9d0094c8de4922ae27216752ad0bf938

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page