From 3679dc98bb0b3c47f5598eef15e90f8849075871 Mon Sep 17 00:00:00 2001 From: Max Piskunov Date: Thu, 8 Jul 2021 10:23:35 -0500 Subject: [PATCH] Change system parameters to symbols. --- Kernel/A1$generatorSystem.m | 40 +++++++++++++---------------- Kernel/AtomicStateSystem.m | 5 ++-- Kernel/MultisetSubstitutionSystem.m | 2 +- Kernel/systemGenerators.m | 2 +- Kernel/systemParameters.m | 19 +++++++++----- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Kernel/A1$generatorSystem.m b/Kernel/A1$generatorSystem.m index 8c869b39..d4210970 100644 --- a/Kernel/A1$generatorSystem.m +++ b/Kernel/A1$generatorSystem.m @@ -27,17 +27,17 @@ (* Parameters in the fourth argument should be declared with declareSystemParameter. Their values are guaranteed to match the pattern from the declaration. Further, the logical expression in the last argument will check if all required parameters are specified. Some parameters may require others to be specified, e.g., - Implies["MaxDestroyerEvents" || "MaxEvents", "EventOrder"] means that if "MaxDestroyerEvents" or "MaxEvents" is - specified, "EventOrder" must be specified as well. The implementation function can expect all specified parameters - present (substituted with defaults if missing) and all values satisfying the constraints (substituted with defaults - if missing). *) + Implies[MaxDestroyerEvents || MaxEvents, EventOrder] means that if MaxDestroyerEvents or MaxEvents is specified, \ + EventOrder must be specified as well. The implementation function can expect all specified parameters present \ + (substituted with defaults if missing) and all values satisfying the constraints (substituted with defaults if \ + missing). *) (* For example, declareSystem[MultisetSubstitutionSystem, generateMultisetSubstitutionSystem, _List, - {"MaxGeneration", "MinEventInputs", "MaxDestroyerEvents", "MaxEvents", "EventOrder"}, - Implies["MaxDestroyerEvents" || "MaxEvents", "EventOrder"]] *) + {MaxGeneration, MinEventInputs, MaxDestroyerEvents, MaxEvents, EventOrder}, + Implies[MaxDestroyerEvents || MaxEvents, EventOrder]] *) (* The implementation function is then called as generateMultisetSubstitutionSystem[MultisetSubstitutionSystem[rules], init, parameters] *) @@ -78,12 +78,12 @@ declareSystemGenerator[EvaluateSingleHistory, evaluateSingleHistory, - <|"MaxDestroyerEvents" -> 1|>, + <|MaxDestroyerEvents -> 1|>, FinalState, "yields a single history object."] Note that the constraint in the last argument of declareSystemGenerator still needs to be specified, which means - "EventOrder" is now a required parameter. *) + EventOrder is now a required parameter. *) (* evaluateSingleHistory is a PackageScope symbol that will throw exceptions instead of returning unevaluated. It cannot be used in operator form. *) @@ -114,11 +114,15 @@ to be supported and define values for them. To declare a new parameter, one needs to specify a default value (which usually disables whatever the parameter is doing) and a pattern the parameter value should match. *) -(* declareSystemParameter["MaxGeneration", Infinity, _ ? (GreaterEqualThan[0])] *) +(* declareSystemParameter[MaxGeneration, + Infinity, + _ ? (GreaterEqualThan[0]), + "is a parameter specifying the maximum generations of tokens that will be created."] *) -declareSystemParameter[name_, defaultValue_, pattern_] := ( +declareSystemParameter[name_, defaultValue_, pattern_, usage_] := ( $parameterDefaults[name] = defaultValue; $parameterPatterns[name] = pattern; + SetUsage @ Evaluate[ToString[name] <> " " <> usage]; ); (* Initialization *) @@ -141,31 +145,23 @@ declareMessage[ General::unknownGeneratorParameters, "Parameters `parameters` are set by `generator` but is not declared."]; -initializeSystemGenerators[] := Module[{parameterKeys, maxParameterCount}, +initializeSystemGenerators[] := ( $SetReplaceSystems = Sort @ Keys @ $systemImplementations; $SetReplaceGenerators = Sort @ Keys @ $generatorParameters; - parameterKeys = Keys[$parameterDefaults]; - With[{missingParameters = Complement[$systemParameters[#], parameterKeys]}, + With[{missingParameters = Complement[$systemParameters[#], Keys[$parameterDefaults]]}, If[missingParameters =!= {}, message[SetReplace, Failure["unknownSystemParameters", <|"parameters" -> missingParameters, "system" -> #|>]]; ]; ] & /@ $SetReplaceSystems; - With[{missingParameters = Complement[Keys @ $generatorParameters[#], parameterKeys]}, + With[{missingParameters = Complement[Keys @ $generatorParameters[#], Keys[$parameterDefaults]]}, If[missingParameters =!= {}, message[ SetReplace, Failure["unknownGeneratorParameters", <|"parameters" -> missingParameters, "generator" -> #|>]]; ]; ] & /@ $SetReplaceGenerators; - maxParameterCount = Length @ parameterKeys; - (* This has quadratic complexity in parameter count. But it does not seem to be possible to define the same set of - completion strings for a range of arguments. *) - With[{ - completionSpec = Join[{0}, Table[parameterKeys, maxParameterCount + 1]]}, - FE`Evaluate[FEPrivate`AddSpecialArgCompletion[# -> completionSpec]] & /@ ToString /@ $SetReplaceGenerators; - ]; Scan[(SyntaxInformation[#] = {"ArgumentsPattern" -> {system_, init_., parameters___}}) &, $SetReplaceGenerators]; defineGeneratorImplementation /@ Keys @ $generatorParameters; -]; +); declareMessage[General::argNotInit, "The init `arg` in `expr` should match `pattern`."]; declareMessage[General::unknownSystem, "`system` is not a recognized SetReplace system."]; diff --git a/Kernel/AtomicStateSystem.m b/Kernel/AtomicStateSystem.m index 2856ca83..33bff92b 100644 --- a/Kernel/AtomicStateSystem.m +++ b/Kernel/AtomicStateSystem.m @@ -12,14 +12,13 @@ SyntaxInformation[AtomicStateSystem] = {"ArgumentsPattern" -> {rules_}}; -declareSystem[ - AtomicStateSystem, generateAtomicStateSystem, _, {"MaxGeneration", "MaxDestroyerEvents", "MaxEvents"}, True]; +declareSystem[AtomicStateSystem, generateAtomicStateSystem, _, {MaxGeneration, MaxDestroyerEvents, MaxEvents}, True]; generateAtomicStateSystem[AtomicStateSystem[rules___], init_, parameters_] := ModuleScope[ toAtomicStateMultihistory[rules] @ generateMultihistory[ MultisetSubstitutionSystem[toMultisetRules[rules]], {init}, - Join[parameters, <|"MinEventInputs" -> 1, "MaxEventInputs" -> 1|>]] + Join[parameters, <|MinEventInputs -> 1, MaxEventInputs -> 1|>]] ]; (* Parsing *) diff --git a/Kernel/MultisetSubstitutionSystem.m b/Kernel/MultisetSubstitutionSystem.m index be045caf..e90ebab8 100644 --- a/Kernel/MultisetSubstitutionSystem.m +++ b/Kernel/MultisetSubstitutionSystem.m @@ -16,7 +16,7 @@ declareSystem[MultisetSubstitutionSystem, generateMultisetSubstitutionSystem, _List, - {"MaxGeneration", "MaxDestroyerEvents", "MinEventInputs", "MaxEventInputs", "MaxEvents"}, + {MaxGeneration, MaxDestroyerEvents, MinEventInputs, MaxEventInputs, MaxEvents}, True]; generateMultisetSubstitutionSystem[MultisetSubstitutionSystem[rawRules___], init_, parameters_] := Block[{ diff --git a/Kernel/systemGenerators.m b/Kernel/systemGenerators.m index da040bec..748f5a17 100644 --- a/Kernel/systemGenerators.m +++ b/Kernel/systemGenerators.m @@ -18,6 +18,6 @@ declareSystemGenerator[ GenerateSingleHistory, generateSingleHistory, - <|"MaxDestroyerEvents" -> 1|>, + <|MaxDestroyerEvents -> 1|>, Identity, "yields a single history of the evaluation of a specified system$ starting from an initial state init$."]; diff --git a/Kernel/systemParameters.m b/Kernel/systemParameters.m index 1c60e781..0df32203 100644 --- a/Kernel/systemParameters.m +++ b/Kernel/systemParameters.m @@ -2,13 +2,20 @@ (* Event-selection parameters *) -declareSystemParameter[##, _ ? (GreaterEqualThan[0])] & @@@ { - {"MaxGeneration", Infinity}, - {"MaxDestroyerEvents", Infinity}, - {"MinEventInputs", 0}, - {"MaxEventInputs", Infinity} +PackageExport["MaxGeneration"] +PackageExport["MaxDestroyerEvents"] +PackageExport["MinEventInputs"] +PackageExport["MaxEventInputs"] + +declareSystemParameter[#, #2, _ ? (GreaterEqualThan[0]), #3] & @@@ { + {MaxGeneration, Infinity, "is a parameter specifying the maximum generations of tokens that will be created."}, + {MaxDestroyerEvents, Infinity, "..."}, + {MinEventInputs, 0, "..."}, + {MaxEventInputs, Infinity, "..."} }; (* Stopping-condition parameters *) -declareSystemParameter["MaxEvents", Infinity, _ ? (GreaterEqualThan[0])]; +PackageExport["MaxEvents"] + +declareSystemParameter[MaxEvents, Infinity, _ ? (GreaterEqualThan[0]), "..."];