Skip to content

Commit

Permalink
Add several more random methods
Browse files Browse the repository at this point in the history
random(ZZ, QQ) and random(QQ, ZZ) keep the result in QQ

random(CC) and random(CC, CC) use the uniform distributions on the
real and imaginary axes

We also add random(Number) and random(Number, Number) so pretty much
everything else should be taken care of by inheritance
  • Loading branch information
d-torrance committed Sep 20, 2024
1 parent 15f1394 commit 54ca6ec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions M2/Macaulay2/m2/reals.m2
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@ random RingFamily := opts -> R -> random(default R,opts)
random QQ := QQ => opts -> hi -> random(0_QQ, hi, opts)
random(QQ, QQ) := QQ => opts -> (lo, hi) -> rawFareyApproximation(
random(numeric lo, random numeric hi), opts.Height)
random(ZZ, QQ) := QQ => opts -> (lo, hi) -> random(lo_QQ, hi, opts)
random(QQ, ZZ) := QQ => opts -> (lo, hi) -> random(lo, hi_QQ, opts)

random CC := CC => opts -> hi -> toCC(
random realPart hi, random imaginaryPart hi)
random(CC, CC) := CC => opts -> (lo, hi) -> toCC(
random(realPart lo, realPart hi),
random(imaginaryPart lo, imaginaryPart hi))
random(RR, CC) := CC => opts -> (lo, hi) -> random(toCC lo, hi)
random(CC, RR) := CC => opts -> (lo, hi) -> random(lo, toCC hi)

random Number := opts -> hi -> random numeric hi
random(Number, Number) := opts -> (lo, hi) -> random(numeric lo, numeric hi)

-- algebraic operations and functions

Expand Down

0 comments on commit 54ca6ec

Please sign in to comment.