Пример #1
0
 public static Lst <Polynomize.Equation> Substitute(Lst <Polynomize.Equation> eqs, Lst <Subst> substs, Style style)
 {
     if (eqs is Cons <Polynomize.Equation> cons)
     {
         Polynomize.Equation eq   = cons.head;
         Lst <Monomial>[]    args = new Lst <Monomial> [eq.args.Length];
         for (int i = 0; i < eq.args.Length; i++)
         {
             args[i] = Substitute(eq.args[i], substs, style);
         }
         Subst subst = Lookup(eq.var, substs);
         if (subst == null)
         {
             return
                 (new Cons <Polynomize.Equation>(new Polynomize.Equation(eq.var, eq.op, args, eq.splitOp),
                                                 Substitute(cons.tail, substs, style)));
         }
         else
         {
             return
                 (new Cons <Polynomize.Equation>(new Polynomize.Equation(subst.plus, eq.op, args, splitOp: Polynomize.Split.Pos),
                                                 new Cons <Polynomize.Equation>(new Polynomize.Equation(subst.minus, eq.op, args, splitOp: Polynomize.Split.Neg),
                                                                                Substitute(cons.tail, substs, style))));
         }
     }
     else
     {
         return(Polynomize.Equation.nil);
     }
 }
Пример #2
0
        public void SubstTest()
        {
            /*
             * SUBST ( s1 s2 s3 -- s )
             * s1 is the string to operate on, s2 is the string to change all occurrences of s3 into, and s is resultant string. For example:
             *
             *  "HEY_YOU_THIS_IS" " " "_" subst
             *
             * results in
             *
             *  "HEY YOU THIS IS"
             *
             * s2 and s3 may be of any length.
             */
            var stack = new Stack <ForthDatum>();

            stack.Push(new ForthDatum("HEY_YOU_THIS_IS"));
            stack.Push(new ForthDatum(" "));
            stack.Push(new ForthDatum("_"));
            var local      = stack.ClonePreservingOrder();
            var parameters = new ForthPrimativeParameters(null, local, null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
            var result     = Subst.Execute(parameters);

            Assert.NotNull(result);
            Assert.IsTrue(result.IsSuccessful, result.Reason);

            Assert.AreEqual(1, local.Count);
            var s1 = local.Pop();

            Assert.AreEqual(ForthDatum.DatumType.String, s1.Type);
            Assert.AreEqual("HEY YOU THIS IS", s1.Value);

            Assert.AreEqual(0, local.Count);
        }
Пример #3
0
 public static Lst <Polynomize.PolyODE> PositivizeODEs(Lst <Polynomize.PolyODE> odes, Lst <Subst> substs, Style style)
 {
     //const int annihilationOrder = 1; // generation of annihilation reactions has been moved to Hungarize, otherwise two reactions are generated instead of one from the annihilation monomial
     if (odes is Cons <Polynomize.PolyODE> cons)
     {
         Lst <Polynomize.PolyODE> tail = PositivizeODEs(cons.tail, substs, style);
         Polynomize.PolyODE       ode  = cons.head;
         Polynomial poly  = Substitute(ode.poly, substs, style);
         Subst      subst = Lookup(ode.var, substs);
         if (subst == null)   // we do not split this ODE
         {
             return(new Cons <Polynomize.PolyODE>(new Polynomize.PolyODE(ode.var, poly, split: Polynomize.Split.No), tail));
         }
         else     // we split this ODE
         {
             (Lst <Monomial> positive, Lst <Monomial> negative) = Separate(poly.monomials, style);
             return(new Cons <Polynomize.PolyODE>(new Polynomize.PolyODE(subst.plus, positive, split: Polynomize.Split.Pos),
                                                  new Cons <Polynomize.PolyODE>(new Polynomize.PolyODE(subst.minus, negative, split: Polynomize.Split.Neg),
                                                                                tail)));
             //Monomial damp = new Monomial(Flow.minusOne, Factor.Cons(new Factor(subst.plus, annihilationOrder), Factor.Singleton(new Factor(subst.minus, annihilationOrder))), style); // annihilation monomial
             //return new Cons<Polynomize.PolyODE>(new Polynomize.PolyODE(subst.plus, Monomial.Cons(damp, positive), split:Polynomize.Split.Pos),
             //       new Cons<Polynomize.PolyODE>(new Polynomize.PolyODE(subst.minus, Monomial.Cons(damp, negative), split:Polynomize.Split.Neg),
             //       tail));
         }
     }
     else
     {
         return(Polynomize.PolyODE.nil);
     }
 }
Пример #4
0
 // substitute x with (x+ - x-) in a flow that is already in polynomial form as a result of Polynomize
 public static Lst <Polynomize.PolyODE> Substitute(Lst <Polynomize.PolyODE> odes, Lst <Subst> substs, Style style)
 {
     if (odes is Cons <Polynomize.PolyODE> cons)
     {
         Polynomize.PolyODE ode = cons.head;
         Subst subst            = Lookup(ode.var, substs);
         if (subst == null)
         {
             return(new Cons <Polynomize.PolyODE>(new Polynomize.PolyODE(ode.var, Substitute(ode.poly, substs, style), ode.split),
                                                  Substitute(cons.tail, substs, style)));
         }
         else     // this should never happen because we split ODEs in PositivizeODEs
         {
             throw new Error("Polynomize.Substitute");
             //return
             //     new Cons<Polynomize.PolyODE>(new Polynomize.PolyODE(subst.plus, Substitute(ode.poly, substs, style)),
             //        new Cons<Polynomize.PolyODE>(new Polynomize.PolyODE(subst.minus, Substitute(ode.poly, substs, style)),
             //            Substitute(cons.tail, substs, style)));
         }
     }
     else
     {
         return(Polynomize.PolyODE.nil);
     }
 }
        private void checkMountedDrive(char mountDrive)
        {
            bool mountedFolderAccess = Subst.HasWriteAccessToFolder(mountDrive + @":\");

            if (!mountedFolderAccess)
            {
                logText(string.Format("WARNING: The mounted drive '{0}:' seems to be not writeableVirtual drive '{0}:'", mountDrive));
            }
        }
        private void mapDrive(char mountDrive, UsbDisk disk, bool unmapfirst = false)
        {
            if (unmapfirst)
            {
                Subst.UnmapDrive(mountDrive); // Unmount the bad one
            }
            string mountedFolder = disk.Name + @"\";

            Subst.MapDrive(mountDrive, mountedFolder); // mount the new one
            logText(string.Format("Virtual drive '{0}:' mounted to disk '{1}' ({2}/{3}) ", mountDrive, disk.Name, disk.Volume, disk.SerialNumber));
        }
        private void initMappedDrive()
        {
            var data = Enumerable.Range('D', 23).Select(x =>
                                                        new
            {
                Value = (char)x,
                Text  = Subst.devName((char)x)
            }).ToList();

            mappedDriveComboBox.ValueMember   = "Value";
            mappedDriveComboBox.DisplayMember = "Text";
            mappedDriveComboBox.DataSource    = data;
        }
Пример #8
0
        public static Lst <Monomial> Substitute(Factor factor, Lst <Subst> substs, Style style)
        {
            Subst subst = Lookup(factor.variable, substs);

            if (subst == null)
            {
                return(Monomial.Singleton(new Monomial(factor)));
            }
            else
            {
                return(Monomial.Power(Monomial.Cons(new Monomial(new Factor(subst.plus)), Monomial.Singleton(new Monomial(Flow.minusOne, new Factor(subst.minus), style))), factor.power, style));
            }
        }
 private void OnMappedDriveComboBoxSelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         allowStateChangeEvent = false;
         if (mappedDrive != previousMappedDrive)
         {
             if (Subst.IsMappedDrive(previousMappedDrive))
             {
                 logText(string.Format("Previous virtual drive '{0}:' removed since no disk attached", previousMappedDrive));
                 Subst.UnmapDrive(previousMappedDrive);
             }
         }
     }
     finally
     {
         allowStateChangeEvent = true;
     }
     SaveConfig(true);
 }
