PES
Pell Equation Solver
rad:z33QL2oAB9iszdd8tHZtCyuV4S6Fi
Visibility
public
Delegates
did:key:z6MkkzoSd5p9d5ZKFf3BRrG247towTjepZtER71QFFkMvgs6
Default branch
master → 65b435327e38841295ca3219b7ce0e261a37baac (Tue Mar 25 01:09:34 2025)
Threshold
1
README.md
# Pell Equation Solver written in Rust
This Rust project provides a command-line tool to solve Pell's equation, a classical problem in number theory. The program can be run in both interactive and non-interactive modes, allowing users to find solutions to the equation x² - n·y² = 1 for a given non-square integer `n`.

## Table of Contents
- [What is Pell's Equation?](#what-is-pells-equation)
- [How to Solve Pell's Equation](#how-to-solve-pells-equation)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Testing](#testing)
- [Contact](#contact)
- [Acknowledgements](#acknowledgements)
## What is Pell's Equation?
Pell's equation is a Diophantine equation of the form:
x² - n·y² = 1
where:
- `x` and `y` are integers,
- `n` is a positive non-square integer.
The equation is named after the 17th-century mathematician John Pell, although it was first studied extensively by Brahmagupta and later by Euler. Pell's equation has infinitely many solutions if `n` is not a perfect square. The smallest non-trivial solution (x₁, y₁) is called the **fundamental solution**, and all other solutions can be generated from it.
## How to Solve Pell's Equation
The standard method to solve Pell's equation involves the following steps:
1. **Continued Fraction Expansion**: Compute the continued fraction expansion of √n. The expansion will eventually become periodic, and the period helps in finding the fundamental solution.
2. **Convergents**: Compute the convergents of the continued fraction. These are rational approximations to √n, and one of them will yield the fundamental solution (x₁, y₁).
3. **Generating Solutions**: Once the fundamental solution is found, all other solutions can be generated using the recurrence relation:
xₖ₊₁ = x₁·xₖ + n·y₁·yₖ
yₖ₊₁ = x₁·yₖ + y₁·xₖ
This project implements these steps efficiently using Rust's powerful numerical libraries.
## Features
- **Interactive Mode**: Run the program interactively to input values and see solutions.
- **Command-Line Mode**: Pass arguments directly to the program for quick solutions.
- **Efficient Computation**: Uses Rust's `num-bigint` library for handling large integers.
- **Customizable Solution Count**: Specify how many solutions you want to generate.
## Installation
To use this tool, you need to have Rust installed on your system. If you don't have Rust installed, you can install it from [rustup.rs](https://rustup.rs/).
1. Clone the repository:
Using Radicle
```bash
rad clone rad:z33QL2oAB9iszdd8tHZtCyuV4S6Fi
```
Using Git
```bash
git clone https://seed.radicle.garden/z33QL2oAB9iszdd8tHZtCyuV4S6Fi.git PES
```
2. Build the project:
```bash
cargo build --release
```
3. Run the program:
```bash
./pes
```
## Usage
Interactive Mode
Run the program without arguments to enter interactive mode:
```bash
./pes
```
You will be prompted to enter a non-square integer n and the number of solutions you want to find.
Command-Line Mode
You can also run the program with command-line arguments:
```bash
./pes 7 -c 10
```
<n>: The value of n in the Pell equation x² - n·y² = 1.
-c <count>: (Optional) The number of solutions to find. Default is 5.
## Examples
1. Find the fundamental solution for n = 92:
```bash
./pes 92 -c 10
```
Output:
```bash
Pell equation solver: x² - 92·y² = 1
Finding solutions...
Fundamental solution (x, y) = (1151, 120)
Generating additional solutions...
Solutions to x² - 92·y² = 1:
Solution 1: (x, y) = (1151, 120)
Solution 2: (x, y) = (2649601, 276240)
Solution 3: (x, y) = (6099380351, 635904360)
Solution 4: (x, y) = (14040770918401, 1463851560480)
Solution 5: (x, y) = (32321848554778751, 3369785656320600)
Solution 6: (x, y) = (74404881332329766401, 7757245116998460720)
Solution 7: (x, y) = (171280004505174567476351, 17857174889544800256840)
Solution 8: (x, y) = (394286495966030522000793601, 41107208838487013192784960)
Solution 9: (x, y) = (907647342433797756471259393151, 94628776889022214824990721080)
Solution 10: (x, y) = (2089403787996106469366317122240001, 217835403291320300040115447141200)
```
## Testing
The project includes unit tests to ensure correctness. You can run the tests using:
```bash
cargo test
```
Output:
```bash
Compiling pes v0.1.0 (/home/h4ck8r/Desktop/my_rust_dossier/pes)
Finished `test` profile [unoptimized + debuginfo] target(s) in 25.96s
Running unittests src/main.rs (target/debug/deps/pes-64c99cdd23c266b2)
running 4 tests
test tests::test_continued_fraction_sqrt ... ok
test tests::test_find_pell_solutions ... ok
test tests::test_generate_more_solutions ... ok
test tests::test_is_pell_solution ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
```
## Contact
For encrypted email correspondence, please refer to the file public-key.asc.
## Official Website
https://enkryp.duckdns.org
## e-mail
battosai@dnmx.su
## LXMF Address
1b634f9ac2aee34bec3276ad17f52d11
An LXMF address is a unique identifier used for secure communication over the LXMF protocol, enabling users to send and receive encrypted messages. I suggest using the Sideband app or Nomad Network for this purpose.
## Briar
To connect via Briar, please first add me using the link provided, and then send your Briar link to my email. I will promptly add you to my trusted contacts.
briar://ac4jkk7rqcb7vbvjudzvoav64lcypoo3qaj3b5wnndcvvsdpz3fvs
## Acknowledgements
I would like to express my deepest gratitude to my friends at #hackfreedom, whose unwavering encouragement and inspiration have been instrumental in the creation of this code. To the Cynics who question everything, the Abstract minds that see patterns where others see noise, and the Crispies who always keep things sharp — thank you. To the Foxes, cunning as ever, and the Lords of Skull and shadow — your support has been invaluable. And finally, to the one whose presence always leaves an effect — et qui comprend ces mots sans effort — you know who you are.
This code began with a simple question — a Pell equation — cast into the noisy void of the chat. Most of it was met with confusion, ignorance, and the sound of braying from those who contribute nothing but emptiness. While they fumbled with nonsense, my friends stood apart — understanding, encouraging, and offering insight where others offered only noise. This work stands as proof that even the most complex ciphers are no match for true friendship — and that intelligence, much like cryptography, thrives in the presence of the right keys.