コード例 #1
0
        public ProdGrid(long size, iProgressIndicator ProgressReceptor)
        {
            long RIndex = 0;
            long IIndex = 0;

            minFactNum      = long.MaxValue;
            GridSize        = size;
            LowerLeftCorner = new ComplNum(-size, -size);
            long ArrSize = (2 * size + 1);

            FactorSets = new ComplFactors[ArrSize, ArrSize];
            double ItemsToAnalyze = ArrSize * ArrSize;

            for (RIndex = 0; RIndex < ArrSize; RIndex++)
            {
                for (IIndex = 0; IIndex < ArrSize; IIndex++)
                {
                    FactorSets[RIndex, IIndex] = new ComplFactors(new ComplNum(LowerLeftCorner.Re + RIndex, LowerLeftCorner.Im + IIndex));
                    try
                    {
                        minFactNum = Math.Min(minFactNum, FactorSets[RIndex, IIndex].NumFactors);
                    }
                    catch
                    {
                        MessageBox.Show("NullException in ProdGrid Constructor after call to ComplFactors constructor");
                        //indicate problem during search
                        ProgressReceptor.UpdateProgress(-1);
                    }
                }
                double CurrentProgress = ((RIndex * ArrSize) + IIndex) / ItemsToAnalyze;
                ProgressReceptor.UpdateProgress(CurrentProgress);
            }
            //indicate that searcn is not running anymore
            ProgressReceptor.UpdateProgress(2);
        }
コード例 #2
0
 public void Assign(ComplNum val)
 {
     try
     {
         Re = val.Re;
         Im = val.Im;
     }
     catch
     { MessageBox.Show("NullException in ComplNum.Assign"); }
 }
コード例 #3
0
        public static ComplNum Sub(ComplNum a, ComplNum b)
        {
            ComplNum Result = new ComplNum();

            try
            {
                Result.Re = a.Re - b.Re;
                Result.Im = a.Im - b.Im;
            }
            catch { MessageBox.Show("NullException in ComplNumCalc.Sub"); }
            return(Result);
        }
コード例 #4
0
        public static ComplNum Mul(ComplNum a, ComplNum b)
        {
            ComplNum Result = new ComplNum();

            try
            {
                Result.Re = (a.Re * b.Re) - (a.Im * b.Im);
                Result.Im = (a.Im * b.Re) + (b.Im * a.Re);
            }
            catch { MessageBox.Show("NullException in ComplNumCalc.Mul"); }
            return(Result);
        }
コード例 #5
0
 public ComplFactors GetFactors(ComplNum Prod)
 {
     if (Math.Abs(Prod.Re) > GridSize || Math.Abs(Prod.Re) > GridSize)
     {
         return(null);
     }
     else
     {
         long RIndex = Prod.Re - LowerLeftCorner.Re;
         long IIndex = Prod.Im - LowerLeftCorner.Im;
         return(FactorSets[RIndex, IIndex]);
     }
 }
コード例 #6
0
        public bool Equal(ComplNum Comparator)
        {
            bool Result = false;

            try
            {
                if ((Comparator.Re == Re) && (Comparator.Im == Im))
                {
                    Result = true;
                }
            }
            catch {
                MessageBox.Show("NullException in ComplNum.Equal");
            }
            return(Result);
        }
コード例 #7
0
        public bool AppendNoRedundancy(ComplNum fact1, ComplNum fact2)
        {
            bool       success  = false;
            bool       notfound = false;
            FactorList current  = First;

            try
            {
                notfound = true;
                while (notfound && (current != null))
                {
                    if ((current.val1.Equal(fact1) && current.val2.Equal(fact2)) || (current.val1.Equal(fact2) && current.val2.Equal(fact1)))
                    {
                        notfound = false;
                    }
                    current = current.next;
                }
            }
            catch { MessageBox.Show("NullException in ComplFactors.AppendNoRedundancy during check"); }
            if (notfound)
            {
                try
                {
                    NumFactors++;
                    if (First == null)
                    {
                        First = new FactorList();
                        Last  = First;
                    }
                    else
                    {
                        Last.next = new FactorList();
                        Last      = Last.next;
                    }
                    Last.val1.Assign(fact1);
                    Last.val2.Assign(fact2);
                    success = true;
                }
                catch { MessageBox.Show("NullException in ComplFactors.AppendNoRedundancy during assignment"); }
            }
            return(success);
        }
