diff --git a/src/FSharp/BigRational.fs b/src/FSharp/BigRational.fs index d711a4a1..1e8032c5 100644 --- a/src/FSharp/BigRational.fs +++ b/src/FSharp/BigRational.fs @@ -10,303 +10,490 @@ namespace MathNet.Numerics #if NOSYSNUMERICS #else - open System - open System.Numerics - open System.Globalization - - module BigRationalLargeImpl = - let ZeroI = new BigInteger(0) - let OneI = new BigInteger(1) - let bigint (x:int) = new BigInteger(x) - let ToDoubleI (x:BigInteger) = double x - let ToInt32I (x:BigInteger) = int32 x - - open BigRationalLargeImpl - - [] - type BigRationalLarge = - | Q of BigInteger * BigInteger // invariants: (p,q) in lowest form, q >= 0 - - override n.ToString() = - let (Q(p,q)) = n - if q.IsOne then p.ToString() - else p.ToString() + "/" + q.ToString() - - - static member Hash (Q(ap,aq)) = - // This hash code must be identical to the hash for BigInteger when the numbers coincide. - if aq.IsOne then ap.GetHashCode() else (ap.GetHashCode() <<< 3) + aq.GetHashCode() - - - override x.GetHashCode() = BigRationalLarge.Hash(x) - - static member Equals(Q(ap,aq), Q(bp,bq)) = - BigInteger.(=) (ap,bp) && BigInteger.(=) (aq,bq) // normal form, so structural equality - - static member LessThan(Q(ap,aq), Q(bp,bq)) = - BigInteger.(<) (ap * bq,bp * aq) - - // note: performance improvement possible here - static member Compare(p,q) = - if BigRationalLarge.LessThan(p,q) then -1 - elif BigRationalLarge.LessThan(q,p)then 1 - else 0 - - interface System.IComparable with - member this.CompareTo(obj:obj) = - match obj with - | :? BigRationalLarge as that -> BigRationalLarge.Compare(this,that) - | _ -> invalidArg "obj" "the object does not have the correct type" - - override this.Equals(that:obj) = - match that with - | :? BigRationalLarge as that -> BigRationalLarge.Equals(this,that) - | _ -> false - - member x.IsNegative = let (Q(ap,_)) = x in sign ap < 0 - member x.IsPositive = let (Q(ap,_)) = x in sign ap > 0 - - member x.Numerator = let (Q(p,_)) = x in p - member x.Denominator = let (Q(_,q)) = x in q - member x.Sign = (let (Q(p,_)) = x in sign p) - - static member ToDouble (Q(p,q)) = - ToDoubleI p / ToDoubleI q - - static member Normalize (p:BigInteger,q:BigInteger) = - if q.IsZero then - raise (System.DivideByZeroException()) (* throw for any x/0 *) - elif q.IsOne then - Q(p,q) - else - let k = BigInteger.GreatestCommonDivisor(p,q) - let p = p / k - let q = q / k - if sign q < 0 then Q(-p,-q) else Q(p,q) - - static member Rational (p:int,q:int) = BigRationalLarge.Normalize (bigint p,bigint q) - static member RationalZ (p,q) = BigRationalLarge.Normalize (p,q) - - static member Parse (str:string) = - let len = str.Length - if len=0 then invalidArg "str" "empty string"; - let j = str.IndexOf '/' - if j >= 0 then - let p = BigInteger.Parse (str.Substring(0,j)) - let q = BigInteger.Parse (str.Substring(j+1,len-j-1)) - BigRationalLarge.RationalZ (p,q) - else - let p = BigInteger.Parse str - BigRationalLarge.RationalZ (p,OneI) - - static member (~-) (Q(bp,bq)) = Q(-bp,bq) // still coprime, bq >= 0 - static member (+) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize ((ap * bq) + (bp * aq),aq * bq) - static member (-) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize ((ap * bq) - (bp * aq),aq * bq) - static member (*) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize (ap * bp,aq * bq) - static member (/) (Q(ap,aq),Q(bp,bq)) = BigRationalLarge.Normalize (ap * bq,aq * bp) - static member ( ~+ )(n1:BigRationalLarge) = n1 - - - [] - module BigRationalLarge = - open System.Numerics - - let inv (Q(ap,aq)) = BigRationalLarge.Normalize(aq,ap) - - let pown (Q(p,q)) (n:int) = Q(BigInteger.Pow(p,n),BigInteger.Pow (q,n)) // p,q powers still coprime - - 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) - let gt a b = BigRationalLarge.LessThan(b,a) - 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) - let d = BigInteger.DivRem (p,q,&r) // have p = d.q + r, |r| < |q| - if r < ZeroI - then d - OneI // p = (d-1).q + (r+q) - else d // p = d.q + r - - - //---------------------------------------------------------------------------- - // BigRational - //-------------------------------------------------------------------------- - - [] - [] - type BigRational = - | Z of BigInteger - | Q of BigRationalLarge - - static member ( + )(n1,n2) = - match n1,n2 with - | Z z ,Z zz -> Z (z + zz) - | 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) - - static member ( * )(n1,n2) = - match n1,n2 with - | Z z ,Z zz -> Z (z * zz) - | 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) - - static member ( - )(n1,n2) = - match n1,n2 with - | Z z ,Z zz -> Z (z - zz) - | 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) - - static member ( / )(n1,n2) = - match n1,n2 with - | Z z ,Z zz -> Q (BigRationalLarge.RationalZ(z,zz)) - | 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) - - static member ( ~- )(n1) = - match n1 with - | Z z -> Z (-z) - | Q q -> Q (-q) - - static member ( ~+ )(n1:BigRational) = n1 - +open System +open System.Numerics +open System.Globalization + + +[] +module private BigRationalLargeImpl = + let ZeroI = BigInteger (0) + let OneI = BigInteger (1) + let bigint (x : int) = BigInteger (x) + let ToDoubleI (x : BigInteger) = float x + let ToInt32I (x : BigInteger) = int32 x + + +[] +type BigRationalLarge = + // invariants: (p,q) in lowest form, q >= 0 + | Q of BigInteger * BigInteger + + member x.IsNegative = + let (Q (ap, _)) = x + sign ap < 0 + + member x.IsPositive = + let (Q (ap, _)) = x + sign ap > 0 + + member x.Numerator = + let (Q (p, _)) = x in p + + member x.Denominator = + let (Q (_, q)) = x in q + + member x.Sign = + let (Q (p,_) ) = x + sign p + + override this.GetHashCode () = + BigRationalLarge.Hash this + + override this.ToString () = + let (Q (p, q)) = this + if q.IsOne then + p.ToString() + else + p.ToString() + "/" + q.ToString() + + static member Hash (Q (ap, aq)) = + // This hash code must be identical to the hash for BigInteger when the numbers coincide. + if aq.IsOne then ap.GetHashCode () + else (ap.GetHashCode () <<< 3) + aq.GetHashCode () + + static member Equals(Q (ap, aq), Q (bp, bq)) = + // normal form, so structural equality + BigInteger.(=) (ap, bp) && BigInteger.(=) (aq, bq) + + static member LessThan (Q (ap, aq), Q (bp, bq)) = + BigInteger.(<) (ap * bq, bp * aq) + + // TODO: performance improvement possible here + static member Compare (p, q) = + if BigRationalLarge.LessThan (p, q) then -1 + elif BigRationalLarge.LessThan (q, p)then 1 + else 0 + + static member ToDouble (Q (p, q)) = + ToDoubleI p / ToDoubleI q + + static member Normalize (p : BigInteger, q : BigInteger) = + if q.IsZero then + (* throw for any x/0 *) + raise <| System.DivideByZeroException () + elif q.IsOne then + Q (p, q) + else + let k = BigInteger.GreatestCommonDivisor (p, q) + let p = p / k + let q = q / k + if sign q < 0 then + Q (-p, -q) + else Q (p, q) + + static member Rational (p : int, q : int) = + BigRationalLarge.Normalize (bigint p, bigint q) + + // TODO : Rename to Rational? It doesn't seem like we need to force the overload resolution here with a separate name... + static member RationalZ (p, q) = + BigRationalLarge.Normalize (p, q) + + /// Return the negation of a rational number + static member (~-) (Q (bp, bq)) = + // still coprime, bq >= 0 + Q(-bp, bq) + + /// Return the sum of two rational numbers + static member (+) (Q (ap, aq), Q (bp, bq)) = + BigRationalLarge.Normalize ((ap * bq) + (bp * aq), aq * bq) + + /// Return the difference of two rational numbers + static member (-) (Q (ap, aq), Q (bp, bq)) = + BigRationalLarge.Normalize ((ap * bq) - (bp * aq), aq * bq) + + /// Return the product of two rational numbers + static member (*) (Q (ap, aq), Q (bp, bq)) = + BigRationalLarge.Normalize (ap * bp, aq * bq) + + /// Return the ratio of two rational numbers + static member (/) (Q (ap, aq), Q (bp, bq)) = + BigRationalLarge.Normalize (ap * bq, aq * bp) + + /// Return the given rational number + static member ( ~+ ) (n1 : BigRationalLarge) = n1 + + // + static member Parse (str : string) = + let len = str.Length + if len=0 then invalidArg "str" "empty string"; + let j = str.IndexOf '/' + if j >= 0 then + let p = BigInteger.Parse (str.Substring(0,j)) + let q = BigInteger.Parse (str.Substring(j+1,len-j-1)) + BigRationalLarge.RationalZ (p,q) + else + let p = BigInteger.Parse str + BigRationalLarge.RationalZ (p,OneI) + + override this.Equals(that : obj) = + match that with + | :? BigRationalLarge as that -> + BigRationalLarge.Equals(this,that) + | _ -> false + + interface System.IComparable with + member this.CompareTo (obj : obj) = + match obj with + | :? BigRationalLarge as other -> + BigRationalLarge.Compare (this, other) + | _ -> + invalidArg "obj" "the object does not have the correct type" + + +// +[] +module private BigRationalLarge = + // + let inv (Q (ap, aq)) = + BigRationalLarge.Normalize (aq, ap) + + // + let pown (Q (p, q)) (n:int) = + // p,q powers still coprime + Q (BigInteger.Pow (p, n), BigInteger.Pow (q, n)) + + // + let equal (Q (ap, aq)) (Q (bp, bq)) = + // normal form, so structural equality + ap = bp && aq = bq + + // + let lt a b = + BigRationalLarge.LessThan (a, b) + + // + let gt a b = + BigRationalLarge.LessThan (b, a) + + // + 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. +[] +[] +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 - override n.GetHashCode() = - match n with - | Z z -> z.GetHashCode() - | Q q -> q.GetHashCode() - - override this.Equals(obj:obj) = + match this with + | Z z -> z.GetHashCode () + | Q q -> q.GetHashCode () + + override this.ToString () = + 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 - | :? BigRational as that -> BigRational.(=)(this, that) - | _ -> false - - interface System.IComparable with - member n1.CompareTo(obj:obj) = - match obj with - | :? BigRational as n2 -> - if BigRational.(<)(n1, n2) then -1 elif BigRational.(=)(n1, n2) then 0 else 1 - | _ -> invalidArg "obj" "the objects are not comparable" - - static member FromInt (x:int) = Z (bigint x) - static member FromBigInt x = Z x - - static member Zero = BigRational.FromInt(0) - static member One = BigRational.FromInt(1) - - - static member PowN (n,i:int) = - match n with - | Z z -> Z (BigInteger.Pow (z,i)) - | Q q -> Q (BigRationalLarge.pown q i) - - static member op_Equality (n,nn) = - match n,nn with - | Z z ,Z zz -> BigInteger.(=) (z,zz) - | Q q ,Q qq -> (BigRationalLarge.equal q qq) - | Z z ,Q qq -> (BigRationalLarge.equal (BigRationalLarge.of_bigint z) qq) - | Q q ,Z zz -> (BigRationalLarge.equal q (BigRationalLarge.of_bigint zz)) - static member op_Inequality (n,nn) = not (BigRational.op_Equality(n,nn)) - - static member op_LessThan (n,nn) = - match n,nn with - | Z z ,Z zz -> BigInteger.(<) (z,zz) - | Q q ,Q qq -> (BigRationalLarge.lt q qq) - | Z z ,Q qq -> (BigRationalLarge.lt (BigRationalLarge.of_bigint z) qq) - | Q q ,Z zz -> (BigRationalLarge.lt q (BigRationalLarge.of_bigint zz)) - static member op_GreaterThan (n,nn) = - 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)) - static member op_LessThanOrEqual (n,nn) = - match n,nn with - | Z z ,Z zz -> BigInteger.(<=) (z,zz) - | Q q ,Q qq -> (BigRationalLarge.lte q qq) - | Z z ,Q qq -> (BigRationalLarge.lte (BigRationalLarge.of_bigint z) qq) - | Q q ,Z zz -> (BigRationalLarge.lte q (BigRationalLarge.of_bigint zz)) - 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)) - - - member n.IsNegative = - match n with - | Z z -> sign z < 0 - | Q q -> q.IsNegative - - member n.IsPositive = - match n with - | Z z -> sign z > 0 - | Q q -> q.IsPositive - - member n.Numerator = - match n with - | Z z -> z - | Q q -> q.Numerator - - member n.Denominator = - match n with - | Z _ -> OneI - | Q q -> q.Denominator - - member n.Sign = - if n.IsNegative then -1 - elif n.IsPositive then 1 - else 0 - - static member Abs(n:BigRational) = - if n.IsNegative then -n else n - - static member ToDouble(n:BigRational) = - match n with - | Z z -> ToDoubleI z - | Q q -> BigRationalLarge.ToDouble q - - static member ToBigInt(n:BigRational) = - match n with - | Z z -> z - | Q q -> BigRationalLarge.integer q - - static member ToInt32(n:BigRational) = - match n with - | Z z -> ToInt32I(z) - | Q q -> ToInt32I(BigRationalLarge.integer q) - - static member op_Explicit (n:BigRational) = BigRational.ToInt32 n - static member op_Explicit (n:BigRational) = BigRational.ToDouble n - static member op_Explicit (n:BigRational) = BigRational.ToBigInt n - - - override n.ToString() = - match n with - | Z z -> z.ToString() - | Q q -> q.ToString() - - member x.StructuredDisplayString = x.ToString() - - static member Parse(s:string) = Q (BigRationalLarge.Parse s) - - type BigNum = BigRational - type bignum = BigNum - - module NumericLiteralN = - let FromZero () = BigRational.Zero - let FromOne () = BigRational.One - let FromInt32 i = BigRational.FromInt i - let FromInt64 (i64:int64) = BigRational.FromBigInt (new BigInteger(i64)) - let FromString s = BigRational.Parse s + | :? BigRational as other -> + if BigRational.(<)(this, other) then -1 + elif BigRational.(=)(this, other) then 0 + else 1 + | _ -> + invalidArg "obj" "The objects are not comparable." + + /// Return the result of converting the given integer to a rational number + static member FromInt (x : int) = + Z (bigint x) + + /// Return the result of converting the given big integer to a rational number + static member FromBigInt x = Z x + + /// Get zero as a rational number + static member Zero = + BigRational.FromInt 0 + + /// Get one as a rational number + static member One = + BigRational.FromInt 1 + + /// Return the sum of two rational numbers + static member ( + ) (n1, n2) = + match n1, n2 with + | Z z, Z zz -> + Z (z + zz) + | 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) + + /// Return the difference of two rational numbers + static member ( - ) (n1, n2) = + match n1, n2 with + | Z z, Z zz -> + Z (z - zz) + | 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) + + /// Return the product of two rational numbers + static member ( * ) (n1, n2) = + match n1,n2 with + | Z z, Z zz -> + Z (z * zz) + | 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) + + /// Return the ratio of two rational numbers + static member ( / ) (n1, n2) = + match n1, n2 with + | Z z, Z zz -> + Q (BigRationalLarge.RationalZ(z,zz)) + | 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) + + /// Return the negation of a rational number + static member ( ~- ) n = + match n with + | Z z -> Z (-z) + | Q q -> Q (-q) + + /// Return the given rational number + static member ( ~+ ) (n : BigRational) = n + + /// This operator is for use from other .NET languages + static member op_Equality (n, nn) = + match n,nn with + | Z z, Z zz -> + BigInteger.(=) (z,zz) + | Q q, Q qq -> + (BigRationalLarge.equal q qq) + | Z z, Q qq -> + (BigRationalLarge.equal (BigRationalLarge.of_bigint z) qq) + | Q q, Z zz -> + (BigRationalLarge.equal q (BigRationalLarge.of_bigint zz)) + + /// This operator is for use from other .NET languages + static member op_Inequality (n, nn) = + not <| BigRational.op_Equality (n, nn) + + /// This operator is for use from other .NET languages + static member op_LessThan (n, nn) = + match n, nn with + | Z z, Z zz -> + BigInteger.(<) (z,zz) + | Q q, Q qq -> + (BigRationalLarge.lt q qq) + | Z z, Q qq -> + (BigRationalLarge.lt (BigRationalLarge.of_bigint z) qq) + | Q q, Z zz -> + (BigRationalLarge.lt q (BigRationalLarge.of_bigint zz)) + + /// This operator is for use from other .NET languages + static member op_LessThanOrEqual (n, nn) = + match n, nn with + | Z z, Z zz -> + BigInteger.(<=) (z,zz) + | Q q, Q qq -> + (BigRationalLarge.lte q qq) + | Z z, Q qq -> + (BigRationalLarge.lte (BigRationalLarge.of_bigint z) qq) + | Q q, Z zz -> + (BigRationalLarge.lte q (BigRationalLarge.of_bigint zz)) + + /// This operator is for use from other .NET languages + static member op_GreaterThan (n, nn) = + 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 + +// +[] +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 diff --git a/src/FSharp/BigRational.fsi b/src/FSharp/BigRational.fsi index 302c364d..bb98fec1 100644 --- a/src/FSharp/BigRational.fsi +++ b/src/FSharp/BigRational.fsi @@ -2,98 +2,73 @@ // https://raw.github.com/fsharp/powerpack/master/src/FSharp.PowerPack/math/q.fsi // (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 #if NOSYSNUMERICS #else - open System - open System.Numerics - - /// The type of arbitrary-sized rational numbers - [] - type BigRational = - /// Return the sum of two rational numbers - static member ( + ) : BigRational * BigRational -> BigRational - /// Return the product of two rational numbers - static member ( * ) : BigRational * BigRational -> BigRational - /// Return the difference of two rational numbers - static member ( - ) : BigRational * BigRational -> BigRational - /// Return the ratio of two rational numbers - static member ( / ) : BigRational * BigRational -> BigRational - /// Return the negation of a rational number - static member ( ~- ): BigRational -> BigRational - /// Return the given rational number - static member ( ~+ ): BigRational -> BigRational - - override ToString: unit -> string - override GetHashCode: unit -> int - interface System.IComparable - - /// Get zero as a rational number - static member Zero : BigRational - /// Get one as a rational number - static member One : BigRational - /// This operator is for use from other .NET languages - static member op_Equality : BigRational * BigRational -> bool - /// This operator is for use from other .NET languages - static member op_Inequality : BigRational * BigRational -> bool - /// This operator is for use from other .NET languages - static member op_LessThan: BigRational * BigRational -> bool - /// This operator is for use from other .NET languages - static member op_GreaterThan: BigRational * BigRational -> bool - /// This operator is for use from other .NET languages - static member op_LessThanOrEqual: BigRational * BigRational -> bool - /// This operator is for use from other .NET languages - static member op_GreaterThanOrEqual: BigRational * BigRational -> bool - - /// Return a boolean indicating if this rational number is strictly negative - member IsNegative: bool - /// Return a boolean indicating if this rational number is strictly positive - member IsPositive: bool - - /// Return the numerator of the normalized rational number - member Numerator: BigInteger - /// Return the denominator of the normalized rational number - member Denominator: BigInteger - - member StructuredDisplayString : string - - /// Return the absolute value of a rational number - static member Abs : BigRational -> BigRational - /// Return the sign of a rational number; 0, +1 or -1 - member Sign : int - /// Return the result of raising the given rational number to the given power - static member PowN : BigRational * int -> BigRational - /// Return the result of converting the given integer to a rational number - static member FromInt : int -> BigRational - /// Return the result of converting the given big integer to a rational number - 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 - - [] - module NumericLiteralN = - val FromZero : unit -> BigRational - val FromOne : unit -> BigRational - val FromInt32 : int32 -> BigRational - val FromInt64 : int64 -> BigRational - val FromString : string -> BigRational +open System +open System.Numerics + +[] +type BigRational = + interface System.IComparable + + override ToString : unit -> string + override GetHashCode : unit -> int + + member IsNegative: bool + member IsPositive: bool + + member Numerator : BigInteger + member Denominator : BigInteger + + member Sign : int + member StructuredDisplayString : string + + static member Zero : BigRational + static member One : BigRational + + static member ( + ) : BigRational * BigRational -> BigRational + static member ( * ) : BigRational * BigRational -> BigRational + static member ( - ) : BigRational * BigRational -> BigRational + static member ( / ) : BigRational * BigRational -> BigRational + static member ( ~- ): BigRational -> BigRational + static member ( ~+ ): BigRational -> BigRational + + static member op_Equality : BigRational * BigRational -> bool + static member op_Inequality : BigRational * BigRational -> bool + static member op_LessThan: BigRational * BigRational -> bool + static member op_LessThanOrEqual: BigRational * BigRational -> bool + static member op_GreaterThan: BigRational * BigRational -> bool + static member op_GreaterThanOrEqual: BigRational * BigRational -> bool + + static member op_Explicit : BigRational -> BigInteger + static member op_Explicit : BigRational -> int + static member op_Explicit : BigRational -> float + + static member Abs : BigRational -> BigRational + static member PowN : BigRational * int -> BigRational + static member Parse: string -> BigRational + + static member FromInt : int -> BigRational + static member FromBigInt : BigInteger -> BigRational + + static member ToDouble: BigRational -> float + static member ToBigInt: BigRational -> BigInteger + static member ToInt32 : BigRational -> int + +[] +module NumericLiteralN = + val FromZero : unit -> BigRational + val FromOne : unit -> BigRational + val FromInt32 : int32 -> BigRational + val FromInt64 : int64 -> BigRational + val FromString : string -> BigRational + +type BigNum = BigRational +type bignum = BigRational #endif diff --git a/src/FSharp/Complex.fs b/src/FSharp/Complex.fs index 665bc487..1dee14e7 100644 --- a/src/FSharp/Complex.fs +++ b/src/FSharp/Complex.fs @@ -4,169 +4,414 @@ namespace MathNet.Numerics - open Microsoft.FSharp.Math - open System - open System.Globalization +open Microsoft.FSharp.Math +open System +open System.Globalization #if NOSYSNUMERICS #else - open System.Numerics +open System.Numerics #endif - type complex = Complex - type complex32 = Complex32 - - [] - [] - module Complex = - - let mkRect(a,b) = new Complex(a,b) - let mkPolar(a,b) = Complex.FromPolarCoordinates(a,b) - let cis b = mkPolar(1.0,b) - let ofComplex32 (x:complex32) = new Complex(float x.Real, float x.Imaginary) - - let zero = Complex.Zero - let one = Complex.One - let onei = Complex.ImaginaryOne - let pi = mkRect (Math.PI,0.0) - - let realPart (c:complex) = c.Real - let imagPart (c:complex) = c.Imaginary - let magnitude (c:complex) = c.Magnitude - let phase (c:complex) = c.Phase - - let neg (a:complex) = -a - let conjugate (c:complex) = c.Conjugate() - - let add (a:complex) (b:complex) = a + b - let sub (a:complex) (b:complex) = a - b - let mul (a:complex) (b:complex) = a * b - let div (x:complex) (y:complex) = x / y - - let smul (a:float) (b:complex) = new Complex(a * b.Real, a * b.Imaginary) - let muls (a:complex) (b:float) = new Complex(a.Real * b, a.Imaginary * b) - - let exp (x:complex) = Complex.Exp(x) - let ln x = Complex.Log(x) - let log10 x = Complex.Log10(x) - let log b x = Complex.Log(x,b) - let pow (power:complex) x = Complex.Pow(x,power) - let powf (power:float) x = Complex.Pow(x,power) - let sqr (x:complex) = x.Square() - let sqrt (x:complex) = x.SquareRoot() // numerically more stable than Complex.Sqrt - - let sin x = Complex.Sin(x) - let cos x = Complex.Cos(x) - let tan x = Complex.Tan(x) - let cot (x:complex) = Trig.Cot(x) - let sec (x:complex) = Trig.Sec(x) - let csc (x:complex) = Trig.Csc(x) - - 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 - let atan x = Complex.Atan(x) - let acot (x:complex) = Trig.Acot(x) - let asec (x:complex) = Trig.Asec(x) - let acsc (x:complex) = Trig.Acsc(x) - - let sinh x = Complex.Sinh(x) - let cosh x = Complex.Cosh(x) - let tanh x = Complex.Tanh(x) - let coth (x:complex) = Trig.Coth(x) - let sech (x:complex) = Trig.Sech(x) - let csch (x:complex) = Trig.Csch(x) - - let asinh (x:complex) = Trig.Asinh(x) - let acosh (x:complex) = Trig.Acosh(x) - let atanh (x:complex) = Trig.Atanh(x) - let acoth (x:complex) = Trig.Acoth(x) - let asech (x:complex) = Trig.Asech(x) - let acsch (x:complex) = Trig.Acsch(x) - - [] - [] - module Complex32 = - - let mkRect(a,b) = new Complex32(a,b) - let mkPolar(a,b) = Complex32.FromPolarCoordinates(a,b) - let cis b = mkPolar(1.0f,b) - let ofComplex (x:complex) = new Complex32(float32 x.Real, float32 x.Imaginary) - - let zero = Complex32.Zero - let one = Complex32.One - let onei = Complex32.ImaginaryOne - let pi = mkRect (float32 Math.PI,0.0f) - - let realPart (c:complex32) = c.Real - let imagPart (c:complex32) = c.Imaginary - let magnitude (c:complex32) = c.Magnitude - let phase (c:complex32) = c.Phase - - let neg (a:complex32) = -a - let conjugate (c:complex32) = c.Conjugate() - - let add (a:complex32) (b:complex32) = a + b - let sub (a:complex32) (b:complex32) = a - b - let mul (a:complex32) (b:complex32) = a * b - let div (x:complex32) (y:complex32) = x / y - - 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) - - let exp (x:complex32) = Complex32.Exp(x) - let ln x = Complex32.Log(x) - let log10 x = Complex32.Log10(x) - let log b x = Complex32.Log(x,b) - let pow (power:complex32) x = Complex32.Pow(x,power) - let powf (power:float32) x = Complex32.Pow(x,power) - let sqr (x:complex32) = x.Square() - let sqrt (x:complex32) = x.SquareRoot() // numerically more stable than Complex.Sqrt - - // no complex32 implementations available yet for some, fix once available - let sin x = Complex32.Sin(x) - let cos x = Complex32.Cos(x) - let tan x = Complex32.Tan(x) - let cot (x:complex32) = ofComplex <| Trig.Cot(x.ToComplex()) - let sec (x:complex32) = ofComplex <| Trig.Sec(x.ToComplex()) - let csc (x:complex32) = ofComplex <| Trig.Csc(x.ToComplex()) - - 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 - let atan x = Complex32.Atan(x) - let acot (x:complex32) = ofComplex <| Trig.Acot(x.ToComplex()) - let asec (x:complex32) = ofComplex <| Trig.Asec(x.ToComplex()) - let acsc (x:complex32) = ofComplex <| Trig.Acsc(x.ToComplex()) - - let sinh x = Complex32.Sinh(x) - let cosh x = Complex32.Cosh(x) - let tanh x = Complex32.Tanh(x) - let coth (x:complex32) = ofComplex <| Trig.Coth(x.ToComplex()) - let sech (x:complex32) = ofComplex <| Trig.Sech(x.ToComplex()) - let csch (x:complex32) = ofComplex <| Trig.Csch(x.ToComplex()) - - let asinh (x:complex32) = ofComplex <| Trig.Asinh(x.ToComplex()) - let acosh (x:complex32) = ofComplex <| Trig.Acosh(x.ToComplex()) - let atanh (x:complex32) = ofComplex <| Trig.Atanh(x.ToComplex()) - let acoth (x:complex32) = ofComplex <| Trig.Acoth(x.ToComplex()) - let asech (x:complex32) = ofComplex <| Trig.Asech(x.ToComplex()) - let acsch (x:complex32) = ofComplex <| Trig.Acsch(x.ToComplex()) - - [] - module ComplexExtensions = - - let complex x y = Complex.mkRect (x,y) - let complex32 x y = Complex32.mkRect (x,y) - - type Complex with - member x.r = x.Real - member x.i = x.Imaginary - - static member Create(a,b) = Complex.mkRect (a,b) - static member CreatePolar(a,b) = Complex.mkPolar (a,b) - - type Complex32 with - member x.r = x.Real - member x.i = x.Imaginary - - static member Create(a,b) = Complex32.mkRect (a,b) - static member CreatePolar(a,b) = Complex32.mkPolar (a,b) +// +type complex = Complex +// +type complex32 = Complex32 + +// +[] +module Complex = + /// Create a complex number using real and imaginary parts + let mkRect(a,b) = Complex(a,b) + + /// Create a complex number using magnitude/phase polar coordinates + let mkPolar(a,b) = Complex.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.0,b) + + // + let private ofComplex32 (x : complex32) = + Complex(float x.Real, float x.Imaginary) + + /// The complex number 0+0i + let zero = Complex.Zero + + /// The complex number 1+0i + let one = Complex.One + + /// The complex number 0+1i + let onei = Complex.ImaginaryOne + + /// pi + let pi = mkRect (Math.PI,0.0) + + + /// The real part of a complex number + let realPart (c:complex) = c.Real + + /// The imaginary part of a complex number + let imagPart (c:complex) = c.Imaginary + + /// The polar-coordinate magnitude of a complex number + let magnitude (c:complex) = c.Magnitude + + /// The polar-coordinate phase of a complex number + let phase (c:complex) = c.Phase + + + /// Unary negation of a complex number + let neg (a:complex) = -a + + /// The conjugate of a complex number, i.e. x-yi + let conjugate (c:complex) = c.Conjugate() + + + /// Add two complex numbers + let add (a:complex) (b:complex) = a + b + + /// Subtract one complex number from another + let sub (a:complex) (b:complex) = a - b + + /// Multiply two complex numbers + let mul (a:complex) (b:complex) = a * b + + /// Complex division of two complex numbers + let div (x:complex) (y:complex) = x / y + + + /// Multiply a scalar by a complex number + let smul (a:float) (b:complex) = new Complex(a * b.Real, a * b.Imaginary) + + /// Multiply a complex number by a scalar + let muls (a:complex) (b:float) = new Complex(a.Real * b, a.Imaginary * b) + + + /// exp(x) = e^x + let exp (x:complex) = Complex.Exp(x) + + /// ln(x) is natural log (base e) + let ln x = Complex.Log(x) + + /// log10(x) is common log (base 10) + let log10 x = Complex.Log10(x) + + /// log(base,x) is log with custom base + let log b x = Complex.Log(x,b) + + /// pow(power,x) is the complex power + let pow (power : complex) x = Complex.Pow(x,power) + + /// pow(power,x) is the scalar power + let powf (power : float) x = Complex.Pow(x,power) + + /// sqr(x) is the square (power 2) + let sqr (x : complex) = x.Square() + + /// sqrt(x) and 0 <= phase(x) < pi + let sqrt (x : complex) = x.SquareRoot() // numerically more stable than Complex.Sqrt + + + /// Sine + let sin x = Complex.Sin(x) + + /// Cosine + let cos x = Complex.Cos(x) + + /// Tagent + let tan x = Complex.Tan(x) + + /// Cotangent + let cot (x : complex) = Trig.Cot(x) + + /// Secant + let sec (x : complex) = Trig.Sec(x) + + /// Cosecant + let csc (x : complex) = Trig.Csc(x) + + + /// Arc Sine + let asin (x : complex) = + // numerically more stable than Complex.Asin + Trig.Asin(x) + + /// Arc Cosine + let acos (x : complex) = + // numerically more stable than Complex.Acos + Trig.Acos(x) + + /// Arc Tagent + let atan x = Complex.Atan(x) + + /// Arc Cotangent + let acot (x : complex) = Trig.Acot(x) + + /// Arc Secant + let asec (x : complex) = Trig.Asec(x) + + /// Arc Cosecant + let acsc (x : complex) = Trig.Acsc(x) + + + /// Hyperbolic Sine + let sinh x = Complex.Sinh(x) + + /// Hyperbolic Cosine + let cosh x = Complex.Cosh(x) + + /// Hyperbolic Tagent + let tanh x = Complex.Tanh(x) + + /// Hyperbolic Cotangent + let coth (x : complex) = Trig.Coth(x) + + /// Hyperbolic Secant + let sech (x : complex) = Trig.Sech(x) + + /// 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) + + +// +[] +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()) + + +// +[] +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) diff --git a/src/FSharp/Complex.fsi b/src/FSharp/Complex.fsi deleted file mode 100644 index 20674c16..00000000 --- a/src/FSharp/Complex.fsi +++ /dev/null @@ -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 - - [] - [] - 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 - - [] - [] - 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 - - - [] - 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 diff --git a/src/FSharp/FSharp-Portable136.fsproj b/src/FSharp/FSharp-Portable136.fsproj index 24a73bcd..dbfde3a0 100644 --- a/src/FSharp/FSharp-Portable136.fsproj +++ b/src/FSharp/FSharp-Portable136.fsproj @@ -50,7 +50,6 @@ - diff --git a/src/FSharp/FSharp-Portable47.fsproj b/src/FSharp/FSharp-Portable47.fsproj index 72f31551..f169b4e9 100644 --- a/src/FSharp/FSharp-Portable47.fsproj +++ b/src/FSharp/FSharp-Portable47.fsproj @@ -50,7 +50,6 @@ - diff --git a/src/FSharp/FSharp.fsproj b/src/FSharp/FSharp.fsproj index 6492e63c..ee0b6295 100644 --- a/src/FSharp/FSharp.fsproj +++ b/src/FSharp/FSharp.fsproj @@ -63,7 +63,6 @@ -