Пример #10
0
 public static Lst <SpeciesFlow> UnsplitVars(Lst <Polynomize.PolyODE> odes, Lst <Subst> substs)
 {
     if (odes is Cons <Polynomize.PolyODE> cons)
     {
         Lst <SpeciesFlow> tail  = UnsplitVars(cons.tail, substs);
         Subst             subst = Lookup(cons.head.var, substs);
         if (subst == null)
         {
             return(new Cons <SpeciesFlow>(cons.head.var, tail));
         }
         else
         {
             return(tail);
         }
     }
     else
     {
         return(new Nil <SpeciesFlow>());
     }
 }
Пример #11
0
        /// <summary>
        /// Unlifts the specified expression by rewriting KeyValuePair&lt;Uri, T&gt; occurrences by uses of T, where T corresponds to the specified entity type.
        /// </summary>
        /// <param name="expression">Expression to unlift.</param>
        /// <param name="entityType">Entity type to search for and to perform the unlifting for.</param>
        /// <returns>Expression with occurrences of KeyValuePair&lt;Uri, T&gt; replaced for uses of T.</returns>
        /// <example>
        /// <code>(IQueryable&lt;KeyValuePair&lt;Uri, Foo&gt;&gt; xs) => xs.Where(x => x.Key == bar &amp;&amp; x.Value.Qux == baz)</code>
        /// becomes
        /// <code>(IQueryable&lt;Foo&gt; xs) => xs.Where(x => x.Uri == bar &amp;&amp; x.Qux == baz)</code>
        /// </example>
        public static Expression Unlift(Expression expression, Type entityType)
        {
            var result = new Subst(entityType).Visit(expression);

            return(result);
        }
        private void updateVirtualDriveMapping()
        {
            try
            {
                allowStateChangeEvent = false;

                bool   isDriveMapped        = false;
                int    driveMappedIndex     = -1;
                string driveStatusText      = String.Empty;
                char   virtualDrive         = mappedDrive; // Copy localy since comes from combobox
                bool   isVirtualDriveMapped = Subst.IsMappedDrive(virtualDrive);

                if (!isVirtualDriveMapped && Subst.IsDriveMounted(virtualDrive))
                {
                    // Husten, when have a problem, we cannot mount anything to this permanent drive
                    logText("WARNING : Target mapping drive '" + virtualDrive + "' is a permanent physical drive!");
                    SetNotifyInfo(isDriveMapped, string.Format("Invalid target drive '{0}:'", virtualDrive));
                    return;
                }

                IList <UsbDisk> usbDisks = disks.ContainsVolumeSerials(usbDrivesToMount);

                if (usbDisks.Count > 0) // A backup disk is available to be mounted
                {
                    UsbDisk diskToMount = usbDisks.First();

                    driveMappedIndex = Array.IndexOf(usbDrivesToMount, diskToMount.SerialNumber) + 1;

                    isDriveMapped = true;

                    if (isVirtualDriveMapped)
                    {
                        if (Subst.IsDriveMounted(virtualDrive))
                        {
                            // A drive is mapped and mounted, is it the good one ?
                            string mountedVolumeSN = Subst.getDriveSerialNumber(virtualDrive);
                            if (diskToMount.SerialNumber != mountedVolumeSN)
                            {
                                mapDrive(virtualDrive, diskToMount, true);
                            }
                            else
                            {
                                // The mapped drive is already the good one, so should be fine
                                logText(string.Format("Virtual drive '{0}:' already set and mounted to disk '{1}' ({2}/{3}) ", virtualDrive, diskToMount.Name, diskToMount.Volume, diskToMount.SerialNumber));
                            }
                        }
                        else // mapped, but not connected ....
                             // probably mapped to the wrong one
                        {
                            mapDrive(virtualDrive, diskToMount, true);
                        }
                    }
                    else // nothing mapped, so add the mapping
                    {
                        mapDrive(virtualDrive, diskToMount);
                    }
                    checkMountedDrive(virtualDrive);
                    driveStatusText = string.Format("{0}/{1} {2} mapped to drive {3}:", diskToMount.Volume, driveMappedIndex, diskToMount.Name, virtualDrive);
                }
                else // cleanup mounted disk
                {
                    if (isVirtualDriveMapped)
                    {
                        logText(string.Format("Virtual drive '{0}:' removed since no disk available", virtualDrive));
                        Subst.UnmapDrive(virtualDrive);
                    }

                    driveStatusText = string.Format("No USB disk on {0} mapped to drive {1}:", usbDrivesToMount.Count(), virtualDrive);
                }
                SetNotifyInfo(isDriveMapped, driveStatusText);

                previousMappedDrive = virtualDrive;
            }
            finally
            {
                allowStateChangeEvent = true;
            }
        }
Пример #13
0
 static B ToB(A a_, int n_)
 {
     return(Subst.Expr((A a, int n) => new B {
         L = a.S.Length + n
     }));
 }
Пример #14
0
 static B ToB(A a_, int n_, string s_)
 {
     return(Subst.Expr((A a, int n, string s) => new B {
         L = (a.S + s).Length + n
     }));
 }
Пример #15
0
 [Substitute] static B ToB_MoreArgs(A a)
 {
     return(Subst.Expr((A aa, int n) => new B()));
 }
Пример #16
0
 [Substitute] static B ToB_FewerArgs(A a)
 {
     return(Subst.Expr(() => new B()));
 }
Пример #17
0
 [Substitute] static B ToB_WrongTypeOfArgs(A a)
 {
     return(Subst.Expr(( B b ) => new B()));
 }
Пример #18
0
 [Substitute] static B ToB_WrongReturnType(A a)
 {
     Subst.Expr(( A b ) => new A()); return(null);
 }
Пример #19
0
 static B ToB(A a_)
 {
     return(Subst.Expr(( A a ) => new B {
         L = a.S.Length
     }));
 }