@Nonnull public Variable newInstance() { return new Constant(name, prime, new Generic[subscripts.length]); }
@Nonnull @Override public Constant getConstant() { if (constant == null) { constant = new Constant(this.name); } return constant; }
@Override public Generic selfExpand() { Generic localContent = content; try { for (String parameterName : parameterNames) { localContent = localContent.substitute(new Constant(parameterName), Expression.valueOf(new Constant(getParameterNameForConstant(parameterName)))); } for (int i = 0; i < parameterNames.size(); i++) { localContent = localContent.substitute(new Constant(getParameterNameForConstant(parameterNames.get(i))), parameters[i]); } } finally { for (String parameterName : parameterNames) { localContent = localContent.substitute(new Constant(getParameterNameForConstant(parameterName)), Expression.valueOf(new Constant(parameterName))); } } return localContent; }
public ConstantsRegistry() { this.add(new PiConstant()); this.add(new ExtendedConstant(Constants.PI_INV, Math.PI, null)); this.add(new ExtendedConstant(Constants.INF, Double.POSITIVE_INFINITY, "JsclDouble.valueOf(Double.POSITIVE_INFINITY)")); this.add(new ExtendedConstant(Constants.INF_2, Double.POSITIVE_INFINITY, "JsclDouble.valueOf(Double.POSITIVE_INFINITY)")); this.add(new ExtendedConstant(Constants.I, "√(-1)", null)); this.add(new ExtendedConstant(new Constant(E), Math.E, null)); this.add(new ExtendedConstant(new Constant(C), C_VALUE, null)); this.add(new ExtendedConstant(new Constant(G), G_VALUE, null)); this.add(new ExtendedConstant(new Constant(H_REDUCED), H_REDUCED_VALUE, null)); this.add(new ExtendedConstant(new Constant(NAN), Double.NaN, null)); } }
public Constant parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { final String name = CompoundIdentifier.parser.parse(p, previousSumElement); List<Generic> l = new ArrayList<Generic>(); while (true) { try { l.add(Subscript.parser.parse(p, previousSumElement)); } catch (ParseException e) { break; } } Integer prime = 0; try { prime = Prime.parser.parse(p, previousSumElement); } catch (ParseException e) { } return new Constant(name, prime, ArrayUtils.toArray(l, new Generic[l.size()])); } }
static Ordering ordering(Generic generic) { Variable v = generic.variableValue(); if (v.compareTo(new Constant("lex")) == 0) return Monomial.lexicographic; else if (v.compareTo(new Constant("tdl")) == 0) return Monomial.totalDegreeLexicographic; else if (v.compareTo(new Constant("drl")) == 0) return Monomial.degreeReverseLexicographic; else if (v instanceof ImplicitFunction) { Generic g[] = ((ImplicitFunction) v).getParameters(); int k = g[0].integerValue().intValue(); if (v.compareTo(new ImplicitFunction("elim", new Generic[]{JsclInteger.valueOf(k)}, new int[]{0}, new Generic[]{})) == 0) return Monomial.kthElimination(k); } throw new ArithmeticException(); }
protected void operator(MathML element, String name) { Variable variable[] = toVariables((JsclVector) GenericVariable.content(parameters[1])); MathML e1 = element.element("msub"); new Constant(name).toMathML(e1, null); MathML e2 = element.element("mrow"); for (int i = 0; i < variable.length; i++) variable[i].expressionValue().toMathML(e2, null); e1.appendChild(e2); element.appendChild(e1); } }
protected void operator(MathML element, String name) { Variable variable[] = toVariables(GenericVariable.content(parameters[1])); MathML e1 = element.element("msubsup"); new Constant(name).toMathML(e1, null); MathML e2 = element.element("mrow"); for (int i = 0; i < variable.length; i++) variable[i].expressionValue().toMathML(e2, null); e1.appendChild(e2); e2 = element.element("mo"); e2.appendChild(element.text("T")); e1.appendChild(e2); element.appendChild(e1); }