Ejemplo n.º 1
0
 public HilbertVector(Unit u, int power)
 {
     value  = (SuperDouble)1.0;
     vector = new List <UnitPower> ()
     {
         new UnitPower(u, power)
     };
     while (vector.Any((UnitPower arg) => arg.unit is CompositeUnit | arg.unit.baseUnit != null))
     {
         int j = vector.FindIndex((UnitPower obj) => obj.unit is CompositeUnit | obj.unit.baseUnit != null);
         if (vector[j].unit is CompositeUnit)
         {
             CompositeUnit comu = vector[j].unit as CompositeUnit;
             int           pw   = vector[j].power;
             vector.RemoveAt(j);
             foreach (UnitPower z in comu.Factors)
             {
                 vector.Add(new UnitPower(z.unit, z.power * pw));
             }
         }
         else
         {
             value    *= ((SuperDouble)vector[j].unit.baseMultiplier) ^ (SuperDouble)vector[j].power;
             vector[j] = new UnitPower(vector[j].unit.baseUnit, vector[j].power);
         }
     }
 }
Ejemplo n.º 2
0
        public static HilbertVector operator *(HilbertVector a, HilbertVector b)
        {
            List <UnitPower> up = new List <UnitPower> ();

            foreach (UnitPower ua in a.vector)
            {
                int ind = b.vector.FindIndex((UnitPower obj) => obj.unit == ua.unit);
                if (ind == -1)
                {
                    up.Add(ua); continue;
                }
                UnitPower ub = b.vector[ind];
                b.vector.RemoveAt(ind);
                UnitPower nu = new UnitPower(ua.unit, ua.power + ub.power);
                up.Add(nu);
            }
            up.AddRange(b.vector);
            return(new HilbertVector(a.value * b.value, up));
        }