public void CalculateReverseTestStrong(double firstValue, double expected) { IOneArgumentCalculator calculator = new Inverse(); double result = calculator.Calculate(firstValue); Assert.AreEqual(expected, result); }
public void ExecuteVectorTest() { var vector = new Vector(new[] { new Number(3), new Number(7), new Number(2), new Number(5) }); var exp = new Inverse(vector); Assert.Throws <ResultIsNotSupportedException>(() => exp.Execute()); }
protected override SDFNode GenerateNode() { var inverse = _cachedNode as Inverse; var offset = _cachedNode as Offset; switch (Type) { case UnaryType.Inverse: if (inverse == null) { _cachedNode = inverse = new Inverse(); } break; case UnaryType.Offset: if (offset == null) { _cachedNode = offset = new Offset(); } offset.Operation.Offset = Offset; break; } return(_cachedNode); }
public void ExecuteEmptyTest() { var matrix = new Matrix(2, 2); var exp = new Inverse(matrix); Assert.Throws <ArgumentException>(() => exp.Execute()); }
public static ImmutableArray <ushort> Create() { var udEdgesConj = new ushort[NUdEdges * NSymD4H]; for (var t = 0; t < 0 + NUdEdges; t++) { if ((t + 1) % 400 == 0) { Console.Write("."); } if ((t + 1) % 32000 == 0) { Console.WriteLine(""); } var cc = SolvedCube.Instance.Clone(); cc.set_ud_edges(t); for (var s = 0; s < 0 + NSymD4H; s++) { var ss = Basic.Cubes[s].Clone(); ss.EdgeMultiply(cc); ss.EdgeMultiply(Inverse.GetCube(s)); udEdgesConj[NSymD4H * t + s] = Convert.ToUInt16(ss.get_ud_edges()); //TODO remove all these } } return(udEdgesConj.ToImmutableArray()); }
public int CompareTo(object obj) { if (obj is IsNullPredicate) { return(Inverse.CompareTo(((Predicate)obj).Inverse)); } return(-1); }
public int CompareTo(object obj) { if (obj is AlwaysFalsePredicate) { return(Inverse.CompareTo(((Predicate)obj).Inverse)); } return(-1); }
//Transformations public void Pan(PointF by) { PointF[] p = new PointF[] { by }; Inverse.TransformVectors(p); by = p[0]; Matrix.Translate(by.X, by.Y); UpdateInverse(); }
public void InversesShouldMultiplyToSolvedCube(int i) { var sym = Basic.Cubes[i].Clone(); var inv = Inverse.GetCube(i); sym.Multiply(inv); sym.Should().Be(SolvedCube.Instance); }
public override ITransformation GetInverse() { if (!HasInverse) { throw new NoInverseException(); } Contract.Ensures(Contract.Result <ITransformation>() != null); return(Inverse.BuildInverse(this)); }
public override void Render(RenderContext context) { var value = context.GetValue(Name); var lambda = value as Lambda; if (lambda != null) { context.Write(lambda(InnerSource()).ToString()); return; } var helper = value as HelperProxy; if (helper != null) { helper(data => { context.Enter(this); context.Push(data); RenderParts(context); context.Pop(); context.Exit(); }, data => { if (Inverse != null) { context.Enter(Inverse); context.Push(data); Inverse.RenderParts(context); context.Pop(); context.Exit(); } }); return; } foreach (var item in context.GetValues(Name)) { context.Enter(this); context.Push(item); base.Render(context); context.Pop(); context.Exit(); } }
public void CloneTest() { var exp = new Inverse(new Matrix(new[] { new Vector(new[] { new Number(1), new Number(-2), new Number(3) }), new Vector(new[] { new Number(4), new Number(0), new Number(6) }), new Vector(new[] { new Number(-7), new Number(8), new Number(9) }) })); var clone = exp.Clone(); Assert.Equal(exp, clone); }
public void ExecuteIsNotSquareTest() { var matrix = new Matrix(new[] { new Vector(new[] { new Number(3), new Number(7), new Number(2), new Number(5) }), new Vector(new[] { new Number(1), new Number(8), new Number(4), new Number(2) }), new Vector(new[] { new Number(2), new Number(1), new Number(9), new Number(3) }) }); var exp = new Inverse(matrix); Assert.Throws <ArgumentException>(() => exp.Execute()); }
public void InverseToStringTest() { var matrix = new Matrix(new[] { new Maths.Expressions.Matrices.Vector(new[] { new Number(1), new Number(-2) }), new Maths.Expressions.Matrices.Vector(new[] { new Number(4), new Number(0) }) }); var exp = new Inverse(matrix); Assert.Equal("inverse({{1, -2}, {4, 0}})", exp.ToString(commoonFormatter)); }
public void TestInverseException2() { var exp = new Inverse( new Vector(new IExpression[] { new Number(3), new Number(7), new Number(2), new Number(5) })); TestException(exp); }
static Config() { IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; partyAddress.Add(PartyType.Client, new IPEndPoint(ipAddress, (int)Port.Client)); partyAddress.Add(PartyType.EVH, new IPEndPoint(ipAddress, (int)Port.EVH)); partyAddress.Add(PartyType.KH, new IPEndPoint(ipAddress, (int)Port.KH)); partyAddress.Add(PartyType.Helper, new IPEndPoint(ipAddress, (int)Port.Helper)); ThreadPool.SetMaxThreads(MaxThreads, 0); Numeric.SetParameters(); Inverse.SetParameters(); }
public Bag(CodeFileBuilder builder) { _builder = builder; _where = new Where(builder); _orderBy = new OrderBy(builder); _cascade = new Cascade(builder); _fetch = new Fetch(builder); _inverse = new Inverse(builder); _table = new Table(builder); _keyColumn = new KeyColumn(builder); _lazyLoad = new LazyLoad(builder); _cacheBuilder = new CacheBuilder(builder); }
public SexagesimalDmsToDecimalDegreesConversion(IUnit from, IUnit to) { if (null == from) { throw new ArgumentNullException("from"); } if (null == to) { throw new ArgumentNullException("to"); } Contract.EndContractBlock(); _from = from; _to = to; _inverse = new Inverse(this); }
public static List <ObstacleModel> GetObsFromFile(string fileName) { var runways = App.RunwayRepsitory.GetAll(); string[] readText = File.ReadAllLines(fileName); int NumberOfLines = readText.Length; List <ObstacleModel> ObstaclesWithin30 = new List <ObstacleModel>(); for (int i = 4; i < NumberOfLines; i++) { string obsRecLine = readText[i]; if (obsRecLine.Substring(0, 3) == "ADD") { double ObsLat = Conversions.ConvertPosition(double.Parse(obsRecLine.Substring(45, 2) + obsRecLine.Substring(48, 2) + obsRecLine.Substring(51, 5))); double ObsLon = Conversions.ConvertPosition(double.Parse(obsRecLine.Substring(58, 3) + obsRecLine.Substring(62, 2) + obsRecLine.Substring(65, 5))); foreach (var rwy in runways) { double result = Inverse.invcalc(rwy.Lat, rwy.Long, ObsLat, ObsLon).xmeters / 1852; if (result < 30) { ObstacleModel NewObstacle = new ObstacleModel() { ObsStudy = obsRecLine.Substring(10, 9), ObsType = obsRecLine.Substring(72, 18).TrimEnd(), ObsAglHeight = int.Parse(obsRecLine.Substring(93, 5)), ObsMslHeight = int.Parse(obsRecLine.Substring(99, 5)), ObsLatitudeHemisphere = obsRecLine.Substring(56, 1), ObsLongitudeHemisphere = obsRecLine.Substring(70, 1), ObsLatitudeDms = double.Parse(obsRecLine.Substring(45, 2) + obsRecLine.Substring(48, 2) + obsRecLine.Substring(51, 5)), ObsLongitudeDms = double.Parse(obsRecLine.Substring(58, 3) + obsRecLine.Substring(62, 2) + obsRecLine.Substring(65, 5)), ObsStatus = obsRecLine.Substring(0, 3), ObsIcao = rwy.Icao }; NewObstacle.ObsLatitudeDd = Conversions.ConvertPosition(NewObstacle.ObsLatitudeDms); NewObstacle.ObsLongitudeDd = Conversions.ConvertPosition(NewObstacle.ObsLongitudeDms); ObstaclesWithin30.Add(NewObstacle); break; } } } } return(ObstaclesWithin30); }
public static List <ObsRec> GetObsFromFile(string fileName, NavGenDataSet.rwDataTable runways) { string[] readText = File.ReadAllLines(fileName); int NumberOfLines = readText.Length; List <ObsRec> ObstaclesWithin30 = new List <ObsRec>(); for (int i = 4; i < NumberOfLines; i++) { string obsRecLine = readText[i]; if (obsRecLine.Substring(0, 3) != "OLD") { double ObsLat = Conversions.ConvertPosition(double.Parse(obsRecLine.Substring(45, 2) + obsRecLine.Substring(48, 2) + obsRecLine.Substring(51, 5))); double ObsLon = Conversions.ConvertPosition(double.Parse(obsRecLine.Substring(58, 3) + obsRecLine.Substring(62, 2) + obsRecLine.Substring(65, 5))); foreach (NavGenDataSet.rwRow rwy in runways) { double result = Inverse.invcalc(rwy.lat, rwy.lon, ObsLat, ObsLon).xmeters / 1852; if (result < 30) { ObsRec NewObstacle = new ObsRec() { Study = obsRecLine.Substring(10, 9), Otype = obsRecLine.Substring(72, 18).TrimEnd(), MSL_Height = int.Parse(obsRecLine.Substring(99, 5)), Latitude_Hemisphere = obsRecLine.Substring(56, 1), Longitude_hemisphere = obsRecLine.Substring(70, 1), Latitude_DMS = double.Parse(obsRecLine.Substring(45, 2) + obsRecLine.Substring(48, 2) + obsRecLine.Substring(51, 5)), Longitude_DMS = double.Parse(obsRecLine.Substring(58, 3) + obsRecLine.Substring(62, 2) + obsRecLine.Substring(65, 5)), Status = obsRecLine.Substring(0, 3), }; NewObstacle.LatitudeDD = Conversions.ConvertPosition(NewObstacle.Latitude_DMS); NewObstacle.Longitude_DD = Conversions.ConvertPosition(NewObstacle.Longitude_DMS); ObstaclesWithin30.Add(NewObstacle); break; } } } } return(ObstaclesWithin30); }
/// <summary> /// Get the symmetries and antisymmetries of the cube /// </summary> public static IEnumerable <int> Symmetries(this ICubieCube cubieCube) { for (var j = 0; j < Definitions.NSym; j++) { var c = Basic.Cubes[j].Clone(); c.Multiply(cubieCube); c.Multiply(Inverse.GetCube(j)); if (CubeComparer.Instance.Equals(cubieCube, c)) { yield return(j); } var d = c.Invert(); if (CubeComparer.Instance.Equals(cubieCube, d)) { yield return(j + Definitions.NSym); } } }
public override bool EnterParameters() { ProcessingAlgorithm algorithm; switch (Program.paramState.algorithmOption) { case "1": algorithm = new MeanFilterImplementation(); algorithm.PreProcessingEvent.Subscribe(new MeanPreProcessingCommand()); algorithm.PostProcessingEvent.Subscribe(new MeanPostProcessingCommand()); algorithm.ProcessingStepEvent.Subscribe(new MeanProcessingStepCommand()); break; case "2": algorithm = new Binarization(); algorithm.PreProcessingEvent.Subscribe(new BinarizationPreProccesingCommand()); algorithm.PostProcessingEvent.Subscribe(new BinarizationPostProccesingCommand()); algorithm.ProcessingStepEvent.Subscribe(new BinarizationProccessingStepCommand()); break; case "3": algorithm = new Inverse(); algorithm.PreProcessingEvent.Subscribe(new InversePreProcessingCommand()); algorithm.PostProcessingEvent.Subscribe(new InversePostProcessingCommand()); break; default: return(false); } var parameters = new Dictionary <String, String>(); foreach (var parameter in algorithm.ExpectedParameters) { Console.Write($"{parameter} = "); var value = Console.ReadLine(); parameters.Add(parameter, value); } Program.builder.WriteImage(algorithm.Process(Program.image, parameters), "result.png"); Program.SetMachineState(Program.unloadedState); return(true); }
public void ExecuteMatrixTest() { var matrix = new Matrix(new[] { new Vector(new[] { new Number(3), new Number(7), new Number(2), new Number(5) }), new Vector(new[] { new Number(1), new Number(8), new Number(4), new Number(2) }), new Vector(new[] { new Number(2), new Number(1), new Number(9), new Number(3) }), new Vector(new[] { new Number(5), new Number(4), new Number(7), new Number(1) }) }); var expected = new Matrix(new[] { new Vector(new[] { new Number(0.0970873786407767), new Number(-0.18270079435128), new Number(-0.114739629302736), new Number(0.224183583406884) }), new Vector(new[] { new Number(-0.0194174757281553), new Number(0.145631067961165), new Number(-0.0679611650485437), new Number(0.00970873786407767) }), new Vector(new[] { new Number(-0.087378640776699), new Number(0.0644307149161518), new Number(0.103265666372463), new Number(-0.00176522506619595) }), new Vector(new[] { new Number(0.203883495145631), new Number(-0.120035304501324), new Number(0.122683142100618), new Number(-0.147396293027361) }) }); var exp = new Inverse(matrix); Assert.Equal(expected, exp.Execute()); }
public static void SetGlobalParameters(int keyLen, int numericBits, byte scaleBits, bool isop) { // EffectiveKeyBits is always larger than NumericBitLength System.Diagnostics.Debug.Assert(keyLen % 8 == 0); //System.Diagnostics.Debug.Assert(keyLen >= numericBits + 4); KeyBits = keyLen; EffectiveKeyBits = keyLen - 3; KeyBytes = keyLen / 8; NumericBits = numericBits; ScaleBits = scaleBits; //IntegerBits = numericBits > scaleBits ? numericBits - scaleBits : 0; isOptimized = isop; if (!isOptimized) { Runtime_Network_BufferMessageThresholdEVH = 1; Runtime_Network_BufferMessageThresholdKH = 1; Runtime_Network_BufferMessageThresholdHelper = 1; Runtime_Network_TimeThreshold = 0; } Numeric.SetParameters(); Inverse.SetParameters(); }
public void InverseTest_1500x1500() { var tileSize = 40; // prepare data var data = MatrixHelpers.Tile(Matrix<double>.DeSerializeFromFile(@"C:\Users\eh\Documents\KU\Inversion-of-Block-Tridiagonal-Matrices\Dataset\m1500x1500-a.mat"), tileSize); Matrix<Matrix<double>> expected = MatrixHelpers.Tile(Matrix<double>.DeSerializeFromFile(@"C:\Users\eh\Documents\KU\Inversion-of-Block-Tridiagonal-Matrices\Dataset\m1500x1500-a-Inverse-result.mat"), tileSize); // the parallel version of Inverse expectes its data to be LU Factorized, the tiled version does not. data = data.GetLU(); var opData1 = new OperationResult<double>(data); OperationResult<double> actual; var mProducer = new Inverse<double>(opData1, out actual); var pm = new Manager(mProducer); pm.Start(); pm.Join(); MatrixHelpers.IsDone(actual); MatrixHelpers.Diff(expected, actual.Data); MatrixHelpers.Compare(expected, actual.Data); }
public static cpolinom Point_Multiplication_Affine_Coord_19(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int A, int B, Inverse inv) { BigInteger[,] mas_k; mas_k = Convert_to_DBNS_1(n, A, B); int lastindex = mas_k.GetLength(0) - 1; cpolinom t = cpolinom.Copy(p); cpolinom res = new cpolinom("1", p.mod); for (int i = 0; i < mas_k[lastindex, 1]; i++) t = mul(t, t) % ir; for (int i = 0; i < mas_k[lastindex, 2]; i++) t = mul(t, mul(t, t)) % ir; if (mas_k[lastindex, 0] == -1) res = mul(res, inv(t, ir)) % ir; else if (mas_k[lastindex, 0] == 1) res = mul(res, t) % ir; for (int i = lastindex - 1; i >= 0; i--) { BigInteger u = mas_k[i, 1] - mas_k[i + 1, 1]; BigInteger v = mas_k[i, 2] - mas_k[i + 1, 2]; for (int j = 0; j < u; j++) t = mul(t, t) % ir; for (int j = 0; j < v; j++) t = mul(t, mul(t, t)) % ir; if (mas_k[i, 0] == -1) res = mul(res, inv(t, ir)) % ir; else if (mas_k[i, 0] == 1) res = mul(res, t) % ir; } return res; }
public void FileIndexing(List <string> words, int docId) { using (indexFiledbContext db = new indexFiledbContext()) { foreach (string word in words) { if (db.Words.Where(item => item.Content == word.ToLower()).Count() == 0) { Word wordDB = new Word(); wordDB.Content = word; db.Words.Add(wordDB); db.SaveChanges(); } Inverse inverse = new Inverse(); inverse.DocId = docId; inverse.WordId = db.Words.Where(p => p.Content == word).Single().WordId; db.Inverse.Add(inverse); db.SaveChanges(); } } }
public static cpolinom Point_Multiplication_Affine_Coord_20(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int A, int B, Inverse inv) { BigInteger[,] mas_k; cpolinom t = cpolinom.Copy(p); cpolinom res = new cpolinom("1", p.mod); mas_k = Convert_to_DBNS_2(n, A, B); if (mas_k[0, 0] == -1) res = inv(t, ir); else if (mas_k[0, 0] == 1) res = t; for (int i = 0; i < mas_k.GetLength(0) - 1; i++) { BigInteger u = mas_k[i, 1] - mas_k[i + 1, 1]; BigInteger v = mas_k[i, 2] - mas_k[i + 1, 2]; for (int j = 0; j < u; j++) res = mul(res, res) % ir; for (int j = 0; j < v; j++) res = mul(res, mul(res, res)) % ir; if (mas_k[i+1, 0] < 0) res = mul(res, inv(t, ir)) % ir; else res = mul(res, t) % ir; } for (int i = 0; i < mas_k[mas_k.GetLength(0) - 1, 1]; i++) res = mul(res, res) % ir; for (int i = 0; i < mas_k[mas_k.GetLength(0) - 1, 2]; i++) res = mul(res, mul(res, res)) % ir; return res; }
public void Inverse_GENDATA_Test1() { var tileSize = 30; var diff = 0.0; // prepare data var data = MatrixHelpers.Tile(Matrix<double>.CreateNewRandomDoubleMatrix(200, 200), tileSize); var clonedData = data.Clone(); // the parallel version of Inverse expectes its data to be LU Factorized, the tiled version does not. data = data.GetLU(); var opData1 = new OperationResult<double>(data); Matrix<Matrix<double>> expected = clonedData.Inverse(); OperationResult<double> actual; var mProducer = new Inverse<double>(opData1, out actual); var pm = new Manager(mProducer); pm.Start(); pm.Join(); MatrixHelpers.IsDone(actual); MatrixHelpers.Diff(expected, actual.Data, diff); MatrixHelpers.Compare(expected, actual.Data); }
public static cpolinom NAFBinaryRL(cpolinom p, cpolinom ir, Multi mul, BigInteger n, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); cpolinom c = cpolinom.Copy(p); List<BigInteger> x = bif.NAF(n); for (int i = 0; i < x.Count; i++) { if (x[i] == 1) res = mul(res, c) % ir; else if (x[i] == -1) res = mul(res, inv(c, ir)) % ir; c = mul(c, c) % ir; } return res; }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns>The result of analysis.</returns> public string Analyze(Inverse exp) { return(ToString(exp, "inverse({0})")); }
public static IEnumerable<Measurement> Inverse() { foreach (int threadCount in ThreadCountGenerator()) foreach (int tileSize in TileSizeGenerator) yield return new OneBlockMatrixMeasurement { TileSize = tileSize, ThreadCount = threadCount, Execute = (a, tc) => { var opRes1 = new OperationResult<double>(a); OperationResult<double> actual; var producer = new Inverse<double>(opRes1, out actual); Runner(producer, tc); } }; }
/// <summary> /// Creates an expression object from <see cref="FunctionToken"/>. /// </summary> /// <param name="token">The function token.</param> /// <returns>An expression.</returns> protected virtual IExpression CreateFunction(FunctionToken token) { IExpression exp; switch (token.Function) { case Functions.Add: exp = new Add(); break; case Functions.Sub: exp = new Sub(); break; case Functions.Mul: exp = new Mul(); break; case Functions.Div: exp = new Div(); break; case Functions.Pow: exp = new Pow(); break; case Functions.Absolute: exp = new Abs(); break; case Functions.Sine: exp = new Sin(); break; case Functions.Cosine: exp = new Cos(); break; case Functions.Tangent: exp = new Tan(); break; case Functions.Cotangent: exp = new Cot(); break; case Functions.Secant: exp = new Sec(); break; case Functions.Cosecant: exp = new Csc(); break; case Functions.Arcsine: exp = new Arcsin(); break; case Functions.Arccosine: exp = new Arccos(); break; case Functions.Arctangent: exp = new Arctan(); break; case Functions.Arccotangent: exp = new Arccot(); break; case Functions.Arcsecant: exp = new Arcsec(); break; case Functions.Arccosecant: exp = new Arccsc(); break; case Functions.Sqrt: exp = new Sqrt(); break; case Functions.Root: exp = new Root(); break; case Functions.Ln: exp = new Ln(); break; case Functions.Lg: exp = new Lg(); break; case Functions.Lb: exp = new Lb(); break; case Functions.Log: exp = new Log(); break; case Functions.Sineh: exp = new Sinh(); break; case Functions.Cosineh: exp = new Cosh(); break; case Functions.Tangenth: exp = new Tanh(); break; case Functions.Cotangenth: exp = new Coth(); break; case Functions.Secanth: exp = new Sech(); break; case Functions.Cosecanth: exp = new Csch(); break; case Functions.Arsineh: exp = new Arsinh(); break; case Functions.Arcosineh: exp = new Arcosh(); break; case Functions.Artangenth: exp = new Artanh(); break; case Functions.Arcotangenth: exp = new Arcoth(); break; case Functions.Arsecanth: exp = new Arsech(); break; case Functions.Arcosecanth: exp = new Arcsch(); break; case Functions.Exp: exp = new Exp(); break; case Functions.GCD: exp = new GCD(); break; case Functions.LCM: exp = new LCM(); break; case Functions.Factorial: exp = new Fact(); break; case Functions.Sum: exp = new Sum(); break; case Functions.Product: exp = new Product(); break; case Functions.Round: exp = new Round(); break; case Functions.Floor: exp = new Floor(); break; case Functions.Ceil: exp = new Ceil(); break; case Functions.Derivative: exp = new Derivative(); break; case Functions.Simplify: exp = new Simplify(); break; case Functions.Del: exp = new Del(); break; case Functions.Define: exp = new Define(); break; case Functions.Vector: exp = new Vector(); break; case Functions.Matrix: exp = new Matrix(); break; case Functions.Transpose: exp = new Transpose(); break; case Functions.Determinant: exp = new Determinant(); break; case Functions.Inverse: exp = new Inverse(); break; case Functions.If: exp = new If(); break; case Functions.For: exp = new For(); break; case Functions.While: exp = new While(); break; case Functions.Undefine: exp = new Undefine(); break; case Functions.Im: exp = new Im(); break; case Functions.Re: exp = new Re(); break; case Functions.Phase: exp = new Phase(); break; case Functions.Conjugate: exp = new Conjugate(); break; case Functions.Reciprocal: exp = new Reciprocal(); break; case Functions.Min: exp = new Min(); break; case Functions.Max: exp = new Max(); break; case Functions.Avg: exp = new Avg(); break; case Functions.Count: exp = new Count(); break; case Functions.Var: exp = new Var(); break; case Functions.Varp: exp = new Varp(); break; case Functions.Stdev: exp = new Stdev(); break; case Functions.Stdevp: exp = new Stdevp(); break; default: exp = null; break; } if (exp is DifferentParametersExpression diff) { diff.ParametersCount = token.CountOfParams; } return(exp); }
public static cpolinom meth7_2(cpolinom p, cpolinom ir, Multi mul, BigInteger n, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); cpolinom c = cpolinom.Copy(p); BigInteger k = n; while (k >= 1) { BigInteger temp = 0; if (k % 2 != 0) { temp = 2 - k % 4; k -= temp; } if (temp == 1) res = mul(res, c) % ir; else if (temp == -1) res = mul(res, inv(c, ir)) % ir; k = k / 2; c = mul(c, c) % ir; } return res; }
public static cpolinom NAFBinaryLR(cpolinom p, cpolinom ir, Multi mul, BigInteger n, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); cpolinom c = cpolinom.Copy(p); List<BigInteger> x = bif.NAF(n); for (int i = x.Count - 1; i > -1; i--) { res = mul(res, res) % ir; if (x[i] == 1) res = mul(res, c) % ir; else if (x[i] == -1) res = mul(res, inv(c, ir)) % ir; } return res; }
public static cpolinom NAFWindowLR(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int w, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); List<BigInteger> x = bif.NAF(n); int pow = (int)Math.Pow(2, w - 1); List<cpolinom> table = NAFLRTable(p, ir, mul, pow, w); for (int i = x.Count - 1; i > -1 ; i--) { res = mul(res, res) % ir; if (x[i] > 0) res = mul(res, table[(int)(x[i] / 2)]) % ir; else if (x[i] < 0) res = mul(res, inv(table[(int)(-x[i] / 2)], ir)) % ir; } return res; }
public static cpolinom NAFWindowRL(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int w, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); List<BigInteger> x = bif.NAF(n); int pow = (int)Math.Pow(2, w - 1); List<cpolinom> table = NAFRLTable(p, ir, mul, pow, w); for (int i = 1; i < pow; i += 2) table.Add(BinaryRL(p, ir, mul, i)); for (int i = 0; i < x.Count; i++) { if (x[i] > 0) res = mul(res, table[(int)(x[i] / 2)]) % ir; else if (x[i] < 0) res = mul(res, inv(table[(int)(-x[i] / 2)], ir)) % ir; for (int j = 0; j < table.Count; j++) table[j] = mul(table[j], table[j]) % ir; } return res; }
public static cpolinom wNAFSlideLR(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int w, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); List<BigInteger> x = bif.wNAF(n, w); int pow = 2 * ((int)Math.Pow(2, w) - (int)Math.Pow((-1), w)) / 3 - 1; List<cpolinom> table = NAFLRTable(p, ir, mul, pow, w); for (int i = 0; i < x.Count; ) { List<BigInteger> max = new List<BigInteger>(); if (x[i] == 0) { max.Add(0); max.Add(1); } else max = FindLargest2(x, i, w); for (int d = 0; d < max[1]; d++) res = mul(res, res) % ir; if (max[0] > 0) res = mul(res, table[(int)(bif.Abs(x[i]) / 2)]) % ir; else if (max[0] < 0) res = mul(res, inv(table[(int)(bif.Abs(x[i]) / 2)], ir)) % ir; i = i + (int)max[1]; } return res; }
public static cpolinom wNAFSlideRL(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int w, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); List<BigInteger> x = bif.wNAF(n, w); int pow = 2 * ((int)Math.Pow(2, w) - (int)Math.Pow((-1), w)) / 3 - 1; List<cpolinom> table = NAFRLTable(p, ir, mul, pow, w); for (int i = x.Count - 1; i > -1; ) { List<BigInteger> max = FindLargest1(x, i, w); if (max[0] > 0) res = mul(res, table[(int)(bif.Abs(x[i]) / 2)]) % ir; else if (max[0] < 0) res = mul(res, inv(table[(int)(bif.Abs(x[i]) / 2)], ir)) % ir; for (int d = 0; d < max[1]; d++) for (int j = 0; j < table.Count; j++) table[j] = mul(table[j], table[j]) % ir; i = i - (int)max[1]; } return res; }
public MInverse(Inverse i, string n) { inv = i; name = n; }
public static cpolinom AddSubLR(cpolinom p, cpolinom ir, Multi mul, BigInteger n, Inverse inv) { cpolinom res = new cpolinom("1", p.mod); cpolinom c = cpolinom.Copy(p); string BinaryT = bif.ToBin(3 * n); string BinaryN = bif.ToBin(n); while (BinaryN.Length < BinaryT.Length) BinaryN = "0" + BinaryN; for (int i = 0; i < BinaryN.Length - 1; i++) { res = mul(res, res) % ir; if (BinaryT[i] != '0' && BinaryN[i] == '0') res = mul(res, c) % ir; else if (BinaryT[i] == '0' && BinaryN[i] != '0') res = mul(res, inv(c, ir)) % ir; } return res; }
private void UpdateInverse() { Inverse = Matrix.Clone(); Inverse.Invert(); }
public static cpolinom DBNS2LR(cpolinom p, cpolinom ir, Multi mul, BigInteger n, Inverse inv) { List<int[]> x = ToDBNS2LR(n); cpolinom res = cpolinom.Copy(p); for (int i = x.Count - 1; i > 0 ; i--) { for (int j = 0; j < x[i][1]; j++) res = mul(res, res) % ir; for (int j = 0; j < x[i][2]; j++) res = mul(res, mul(res, res)) % ir; if (x[i][0] == 1) res = mul(res, p) % ir; else if (x[i][0] == -1) res = mul(res, inv(p, ir)) % ir; } for (int j = 0; j < x[0][1]; j++) res = mul(res, res) % ir; for (int j = 0; j < x[0][2]; j++) res = mul(res, mul(res, res)) % ir; return res; }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> /// <exception cref="System.NotSupportedException">Always.</exception> public virtual TResult Analyze(Inverse exp) { throw new NotSupportedException(); }
public static cpolinom DBNS1LR(cpolinom p, cpolinom ir, Multi mul, BigInteger n, int A, int B, Inverse inv) { return methods.Point_Multiplication_Affine_Coord_20(p, ir, mul, n, A, B, inv); }
public void Inverse_MAPLE_100x100Test() { var tilesize = 30; var delta = 1.0E-11; var data = Matrix<double>.ReadFromFile(@"C:\Users\eh\Documents\KU\Inversion-of-Block-Tridiagonal-Matrices\Dataset\Maple Test Data\a-100x100.csv"); var expected = Matrix<double>.ReadFromFile(@"C:\Users\eh\Documents\KU\Inversion-of-Block-Tridiagonal-Matrices\Dataset\Maple Test Data\a-inverse-100x100.csv"); var tiledData = MatrixHelpers.Tile(data, tilesize); tiledData = tiledData.GetLU(); var opData1 = new OperationResult<double>(tiledData); OperationResult<double> actualOR; var mProducer = new Inverse<double>(opData1, out actualOR); var pm = new Manager(mProducer, 1); pm.Start(); pm.Join(); MatrixHelpers.IsDone(actualOR); var actual = MatrixHelpers.Untile(actualOR.Data); MatrixHelpers.Diff(expected, actual, delta); MatrixHelpers.Compare(expected, actual, delta); }
public Point ScreenToEditor(Point screenPos) { Point[] points = new Point[] { screenPos }; Inverse.TransformPoints(points); return(points[0]); }
public static cpolinom DBNS2RL(cpolinom p, cpolinom ir, Multi mul, BigInteger n, Inverse inv) { List<int[]> x = ToDBNS2RL(n); cpolinom res = new cpolinom("1", p.mod); cpolinom t = cpolinom.Copy(p); for (int i = x.Count - 1; i > -1; i--) { for (int j = 0; j < x[i][1]; j++) t = mul(t, t) % ir; for (int j = 0; j < x[i][2]; j++) t = mul(t, mul(t, t)) % ir; if (x[i][0] == 1) res = mul(res, t) % ir; else if (x[i][0] == -1) res = mul(res, inv(t, ir)) % ir; } return res; }