Browse Source

Merge pull request #193 from jack-pappas/fs-bignum-cleanup

General cleanup of Complex and BigRational code imported from the F# PowerPack
provider
Christoph Ruegg 13 years ago
parent
commit
b157a1398d
  1. 779
      src/FSharp/BigRational.fs
  2. 151
      src/FSharp/BigRational.fsi
  3. 567
      src/FSharp/Complex.fs
  4. 286
      src/FSharp/Complex.fsi
  5. 1
      src/FSharp/FSharp-Portable136.fsproj
  6. 1
      src/FSharp/FSharp-Portable47.fsproj
  7. 1
      src/FSharp/FSharp.fsproj

779
src/FSharp/BigRational.fs

@ -10,303 +10,490 @@ namespace MathNet.Numerics
#if NOSYSNUMERICS #if NOSYSNUMERICS
#else #else
open System open System
open System.Numerics open System.Numerics
open System.Globalization open System.Globalization
module BigRationalLargeImpl =
let ZeroI = new BigInteger(0) [<AutoOpen>]
let OneI = new BigInteger(1) module private BigRationalLargeImpl =
let bigint (x:int) = new BigInteger(x) let ZeroI = BigInteger (0)
let ToDoubleI (x:BigInteger) = double x let OneI = BigInteger (1)
let ToInt32I (x:BigInteger) = int32 x let bigint (x : int) = BigInteger (x)
let ToDoubleI (x : BigInteger) = float x
open BigRationalLargeImpl let ToInt32I (x : BigInteger) = int32 x
[<CustomEquality; CustomComparison>]
type BigRationalLarge = [<CustomEquality; CustomComparison>]
| Q of BigInteger * BigInteger // invariants: (p,q) in lowest form, q >= 0 type BigRationalLarge =
// invariants: (p,q) in lowest form, q >= 0
override n.ToString() = | Q of BigInteger * BigInteger
let (Q(p,q)) = n
if q.IsOne then p.ToString() member x.IsNegative =
else p.ToString() + "/" + q.ToString() let (Q (ap, _)) = x
sign ap < 0
static member Hash (Q(ap,aq)) = member x.IsPositive =
// This hash code must be identical to the hash for BigInteger when the numbers coincide. let (Q (ap, _)) = x
if aq.IsOne then ap.GetHashCode() else (ap.GetHashCode() <<< 3) + aq.GetHashCode() sign ap > 0
member x.Numerator =
override x.GetHashCode() = BigRationalLarge.Hash(x) let (Q (p, _)) = x in p
static member Equals(Q(ap,aq), Q(bp,bq)) = member x.Denominator =
BigInteger.(=) (ap,bp) && BigInteger.(=) (aq,bq) // normal form, so structural equality let (Q (_, q)) = x in q
static member LessThan(Q(ap,aq), Q(bp,bq)) = member x.Sign =
BigInteger.(<) (ap * bq,bp * aq) let (Q (p,_) ) = x
sign p
// note: performance improvement possible here
static member Compare(p,q) = override this.GetHashCode () =
if BigRationalLarge.LessThan(p,q) then -1 BigRationalLarge.Hash this
elif BigRationalLarge.LessThan(q,p)then 1
else 0 override this.ToString () =
let (Q (p, q)) = this
interface System.IComparable with if q.IsOne then
member this.CompareTo(obj:obj) = p.ToString()
match obj with else
| :? BigRationalLarge as that -> BigRationalLarge.Compare(this,that) p.ToString() + "/" + q.ToString()
| _ -> invalidArg "obj" "the object does not have the correct type"
static member Hash (Q (ap, aq)) =
override this.Equals(that:obj) = // This hash code must be identical to the hash for BigInteger when the numbers coincide.
match that with if aq.IsOne then ap.GetHashCode ()
| :? BigRationalLarge as that -> BigRationalLarge.Equals(this,that) else (ap.GetHashCode () <<< 3) + aq.GetHashCode ()
| _ -> false
static member Equals(Q (ap, aq), Q (bp, bq)) =
member x.IsNegative = let (Q(ap,_)) = x in sign ap < 0 // normal form, so structural equality
member x.IsPositive = let (Q(ap,_)) = x in sign ap > 0 BigInteger.(=) (ap, bp) && BigInteger.(=) (aq, bq)
member x.Numerator = let (Q(p,_)) = x in p static member LessThan (Q (ap, aq), Q (bp, bq)) =
member x.Denominator = let (Q(_,q)) = x in q BigInteger.(<) (ap * bq, bp * aq)
member x.Sign = (let (Q(p,_)) = x in sign p)
// TODO: performance improvement possible here
static member ToDouble (Q(p,q)) = static member Compare (p, q) =
ToDoubleI p / ToDoubleI q if BigRationalLarge.LessThan (p, q) then -1
elif BigRationalLarge.LessThan (q, p)then 1
static member Normalize (p:BigInteger,q:BigInteger) = else 0
if q.IsZero then
raise (System.DivideByZeroException()) (* throw for any x/0 *) static member ToDouble (Q (p, q)) =
elif q.IsOne then ToDoubleI p / ToDoubleI q
Q(p,q)
else static member Normalize (p : BigInteger, q : BigInteger) =
let k = BigInteger.GreatestCommonDivisor(p,q) if q.IsZero then
let p = p / k (* throw for any x/0 *)
let q = q / k raise <| System.DivideByZeroException ()
if sign q < 0 then Q(-p,-q) else Q(p,q) elif q.IsOne then
Q (p, q)
static member Rational (p:int,q:int) = BigRationalLarge.Normalize (bigint p,bigint q) else
static member RationalZ (p,q) = BigRationalLarge.Normalize (p,q) let k = BigInteger.GreatestCommonDivisor (p, q)
let p = p / k
static member Parse (str:string) = let q = q / k
let len = str.Length if sign q < 0 then
if len=0 then invalidArg "str" "empty string"; Q (-p, -q)
let j = str.IndexOf '/' else Q (p, q)
if j >= 0 then
let p = BigInteger.Parse (str.Substring(0,j)) static member Rational (p : int, q : int) =
let q = BigInteger.Parse (str.Substring(j+1,len-j-1)) BigRationalLarge.Normalize (bigint p, bigint q)
BigRationalLarge.RationalZ (p,q)
else // TODO : Rename to Rational? It doesn't seem like we need to force the overload resolution here with a separate name...
let p = BigInteger.Parse str static member RationalZ (p, q) =
BigRationalLarge.RationalZ (p,OneI) BigRationalLarge.Normalize (p, q)
static member (~-) (Q(bp,bq)) = Q(-bp,bq) // still coprime, bq >= 0 /// Return the negation of a rational number
static member (+) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize ((ap * bq) + (bp * aq),aq * bq) static member (~-) (Q (bp, bq)) =
static member (-) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize ((ap * bq) - (bp * aq),aq * bq) // still coprime, bq >= 0
static member (*) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize (ap * bp,aq * bq) Q(-bp, bq)
static member (/) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize (ap * bq,aq * bp)
static member ( ~+ )(n1:BigRationalLarge) = n1 /// Return the sum of two rational numbers
static member (+) (Q (ap, aq), Q (bp, bq)) =
BigRationalLarge.Normalize ((ap * bq) + (bp * aq), aq * bq)
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module BigRationalLarge = /// Return the difference of two rational numbers
open System.Numerics static member (-) (Q (ap, aq), Q (bp, bq)) =
BigRationalLarge.Normalize ((ap * bq) - (bp * aq), aq * bq)
let inv (Q(ap,aq)) = BigRationalLarge.Normalize(aq,ap)
/// Return the product of two rational numbers
let pown (Q(p,q)) (n:int) = Q(BigInteger.Pow(p,n),BigInteger.Pow (q,n)) // p,q powers still coprime static member (*) (Q (ap, aq), Q (bp, bq)) =
BigRationalLarge.Normalize (ap * bp, aq * bq)
let equal (Q(ap,aq)) (Q(bp,bq)) = ap=bp && aq=bq // normal form, so structural equality
let lt a b = BigRationalLarge.LessThan(a,b) /// Return the ratio of two rational numbers
let gt a b = BigRationalLarge.LessThan(b,a) static member (/) (Q (ap, aq), Q (bp, bq)) =
let lte (Q(ap,aq)) (Q(bp,bq)) = BigInteger.(<=) (ap * bq,bp * aq) BigRationalLarge.Normalize (ap * bq, aq * bp)
let gte (Q(ap,aq)) (Q(bp,bq)) = BigInteger.(>=) (ap * bq,bp * aq)
/// Return the given rational number
let of_bigint z = BigRationalLarge.RationalZ(z,OneI) static member ( ~+ ) (n1 : BigRationalLarge) = n1
let of_int n = BigRationalLarge.Rational(n,1)
//
// integer part static member Parse (str : string) =
let integer (Q(p,q)) = let len = str.Length
let mutable r = BigInteger(0) if len=0 then invalidArg "str" "empty string";
let d = BigInteger.DivRem (p,q,&r) // have p = d.q + r, |r| < |q| let j = str.IndexOf '/'
if r < ZeroI if j >= 0 then
then d - OneI // p = (d-1).q + (r+q) let p = BigInteger.Parse (str.Substring(0,j))
else d // p = d.q + r let q = BigInteger.Parse (str.Substring(j+1,len-j-1))
BigRationalLarge.RationalZ (p,q)
else
//---------------------------------------------------------------------------- let p = BigInteger.Parse str
// BigRational BigRationalLarge.RationalZ (p,OneI)
//--------------------------------------------------------------------------
override this.Equals(that : obj) =
[<CustomEquality; CustomComparison>] match that with
[<StructuredFormatDisplay("{StructuredDisplayString}N")>] | :? BigRationalLarge as that ->
type BigRational = BigRationalLarge.Equals(this,that)
| Z of BigInteger | _ -> false
| Q of BigRationalLarge
interface System.IComparable with
static member ( + )(n1,n2) = member this.CompareTo (obj : obj) =
match n1,n2 with match obj with
| Z z ,Z zz -> Z (z + zz) | :? BigRationalLarge as other ->
| Q q ,Q qq -> Q (q + qq) BigRationalLarge.Compare (this, other)
| Z z ,Q qq -> Q (BigRationalLarge.of_bigint z + qq) | _ ->
| Q q ,Z zz -> Q (q + BigRationalLarge.of_bigint zz) invalidArg "obj" "the object does not have the correct type"
static member ( * )(n1,n2) =
match n1,n2 with //
| Z z ,Z zz -> Z (z * zz) [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
| Q q ,Q qq -> Q (q * qq) module private BigRationalLarge =
| Z z ,Q qq -> Q (BigRationalLarge.of_bigint z * qq) //
| Q q ,Z zz -> Q (q * BigRationalLarge.of_bigint zz) let inv (Q (ap, aq)) =
BigRationalLarge.Normalize (aq, ap)
static member ( - )(n1,n2) =
match n1,n2 with //
| Z z ,Z zz -> Z (z - zz) let pown (Q (p, q)) (n:int) =
| Q q ,Q qq -> Q (q - qq) // p,q powers still coprime
| Z z ,Q qq -> Q (BigRationalLarge.of_bigint z - qq) Q (BigInteger.Pow (p, n), BigInteger.Pow (q, n))
| Q q ,Z zz -> Q (q - BigRationalLarge.of_bigint zz)
//
static member ( / )(n1,n2) = let equal (Q (ap, aq)) (Q (bp, bq)) =
match n1,n2 with // normal form, so structural equality
| Z z ,Z zz -> Q (BigRationalLarge.RationalZ(z,zz)) ap = bp && aq = bq
| Q q ,Q qq -> Q (q / qq)
| Z z ,Q qq -> Q (BigRationalLarge.of_bigint z / qq) //
| Q q ,Z zz -> Q (q / BigRationalLarge.of_bigint zz) let lt a b =
BigRationalLarge.LessThan (a, b)
static member ( ~- )(n1) =
match n1 with //
| Z z -> Z (-z) let gt a b =
| Q q -> Q (-q) BigRationalLarge.LessThan (b, a)
static member ( ~+ )(n1:BigRational) = n1 //
let lte (Q(ap, aq)) (Q(bp, bq)) =
BigInteger.(<=) (ap * bq,bp * aq)
//
let gte (Q(ap, aq)) (Q(bp, bq)) =
BigInteger.(>=) (ap * bq, bp * aq)
//
let of_bigint z =
BigRationalLarge.RationalZ(z,OneI)
//
let of_int n =
BigRationalLarge.Rational(n,1)
// integer part
let integer (Q (p, q)) =
let mutable r = BigInteger(0)
// have p = d.q + r, |r| < |q|
let d = BigInteger.DivRem (p, q, &r)
if r < ZeroI then
// p = (d-1).q + (r+q)
d - OneI
else
// p = d.q + r
d
/// The type of arbitrary-sized rational numbers.
[<CustomEquality; CustomComparison>]
[<StructuredFormatDisplay("{StructuredDisplayString}N")>]
type BigRational =
private
//
| Z of BigInteger
//
| Q of BigRationalLarge
/// Return the numerator of the normalized rational number
member this.Numerator =
match this with
| Z z -> z
| Q q -> q.Numerator
/// Return the denominator of the normalized rational number
member this.Denominator =
match this with
| Z _ -> OneI
| Q q -> q.Denominator
/// Return a boolean indicating if this rational number is strictly negative
member this.IsNegative =
match this with
| Z z -> sign z < 0
| Q q -> q.IsNegative
/// Return a boolean indicating if this rational number is strictly positive
member this.IsPositive =
match this with
| Z z -> sign z > 0
| Q q -> q.IsPositive
/// Return the sign of a rational number; 0, +1 or -1
member this.Sign =
if this.IsNegative then -1
elif this.IsPositive then 1
else 0
override this.Equals (obj : obj) =
match obj with
| :? BigRational as other ->
BigRational.(=)(this, other)
| _ -> false
override this.GetHashCode () =
// nb. Q and Z hash codes must match up - see notes above // nb. Q and Z hash codes must match up - see notes above
override n.GetHashCode() = match this with
match n with | Z z -> z.GetHashCode ()
| Z z -> z.GetHashCode() | Q q -> q.GetHashCode ()
| Q q -> q.GetHashCode()
override this.ToString () =
override this.Equals(obj:obj) = match this with
| Z z ->
z.ToString()
| Q q ->
q.ToString()
member this.StructuredDisplayString =
this.ToString ()
/// Return the result of converting the string to a rational number
static member Parse (str : string) =
Q (BigRationalLarge.Parse str)
interface System.IComparable with
member this.CompareTo (obj : obj) =
match obj with match obj with
| :? BigRational as that -> BigRational.(=)(this, that) | :? BigRational as other ->
| _ -> false if BigRational.(<)(this, other) then -1
elif BigRational.(=)(this, other) then 0
interface System.IComparable with else 1
member n1.CompareTo(obj:obj) = | _ ->
match obj with invalidArg "obj" "The objects are not comparable."
| :? BigRational as n2 ->
if BigRational.(<)(n1, n2) then -1 elif BigRational.(=)(n1, n2) then 0 else 1 /// Return the result of converting the given integer to a rational number
| _ -> invalidArg "obj" "the objects are not comparable" static member FromInt (x : int) =
Z (bigint x)
static member FromInt (x:int) = Z (bigint x)
static member FromBigInt x = Z x /// Return the result of converting the given big integer to a rational number
static member FromBigInt x = Z x
static member Zero = BigRational.FromInt(0)
static member One = BigRational.FromInt(1) /// Get zero as a rational number
static member Zero =
BigRational.FromInt 0
static member PowN (n,i:int) =
match n with /// Get one as a rational number
| Z z -> Z (BigInteger.Pow (z,i)) static member One =
| Q q -> Q (BigRationalLarge.pown q i) BigRational.FromInt 1
static member op_Equality (n,nn) = /// Return the sum of two rational numbers
match n,nn with static member ( + ) (n1, n2) =
| Z z ,Z zz -> BigInteger.(=) (z,zz) match n1, n2 with
| Q q ,Q qq -> (BigRationalLarge.equal q qq) | Z z, Z zz ->
| Z z ,Q qq -> (BigRationalLarge.equal (BigRationalLarge.of_bigint z) qq) Z (z + zz)
| Q q ,Z zz -> (BigRationalLarge.equal q (BigRationalLarge.of_bigint zz)) | Q q, Q qq ->
static member op_Inequality (n,nn) = not (BigRational.op_Equality(n,nn)) Q (q + qq)
| Z z, Q qq ->
static member op_LessThan (n,nn) = Q (BigRationalLarge.of_bigint z + qq)
match n,nn with | Q q, Z zz ->
| Z z ,Z zz -> BigInteger.(<) (z,zz) Q (q + BigRationalLarge.of_bigint zz)
| Q q ,Q qq -> (BigRationalLarge.lt q qq)
| Z z ,Q qq -> (BigRationalLarge.lt (BigRationalLarge.of_bigint z) qq) /// Return the difference of two rational numbers
| Q q ,Z zz -> (BigRationalLarge.lt q (BigRationalLarge.of_bigint zz)) static member ( - ) (n1, n2) =
static member op_GreaterThan (n,nn) = match n1, n2 with
match n,nn with | Z z, Z zz ->
| Z z ,Z zz -> BigInteger.(>) (z,zz) Z (z - zz)
| Q q ,Q qq -> (BigRationalLarge.gt q qq) | Q q, Q qq ->
| Z z ,Q qq -> (BigRationalLarge.gt (BigRationalLarge.of_bigint z) qq) Q (q - qq)
| Q q ,Z zz -> (BigRationalLarge.gt q (BigRationalLarge.of_bigint zz)) | Z z, Q qq ->
static member op_LessThanOrEqual (n,nn) = Q (BigRationalLarge.of_bigint z - qq)
match n,nn with | Q q, Z zz ->
| Z z ,Z zz -> BigInteger.(<=) (z,zz) Q (q - BigRationalLarge.of_bigint zz)
| Q q ,Q qq -> (BigRationalLarge.lte q qq)
| Z z ,Q qq -> (BigRationalLarge.lte (BigRationalLarge.of_bigint z) qq) /// Return the product of two rational numbers
| Q q ,Z zz -> (BigRationalLarge.lte q (BigRationalLarge.of_bigint zz)) static member ( * ) (n1, n2) =
static member op_GreaterThanOrEqual (n,nn) = match n1,n2 with
match n,nn with | Z z, Z zz ->
| Z z ,Z zz -> BigInteger.(>=) (z,zz) Z (z * zz)
| Q q ,Q qq -> (BigRationalLarge.gte q qq) | Q q, Q qq ->
| Z z ,Q qq -> (BigRationalLarge.gte (BigRationalLarge.of_bigint z) qq) Q (q * qq)
| Q q ,Z zz -> (BigRationalLarge.gte q (BigRationalLarge.of_bigint zz)) | Z z, Q qq ->
Q (BigRationalLarge.of_bigint z * qq)
| Q q, Z zz ->
member n.IsNegative = Q (q * BigRationalLarge.of_bigint zz)
match n with
| Z z -> sign z < 0 /// Return the ratio of two rational numbers
| Q q -> q.IsNegative static member ( / ) (n1, n2) =
match n1, n2 with
member n.IsPositive = | Z z, Z zz ->
match n with Q (BigRationalLarge.RationalZ(z,zz))
| Z z -> sign z > 0 | Q q, Q qq ->
| Q q -> q.IsPositive Q (q / qq)
| Z z, Q qq ->
member n.Numerator = Q (BigRationalLarge.of_bigint z / qq)
match n with | Q q, Z zz ->
| Z z -> z Q (q / BigRationalLarge.of_bigint zz)
| Q q -> q.Numerator
/// Return the negation of a rational number
member n.Denominator = static member ( ~- ) n =
match n with match n with
| Z _ -> OneI | Z z -> Z (-z)
| Q q -> q.Denominator | Q q -> Q (-q)
member n.Sign = /// Return the given rational number
if n.IsNegative then -1 static member ( ~+ ) (n : BigRational) = n
elif n.IsPositive then 1
else 0 /// This operator is for use from other .NET languages
static member op_Equality (n, nn) =
static member Abs(n:BigRational) = match n,nn with
if n.IsNegative then -n else n | Z z, Z zz ->
BigInteger.(=) (z,zz)
static member ToDouble(n:BigRational) = | Q q, Q qq ->
match n with (BigRationalLarge.equal q qq)
| Z z -> ToDoubleI z | Z z, Q qq ->
| Q q -> BigRationalLarge.ToDouble q (BigRationalLarge.equal (BigRationalLarge.of_bigint z) qq)
| Q q, Z zz ->
static member ToBigInt(n:BigRational) = (BigRationalLarge.equal q (BigRationalLarge.of_bigint zz))
match n with
| Z z -> z /// This operator is for use from other .NET languages
| Q q -> BigRationalLarge.integer q static member op_Inequality (n, nn) =
not <| BigRational.op_Equality (n, nn)
static member ToInt32(n:BigRational) =
match n with /// This operator is for use from other .NET languages
| Z z -> ToInt32I(z) static member op_LessThan (n, nn) =
| Q q -> ToInt32I(BigRationalLarge.integer q) match n, nn with
| Z z, Z zz ->
static member op_Explicit (n:BigRational) = BigRational.ToInt32 n BigInteger.(<) (z,zz)
static member op_Explicit (n:BigRational) = BigRational.ToDouble n | Q q, Q qq ->
static member op_Explicit (n:BigRational) = BigRational.ToBigInt n (BigRationalLarge.lt q qq)
| Z z, Q qq ->
(BigRationalLarge.lt (BigRationalLarge.of_bigint z) qq)
override n.ToString() = | Q q, Z zz ->
match n with (BigRationalLarge.lt q (BigRationalLarge.of_bigint zz))
| Z z -> z.ToString()
| Q q -> q.ToString() /// This operator is for use from other .NET languages
static member op_LessThanOrEqual (n, nn) =
member x.StructuredDisplayString = x.ToString() match n, nn with
| Z z, Z zz ->
static member Parse(s:string) = Q (BigRationalLarge.Parse s) BigInteger.(<=) (z,zz)
| Q q, Q qq ->
type BigNum = BigRational (BigRationalLarge.lte q qq)
type bignum = BigNum | Z z, Q qq ->
(BigRationalLarge.lte (BigRationalLarge.of_bigint z) qq)
module NumericLiteralN = | Q q, Z zz ->
let FromZero () = BigRational.Zero (BigRationalLarge.lte q (BigRationalLarge.of_bigint zz))
let FromOne () = BigRational.One
let FromInt32 i = BigRational.FromInt i /// This operator is for use from other .NET languages
let FromInt64 (i64:int64) = BigRational.FromBigInt (new BigInteger(i64)) static member op_GreaterThan (n, nn) =
let FromString s = BigRational.Parse s match n, nn with
| Z z, Z zz ->
BigInteger.(>) (z,zz)
| Q q, Q qq ->
(BigRationalLarge.gt q qq)
| Z z, Q qq ->
(BigRationalLarge.gt (BigRationalLarge.of_bigint z) qq)
| Q q, Z zz ->
(BigRationalLarge.gt q (BigRationalLarge.of_bigint zz))
/// This operator is for use from other .NET languages
static member op_GreaterThanOrEqual (n, nn) =
match n, nn with
| Z z, Z zz ->
BigInteger.(>=) (z,zz)
| Q q, Q qq ->
(BigRationalLarge.gte q qq)
| Z z, Q qq ->
(BigRationalLarge.gte (BigRationalLarge.of_bigint z) qq)
| Q q, Z zz ->
(BigRationalLarge.gte q (BigRationalLarge.of_bigint zz))
/// Return the absolute value of a rational number
static member Abs (n : BigRational) =
if n.IsNegative then -n else n
/// Return the result of raising the given rational number to the given power
static member PowN (n, i : int) =
match n with
| Z z ->
Z (BigInteger.Pow (z, i))
| Q q ->
Q (BigRationalLarge.pown q i)
/// Return the result of converting the given rational number to a floating point number
static member ToDouble (n : BigRational) =
match n with
| Z z ->
ToDoubleI z
| Q q ->
BigRationalLarge.ToDouble q
/// Return the result of converting the given rational number to a big integer
static member ToBigInt (n : BigRational) =
match n with
| Z z -> z
| Q q ->
BigRationalLarge.integer q
/// Return the result of converting the given rational number to an integer
static member ToInt32 (n : BigRational) =
match n with
| Z z ->
ToInt32I z
| Q q ->
ToInt32I (BigRationalLarge.integer q)
/// Return the result of converting the given rational number to an integer
static member op_Explicit (n : BigRational) =
BigRational.ToInt32 n
/// Return the result of converting the given rational number to a big integer
static member op_Explicit (n : BigRational) =
BigRational.ToBigInt n
/// Return the result of converting the given rational number to a floating point number
static member op_Explicit (n : BigRational) =
BigRational.ToDouble n
//
[<RequireQualifiedAccess>]
module NumericLiteralN =
let private zero = BigRational.Zero
let private one = BigRational.One
//
let FromZero () = zero
//
let FromOne () = one
//
let FromInt32 x =
BigRational.FromInt x
//
let FromInt64 (x : int64) =
BigInteger (x)
|> BigRational.FromBigInt
//
let FromString str =
BigRational.Parse str
//
type BigNum = BigRational
//
type bignum = BigRational
#endif #endif

151
src/FSharp/BigRational.fsi

@ -2,98 +2,73 @@
// https://raw.github.com/fsharp/powerpack/master/src/FSharp.PowerPack/math/q.fsi // https://raw.github.com/fsharp/powerpack/master/src/FSharp.PowerPack/math/q.fsi
// (c) Microsoft Corporation 2005-2009. // (c) Microsoft Corporation 2005-2009.
(* NOTE : This signature file is necessary now _only_ to hide the case constructors for the BigRational type. *)
namespace MathNet.Numerics namespace MathNet.Numerics
#if NOSYSNUMERICS #if NOSYSNUMERICS
#else #else
open System open System
open System.Numerics open System.Numerics
/// The type of arbitrary-sized rational numbers [<Sealed>]
[<Sealed>] type BigRational =
type BigRational = interface System.IComparable
/// Return the sum of two rational numbers
static member ( + ) : BigRational * BigRational -> BigRational override ToString : unit -> string
/// Return the product of two rational numbers override GetHashCode : unit -> int
static member ( * ) : BigRational * BigRational -> BigRational
/// Return the difference of two rational numbers member IsNegative: bool
static member ( - ) : BigRational * BigRational -> BigRational member IsPositive: bool
/// Return the ratio of two rational numbers
static member ( / ) : BigRational * BigRational -> BigRational member Numerator : BigInteger
/// Return the negation of a rational number member Denominator : BigInteger
static member ( ~- ): BigRational -> BigRational
/// Return the given rational number member Sign : int
static member ( ~+ ): BigRational -> BigRational member StructuredDisplayString : string
override ToString: unit -> string static member Zero : BigRational
override GetHashCode: unit -> int static member One : BigRational
interface System.IComparable
static member ( + ) : BigRational * BigRational -> BigRational
/// Get zero as a rational number static member ( * ) : BigRational * BigRational -> BigRational
static member Zero : BigRational static member ( - ) : BigRational * BigRational -> BigRational
/// Get one as a rational number static member ( / ) : BigRational * BigRational -> BigRational
static member One : BigRational static member ( ~- ): BigRational -> BigRational
/// This operator is for use from other .NET languages static member ( ~+ ): BigRational -> BigRational
static member op_Equality : BigRational * BigRational -> bool
/// This operator is for use from other .NET languages static member op_Equality : BigRational * BigRational -> bool
static member op_Inequality : BigRational * BigRational -> bool static member op_Inequality : BigRational * BigRational -> bool
/// This operator is for use from other .NET languages static member op_LessThan: BigRational * BigRational -> bool
static member op_LessThan: BigRational * BigRational -> bool static member op_LessThanOrEqual: BigRational * BigRational -> bool
/// This operator is for use from other .NET languages static member op_GreaterThan: BigRational * BigRational -> bool
static member op_GreaterThan: BigRational * BigRational -> bool static member op_GreaterThanOrEqual: BigRational * BigRational -> bool
/// This operator is for use from other .NET languages
static member op_LessThanOrEqual: BigRational * BigRational -> bool static member op_Explicit : BigRational -> BigInteger
/// This operator is for use from other .NET languages static member op_Explicit : BigRational -> int
static member op_GreaterThanOrEqual: BigRational * BigRational -> bool static member op_Explicit : BigRational -> float
/// Return a boolean indicating if this rational number is strictly negative static member Abs : BigRational -> BigRational
member IsNegative: bool static member PowN : BigRational * int -> BigRational
/// Return a boolean indicating if this rational number is strictly positive static member Parse: string -> BigRational
member IsPositive: bool
static member FromInt : int -> BigRational
/// Return the numerator of the normalized rational number static member FromBigInt : BigInteger -> BigRational
member Numerator: BigInteger
/// Return the denominator of the normalized rational number static member ToDouble: BigRational -> float
member Denominator: BigInteger static member ToBigInt: BigRational -> BigInteger
static member ToInt32 : BigRational -> int
member StructuredDisplayString : string
[<RequireQualifiedAccess>]
/// Return the absolute value of a rational number module NumericLiteralN =
static member Abs : BigRational -> BigRational val FromZero : unit -> BigRational
/// Return the sign of a rational number; 0, +1 or -1 val FromOne : unit -> BigRational
member Sign : int val FromInt32 : int32 -> BigRational
/// Return the result of raising the given rational number to the given power val FromInt64 : int64 -> BigRational
static member PowN : BigRational * int -> BigRational val FromString : string -> BigRational
/// Return the result of converting the given integer to a rational number
static member FromInt : int -> BigRational type BigNum = BigRational
/// Return the result of converting the given big integer to a rational number type bignum = BigRational
static member FromBigInt : BigInteger -> BigRational
/// Return the result of converting the given rational number to a floating point number
static member ToDouble: BigRational -> float
/// Return the result of converting the given rational number to a big integer
static member ToBigInt: BigRational -> BigInteger
/// Return the result of converting the given rational number to an integer
static member ToInt32 : BigRational -> int
/// Return the result of converting the given rational number to a floating point number
static member op_Explicit : BigRational -> float
/// Return the result of converting the given rational number to a big integer
static member op_Explicit : BigRational -> BigInteger
/// Return the result of converting the given rational number to an integer
static member op_Explicit : BigRational -> int
/// Return the result of converting the string to a rational number
static member Parse: string -> BigRational
type BigNum = BigRational
type bignum = BigRational
[<RequireQualifiedAccess>]
module NumericLiteralN =
val FromZero : unit -> BigRational
val FromOne : unit -> BigRational
val FromInt32 : int32 -> BigRational
val FromInt64 : int64 -> BigRational
val FromString : string -> BigRational
#endif #endif

567
src/FSharp/Complex.fs

@ -4,169 +4,414 @@
namespace MathNet.Numerics namespace MathNet.Numerics
open Microsoft.FSharp.Math open Microsoft.FSharp.Math
open System open System
open System.Globalization open System.Globalization
#if NOSYSNUMERICS #if NOSYSNUMERICS
#else #else
open System.Numerics open System.Numerics
#endif #endif
type complex = Complex //
type complex32 = Complex32 type complex = Complex
//
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] type complex32 = Complex32
[<RequireQualifiedAccess>]
module Complex = //
[<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
let mkRect(a,b) = new Complex(a,b) module Complex =
let mkPolar(a,b) = Complex.FromPolarCoordinates(a,b) /// Create a complex number using real and imaginary parts
let cis b = mkPolar(1.0,b) let mkRect(a,b) = Complex(a,b)
let ofComplex32 (x:complex32) = new Complex(float x.Real, float x.Imaginary)
/// Create a complex number using magnitude/phase polar coordinates
let zero = Complex.Zero let mkPolar(a,b) = Complex.FromPolarCoordinates(a,b)
let one = Complex.One
let onei = Complex.ImaginaryOne /// A complex of magnitude 1 and the given phase and , i.e. cis x = mkPolar 1.0 x
let pi = mkRect (Math.PI,0.0) let cis b = mkPolar(1.0,b)
let realPart (c:complex) = c.Real //
let imagPart (c:complex) = c.Imaginary let private ofComplex32 (x : complex32) =
let magnitude (c:complex) = c.Magnitude Complex(float x.Real, float x.Imaginary)
let phase (c:complex) = c.Phase
/// The complex number 0+0i
let neg (a:complex) = -a let zero = Complex.Zero
let conjugate (c:complex) = c.Conjugate()
/// The complex number 1+0i
let add (a:complex) (b:complex) = a + b let one = Complex.One
let sub (a:complex) (b:complex) = a - b
let mul (a:complex) (b:complex) = a * b /// The complex number 0+1i
let div (x:complex) (y:complex) = x / y let onei = Complex.ImaginaryOne
let smul (a:float) (b:complex) = new Complex(a * b.Real, a * b.Imaginary) /// pi
let muls (a:complex) (b:float) = new Complex(a.Real * b, a.Imaginary * b) let pi = mkRect (Math.PI,0.0)
let exp (x:complex) = Complex.Exp(x)
let ln x = Complex.Log(x) /// The real part of a complex number
let log10 x = Complex.Log10(x) let realPart (c:complex) = c.Real
let log b x = Complex.Log(x,b)
let pow (power:complex) x = Complex.Pow(x,power) /// The imaginary part of a complex number
let powf (power:float) x = Complex.Pow(x,power) let imagPart (c:complex) = c.Imaginary
let sqr (x:complex) = x.Square()
let sqrt (x:complex) = x.SquareRoot() // numerically more stable than Complex.Sqrt /// The polar-coordinate magnitude of a complex number
let magnitude (c:complex) = c.Magnitude
let sin x = Complex.Sin(x)
let cos x = Complex.Cos(x) /// The polar-coordinate phase of a complex number
let tan x = Complex.Tan(x) let phase (c:complex) = c.Phase
let cot (x:complex) = Trig.Cot(x)
let sec (x:complex) = Trig.Sec(x)
let csc (x:complex) = Trig.Csc(x) /// Unary negation of a complex number
let neg (a:complex) = -a
let asin (x:complex) = Trig.Asin(x) // numerically more stable than Complex.Asin
let acos (x:complex) = Trig.Acos(x) // numerically more stable than Complex.Acos /// The conjugate of a complex number, i.e. x-yi
let atan x = Complex.Atan(x) let conjugate (c:complex) = c.Conjugate()
let acot (x:complex) = Trig.Acot(x)
let asec (x:complex) = Trig.Asec(x)
let acsc (x:complex) = Trig.Acsc(x) /// Add two complex numbers
let add (a:complex) (b:complex) = a + b
let sinh x = Complex.Sinh(x)
let cosh x = Complex.Cosh(x) /// Subtract one complex number from another
let tanh x = Complex.Tanh(x) let sub (a:complex) (b:complex) = a - b
let coth (x:complex) = Trig.Coth(x)
let sech (x:complex) = Trig.Sech(x) /// Multiply two complex numbers
let csch (x:complex) = Trig.Csch(x) let mul (a:complex) (b:complex) = a * b
let asinh (x:complex) = Trig.Asinh(x) /// Complex division of two complex numbers
let acosh (x:complex) = Trig.Acosh(x) let div (x:complex) (y:complex) = x / y
let atanh (x:complex) = Trig.Atanh(x)
let acoth (x:complex) = Trig.Acoth(x)
let asech (x:complex) = Trig.Asech(x) /// Multiply a scalar by a complex number
let acsch (x:complex) = Trig.Acsch(x) let smul (a:float) (b:complex) = new Complex(a * b.Real, a * b.Imaginary)
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] /// Multiply a complex number by a scalar
[<RequireQualifiedAccess>] let muls (a:complex) (b:float) = new Complex(a.Real * b, a.Imaginary * b)
module Complex32 =
let mkRect(a,b) = new Complex32(a,b) /// exp(x) = e^x
let mkPolar(a,b) = Complex32.FromPolarCoordinates(a,b) let exp (x:complex) = Complex.Exp(x)
let cis b = mkPolar(1.0f,b)
let ofComplex (x:complex) = new Complex32(float32 x.Real, float32 x.Imaginary) /// ln(x) is natural log (base e)
let ln x = Complex.Log(x)
let zero = Complex32.Zero
let one = Complex32.One /// log10(x) is common log (base 10)
let onei = Complex32.ImaginaryOne let log10 x = Complex.Log10(x)
let pi = mkRect (float32 Math.PI,0.0f)
/// log(base,x) is log with custom base
let realPart (c:complex32) = c.Real let log b x = Complex.Log(x,b)
let imagPart (c:complex32) = c.Imaginary
let magnitude (c:complex32) = c.Magnitude /// pow(power,x) is the complex power
let phase (c:complex32) = c.Phase let pow (power : complex) x = Complex.Pow(x,power)
let neg (a:complex32) = -a /// pow(power,x) is the scalar power
let conjugate (c:complex32) = c.Conjugate() let powf (power : float) x = Complex.Pow(x,power)
let add (a:complex32) (b:complex32) = a + b /// sqr(x) is the square (power 2)
let sub (a:complex32) (b:complex32) = a - b let sqr (x : complex) = x.Square()
let mul (a:complex32) (b:complex32) = a * b
let div (x:complex32) (y:complex32) = x / y /// sqrt(x) and 0 <= phase(x) < pi
let sqrt (x : complex) = x.SquareRoot() // numerically more stable than Complex.Sqrt
let smul (a:float32) (b:complex32) = new Complex32(a * b.Real, a * b.Imaginary)
let muls (a:complex32) (b:float32) = new Complex32(a.Real * b, a.Imaginary * b)
/// Sine
let exp (x:complex32) = Complex32.Exp(x) let sin x = Complex.Sin(x)
let ln x = Complex32.Log(x)
let log10 x = Complex32.Log10(x) /// Cosine
let log b x = Complex32.Log(x,b) let cos x = Complex.Cos(x)
let pow (power:complex32) x = Complex32.Pow(x,power)
let powf (power:float32) x = Complex32.Pow(x,power) /// Tagent
let sqr (x:complex32) = x.Square() let tan x = Complex.Tan(x)
let sqrt (x:complex32) = x.SquareRoot() // numerically more stable than Complex.Sqrt
/// Cotangent
// no complex32 implementations available yet for some, fix once available let cot (x : complex) = Trig.Cot(x)
let sin x = Complex32.Sin(x)
let cos x = Complex32.Cos(x) /// Secant
let tan x = Complex32.Tan(x) let sec (x : complex) = Trig.Sec(x)
let cot (x:complex32) = ofComplex <| Trig.Cot(x.ToComplex())
let sec (x:complex32) = ofComplex <| Trig.Sec(x.ToComplex()) /// Cosecant
let csc (x:complex32) = ofComplex <| Trig.Csc(x.ToComplex()) let csc (x : complex) = Trig.Csc(x)
let asin (x:complex32) = ofComplex <| Trig.Asin(x.ToComplex()) // numerically more stable than Complex.Asin
let acos (x:complex32) = ofComplex <| Trig.Acos(x.ToComplex()) // numerically more stable than Complex.Acos /// Arc Sine
let atan x = Complex32.Atan(x) let asin (x : complex) =
let acot (x:complex32) = ofComplex <| Trig.Acot(x.ToComplex()) // numerically more stable than Complex.Asin
let asec (x:complex32) = ofComplex <| Trig.Asec(x.ToComplex()) Trig.Asin(x)
let acsc (x:complex32) = ofComplex <| Trig.Acsc(x.ToComplex())
/// Arc Cosine
let sinh x = Complex32.Sinh(x) let acos (x : complex) =
let cosh x = Complex32.Cosh(x) // numerically more stable than Complex.Acos
let tanh x = Complex32.Tanh(x) Trig.Acos(x)
let coth (x:complex32) = ofComplex <| Trig.Coth(x.ToComplex())
let sech (x:complex32) = ofComplex <| Trig.Sech(x.ToComplex()) /// Arc Tagent
let csch (x:complex32) = ofComplex <| Trig.Csch(x.ToComplex()) let atan x = Complex.Atan(x)
let asinh (x:complex32) = ofComplex <| Trig.Asinh(x.ToComplex()) /// Arc Cotangent
let acosh (x:complex32) = ofComplex <| Trig.Acosh(x.ToComplex()) let acot (x : complex) = Trig.Acot(x)
let atanh (x:complex32) = ofComplex <| Trig.Atanh(x.ToComplex())
let acoth (x:complex32) = ofComplex <| Trig.Acoth(x.ToComplex()) /// Arc Secant
let asech (x:complex32) = ofComplex <| Trig.Asech(x.ToComplex()) let asec (x : complex) = Trig.Asec(x)
let acsch (x:complex32) = ofComplex <| Trig.Acsch(x.ToComplex())
/// Arc Cosecant
[<AutoOpen>] let acsc (x : complex) = Trig.Acsc(x)
module ComplexExtensions =
let complex x y = Complex.mkRect (x,y) /// Hyperbolic Sine
let complex32 x y = Complex32.mkRect (x,y) let sinh x = Complex.Sinh(x)
type Complex with /// Hyperbolic Cosine
member x.r = x.Real let cosh x = Complex.Cosh(x)
member x.i = x.Imaginary
/// Hyperbolic Tagent
static member Create(a,b) = Complex.mkRect (a,b) let tanh x = Complex.Tanh(x)
static member CreatePolar(a,b) = Complex.mkPolar (a,b)
/// Hyperbolic Cotangent
type Complex32 with let coth (x : complex) = Trig.Coth(x)
member x.r = x.Real
member x.i = x.Imaginary /// Hyperbolic Secant
let sech (x : complex) = Trig.Sech(x)
static member Create(a,b) = Complex32.mkRect (a,b)
static member CreatePolar(a,b) = Complex32.mkPolar (a,b) /// Hyperbolic Cosecant
let csch (x : complex) = Trig.Csch(x)
/// Inverse Hyperbolic Sine
let asinh (x : complex) = Trig.Asinh(x)
/// Inverse Hyperbolic Cosine
let acosh (x : complex) = Trig.Acosh(x)
/// Inverse Hyperbolic Tagent
let atanh (x : complex) = Trig.Atanh(x)
/// Inverse Hyperbolic Cotangent
let acoth (x : complex) = Trig.Acoth(x)
/// Inverse Hyperbolic Secant
let asech (x : complex) = Trig.Asech(x)
/// Inverse Hyperbolic Cosecant
let acsch (x : complex) = Trig.Acsch(x)
//
[<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Complex32 =
/// Create a complex number using real and imaginary parts
let mkRect(a,b) = new Complex32(a,b)
/// Create a complex number using magnitude/phase polar coordinates
let mkPolar(a,b) = Complex32.FromPolarCoordinates(a,b)
/// A complex of magnitude 1 and the given phase and , i.e. cis x = mkPolar 1.0 x
let cis b = mkPolar(1.0f,b)
//
let private ofComplex (x : complex) =
Complex32 (float32 x.Real, float32 x.Imaginary)
/// The complex number 0+0i
let zero = Complex32.Zero
/// The complex number 1+0i
let one = Complex32.One
/// The complex number 0+1i
let onei = Complex32.ImaginaryOne
/// pi
let pi = mkRect (float32 Math.PI,0.0f)
/// The real part of a complex number
let realPart (c:complex32) = c.Real
/// The imaginary part of a complex number
let imagPart (c:complex32) = c.Imaginary
/// The polar-coordinate magnitude of a complex number
let magnitude (c:complex32) = c.Magnitude
/// The polar-coordinate phase of a complex number
let phase (c:complex32) = c.Phase
/// Unary negation of a complex number
let neg (a:complex32) = -a
/// The conjugate of a complex number, i.e. x-yi
let conjugate (c:complex32) = c.Conjugate()
/// Add two complex numbers
let add (a:complex32) (b:complex32) = a + b
/// Subtract one complex number from another
let sub (a:complex32) (b:complex32) = a - b
/// Multiply two complex numbers
let mul (a:complex32) (b:complex32) = a * b
/// Complex division of two complex numbers
let div (x:complex32) (y:complex32) = x / y
/// Multiply a scalar by a complex number
let smul (a:float32) (b:complex32) =
Complex32(a * b.Real, a * b.Imaginary)
/// Multiply a complex number by a scalar
let muls (a:complex32) (b:float32) =
Complex32(a.Real * b, a.Imaginary * b)
/// exp(x) = e^x
let exp (x:complex32) = Complex32.Exp(x)
/// ln(x) is natural log (base e)
let ln x = Complex32.Log(x)
/// log10(x) is common log (base 10)
let log10 x = Complex32.Log10(x)
/// log(base,x) is log with custom base
let log b x = Complex32.Log(x,b)
/// pow(power,x) is the complex power
let pow (power:complex32) x = Complex32.Pow(x,power)
/// pow(power,x) is the scalar power
let powf (power:float32) x = Complex32.Pow(x,power)
/// sqr(x) is the square (power 2)
let sqr (x:complex32) = x.Square()
/// sqrt(x) and 0 <= phase(x) < pi
let sqrt (x:complex32) =
// numerically more stable than Complex.Sqrt
x.SquareRoot()
(* Complex32 implementations are not yet available for some of the functions below.
TODO : Fix the functions below to use the Complex32 implementations once available. *)
/// Sine
let sin x = Complex32.Sin(x)
/// Cosine
let cos x = Complex32.Cos(x)
/// Tagent
let tan x = Complex32.Tan(x)
/// Cotangent
let cot (x:complex32) = ofComplex <| Trig.Cot(x.ToComplex())
/// Secant
let sec (x:complex32) = ofComplex <| Trig.Sec(x.ToComplex())
/// Cosecant
let csc (x:complex32) = ofComplex <| Trig.Csc(x.ToComplex())
/// Arc Sine
let asin (x:complex32) =
// numerically more stable than Complex.Asin
ofComplex <| Trig.Asin(x.ToComplex())
/// Arc Cosine
let acos (x:complex32) =
// numerically more stable than Complex.Acos
ofComplex <| Trig.Acos(x.ToComplex())
/// Arc Tagent
let atan x = Complex32.Atan(x)
/// Arc Cotangent
let acot (x:complex32) = ofComplex <| Trig.Acot(x.ToComplex())
/// Arc Secant
let asec (x:complex32) = ofComplex <| Trig.Asec(x.ToComplex())
/// Arc Cosecant
let acsc (x:complex32) = ofComplex <| Trig.Acsc(x.ToComplex())
/// Hyperbolic Sine
let sinh x = Complex32.Sinh(x)
/// Hyperbolic Cosine
let cosh x = Complex32.Cosh(x)
/// Hyperbolic Tagent
let tanh x = Complex32.Tanh(x)
/// Hyperbolic Cotangent
let coth (x:complex32) = ofComplex <| Trig.Coth(x.ToComplex())
/// Hyperbolic Secant
let sech (x:complex32) = ofComplex <| Trig.Sech(x.ToComplex())
/// Hyperbolic Cosecant
let csch (x:complex32) = ofComplex <| Trig.Csch(x.ToComplex())
/// Inverse Hyperbolic Sine
let asinh (x:complex32) = ofComplex <| Trig.Asinh(x.ToComplex())
/// Inverse Hyperbolic Cosine
let acosh (x:complex32) = ofComplex <| Trig.Acosh(x.ToComplex())
/// Inverse Hyperbolic Tagent
let atanh (x:complex32) = ofComplex <| Trig.Atanh(x.ToComplex())
/// Inverse Hyperbolic Cotangent
let acoth (x:complex32) = ofComplex <| Trig.Acoth(x.ToComplex())
/// Inverse Hyperbolic Secant
let asech (x:complex32) = ofComplex <| Trig.Asech(x.ToComplex())
/// Inverse Hyperbolic Cosecant
let acsch (x:complex32) = ofComplex <| Trig.Acsch(x.ToComplex())
//
[<AutoOpen>]
module ComplexExtensions =
/// Constructs a double precision complex number from both the real and imaginary part.
let complex x y =
Complex.mkRect (x,y)
/// Constructs a single precision complex number from both the real and imaginary part.
let complex32 x y =
Complex32.mkRect (x,y)
// The type of complex numbers stored as pairs of 64-bit floating point numbers in rectangular coordinates
type Complex with
/// The real part of a complex number
member x.r = x.Real
/// The imaginary part of a complex number
member x.i = x.Imaginary
/// Create a complex number x+ij using rectangular coordinates
static member Create(a,b) =
Complex.mkRect (a,b)
/// Create a complex number using magnitude/phase polar coordinates
static member CreatePolar(a,b) =
Complex.mkPolar (a,b)
/// The type of complex numbers stored as pairs of 32-bit floating point numbers in rectangular coordinates
type Complex32 with
/// The real part of a complex number
member x.r = x.Real
/// The imaginary part of a complex number
member x.i = x.Imaginary
/// Create a complex number x+ij using rectangular coordinates
static member Create(a,b) =
Complex32.mkRect (a,b)
/// Create a complex number using magnitude/phase polar coordinates
static member CreatePolar(a,b) =
Complex32.mkPolar (a,b)

286
src/FSharp/Complex.fsi

@ -1,286 +0,0 @@
// First version copied from the F# Power Pack
// https://raw.github.com/fsharp/powerpack/master/src/FSharp.PowerPack/math/complex.fsi
// (c) Microsoft Corporation 2005-2009.
namespace MathNet.Numerics
open System
#if NOSYSNUMERICS
#else
open System.Numerics
#endif
/// The type of complex numbers
type complex = Complex
type complex32 = Complex32
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module Complex =
/// Create a complex number using real and imaginary parts
val mkRect : float * float -> complex
/// Create a complex number using magnitude/phase polar coordinates
val mkPolar : float * float -> complex
/// A complex of magnitude 1 and the given phase and , i.e. cis x = mkPolar 1.0 x
val cis : float -> complex
/// The complex number 0+0i
val zero : complex
/// The complex number 1+0i
val one : complex
/// The complex number 0+1i
val onei : complex
/// pi
val pi : complex
/// The real part of a complex number
val realPart : complex -> float
/// The imaginary part of a complex number
val imagPart : complex -> float
/// The polar-coordinate magnitude of a complex number
val magnitude : complex -> float
/// The polar-coordinate phase of a complex number
val phase : complex -> float
/// Unary negation of a complex number
val neg : complex -> complex
/// The conjugate of a complex number, i.e. x-yi
val conjugate : complex -> complex
/// Add two complex numbers
val add : complex -> complex -> complex
/// Subtract one complex number from another
val sub : complex -> complex -> complex
/// Multiply two complex numbers
val mul : complex -> complex -> complex
/// Complex division of two complex numbers
val div : complex -> complex -> complex
/// Multiply a scalar by a complex number
val smul : float -> complex -> complex
/// Multiply a complex number by a scalar
val muls : complex -> float -> complex
/// exp(x) = e^x
val exp : complex -> complex
/// ln(x) is natural log (base e)
val ln : complex -> complex
/// log10(x) is common log (base 10)
val log10 : complex -> complex
/// log(base,x) is log with custom base
val log : float -> complex -> complex
/// pow(power,x) is the complex power
val pow : complex -> complex -> complex
/// pow(power,x) is the float power
val powf : float -> complex -> complex
/// sqr(x) is the square (power 2)
val sqr : complex -> complex
/// sqrt(x) and 0 <= phase(x) < pi
val sqrt : complex -> complex
/// Sine
val sin : complex -> complex
/// Cosine
val cos : complex -> complex
/// Tagent
val tan : complex -> complex
/// Cotangent
val cot : complex -> complex
/// Secant
val sec : complex -> complex
/// Cosecant
val csc : complex -> complex
/// Arc Sine
val asin : complex -> complex
/// Arc Cosine
val acos : complex -> complex
/// Arc Tagent
val atan : complex -> complex
/// Arc Cotangent
val acot : complex -> complex
/// Arc Secant
val asec : complex -> complex
/// Arc Cosecant
val acsc : complex -> complex
/// Hyperbolic Sine
val sinh : complex -> complex
/// Hyperbolic Cosine
val cosh : complex -> complex
/// Hyperbolic Tagent
val tanh : complex -> complex
/// Hyperbolic Cotangent
val coth : complex -> complex
/// Hyperbolic Secant
val sech : complex -> complex
/// Hyperbolic Cosecant
val csch : complex -> complex
/// Inverse Hyperbolic Sine
val asinh : complex -> complex
/// Inverse Hyperbolic Cosine
val acosh : complex -> complex
/// Inverse Hyperbolic Tagent
val atanh : complex -> complex
/// Inverse Hyperbolic Cotangent
val acoth : complex -> complex
/// Inverse Hyperbolic Secant
val asech : complex -> complex
/// Inverse Hyperbolic Cosecant
val acsch : complex -> complex
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module Complex32 =
/// Create a complex number using real and imaginary parts
val mkRect : float32 * float32 -> complex32
/// Create a complex number using magnitude/phase polar coordinates
val mkPolar : float32 * float32 -> complex32
/// A complex of magnitude 1 and the given phase and , i.e. cis x = mkPolar 1.0 x
val cis : float32 -> complex32
/// The complex number 0+0i
val zero : complex32
/// The complex number 1+0i
val one : complex32
/// The complex number 0+1i
val onei : complex32
/// pi
val pi : complex32
/// The real part of a complex number
val realPart : complex32 -> float32
/// The imaginary part of a complex number
val imagPart : complex32 -> float32
/// The polar-coordinate magnitude of a complex number
val magnitude : complex32 -> float32
/// The polar-coordinate phase of a complex number
val phase : complex32 -> float32
/// Unary negation of a complex number
val neg : complex32 -> complex32
/// The conjugate of a complex number, i.e. x-yi
val conjugate : complex32 -> complex32
/// Add two complex numbers
val add : complex32 -> complex32 -> complex32
/// Subtract one complex number from another
val sub : complex32 -> complex32 -> complex32
/// Multiply two complex numbers
val mul : complex32 -> complex32 -> complex32
/// Complex division of two complex numbers
val div : complex32 -> complex32 -> complex32
/// Multiply a scalar by a complex number
val smul : float32 -> complex32 -> complex32
/// Multiply a complex number by a scalar
val muls : complex32 -> float32 -> complex32
/// exp(x) = e^x
val exp : complex32 -> complex32
/// ln(x) is natural log (base e)
val ln : complex32 -> complex32
/// log10(x) is common log (base 10)
val log10 : complex32 -> complex32
/// log(base,x) is log with custom base
val log : float32 -> complex32 -> complex32
/// pow(power,x) is the complex power
val pow : complex32 -> complex32 -> complex32
/// pow(power,x) is the float power
val powf : float32 -> complex32 -> complex32
/// sqr(x) is the square (power 2)
val sqr : complex32 -> complex32
/// sqrt(x) and 0 <= phase(x) < pi
val sqrt : complex32 -> complex32
/// Sine
val sin : complex32 -> complex32
/// Cosine
val cos : complex32 -> complex32
/// Tagent
val tan : complex32 -> complex32
/// Cotangent
val cot : complex32 -> complex32
/// Secant
val sec : complex32 -> complex32
/// Cosecant
val csc : complex32 -> complex32
/// Arc Sine
val asin : complex32 -> complex32
/// Arc Cosine
val acos : complex32 -> complex32
/// Arc Tagent
val atan : complex32 -> complex32
/// Arc Cotangent
val acot : complex32 -> complex32
/// Arc Secant
val asec : complex32 -> complex32
/// Arc Cosecant
val acsc : complex32 -> complex32
/// Hyperbolic Sine
val sinh : complex32 -> complex32
/// Hyperbolic Cosine
val cosh : complex32 -> complex32
/// Hyperbolic Tagent
val tanh : complex32 -> complex32
/// Hyperbolic Cotangent
val coth : complex32 -> complex32
/// Hyperbolic Secant
val sech : complex32 -> complex32
/// Hyperbolic Cosecant
val csch : complex32 -> complex32
/// Inverse Hyperbolic Sine
val asinh : complex32 -> complex32
/// Inverse Hyperbolic Cosine
val acosh : complex32 -> complex32
/// Inverse Hyperbolic Tagent
val atanh : complex32 -> complex32
/// Inverse Hyperbolic Cotangent
val acoth : complex32 -> complex32
/// Inverse Hyperbolic Secant
val asech : complex32 -> complex32
/// Inverse Hyperbolic Cosecant
val acsch : complex32 -> complex32
[<AutoOpen>]
module ComplexExtensions =
/// Constructs a double precision complex number from both the real and imaginary part.
val complex : float -> float -> complex
/// Constructs a single precision complex number from both the real and imaginary part.
val complex32 : float32 -> float32 -> complex32
/// The type of complex numbers stored as pairs of 64-bit floating point numbers in rectangular coordinates
type Complex with
/// Create a complex number x+ij using rectangular coordinates
static member Create : float * float -> Complex
/// Create a complex number using magnitude/phase polar coordinates
static member CreatePolar : float * float -> Complex
/// The real part of a complex number
member r: float
/// The imaginary part of a complex number
member i: float
/// The type of complex numbers stored as pairs of 32-bit floating point numbers in rectangular coordinates
type Complex32 with
/// Create a complex number x+ij using rectangular coordinates
static member Create : float32 * float32 -> Complex32
/// Create a complex number using magnitude/phase polar coordinates
static member CreatePolar : float32 * float32 -> Complex32
/// The real part of a complex number
member r: float32
/// The imaginary part of a complex number
member i: float32

1
src/FSharp/FSharp-Portable136.fsproj

@ -50,7 +50,6 @@
<Compile Include="Distributions.fs" /> <Compile Include="Distributions.fs" />
<Compile Include="LinearAlgebra.Vector.fs" /> <Compile Include="LinearAlgebra.Vector.fs" />
<Compile Include="LinearAlgebra.Matrix.fs" /> <Compile Include="LinearAlgebra.Matrix.fs" />
<Compile Include="Complex.fsi" />
<Compile Include="Complex.fs" /> <Compile Include="Complex.fs" />
<Compile Include="BigIntegerExtensions.fs" /> <Compile Include="BigIntegerExtensions.fs" />
<Compile Include="BigRational.fsi" /> <Compile Include="BigRational.fsi" />

1
src/FSharp/FSharp-Portable47.fsproj

@ -50,7 +50,6 @@
<Compile Include="Distributions.fs" /> <Compile Include="Distributions.fs" />
<Compile Include="LinearAlgebra.Vector.fs" /> <Compile Include="LinearAlgebra.Vector.fs" />
<Compile Include="LinearAlgebra.Matrix.fs" /> <Compile Include="LinearAlgebra.Matrix.fs" />
<Compile Include="Complex.fsi" />
<Compile Include="Complex.fs" /> <Compile Include="Complex.fs" />
<Compile Include="BigIntegerExtensions.fs" /> <Compile Include="BigIntegerExtensions.fs" />
<Compile Include="BigRational.fsi" /> <Compile Include="BigRational.fsi" />

1
src/FSharp/FSharp.fsproj

@ -63,7 +63,6 @@
<Compile Include="Distributions.fs" /> <Compile Include="Distributions.fs" />
<Compile Include="LinearAlgebra.Vector.fs" /> <Compile Include="LinearAlgebra.Vector.fs" />
<Compile Include="LinearAlgebra.Matrix.fs" /> <Compile Include="LinearAlgebra.Matrix.fs" />
<Compile Include="Complex.fsi" />
<Compile Include="Complex.fs" /> <Compile Include="Complex.fs" />
<Compile Include="BigIntegerExtensions.fs" /> <Compile Include="BigIntegerExtensions.fs" />
<Compile Include="BigRational.fsi" /> <Compile Include="BigRational.fsi" />

Loading…
Cancel
Save