NTLib - Number Theory Library 0.9
Loading...
Searching...
No Matches
pell_equation.cpp File Reference

Primary module interface unit for module pell_equation. More...

#include <cassert>
#include <tuple>
#include <vector>
import rational;
import continued_fraction;
import base;
Include dependency graph for pell_equation.cpp:

Functions

template<Integer T>
constexpr std::tuple< T, T > ntlib::pell_fundamental_solution (T D) noexcept
 Compute the fundamental solution.
template<Integer T>
constexpr std::tuple< T, T > ntlib::pell_next_solution (T D, const std::tuple< T, T > &initial, const std::tuple< T, T > &current) noexcept
 Generates the next larger solution to Pell's equation.

Detailed Description

Primary module interface unit for module pell_equation.

Function Documentation

◆ pell_fundamental_solution()

template<Integer T>
std::tuple< T, T > ntlib::pell_fundamental_solution ( T D)
nodiscardconstexprexportnoexcept

Compute the fundamental solution.

There are infinitely many integer solutions. The fundamental solution is the one minimal in \(x\) (by absolute value) and therefore also in \(y\).

Template Parameters
TAn integer-like type.
Parameters
DParameter \(D \in \mathbb{N}\). Must not be a square number.
Returns
Fundamental solution \((x,y)\).

◆ pell_next_solution()

template<Integer T>
std::tuple< T, T > ntlib::pell_next_solution ( T D,
const std::tuple< T, T > & initial,
const std::tuple< T, T > & current )
nodiscardconstexprexportnoexcept

Generates the next larger solution to Pell's equation.

Template Parameters
TAn integer like type.
Parameters
DThe parameter \(D\).
initialThe fundamental solution, i.e., the one minimal in x by absolute value.
currentAny solution.
Returns
The next bigger solution than current (in x, by absolute value).