// Use derivatives to match regular expressions public static boolean match(Node regex, String string) { // Two visitors Derivative d = new Derivative(); Nullable nullable = new Nullable(); // For debugging, create the printer here Printer printer = new Printer(); int index = 1; // Just compute the derivative with respect to the first character, then the second, then the // third and so on. for (char c : string.toCharArray()) { d.c = c; // Set the first character // For debugging purposes, // Print out the new regex System.out.println("Derivative: " + index); System.out.println("Regex: " + regex.accept(printer)); regex = regex.accept(d); // regex should match what it used to match, sans first character c index++; } System.out.println("Final Regex: " + regex.accept(printer)); // If the final language contains the empty string, then the original string was in the original // language. // Does the regex match the empty string? return regex.accept(nullable); }
public MultivariateIntervalNewton(Store store, FloatVar[] f, FloatVar[] x) { this.store = store; this.f = f; this.x = x; eval = new Stack<Constraint>(); Set<FloatVar> vars = new HashSet<FloatVar>(); for (FloatVar v : x) vars.add(v); fprime = new FloatVar[f.length][x.length]; Derivative.init(store); for (int i = 0; i < f.length; i++) for (int j = 0; j < x.length; j++) { if (debug) System.out.println( "Derivative of " + f[i] + " on " + x[j] + " primitive variables = " + vars); fprime[i][j] = Derivative.getDerivative(store, f[i], vars, x[j]); if (debug) System.out.println("\t derivate = " + fprime[i][j]); } }
public Future( String instrumentId, String description, Long expiry, Double lotSize, Double tickSize, Double tickValue) { super(Future.class.getCanonicalName()); super.setShortName(instrumentId); super.setDescription(description); this.expiry = expiry; this.lotSize = lotSize; this.tickSize = tickSize; this.tickValue = tickValue; }
public FloatVar derivative(Store store, FloatVar f, java.util.Set<FloatVar> vars, FloatVar x) { if (f.equals(r)) { // f = p + c // f' = d(p) FloatVar v = Derivative.getDerivative(store, p, vars, x); return v; } else if (f.equals(p)) { // f = r - c // f' = d(r) FloatVar v = Derivative.getDerivative(store, r, vars, x); return v; } return null; }
Constraint constraint(FloatVar v) { ArrayList<Constraint> list = new ArrayList<Constraint>(); for (int i = 0; i < v.dom().modelConstraints.length; i++) if (v.dom().modelConstraints[i] != null) for (int j = 0; j < v.dom().modelConstraints[i].length; j++) { if (v.dom().modelConstraints[i][j] != null) { Constraint c = v.dom().modelConstraints[i][j]; if (eval.search(c) == -1) { if (Derivative.derivateConstraints.contains(c)) continue; if (!list.contains(c)) list.add(c); } } } // if (debug) // System.out.println ("Possible constraints for variable " + v + " are " + list); Constraint c; if (list.size() == 1) c = list.get(0); else c = Derivative.resolveConstraint(v, list); return c; }