コード例 #8
0
 private void ProdIndicator_Click(object sender, MouseButtonEventArgs e)
 {
     // search for clicked ellipse in array to get the corresponding number
     if (FoundProducts != null)
     {
         SelectedProd = FindIndicator((Ellipse)sender, FoundProducts);
         if (SelectedProd != null) //found?
         {
             // get all factor pairs
             if (Factors != null)
             {
                 ComplFactors CurFactors = Factors.GetFactors(SelectedProd);
                 if (CurFactors != null)
                 {// color all factors w/ equal colors for factor pairs and special markings for "double" factors
                     RecolorFactors(SelectedProd, CurFactors);
                 }
             }
         }
     }
 }
コード例 #9
0
 public void Append(ComplNum fact1, ComplNum fact2)
 {
     NumFactors++;
     if (First == null)
     {
         First = new FactorList();
         Last  = First;
     }
     else
     {
         Last.next = new FactorList();
         Last      = Last.next;
     }
     try
     {
         Last.val1.Assign(fact1);
         Last.val2.Assign(fact2);
     }
     catch { MessageBox.Show("NullException in ComplFactors.Append"); }
 }
コード例 #10
0
        private ComplNum FindIndicator(Ellipse SearchTarget, Ellipse[,] SearchSpace)
        {
            ComplNum SearchRes = null;

            if (SearchSpace != null)
            {
                long rows = SearchSpace.GetLength(0);
                long cols = SearchSpace.GetLength(1);
                for (long i = 0; i < rows; i++)
                {
                    for (long j = 0; j < cols; j++)
                    {
                        if (SearchSpace[i, j] == SearchTarget)
                        {
                            SearchRes = new ComplNum(j - size, i - size);
                        }
                    }
                }
            }
            return(SearchRes);
        }
コード例 #11
0
        private void ShowFactors_Click(object sender, RoutedEventArgs e)
        {
            double       diameter;
            bool         critfulfilled;
            ComplFactors CurrentFactors;

            //make button unavailable
            ShowFactors.IsEnabled = false;

            //clean up from possible previous drawing
            CleanUpDrawingElements();
            SelectedProd = null;

            //actual new drawing
            diameter = GetCurrentDiameter();


            //actual show action
            FoundProducts    = new Ellipse[2 * size + 1, 2 * size + 1];
            FoundFactors     = new Ellipse[2 * size + 1, 2 * size + 1];
            CorrectFactorNum = new bool[2 * size + 1, 2 * size + 1];
            for (long i = 0; i < ((2 * size) + 1); i++)
            {
                for (long j = 0; j < ((2 * size) + 1); j++)
                {
                    CorrectFactorNum[i, j] = false; // general assumption: current number does *not* fulfill the search criterion for the number of factor pairs.
                    if ((j - size == 0) && (i - size == 0))
                    {
                        // special marking for origin
                        FoundProducts[i, j]         = ResultIndicator(diameter, smallmargfract, i, j, 100, 255, 100, true, NumGrid);
                        FoundProducts[i, j].ToolTip = "0+0i (origin, #of factor pairs infinite)";
                        FoundFactors[i, j]          = ResultIndicator(diameter, bigmargfract, i, j, 50, 255, 50, false, NumGrid);
                    }
                    else
                    {
                        ComplNum CurProd = new ComplNum(j - size, i - size);
                        if (this.Factors != null)
                        {
                            CurrentFactors = Factors.GetFactors(CurProd);
                            if (SearchLEq)
                            {
                                critfulfilled = ((CurrentFactors.NumFactors >= minfactors) && (CurrentFactors.NumFactors <= maxfactors));
                            }
                            else
                            {
                                critfulfilled = (CurrentFactors.NumFactors == maxfactors);
                            }
                            //if ((CurrentFactors.NumFactors>=minfactors)&& (CurrentFactors.NumFactors <= maxfactors))
                            if (critfulfilled)
                            {
                                // actions if current number turns out to fulfill the search criterion
                                FoundProducts[i, j]    = ResultIndicator(diameter, smallmargfract, i, j, 100, 100, 255, true, NumGrid);
                                CorrectFactorNum[i, j] = true;
                            }
                            else
                            {
                                FoundProducts[i, j] = ResultIndicator(diameter, smallmargfract, i, j, 150, 150, 150, true, NumGrid);
                            }
                            FoundFactors[i, j]          = ResultIndicator(diameter, bigmargfract, i, j, 100, 100, 100, false, NumGrid);
                            FoundProducts[i, j].ToolTip = CurProd.ToString() + " # Factor Pairs: " + CurrentFactors.NumFactors + ".\nClick to show factor pairs.";
                        }
                        else
                        {
                            // fall-back if something is wrong with the data base
                            FoundProducts[i, j]         = ResultIndicator(diameter, smallmargfract, i, j, 255, 100, 100, true, NumGrid);
                            FoundProducts[i, j].ToolTip = CurProd.ToString() + " (No Info on Factors found)";
                            FoundFactors[i, j]          = ResultIndicator(diameter, bigmargfract, i, j, 255, 50, 50, false, NumGrid);
                        }
                    }
                }
            }
        }
