Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
        public static Polynomize.Equation Rename(Dictionary <Symbol, SpeciesFlow> dict, Polynomize.Equation eq, Style style)
        {
            Lst <Monomial>[] args = new Lst <Monomial> [eq.args.Length];
            for (int i = 0; i < eq.args.Length; i++)
            {
                args[i] = Rename(dict, eq.args[i], style);
            }
            if (dict.ContainsKey(eq.var.species) && eq.splitOp != Polynomize.Split.No)
            {
                throw new Error("Positivize.Rename");
            }
            SpeciesFlow newVar = dict.ContainsKey(eq.var.species) ? dict[eq.var.species] : eq.var;

            return(new Polynomize.Equation(newVar, eq.op, args, eq.splitOp));
        }