コード例 #1
0
 public static Lst <Monomial> Substitute(Lst <Factor> factors, Lst <Subst> substs, Style style)
 {
     if (factors is Cons <Factor> cons)
     {
         return(Monomial.Product(Substitute(cons.head, substs, style), Substitute(cons.tail, substs, style), style));
     }
     else
     {
         return(Monomial.Singleton(new Monomial(1.0)));
     }
 }
コード例 #2
0
ファイル: Polynomial.cs プロジェクト: luca-cardelli/KaemikaXM
 public static Lst <Monomial> ToMonomials(Flow flow, Style style)
 {
     if (flow is NumberFlow num)
     {
         return(Monomial.Singleton(new Monomial(new NumberFlow(num.value), style)));
     }
     else if (flow is SpeciesFlow species)
     {
         return(Monomial.Singleton(new Monomial(new Factor(species))));
     }
     else if (flow is OpFlow op)
     {
         if (op.arity == 1)
         {
             if (op.op == "-")
             {
                 return(ToMonomials(op.args[0], style).Map((Monomial m) => m.Product(Flow.minusOne, style)));
             }
         }
         else if (op.arity == 2)
         {
             if (op.op == "+")
             {
                 return(Monomial.Sum(ToMonomials(op.args[0], style), ToMonomials(op.args[1], style), style));
             }
             else if (op.op == "-")
             {
                 return(Monomial.Sum(ToMonomials(op.args[0], style), ToMonomials(op.args[1], style).Map((Monomial m) => m.Product(Flow.minusOne, style)), style));
             }
             else if (op.op == "*")
             {
                 return(Monomial.Product(ToMonomials(op.args[0], style), ToMonomials(op.args[1], style), style));
             }
             else if (op.op == "^")
             {
                 if (op.args[1] is NumberFlow exp && IsInt(exp.value) && (int)exp.value >= 0)
                 {
                     return(Monomial.Power(ToMonomials(op.args[0], style), (int)exp.value, style));
                 }
                 else
                 {
                     throw new Error("Polynomial.ToMonomials: " + flow.Format(style));
                 }
             }
             else
             {
                 throw new Error("Polynomial.ToMonomials: " + flow.Format(style));
             }
         }
     }
コード例 #3
0
 public static Lst <Monomial> Substitute(Monomial monomial, Lst <Subst> substs, Style style)
 {
     return(Monomial.Product(new Monomial(monomial.coefficient, style), Substitute(monomial.factors, substs, style), style));
 }