add more help text
This commit is contained in:
parent
4b4858c54f
commit
9e6f648f0b
|
|
@ -49,7 +49,12 @@ func convergents(cmd *cobra.Command, args []string) {
|
||||||
var convergentsCmd = &cobra.Command{
|
var convergentsCmd = &cobra.Command{
|
||||||
Use: "convergents N N [N ...]",
|
Use: "convergents N N [N ...]",
|
||||||
Short: "Compute convergents of a periodic continued fraction",
|
Short: "Compute convergents of a periodic continued fraction",
|
||||||
Long: `Compute convergents of a periodic continued fraction.`,
|
Long: `Compute convergents of a periodic continued fraction.
|
||||||
|
|
||||||
|
The first number given is the integer part. The following numbers give the repetend of the continued fraction.
|
||||||
|
|
||||||
|
This will output convergents infinitely. Try piping to head to only output a certain number of convergents, like this:
|
||||||
|
mathtools convergents 3 2 6 | head -n 5`,
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.MinimumNArgs(2),
|
||||||
Run: convergents,
|
Run: convergents,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,13 @@ func discreteLog(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// discreteLogCmd represents the discreteLog command
|
// discreteLogCmd represents the discreteLog command
|
||||||
var discreteLogCmd = &cobra.Command{
|
var discreteLogCmd = &cobra.Command{
|
||||||
Use: "discrete-log",
|
Use: "discrete-log -b N -m N -e N",
|
||||||
Short: "Compute the discrete logarithm",
|
Short: "Compute the discrete logarithm",
|
||||||
Long: `Compute the discrete logarithm.`,
|
Long: `Compute the discrete logarithm.
|
||||||
|
|
||||||
|
Given a base b, modulus m, and element e, compute a value k such that b^k = e (mod m).
|
||||||
|
|
||||||
|
Note that no efficient method of finding the discrete logarithm is currently known. For slightly improved performance, the order of the group (i.e. the totient of m) can be provided.`,
|
||||||
Run: discreteLog,
|
Run: discreteLog,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,10 @@ func divisorSum(cmd *cobra.Command, args []string) {
|
||||||
var divisorCmd = &cobra.Command{
|
var divisorCmd = &cobra.Command{
|
||||||
Use: "divisor N [N ...]",
|
Use: "divisor N [N ...]",
|
||||||
Short: "Compute the divisor summatory function",
|
Short: "Compute the divisor summatory function",
|
||||||
Long: `Compute the divisor summatory function.`,
|
Long: `Compute the divisor summatory function.
|
||||||
|
|
||||||
|
For each argument n, compute D(n) = d(1) + d(2) + d(3) + ... + d(n), where d(n) is the number of divisors of n.`,
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Run: divisorSum,
|
Run: divisorSum,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,18 @@ func divisors(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// divisorsCmd represents the divisors command
|
// divisorsCmd represents the divisors command
|
||||||
var divisorsCmd = &cobra.Command{
|
var divisorsCmd = &cobra.Command{
|
||||||
Use: "divisors",
|
Use: "divisors -n N",
|
||||||
Short: "Compute the divisor function for all numbers less than n",
|
Short: "Compute the divisor function for all numbers less than n",
|
||||||
Long: `Compute the divisor function for all numbers less than n.`,
|
Long: `Compute the divisor function for all numbers less than n.
|
||||||
|
|
||||||
|
sigma_x(n) computes the sum of the xth powers of the divisors of n.
|
||||||
|
For example, the divisors of 12 are 1, 2, 3, 4, 6, and 12.
|
||||||
|
sigma_0(12) = 6
|
||||||
|
sigma_1(12) = 1 + 2 + 3 + 4 + 6 + 12 = 28
|
||||||
|
sigma_2(12) = 1^2 + 2^2 + 3^2 + 4^2 + 6^2 + 12^2 = 210
|
||||||
|
|
||||||
|
This program computes sigma for all values less than the input n.
|
||||||
|
Provide the --exponent flag to set the desired exponent for each sum.`,
|
||||||
Run: divisors,
|
Run: divisors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,10 @@ func gcd(cmd *cobra.Command, args []string) {
|
||||||
var gcdCmd = &cobra.Command{
|
var gcdCmd = &cobra.Command{
|
||||||
Use: "gcd N N [N ...]",
|
Use: "gcd N N [N ...]",
|
||||||
Short: "Compute the greatest common denominator of a set of numbers",
|
Short: "Compute the greatest common denominator of a set of numbers",
|
||||||
Long: `Compute the greatest common denominator of a set of numbers.`,
|
Long: `Compute the greatest common denominator of a set of numbers.
|
||||||
|
|
||||||
|
Provide the --extended flag to also compute the Bézout coefficients, i.e. coefficients a,b,c,... such that
|
||||||
|
ax + by + cz + ... = gcd(x,y,z,...)`,
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.MinimumNArgs(2),
|
||||||
Run: gcd,
|
Run: gcd,
|
||||||
}
|
}
|
||||||
|
|
@ -87,5 +90,5 @@ func init() {
|
||||||
// is called directly, e.g.:
|
// is called directly, e.g.:
|
||||||
// gcdCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
// gcdCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
|
||||||
gcdCmd.Flags().BoolVarP(&extended, "extended", "e", false, "also compute the Bezout coefficients")
|
gcdCmd.Flags().BoolVarP(&extended, "extended", "e", false, "also compute the Bézout coefficients")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,15 @@ func jacobi(cmd *cobra.Command, args []string) {
|
||||||
var jacobiCmd = &cobra.Command{
|
var jacobiCmd = &cobra.Command{
|
||||||
Use: "jacobi -a A -n N",
|
Use: "jacobi -a A -n N",
|
||||||
Short: "Compute the Jacobi symbol",
|
Short: "Compute the Jacobi symbol",
|
||||||
Long: `Compute the Jacobi symbol (a | n).`,
|
Long: `Compute the Jacobi symbol (a | n).
|
||||||
|
|
||||||
|
The Jacobi symbol is useful for studying quadratic residues. a is a quadratic residue modulo n if there exists a value x such that
|
||||||
|
x^2 = a (mod n)
|
||||||
|
|
||||||
|
If a is a quadratic residue modulo n and gcd(a, n) = 1, then (a | n) = 1.
|
||||||
|
If (a | n) = -1, then a is a quadratic nonresidue modulo n.
|
||||||
|
|
||||||
|
However, (a | n) = 1 does not guarantee that a is a quadratic residue modulo n.`,
|
||||||
Run: jacobi,
|
Run: jacobi,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,15 @@ func mobius(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// mobiusCmd represents the mobius command
|
// mobiusCmd represents the mobius command
|
||||||
var mobiusCmd = &cobra.Command{
|
var mobiusCmd = &cobra.Command{
|
||||||
Use: "mobius",
|
Use: "mobius -n N",
|
||||||
Short: "Compute the Möbius function for all numbers less than n",
|
Short: "Compute the Möbius function for all numbers less than n",
|
||||||
Long: `Compute the Möbius function for all numbers less than n.`,
|
Long: `Compute the Möbius function for all numbers less than n.
|
||||||
|
|
||||||
|
The Möbius function mu(n) is a multiplicative function defined as follows for prime p:
|
||||||
|
mu(p) = -1
|
||||||
|
mu(p^k) = 0 for k > 1
|
||||||
|
|
||||||
|
This means for squarefree n, mu(n) = -1 if n has an odd number of prime factors and mu(n) = 1 if n has an even number of prime factors. mu(n) = 0 if n is not squarefree.`,
|
||||||
Run: mobius,
|
Run: mobius,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,11 @@ func modInverse(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// modInverseCmd represents the modInverse command
|
// modInverseCmd represents the modInverse command
|
||||||
var modInverseCmd = &cobra.Command{
|
var modInverseCmd = &cobra.Command{
|
||||||
Use: "mod-inverse",
|
Use: "mod-inverse -g N -m N",
|
||||||
Short: "Compute a modular inverse",
|
Short: "Compute a modular inverse",
|
||||||
Long: `Compute a modular inverse.`,
|
Long: `Compute a modular inverse.
|
||||||
|
|
||||||
|
Given a base g and modulus m, compute a value x such that gx = 1 (mod m). A solution only exists if g and m are coprime.`,
|
||||||
Run: modInverse,
|
Run: modInverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,19 @@ func partitions(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// partitionsCmd represents the partitions command
|
// partitionsCmd represents the partitions command
|
||||||
var partitionsCmd = &cobra.Command{
|
var partitionsCmd = &cobra.Command{
|
||||||
Use: "partitions",
|
Use: "partitions -n N -k N",
|
||||||
Short: "Compute the number of partitions of an integer",
|
Short: "Compute the number of partitions of an integer",
|
||||||
Long: `Compute the number of partitions of an integer.`,
|
Long: `Compute the number of partitions of an integer.
|
||||||
|
|
||||||
|
For example, 4 can be partitioned into
|
||||||
|
4
|
||||||
|
3+1
|
||||||
|
2+2
|
||||||
|
2+1+1
|
||||||
|
1+1+1+1
|
||||||
|
so p(n) = 5.
|
||||||
|
|
||||||
|
To compute the number of partitions into at most k parts, provide the -k flag.`,
|
||||||
Run: partitions,
|
Run: partitions,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,12 @@ func pell(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// pellCmd represents the pell command
|
// pellCmd represents the pell command
|
||||||
var pellCmd = &cobra.Command{
|
var pellCmd = &cobra.Command{
|
||||||
Use: "pell",
|
Use: "pell -d N",
|
||||||
Short: "Find solutions to a Pell equation",
|
Short: "Find solutions to a Pell equation",
|
||||||
Long: `Find solutions to a Pell equation x^2 - dy^2 = 1.`,
|
Long: `Find integer solutions to a Pell equation x^2 - dy^2 = 1.
|
||||||
|
|
||||||
|
This will output solutions infinitely. Try piping to head to only output a certain number of solutions, like this:
|
||||||
|
mathtools pell -d 12 | head -n 5`,
|
||||||
Run: pell,
|
Run: pell,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,17 @@ func shoelace(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// shoelaceCmd represents the shoelace command
|
// shoelaceCmd represents the shoelace command
|
||||||
var shoelaceCmd = &cobra.Command{
|
var shoelaceCmd = &cobra.Command{
|
||||||
Use: "shoelace",
|
Use: "shoelace -f FILE",
|
||||||
Short: "Compute the area of a simple polygon from the vertex coordinates",
|
Short: "Compute the area of a simple polygon from the vertex coordinates",
|
||||||
Long: `Compute the area of a simple polygon from the vertex coordinates.`,
|
Long: `Compute the area of a simple polygon from the vertex coordinates.
|
||||||
|
|
||||||
|
Put each point on its own line, with each coordinate separated by whitespace. For example, a file with
|
||||||
|
1 6
|
||||||
|
3 1
|
||||||
|
7 2
|
||||||
|
4 4
|
||||||
|
8 5
|
||||||
|
will output an area of 16.5.`,
|
||||||
Run: shoelace,
|
Run: shoelace,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,15 @@ func sqrtRepetend(cmd *cobra.Command, args []string) {
|
||||||
// sqrtRepetendCmd represents the sqrtRepetend command
|
// sqrtRepetendCmd represents the sqrtRepetend command
|
||||||
var sqrtRepetendCmd = &cobra.Command{
|
var sqrtRepetendCmd = &cobra.Command{
|
||||||
Use: "sqrt-repetend N [N ...]",
|
Use: "sqrt-repetend N [N ...]",
|
||||||
Short: "Compute the repetend of the square root of the input",
|
Short: "Compute the repetend of the continued fraction of square roots",
|
||||||
Long: `Compute the repetend of the square root of the input.`,
|
Long: `Compute the repetend of the continued fraction of the square root of the input.
|
||||||
|
|
||||||
|
For each argument n, this will output the repetend of the continued fraction of sqrt(n). For example,
|
||||||
|
mathtools sqrt-repetend 12 15 19
|
||||||
|
will output
|
||||||
|
2 6
|
||||||
|
1 6
|
||||||
|
2 1 3 1 2 8`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
Run: sqrtRepetend,
|
Run: sqrtRepetend,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,23 @@ func stirling(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// stirlingCmd represents the stirling command
|
// stirlingCmd represents the stirling command
|
||||||
var stirlingCmd = &cobra.Command{
|
var stirlingCmd = &cobra.Command{
|
||||||
Use: "stirling",
|
Use: "stirling [-1|-2] -n N -k N",
|
||||||
Short: "Compute the Stirling numbers",
|
Short: "Compute the Stirling numbers",
|
||||||
Long: `Compute the Stirling numbers.`,
|
Long: `Compute the Stirling numbers.
|
||||||
|
|
||||||
|
The Stirling numbers of the first kind give the coefficients in the expansion of the falling factorial. For example,
|
||||||
|
x(x-1)(x-2) = x^3 - 3x^2 + 2x
|
||||||
|
Consequently, s(3,1) = 2, s(3,2) = -3, and s(3,3) = 3.
|
||||||
|
|
||||||
|
The Stirling numbers of the second kind count the number of ways to partition a set of n objects into k non-empty subsets. For example, there are 7 ways to partition a set of 4 objects into 2 non-empty subsets:
|
||||||
|
{1} {2,3,4}
|
||||||
|
{2} {1,3,4}
|
||||||
|
{3} {1,2,4}
|
||||||
|
{4} {1,2,3}
|
||||||
|
{1,2} {3,4}
|
||||||
|
{1,3} {2,4}
|
||||||
|
{1,4} {2,3}
|
||||||
|
Therefore S(4,2) = 7.`,
|
||||||
Run: stirling,
|
Run: stirling,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,11 @@ func totient(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// totientCmd represents the totient command
|
// totientCmd represents the totient command
|
||||||
var totientCmd = &cobra.Command{
|
var totientCmd = &cobra.Command{
|
||||||
Use: "totient",
|
Use: "totient -n N",
|
||||||
Short: "Compute the totient function for all numbers less than n",
|
Short: "Compute the totient function for all numbers less than n",
|
||||||
Long: `Compute the totient function for all numbers less than n.`,
|
Long: `Compute the totient function for all numbers less than n.
|
||||||
|
|
||||||
|
The totient function phi(n) counts the numbers up to n that are coprime to n.`,
|
||||||
Run: totient,
|
Run: totient,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue