public static void Main(String[] args) { Regex a = new Sym("A"); Regex b = new Sym("B"); Regex c = new Sym("C"); Regex abStar = new Star(new Alt(a, b)); Regex bb = new Seq(b, b); Regex r = new Seq(abStar, new Seq(a, b)); // The regular expression (a|b)*ab BuildAndShow("dfa1.dot", r); // The regular expression ((a|b)*ab)* BuildAndShow("dfa2.dot", new Star(r)); // The regular expression ((a|b)*ab)((a|b)*ab) BuildAndShow("dfa3.dot", new Seq(r, r)); // The regular expression (a|b)*abb, from ASU 1986 p 136 BuildAndShow("dfa4.dot", new Seq(abStar, new Seq(a, bb))); // SML reals: sign?((digit+(\.digit+)?))([eE]sign?digit+)? Regex d = new Sym("digit"); Regex dPlus = new Seq(d, new Star(d)); Regex s = new Sym("sign"); Regex sOpt = new Alt(s, new Eps()); Regex dot = new Sym("."); Regex dotDigOpt = new Alt(new Eps(), new Seq(dot, dPlus)); Regex mant = new Seq(sOpt, new Seq(dPlus, dotDigOpt)); Regex e = new Sym("e"); Regex exp = new Alt(new Eps(), new Seq(e, new Seq(sOpt, dPlus))); Regex smlReal = new Seq(mant, exp); BuildAndShow("dfa5.dot", smlReal); }
public MemoryTier this[Sym sym] { get { return(Symbols[sym]); } }
public override void FillEquationSystem(EquationSystem problem) { int NC = System.Components.Count; var In = FindMaterialPort("In"); var Out = FindMaterialPort("Out"); for (int i = 0; i < NC; i++) { var cindex = i; AddEquationToEquationSystem(problem, Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[cindex]) .IsEqualTo(Sym.Sum(0, Out.NumberOfStreams, (j) => Out.Streams[j].Mixed.ComponentMolarflow[cindex])), "Mass Balance"); } AddEquationToEquationSystem(problem, (p / 1e4).IsEqualTo(Sym.Par(Sym.Min(In.Streams[0].Mixed.Pressure, In.Streams[1].Mixed.Pressure) - dp) / 1e4), "Pressure Balance"); foreach (var outlet in Out.Streams) { AddEquationToEquationSystem(problem, (outlet.Mixed.Pressure / 1e4).IsEqualTo(Sym.Par(p) / 1e4), "Pressure drop"); } AddEquationToEquationSystem(problem, ((Sym.Sum(0, In.NumberOfStreams, (i) => In.Streams[i].Mixed.SpecificEnthalpy * In.Streams[i].Mixed.TotalMolarflow) / 1e4)) .IsEqualTo(Sym.Sum(0, Out.NumberOfStreams, (i) => Out.Streams[i].Mixed.SpecificEnthalpy * Out.Streams[i].Mixed.TotalMolarflow) / 1e4), "Heat Balance"); base.FillEquationSystem(problem); }
Expression GetFactor(MaterialStream stream) { switch (Type) { case ReactionType.EQLA: Expression lnK = Coefficients[0]; if (Coefficients.Count > 1) { lnK += Coefficients[1] / stream.Mixed.Temperature; } if (Coefficients.Count > 2) { lnK += Coefficients[2] * Sym.Ln(stream.Mixed.Temperature); } if (Coefficients.Count > 3) { lnK += Coefficients[3] * stream.Mixed.Temperature; } if (Coefficients.Count > 4) { lnK += Coefficients[4] * Sym.Pow(stream.Mixed.Temperature, 2.0); } if (Coefficients.Count > 5) { lnK += Coefficients[5] * Sym.Pow(stream.Mixed.Temperature, 3.0); } return(Sym.Exp(lnK)); } return(1); }
static void TestHS71() { Console.WriteLine(); Console.WriteLine("### Test Problem: Hock-Schittkowski #71"); var problem = new OptimizationProblem(); var x1 = new Variable("x1", 1, 1, 5); var x2 = new Variable("x2", 2, 1, 5); var x3 = new Variable("x3", 5, 1, 5); var x4 = new Variable("x4", 1, 1, 5); problem.AddVariables(x1, x2, x3, x4); problem.ObjectiveFunction = x1 * x4 * Sym.Par(x1 + x2 + x3) + x3; problem.AddInequalityConstraints(new Constraint(x1 * x2 * x3 * x4, ConstraintComparisonOperator.GreaterThanOrEqual, 25)); problem.AddConstraints((Sym.Pow(x1, 2) + Sym.Pow(x2, 2) + Sym.Pow(x3, 2) + Sym.Pow(x4, 2)).IsEqualTo(40)); // var solver = new IpoptSolver(); solver.OnLog += Console.WriteLine; solver.Solve(problem); Console.WriteLine(x1.WriteReport()); Console.WriteLine(x2.WriteReport()); Console.WriteLine(x3.WriteReport()); Console.WriteLine(x4.WriteReport()); }
public override void FillEquationSystem(EquationSystem problem) { int NC = System.Components.Count; var In = FindMaterialPort("In"); var Out1 = FindMaterialPort("Out1"); var Out2 = FindMaterialPort("Out2"); for (int i = 0; i < NC; i++) { var cindex = i; AddEquationToEquationSystem(problem, (SplitFactor * In.Streams[0].Mixed.ComponentMolarflow[cindex]) .IsEqualTo(Out1.Streams[0].Mixed.ComponentMolarflow[cindex]), "Mass Balance"); } for (int i = 0; i < NC; i++) { var cindex = i; AddEquationToEquationSystem(problem, (Sym.Par(1 - SplitFactor) * In.Streams[0].Mixed.ComponentMolarflow[cindex]) .IsEqualTo(Out2.Streams[0].Mixed.ComponentMolarflow[cindex]), "Mass Balance"); } AddEquationToEquationSystem(problem, (p / 1e4).IsEqualTo((In.Streams[0].Mixed.Pressure - dp) / 1e4), "Pressure drop"); AddEquationToEquationSystem(problem, (Out1.Streams[0].Mixed.Pressure / 1e4).IsEqualTo(Sym.Par(p) / 1e4), "Pressure Balance"); AddEquationToEquationSystem(problem, (Out1.Streams[0].Mixed.Temperature / 1e3).IsEqualTo(Sym.Par(In.Streams[0].Mixed.Temperature) / 1e3), "Temperature Balance"); AddEquationToEquationSystem(problem, (Out2.Streams[0].Mixed.Pressure / 1e4).IsEqualTo(Sym.Par(p) / 1e4), "Pressure Balance"); AddEquationToEquationSystem(problem, (Out2.Streams[0].Mixed.Temperature / 1e3).IsEqualTo(Sym.Par(In.Streams[0].Mixed.Temperature) / 1e3), "Temperature Balance"); base.FillEquationSystem(problem); }
Expression GetCharacteristicCurve() { switch (CharacteristicCurve) { case ValveCharacteristic.Linear: return(Position); case ValveCharacteristic.Parabolic: return(0.01 * Sym.Pow(Position, 2)); case ValveCharacteristic.SquareRoot: return(10 * Sym.Sqrt(Position)); case ValveCharacteristic.QuickOpening: return(Sym.Par(10 * Position) / (Sym.Sqrt(1.0 + 9.9e-3 * Sym.Pow(Position, 2)))); case ValveCharacteristic.EqualPercentage: return(Sym.Par(0.01 * Sym.Pow(Position, 2)) / (Sym.Sqrt(2.0 - 1e-8 * Sym.Pow(Position, 4)))); case ValveCharacteristic.Hyperbolic: return(Sym.Par(0.1 * Position) / (Sym.Sqrt(1.0 - 9.9e-5 * Sym.Pow(Position, 2)))); default: return(Position); } }
void initialise() { resolved_sym_map = new Dictionary <object, Sym>(); resolved_val_map = new Dictionary <Expr, Val>(); package_map = new Dictionary <string, Package>(); resolved_expected_type_map = new Dictionary <Expr, Type>(); resolved_type_map = new Dictionary <object, Type>(); package_map = new Dictionary <string, Package>(); pointer_promo_map = new Dictionary <Expr, Type>(); labels_map = new Dictionary <string, Label>(); reachable_map = new Dictionary <Type, SymReachable>(); type_conv_map = new Dictionary <Expr, Type>(); local_syms = new Sym[MAX_LOCAL_SYMS]; local_sym_pos = 0; implicit_any_list = new List <Expr>(); reachable_syms = new List <Sym>(); package_list = new List <Package>(); sorted_syms = new List <Sym>(256); decl_note_names = new List <string>(); labels = new List <Label>(); type_allocator = new Type(); type_allocator_ptr = new Type(); init_compiler(); init_chars(); inited = true; }
public LexicalRule Add(string pat, Sym sym) { var rule = new LexicalRule(pat, sym); Add(rule); return rule; }
public void LoadModulesInRange(long VA, long length, string OnlyModule = null) { var KVS = new VirtualScanner(this, new Mem(MemAccess)); foreach (var artifact in KVS.Run(VA, VA + length)) { var ms = new MemSection() { IsExec = true, Module = artifact, VA = new VIRTUAL_ADDRESS(artifact.VA) }; var extracted = ExtractCVDebug(ms); if (extracted == null) { continue; } if (!string.IsNullOrWhiteSpace(OnlyModule) && OnlyModule != ms.Name) { continue; } if (!Sections.ContainsKey(artifact.VA)) { Sections.TryAdd(artifact.VA, ms); } // we can clobber this guy all the time I guess since everything is stateless in Sym and managed // entirely by the handle ID really which is local to our GUID so.... sym = Vtero.TryLoadSymbols(ID.GetHashCode(), ms.DebugDetails, ms.VA.Address); if (Vtero.VerboseOutput) { WriteColor(ConsoleColor.Green, $"symbol loaded [{sym != null}] from file [{ms.DebugDetails.PDBFullPath}]"); } } }
public override ProcessUnit Initialize() { var In = FindMaterialPort("In"); var Out = FindMaterialPort("Out"); int NC = System.Components.Count; if (!p.IsFixed) { p.ValueInSI = In.Streams[0].Mixed.Pressure.ValueInSI; } var eval = new Evaluator(); for (int i = 0; i < NC; i++) { Out.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[i]).Eval(eval); } Out.Streams[0].Mixed.Temperature.ValueInSI = T.ValueInSI; Out.Streams[0].Mixed.Pressure.ValueInSI = p.ValueInSI - dp.ValueInSI; Out.Streams[0].Vfmolar.ValueInSI = In.Streams[0].Vfmolar.ValueInSI; var flash = new FlashRoutines(new Numerics.Solvers.Newton()); if (T.IsFixed) { flash.CalculateTP(Out.Streams[0]); } Q.ValueInSI = -(In.Streams[0].Mixed.SpecificEnthalpy * In.Streams[0].Mixed.TotalMolarflow - Out.Streams[0].Mixed.SpecificEnthalpy * Out.Streams[0].Mixed.TotalMolarflow).Eval(eval); return(this); }
public Lexer(Parser ps, string inp) { psr = ps; input = inp.ToCharArray(); Advance(); tok = Next(); }
List <CryptoCoin> ListByText(string query) { List <CryptoCoin> lstCoins = new List <CryptoCoin>(); string Name; string Sym; foreach (var item in myStuff.data) { Name = item.name; Sym = item.symbol; if (Sym.ToLower().Contains(query.ToLower()) || Name.ToLower().Contains(query.ToLower())) { CryptoCoin newCoin = new CryptoCoin(); newCoin.Name = item.name; newCoin.Symbol = item.symbol; newCoin.Price = item.quote.USD.price; newCoin.UpdateDate = item.quote.USD.last_updated + " UTC"; lstCoins.Add(newCoin); } else { continue; } } return(lstCoins); }
public Expression GetLiquidEnthalpyExpression(ThermodynamicSystem sys, int idx, Variable T) { Variable Tref = sys.EnthalpyMethod.PureComponentEnthalpies[idx].Tref; Expression expr = null; var comp = sys.Components[idx]; if (sys.EnthalpyMethod.PureComponentEnthalpies[idx].ReferenceState == PhaseState.Liquid) { expr = sys.EnthalpyMethod.PureComponentEnthalpies[idx].Href + Sym.Par(sys.EquationFactory.GetLiquidHeatCapacityIntegralExpression(sys, comp, T, Tref)); } else { if (sys.EnthalpyMethod.PureComponentEnthalpies[idx].PhaseChangeAtSystemTemperature) { expr = sys.EnthalpyMethod.PureComponentEnthalpies[idx].Href + Sym.Par(sys.EquationFactory.GetIdealGasHeatCapacityIntegralExpression(sys, comp, T, Tref)) - sys.EquationFactory.GetEnthalpyOfVaporizationExpression(sys, comp, T); } else { expr = sys.EnthalpyMethod.PureComponentEnthalpies[idx].Href + Sym.Par(sys.EquationFactory.GetIdealGasHeatCapacityIntegralExpression(sys, comp, sys.EnthalpyMethod.PureComponentEnthalpies[idx].TPhaseChange, Tref)) - sys.EquationFactory.GetEnthalpyOfVaporizationExpression(sys, comp, sys.EnthalpyMethod.PureComponentEnthalpies[idx].TPhaseChange) + Sym.Par(sys.EquationFactory.GetLiquidHeatCapacityIntegralExpression(sys, comp, T, sys.EnthalpyMethod.PureComponentEnthalpies[idx].TPhaseChange)); } } Variable prop = new Variable("hL" + "(" + T.FullName + ")", 1); prop.Subscript = sys.Components[idx].ID; prop.BindTo(expr); return(expr); }
private static void InitReceiver(int intervalSeconds, int repeats, Sym protocolMode) { if (protocolMode != Sym.NAK && protocolMode != Sym.C) { throw new Exception("Bad protocol mode passed!"); } first = true; byte receivedByte = 0; port.ReadTimeout = intervalSeconds * 1000; for (int i = 0; i < repeats; i++) { PortWriteByte((byte)protocolMode); // Should write NAK or C try { receivedByte = (byte)port.ReadByte(); } catch (TimeoutException) { } if (receivedByte == (byte)Sym.SOH && protocolMode == Sym.NAK) { return; } if (receivedByte == (byte)Sym.C && protocolMode == Sym.C) { return; } } throw new TimeoutException("Initialization failed. Didn't receive SOH or C symbol thru " + repeats + " repeats between " + intervalSeconds + " interval seconds."); }
public Expression CreateIntegratedExpression(FunctionType typeToCreate, PropertyFunction func, Variable T, Variable Tref) { Expression expr = null; switch (typeToCreate) { case FunctionType.PolynomialIntegrated: EnsureCoefficients(func.Coefficients, 1); expr = func.Coefficients[0] * Sym.Par(T - Tref); for (int i = 1; i < func.NumberOfCoefficients; i++) { expr += 1.0 / (double)(i + 1) * func.Coefficients[i] * Sym.Par(Sym.Pow(T, i + 1) - Sym.Pow(Tref, i + 1)); } break; case FunctionType.Dippr117: { EnsureCoefficients(func.Coefficients, 5); var Tcon = Sym.Convert(T, func.XUnit); var Trefcon = Sym.Convert(Tref, func.XUnit); expr = func.Coefficients[0] * Sym.Par(Tcon - Trefcon) + func.Coefficients[1] * func.Coefficients[2] * Sym.Par(Sym.Coth(func.Coefficients[2] / Tcon) - Sym.Coth(func.Coefficients[2] / Trefcon)) - func.Coefficients[3] * func.Coefficients[4] * Sym.Par(Sym.Tanh(func.Coefficients[4] / Tcon) - Sym.Tanh(func.Coefficients[4] / Trefcon)); break; } } return(expr); }
public dynamic xStructInfo(string Struct, long[] memRead = null, string Module = "ntkrnlmp") { MemSection pdb = null; if (Module == "ntkrnlmp" && KernelSection != null) { pdb = KernelSection; } else { var pdbPaths = from files in Sections.Values where files.DebugDetails != null && !string.IsNullOrWhiteSpace(files.DebugDetails.PDBFullPath) && files.DebugDetails.PDBFullPath.ToLower().Contains(Module.ToLower()) select files; pdb = pdbPaths.FirstOrDefault(); KernelSection = pdb; } if (sym == null) { sym = Vtero.TryLoadSymbols(ID.GetHashCode(), pdb.DebugDetails, pdb.VA.Address); } return(sym.xStructInfo(pdb.DebugDetails.PDBFullPath, Struct, memRead, GetVirtualByte, GetVirtualLong)); }
// whether the i-th bit is set. private static bool Has(this bitmap bm, Sym i) { var n = uint(i) / 32L; var r = uint(i) % 32L; return(bm[n] & (1L << (int)(r)) != 0L); }
// set the i-th bit. private static void Set(this bitmap bm, Sym i) { var n = uint(i) / 32L; var r = uint(i) % 32L; bm[n] |= 1L << (int)(r); }
void Mustbe(Sym t) { if (lxr.tok != t) { throw new Exception(CheckEOF()); } Next(); }
Sym PushBack(Sym old) { pushBack = old; pushCh = ch; pushPos = pos; tok = old; return(tok); }
public void Equality() { Assert.Multiple(() => { Assert.That(Sym.From('A'), Is.EqualTo(Sym.From('A'))); Assert.That(Sym.From("HAMSTER"), Is.EqualTo(Sym.From("HAMSTER"))); }); }
public InlTreeNode(int Parent = default, Sym File = default, int Line = default, Sym Func = default, int ParentPC = default) { this.Parent = Parent; this.File = File; this.Line = Line; this.Func = Func; this.ParentPC = ParentPC; }
public Token(string lexeme, int row, int column, int length, Sym type) { this.lexeme = lexeme; this.row = row; this.column = column; this.type = type; this.length = length; //COMMENT }
public void Can_Abs_Minus4() { var x = new Variable { Name = "x", ValueInSI = -4 }; var evaluator = new Evaluator(); Assert.AreEqual(4, Sym.Abs(x).Eval(evaluator)); }
public void Can_Log6() { var x = new Variable { Name = "x", ValueInSI = 6 }; var evaluator = new Evaluator(); Assert.AreEqual(Math.Log(6), Sym.Ln(x).Eval(evaluator)); }
public void Can_Sqrt_4() { var x = new Variable { Name = "x", ValueInSI = 4 }; var evaluator = new Evaluator(); Assert.AreEqual(2, Sym.Sqrt(x).Eval(evaluator)); }
public MixtureHenryCoefficient(ThermodynamicSystem system, Variable T, List<Variable> x, int idx) { index = idx; _system = system; var parameterSet = _system.BinaryParameters.FirstOrDefault(ps => ps.Name == "HENRY"); if (parameterSet == null) throw new ArgumentNullException("No HENRY parameters defined"); double[,] a = parameterSet.Matrices["A"]; double[,] b = parameterSet.Matrices["B"]; double[,] c = parameterSet.Matrices["C"]; double[,] d = parameterSet.Matrices["D"]; Symbol = "HENRY"; this.T = T; this.x = x; Parameters.Add(T); foreach (var comp in x) Parameters.Add(comp); NC = system.Components.Count; Expression sumxj = 0; Expression _lnHenry = 0; for (int j = 0; j < system.Components.Count; j++) { if (!system.Components[j].IsInert) { Expression lnHij = a[idx, j]; if (b[idx, j] != 0.0) lnHij += b[idx, j] / T; if (c[idx, j] != 0.0) lnHij += c[idx, j] * Sym.Ln(T); if (d[idx, j] != 0.0) lnHij += d[idx, j] * T; sumxj += x[j]; _lnHenry += x[j] * Sym.Par(lnHij); } } _lnHenry = _lnHenry / Sym.Par(sumxj); _henry = Sym.Exp(_lnHenry); _dhenryDx = new Expression[NC]; DiffFunctional = (cache, v) => _henry.Diff(cache, v); EvalFunctional = (cache) => _henry.Eval(cache); }
public Variable GetAverageVaporViscosityExpression(ThermodynamicSystem system, Variable[] y, Variable T, Variable p) { var NC = system.Components.Count; var visv = Sym.Sum(0, NC, j => y[j] * Sym.Sqrt(Sym.Convert(system.Components[j].MolarWeight, system.VariableFactory.Internal.UnitDictionary[PhysicalDimension.MolarWeight])) * GetVaporViscosityExpression(system, system.Components[j], T, p)) / Sym.Sum(0, NC, j => y[j] * Sym.Sqrt(Sym.Convert(system.Components[j].MolarWeight, system.VariableFactory.Internal.UnitDictionary[PhysicalDimension.MolarWeight]))); Variable prop = new Variable("VISV" + "(" + T.FullName + ")", 1); prop.Subscript = "avg"; prop.BindTo(visv); return(prop); }
public Variable GetAverageMolarWeightExpression(ThermodynamicSystem system, Variable[] z) { var NC = system.Components.Count; var molw = Sym.Sum(0, NC, j => Sym.Convert(system.Components[j].MolarWeight, system.VariableFactory.Internal.UnitDictionary[PhysicalDimension.MolarWeight]) * z[j]); Variable prop = new Variable("MOLW", 1); prop.Subscript = "avg"; prop.BindTo(molw); return(prop); }
public void Can_Raise_VariabletoPower2() { var x = new Variable { Name = "x", ValueInSI = 2 }; var evaluator = new Evaluator(); Assert.AreEqual(4, Sym.Pow(x, 2).Eval(evaluator)); }
private void AddRule(string pat, Sym sym, bool isKeyword = false) { var rule = table.Add(pat, sym); if (isKeyword) keywordTable.Add(pat, rule); }
public bool Is(Sym expected) { return this.Sym == expected; }
private Expr _Substitute(Sym s) { if (s == _orig) return _replacement; else return s; }