コード例 #12
0
 private void FactIndicator_Click(object sender, MouseButtonEventArgs e)
 {
     if (SelectedProd != null)// react only if previously some number has been selected as product
     {
         // search for clicked ellipse in array to get the corresponding number
         if (FoundFactors != null)
         {
             ComplNum SelectedFactor = FindIndicator((Ellipse)sender, FoundFactors);
             if (SelectedFactor != null)//found?
             {
                 // get all factor pairs
                 if (Factors != null)
                 {
                     ComplFactors CurFactors = Factors.GetFactors(SelectedProd);
                     if (CurFactors != null)
                     {
                         //look if the currently selected number is actually a factor of the previously selected product
                         FactorList CurFactPair = CurFactors.First;
                         //get current necessary thickness of edge to be seen and not be too big.
                         double EdgeThickness = GetCurrentDiameter() * smallmargfract;
                         while (CurFactPair != null) //go through *all* factor pairs to clean up edges from possible previous factor selection
                         {
                             //clean up any previous black edges from non-double factors
                             if (!CurFactPair.val1.Equal(CurFactPair.val2))
                             {
                                 FoundFactors[CurFactPair.val1.Im + size, CurFactPair.val1.Re + size].StrokeThickness = 0;
                                 FoundFactors[CurFactPair.val2.Im + size, CurFactPair.val2.Re + size].StrokeThickness = 0;
                             }
                             // is the lastly selected number part of the current factor pair?
                             if (CurFactPair.val1.Equal(SelectedFactor))
                             {
                                 // only need to do sth if no "double factor"
                                 if (!CurFactPair.val2.Equal(SelectedFactor))
                                 {
                                     // recolor current and corresponding factor's inner edge
                                     SolidColorBrush myBrush = new SolidColorBrush();
                                     myBrush.Color                     = Color.FromRgb(0, 0, 0);
                                     ((Ellipse)sender).Stroke          = myBrush;
                                     ((Ellipse)sender).StrokeThickness = EdgeThickness;
                                     FoundFactors[CurFactPair.val2.Im + size, CurFactPair.val2.Re + size].Stroke          = myBrush;
                                     FoundFactors[CurFactPair.val2.Im + size, CurFactPair.val2.Re + size].StrokeThickness = EdgeThickness;
                                 }
                             }
                             else if (CurFactPair.val2.Equal(SelectedFactor))
                             {
                                 //possibility of "double factor" already excluded
                                 // recolor current and corresponding factor's inner edge
                                 SolidColorBrush myBrush = new SolidColorBrush();
                                 myBrush.Color                     = Color.FromRgb(0, 0, 0);
                                 ((Ellipse)sender).Stroke          = myBrush;
                                 ((Ellipse)sender).StrokeThickness = EdgeThickness;
                                 FoundFactors[CurFactPair.val1.Im + size, CurFactPair.val1.Re + size].Stroke          = myBrush;
                                 FoundFactors[CurFactPair.val1.Im + size, CurFactPair.val1.Re + size].StrokeThickness = EdgeThickness;
                             }
                             else
                             {
                                 //if current selected factor is not part
                             }
                             CurFactPair = CurFactPair.next;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #13
0
        private void RecolorFactors(ComplNum Prod, ComplFactors Factors)
        {
            if (FoundFactors != null)
            {
                // cleanup before special coloring
                StandardColorFactors();
                StandardOutlineFactors();
                StandardOutlineProducts();
                StandardToolTipFactors();

                //actual re-color action
                double diameter = GetCurrentDiameter();
                // mark the selected product
                if (FoundProducts != null)
                {
                    FoundProducts[Prod.Im + size, Prod.Re + size].StrokeThickness = diameter * smallmargfract;
                }
                //mark factors
                long FactNum = Factors.NumFactors;
                SolidColorBrush[] BrushList = Colors(FactNum);
                long       ColInd           = 0;
                FactorList CurFactPair      = Factors.First;
                while (CurFactPair != null)
                {
                    if (CurFactPair.val1.Equal(CurFactPair.val2))
                    {
                        long i = CurFactPair.val1.Im + size;
                        long j = CurFactPair.val1.Re + size;
                        if (FoundFactors[i, j] != null)
                        {
                            FoundFactors[i, j].StrokeThickness = diameter * smallmargfract;
                            FoundFactors[i, j].Fill            = BrushList[ColInd];
                            FoundFactors[i, j].ToolTip         = "Factor " + CurFactPair.val1.ToString() +
                                                                 " (both factors of " + Prod.ToString() + " identical)";
                        }
                    }
                    else
                    {
                        long i = CurFactPair.val1.Im + size;
                        long j = CurFactPair.val1.Re + size;
                        if (FoundFactors[i, j] != null)
                        {
                            FoundFactors[i, j].Fill = BrushList[ColInd];
                        }
                        FoundFactors[i, j].ToolTip = "Factor " + CurFactPair.val1.ToString() +
                                                     " (corresponding factor of " + Prod.ToString() + ": "
                                                     + CurFactPair.val2.ToString() + ").\n Click to show corresponding factor.";
                        i = CurFactPair.val2.Im + size;
                        j = CurFactPair.val2.Re + size;
                        if (FoundFactors[i, j] != null)
                        {
                            FoundFactors[i, j].Fill = BrushList[ColInd];
                        }
                        FoundFactors[i, j].ToolTip = "Factor " + CurFactPair.val2.ToString() +
                                                     " (corresponding factor of " + Prod.ToString() + ": "
                                                     + CurFactPair.val1.ToString() + ").\n Click to show corresponding factor.";
                    }
                    ColInd++;
                    CurFactPair = CurFactPair.next;
                }
            }
        }
コード例 #14
0
        public ComplFactors(ComplNum InputProd)
        {
            double   AbsVal;
            uint     OuterPhase;
            long     Size1, Size2, Size3, OuterSize;
            long     SearchReAbs1, SearchImAbs1, SearchReAbs2, SearchImAbs2;
            ComplNum Fact1, Fact2, Prod;

            AbsVal = 0;
            Size1  = 0;
            Size2  = 0;
            Size3  = 0;
            Fact1  = null;
            Fact2  = null;
            Prod   = new ComplNum();

            try
            {
                AbsVal = InputProd.Absolute();
                Size3  = (long)Math.Ceiling(AbsVal);
                Size2  = (long)Math.Floor(Math.Sqrt(AbsVal) * Math.Sqrt(0.5));
                Prod.Assign(InputProd);
            }
            catch { MessageBox.Show("NullException in ComplFactors constructor"); }
            First      = null;
            Last       = null;
            NumFactors = 0;

            for (OuterSize = Size2; OuterSize <= Size3; OuterSize++)
            {
                OuterPhase   = 0;
                SearchReAbs1 = -OuterSize;
                SearchImAbs1 = -OuterSize;
                Size1        = (long)Math.Ceiling(AbsVal / ((double)OuterSize));
                while (OuterPhase < 4)
                {
                    for (SearchReAbs2 = 0; SearchReAbs2 <= Size1; SearchReAbs2++)
                    {
                        for (SearchImAbs2 = 0; SearchImAbs2 <= Size1; SearchImAbs2++)
                        {
                            //Test with all sign combinations
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                        }
                    }
                    if (OuterPhase == 0)
                    {
                        if (SearchImAbs1 < OuterSize)
                        {
                            SearchImAbs1++;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                    else if (OuterPhase == 1)
                    {
                        if (SearchReAbs1 < OuterSize)
                        {
                            SearchReAbs1++;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                    else if (OuterPhase == 2)
                    {
                        if (SearchImAbs1 > -OuterSize)
                        {
                            SearchImAbs1--;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                    else if (OuterPhase == 3)
                    {
                        if (SearchReAbs1 > -OuterSize)
                        {
                            SearchReAbs1--;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                }
            }
        }
コード例 #15
0
 public FactorList()
 {
     val1 = new ComplNum();
     val2 = new ComplNum();
     next = null;
 }