-
Notifications
You must be signed in to change notification settings - Fork 2
Template difference with tests #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
608faee
13bbfdf
3305443
dea04e1
f00df70
9a0bb9b
1408f7d
ebc15a6
ce0d8b4
5b50711
0915277
76136d0
2fe266a
f5c6bec
47f087f
c805ed1
fa35caf
3b81edf
538a1b1
bea7b82
f10b8bf
f7022cc
b0cfbf8
258e102
c06342c
f32050c
6cefff3
8369dfa
7311e09
33eb8fd
2afda86
43604e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ TemplateOperations/*.nb | |
TemplateGeneration/*.nb | ||
.DS_Store | ||
.idea/* | ||
*.iml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
BeginPackage["CATemplates`Basic`"]; | ||
|
||
|
||
BooleanFromRule::usage="Transforms a rule into boolean form."; | ||
ConjunctionFromRuleSet::usage="Transforms a rule set into a boolean conjunction"; | ||
DNFFromRuleSet::usage="Transforms a set of set of rules into a DNF form boolean expression"; | ||
MinimizedRuleSets::usage = "Minimize a subset boolean expression"; | ||
Partial::usage = "Partial[f_, args__] := partially applies arguments args to function f."; | ||
|
||
PrintTestResults::usage = "PrintTestResults[testReport_] := Prints the results of a testReport in a terminal friendly manner"; | ||
|
||
SubstitutionRange::usage = "SubstitutionRange[template_Association] := Gives a range from 0 to the maximum possible substitution the template could have"; | ||
|
||
OldBaseTemplate::usage = "Gives the base template for a radius r k-ary rule."; | ||
TakeNeighbourhoods::usage = "Returns the n first neighborhoods from a given space."; | ||
TemplateFromNeighbourhoods::usage = "Builds a template given a list of neighbourhoods. Converts the neighbourhoods to symbols in the form xN, where N is the decimal conversion of the k-ary neighbourhood."; | ||
|
@@ -23,33 +23,14 @@ KAryFromRuleTable::usage = "Auxiliary function that converts a rule table to its | |
RuleTableFromKAry::usage= "Auxiliary function that converts k-ary rule table to its classical representation."; | ||
RuleTable::usage = "Creates the rule table of rnum, under Wolfram\.b4s lexicographic order. "; | ||
RuleOutputFromNeighbourhood::usage="Yields the output bit of a given neighbourhood from rule rnum. The neighbourhood may be given as the k-ary sequence that defines it, or as the decimal number it represents (e.g, decimal 6 for neighbourhood {0, 1, 1, 0}, etc)."; | ||
|
||
ExceptionTemplates::usage= "ExceptionTemplates[t_List, k_Integer:2, r_Integer:2] generate all the templates with variable assignments that make the template t with k colors and r range invalid."; | ||
|
||
|
||
PossibleStateReplacements::usage="Retorna todas as permuta\[CCedilla]\[OTilde]es poss\[IAcute]veis de estados de acordo com k."; | ||
|
||
|
||
RawTemplate::usage="RawTemplate[t_List]: Receives a template t, and drops any special sintax construct from it. Currently, it removes expressions of the form x \[Element] {__}."; | ||
|
||
|
||
ImprisonmentExpressions::usage="ImprisonmentExpressions[t_List]: Receives a template t, and returns all of the expressions of the form x \[Element] {__}."; | ||
|
||
|
||
ValueRestrictions::usage = "ValueRestrictions[imprisonmentExpression_]: Returns an expression that represents the value restricions dictated by an ImprisonmentExpression. Example: ValueRestrictions[x1 \[Element] {0,1}] -> x1 == 0 || x1 == 1"; | ||
|
||
|
||
FreeVariableQ::usage = "FreeVariableQ[expression_]: Receives an expression, and returns true if the expression is a free variable and false otherwise."; | ||
|
||
|
||
CorrespondsToNeighborhoodQ::usage = "CorrespondsToNeighborhoodQ[freeVariable_Symbol, nbIndex_Integer]: Receives a free variable expression and a neighborhood index, and returns true if the variable's index corresponds to the received nb index."; | ||
|
||
|
||
PreservesIndexVariableDualityQ::usage = "PreservesIndexVariableDualityQ[template_]: Receives a template and returns true if the template preserver the index-variable diality."; | ||
|
||
|
||
ConstantsToVariables::usage = "ConstantsToVariables[replacementRules_]: Receives a list of replacement rules, and converts any symbol of the type C[i_Integer] into its corresponding template variable, preserving the index-variable duality." | ||
|
||
Begin["`Private`"]; | ||
|
||
SetAttributes[Partial, HoldAll]; | ||
|
@@ -62,7 +43,7 @@ OldBaseTemplate[k_Integer: 2, r_: 1] := | |
RuleTemplateVars[ruletemplate_Association] := | ||
RuleTemplateVars[ruletemplate[["core"]]]; | ||
(*Deprecated!!*) | ||
RuleTemplateVars[ruletemplate_] := | ||
RuleTemplateVars[ruletemplate_] := | ||
SortBy[Union[Cases[ruletemplate, _Symbol, Infinity]], FromDigits[StringDrop[SymbolName[#],1]]&] | ||
|
||
TakeNeighbourhoods[n_Integer, k_Integer: 2, r_Integer: 1] := | ||
|
@@ -180,10 +161,36 @@ ImprisonmentExpressions[template_List]:= Cases[template, x_ \[Element] set_ ,Inf | |
ValueRestrictions[imprisonmentExpression_]:= | ||
Apply[Or,imprisonmentExpression[[1]] == #&/@ imprisonmentExpression[[2]]]; | ||
|
||
RemoveContainedSubsSets[allSubSet_List, subSet_List] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems this is not being used anywhere. |
||
Module[{listToRemove, result}, | ||
listToRemove = ContainsAll[#, subSet] && subSet =!= # & /@ allSubSet; | ||
result = MapThread[If[! #2, #1, ## &[]] &, {allSubSet, listToRemove}] | ||
]; | ||
|
||
BooleanFromRule[x_ /; x[[2]] == 0] := Not[x[[1]]]; | ||
BooleanFromRule[x_ /; x[[2]] == 1] := x[[1]]; | ||
|
||
ConjunctionFromRuleSet[ruleSet_List] := | ||
Apply[And, Map[BooleanFromRule, ruleSet]]; | ||
|
||
DNFFromRuleSet[ruleSet_List] := | ||
Apply[Or, Map[ConjunctionFromRuleSet, ruleSet]]; | ||
|
||
MinimizedRuleSets[ruleSets_List] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no tests for this function (add them if you think it is worth it) |
||
RuleSetFromDNFF[BooleanMinimize[DNFFromRuleSet[ruleSets]]]; | ||
|
||
RuleSetFromDNFF[minimizeBooleanExpression_] := Module[{RootExpressionToSubSet, ExpressionToSubSet, LeafExpressionToSubSet}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need this |
||
RootExpressionToSubSet[expr_ /; Head[expr] === Or] := Map[ExpressionToSubSet, expr, {1}] /. And -> List /. Or -> List; | ||
RootExpressionToSubSet[expr_] := {ExpressionToSubSet[expr]} /. And -> List /. Or -> List; | ||
|
||
ExpressionToSubSet[expr_ /; Head[expr] === And] := Map[LeafExpressionToSubSet, expr]; | ||
ExpressionToSubSet[expr_] := {LeafExpressionToSubSet[expr]}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
|
||
ExceptionTemplates[intemplate_, k_Integer:2, r_Integer:1] := | ||
MapThread[If[#2=== _,#1,#2]&,{OldBaseTemplate[k,r],#}]&/@Union[(If[NumberQ[#],#,_]&/@#)&/@((OldBaseTemplate[k,r]/.#[[1]])&/@Cases[{#[[2]],#[[1]]/.#[[2]]}&/@Flatten[Outer[List,{#[[1]]},#[[2]],1]&/@({#[[2]],MapThread[#1->#2&,{#[[1]],#[[2]]}]&/@#[[1]]}&/@({First@Outer[List,{#[[1]]},#[[2]],1],#[[3]]}&/@({#[[1]],Tuples[Range[0,k-1],Length[#[[1]]]],#[[2]]}&/@({RuleTemplateVars[{#}],#}&/@Select[intemplate,(Depth[#]>1)&])))),2],{_,x_/;\[Not]MemberQ[Range[0,k-1],x]}])] | ||
LeafExpressionToSubSet[expr_ /; Head[expr] === Symbol] := expr -> 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is equivalent to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
LeafExpressionToSubSet[expr_ /; Head[expr] === Not] := expr[[1]] -> 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if I'm not mistaken. |
||
|
||
result = RootExpressionToSubSet[minimizeBooleanExpression] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need this |
||
]; | ||
|
||
FreeVariableQ[expression_] := MatchQ[expression, _Symbol]; | ||
|
||
|
@@ -207,7 +214,7 @@ PrintTestResults[testReport_] := | |
Module[{red = "\033[0;31m", green = "\033[0;32m", noColor = "\033[0m"}, | ||
Print[green <> "Suceeded: " <> ToString[testReport["TestsSucceededCount"]] <> noColor]; | ||
If[testReport["TestsFailedCount"] > 0, | ||
Print[red <> "Failed: " <> ToString[testReport["TestsFailedCount"]] <> noColor]]; | ||
Print[red <> "Failed: " <> ToString[testReport["TestsFailedCount"]]<> "; Indices:" <> ToString[testReport["TestsFailedIndices"]] <> noColor]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🆒 😎 |
||
]; | ||
|
||
End[]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(* ::Package:: *) | ||
|
||
BeginPackage["CATemplates`TemplateOperations`Difference`Common`", { | ||
"CATemplates`Basic`", | ||
"CATemplates`CATemplate`"}]; | ||
|
||
|
||
DualEquationSystem::usage = "bl2"; | ||
DifferenceReplacementRules::usage = " | ||
DifferenceReplacementRules[template1_List, template2_List]: Takes two templates template1 and template2, and returns the replacement rules that could be applied to template1 or template2 in order to find the diference between then. Returns {} if there is no possible diference template or if they are both templates are the same. | ||
DifferenceReplacementRules[template1_List, template2_List, modulus_Integer]: Takes two templates template1 and template2, and returns the replacement rules that could be applied to template1 or template2 in order to find the diference between then. Returns {} if there is no possible diference template or if they are both templates are the same. Assumes both templates are modular. | ||
"; | ||
|
||
|
||
Begin["`Private`"]; | ||
|
||
EquationSystem[template1_List,template2_List]:= | ||
Equal @@ # & /@ Transpose[{template1, template2}]; | ||
|
||
DualEquationSystem[template1_List, template2_List] := | ||
Module[{notTemplate2, equationSystem, cleanEquationSystem, dualEquationSystem, dualEquationSystemResult}, | ||
equationSystem = EquationSystem[template1, template2];(*Make a equation System*) | ||
cleanEquationSystem = Select[equationSystem, !TrueQ[#]&];(*Remove tautologies*) | ||
dualEquationSystem = Map[Part[#, 1] == 1 - (Part[#, 2])&, cleanEquationSystem];(*Apply Not to all variables*) | ||
dualEquationSystemResult = Or @@ (# & /@ dualEquationSystem) (*Change boolean operator AND to OR*) | ||
]; | ||
|
||
DifferenceReplacementRules[template1_List, template2_List, modulus_Integer : 0] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you receive full templates instead of their |
||
Module[{ | ||
templateVars = SortBy[Union[Flatten[{TemplateCoreVars[template1], TemplateCoreVars[template2]}, 1]], | ||
FromDigits[StringDrop[SymbolName[#], 1]] &], | ||
dualEquationSystem | ||
}, | ||
dualEquationSystem = DualEquationSystem[template1, template2]; | ||
If[dualEquationSystem =!= False, | ||
If[modulus === 0, | ||
Union[Quiet[Solve[DualEquationSystem[template1, template2], templateVars]]], | ||
Union[Quiet[Solve[DualEquationSystem[template1, template2], Reverse[templateVars], Modulus -> modulus]]] | ||
], {} | ||
] | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this |
||
|
||
End[]; | ||
EndPackage[]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
(* ::Package:: *) | ||
|
||
BeginPackage[ | ||
"CATemplates`TemplateOperations`Difference`ExceptionTemplates`", | ||
{ | ||
"CATemplates`Basic`", | ||
"CATemplates`CATemplate`" | ||
} | ||
]; | ||
|
||
PossibleInvalidSubsets::usage = "bl1"; | ||
SubstitutionRangeVar::usage = "bl1"; | ||
ExpandVar::usage = "bl1"; | ||
ExpandVars::usage = "bl1"; | ||
InvalidSubSets::usage = "bl1"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bogus |
||
ExceptionTemplates::usage= "ExceptionTemplates[t_List, k_Integer:2, r_Real:1] generate all the templates with variable assignments that make the template t with k colors and r range invalid."; | ||
|
||
Begin["`Private`"]; | ||
PossibleInvalidSubsets[intemplate_Association] := PossibleInvalidSubsets[intemplate[["rawList"]]]; | ||
PossibleInvalidSubsets[intemplate_List] := Select[intemplate, (Depth[#] > 1) &]; | ||
|
||
SubstitutionRangeVar[var_, k_Integer : 2] := Range[0, k^Length[TemplateCoreVars[{var}]] - 1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about renaming this to |
||
|
||
ExpandVar[var_, i_Integer] := Module[{variables = TemplateCoreVars[{var}], substitution, transformationRules, result}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this related to template expasion? If not, please use another name so we don't get confused |
||
substitution = Reverse[IntegerDigits[i, 2, Length[variables]]]; | ||
transformationRules = MapThread[#1 -> #2 &, {variables, substitution}]; | ||
result = var /. transformationRules; | ||
If[result >= 2|| result < 0, transformationRules, (##) &[]] | ||
]; | ||
ExpandVars[vars_, range_] := | ||
Module[{result}, result = Map[ExpandVar[vars, #] &, range]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer |
||
If[result == {}, Nothing, result]]; | ||
|
||
InvalidSubSets[intemplate_List] := | ||
Module[{possibleInvalids = PossibleInvalidSubsets[intemplate], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be a |
||
result}, | ||
result = | ||
MapThread[ | ||
ExpandVars, {possibleInvalids, | ||
SubstitutionRangeVar[#, 2] & /@ possibleInvalids}]; | ||
If[result == {}, {}, Flatten[result, 1]]]; | ||
|
||
InvalidSubSets[intemplate_Association] := Module[{possibleInvalids = PossibleInvalidSubsets[intemplate]}, | ||
MapThread[ExpandVars, {possibleInvalids, SubstitutionRangeVar[#, intemplate[["k"]]]& /@ possibleInvalids}] | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. close |
||
|
||
ExceptionTemplates[intemplate_Association] := | ||
Module[{exceptionTemplates}, | ||
exceptionTemplates = ExceptionTemplates[intemplate[["core"]], intemplate[["k"]], intemplate[["r"]]]; | ||
BuildTemplate[intemplate[["k"]], intemplate[["r"]], #] & /@ exceptionTemplates | ||
]; | ||
|
||
ExceptionTemplates[intemplate_List] := | ||
ExceptionTemplates[intemplate, 2, 1.0]; | ||
|
||
ExceptionTemplates[intemplate_List, k_ /; k === 2, r_Real : 1.0] := | ||
Module[{invalidSubsSets, filteredInvalidSubsSets, baseTemplate = OldBaseTemplate[k, r], result = {}}, | ||
invalidSubsSets = Union[ | ||
SortBy[InvalidSubSets[intemplate], Total] | ||
]; | ||
If[invalidSubsSets =!= {}, | ||
filteredInvalidSubsSets = MinimizedRuleSets[invalidSubsSets]; | ||
result = (baseTemplate /. #) & /@ filteredInvalidSubsSets; | ||
]; | ||
result | ||
]; | ||
|
||
ExceptionTemplates[intemplate_List, k_Integer:2, r_Real : 1.0] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably shadowing the previous definition of |
||
MapThread[If[#2 === _, #1, #2]&, {OldBaseTemplate[k, r], #}]& /@ Union[(If[NumberQ[#], #, _]& /@ #)& /@ ((OldBaseTemplate[k, r] /. #[[1]])& /@ Cases[{#[[2]], #[[1]] /. #[[2]]}& /@ Flatten[Outer[List, {#[[1]]}, #[[2]], 1]& /@ ({#[[2]], MapThread[#1 -> #2&, {#[[1]], #[[2]]}]& /@ #[[1]]}& /@ ({First@Outer[List, {#[[1]]}, #[[2]], 1], #[[3]]}& /@ ({#[[1]], Tuples[Range[0, k - 1], Length[#[[1]]]], #[[2]]}& /@ ({TemplateCoreVars[{#}], #}& /@ Select[intemplate, (Depth[#] > 1)&])))), 2], {_, x_ /; \[Not]MemberQ[Range[0, k - 1], x]}])] | ||
|
||
End[]; | ||
EndPackage[]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(* ::Package:: *) | ||
|
||
Get["CATemplates`TemplateOperations`Difference`Common`"]; | ||
|
||
Get["CATemplates`TemplateOperations`Difference`RawDifference`"] | ||
|
||
Get["CATemplates`TemplateOperations`Difference`TemplateDifference`"] | ||
|
||
Get["CATemplates`TemplateOperations`Difference`ExceptionTemplates`"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
(* ::Package:: *) | ||
|
||
BeginPackage[ | ||
"CATemplates`TemplateOperations`Difference`RawDifference`", | ||
{ | ||
"CATemplates`Basic`", | ||
"CATemplates`CATemplate`", | ||
"CATemplates`TemplateOperations`Intersection`TemplateIntersection`", | ||
"CATemplates`TemplateOperations`Difference`Common`", | ||
"CATemplates`TemplateOperations`Difference`ExceptionTemplates`"} | ||
]; | ||
|
||
|
||
RawDifference::usage = "bl1"; | ||
RawDifferenceOld::usage = "bl1"; | ||
RawDifferenceDirect::usage = "bl1"; | ||
RawDifferenceDirectOld::usage = "bl1"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bogus |
||
|
||
Begin["`Private`"]; | ||
|
||
RawDifferenceOld[template1_List, template2_List, radius_ : 1.0] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not being used |
||
Module[{templateIntersection, exceptionTemplates, templateDifferenceP1, templateDifferenceP2, templateDifference, replacementRules, replacementRulesFinal}, | ||
templateIntersection = Flatten[RawIntersection[template1, template2]]; | ||
If[!ValidTemplateCoreQ[templateIntersection] || templateIntersection === {}, | ||
templateDifference = {template1};, | ||
replacementRules = DifferenceReplacementRules[template1, templateIntersection]; | ||
replacementRulesFinal = Select[replacementRules, FreeQ[#, _Rational] &]; | ||
|
||
If[replacementRulesFinal == {}, templateDifference = {};, | ||
templateDifferenceP1 = template1 /. replacementRulesFinal; | ||
exceptionTemplates = ExceptionTemplates[templateIntersection, 2, radius]; | ||
templateDifferenceP2 = RawIntersection[template1, #] & /@ exceptionTemplates; | ||
templateDifference = Join[templateDifferenceP1, templateDifferenceP2]; | ||
] | ||
]; | ||
templateDifference | ||
]; | ||
|
||
RawDifferenceDirectOld[template1_List, template2_List, radius_ : 1.0] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
Module[{templateIntersection, exceptionTemplates, templateDifferenceP1, templateDifferenceP2, templateDifference, replacementRules, replacementRulesFinal}, | ||
templateIntersection = Flatten[RawIntersection[template1, template2]]; | ||
If[!ValidTemplateCoreQ[templateIntersection] || templateIntersection === {}, | ||
templateDifference = {template1};, | ||
replacementRules = DifferenceReplacementRules[template1, template2]; | ||
replacementRulesFinal = Select[replacementRules, FreeQ[#, _Rational] &]; | ||
replacementRulesFinal = Select[replacementRules, ContainsOnly[TemplateCoreVars[#], TemplateCoreVars[template1]]&]; | ||
|
||
If[replacementRulesFinal == {}, | ||
templateDifferenceP1 = {};, | ||
templateDifferenceP1 = template1 /. replacementRulesFinal; | ||
]; | ||
exceptionTemplates = ExceptionTemplates[template2, 2, radius]; | ||
templateDifferenceP2 = RawIntersection[template1, #] & /@ exceptionTemplates; | ||
templateDifference = Join[templateDifferenceP1, templateDifferenceP2]; | ||
(*Print[templateDifferenceP1];*) | ||
(*Print[templateDifferenceP2];*) | ||
]; | ||
templateDifference | ||
]; | ||
|
||
RawDifference[template1A_Association, template2A_Association, radius_ : 1.0] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try to extract some of this code to functions with meaningful names? |
||
Module[{template1, template2, templateIntersection, template1And2HasIntersection, templateIntersectionA, exceptionTemplates, templateDifferenceP1, templateDifferenceP2, templateDifference, replacementRules, replacementRulesFinal}, | ||
template1 = template1A[["core"]]; | ||
template2 = template2A[["core"]]; | ||
templateIntersectionA = TemplateIntersection[template1A,template2A]; | ||
templateIntersection = templateIntersectionA[["core"]]; | ||
template1And2HasIntersection = !(!ValidTemplateCoreQ[templateIntersection] || templateIntersection === {}); | ||
If[!template1And2HasIntersection, | ||
templateDifference = {template1};, | ||
replacementRules = DifferenceReplacementRules[template1, templateIntersection]; | ||
replacementRulesFinal = Select[replacementRules, FreeQ[#, _Rational] &]; | ||
replacementRulesFinal = Select[replacementRules, ContainsOnly[TemplateCoreVars[#], TemplateCoreVars[template1]]&]; | ||
|
||
If[replacementRulesFinal == {}, | ||
templateDifferenceP1 = {};, | ||
templateDifferenceP1 = template1 /. replacementRulesFinal; | ||
]; | ||
exceptionTemplates = ExceptionTemplates[templateIntersectionA]; | ||
templateDifferenceP2 = TemplateIntersection[template1A, #] & /@ exceptionTemplates; | ||
templateDifferenceP2 = #[["core"]] & /@templateDifferenceP2; | ||
templateDifference = Join[templateDifferenceP1, templateDifferenceP2]; | ||
]; | ||
templateDifference | ||
]; | ||
|
||
|
||
RawDifferenceDirect[template1A_Association, template2A_Association, radius_ : 1.0] := | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between |
||
Module[{template1, template2, templateIntersection, template1And2HasIntersection, templateIntersectionA, exceptionTemplates, templateDifferenceP1, templateDifferenceP2, templateDifference, replacementRules, replacementRulesFinal}, | ||
template1 = template1A[["core"]]; | ||
template2 = template2A[["core"]]; | ||
templateIntersectionA = TemplateIntersection[template1A,template2A]; | ||
templateIntersection = templateIntersectionA[["core"]]; | ||
template1And2HasIntersection = !(!ValidTemplateCoreQ[templateIntersection] || templateIntersection === {}); | ||
If[!template1And2HasIntersection, | ||
templateDifference = {template1};, | ||
replacementRules = DifferenceReplacementRules[template1, template2]; | ||
replacementRulesFinal = Select[replacementRules, FreeQ[#, _Rational] &]; | ||
replacementRulesFinal = Select[replacementRules, ContainsOnly[TemplateCoreVars[#], TemplateCoreVars[template1]]&]; | ||
|
||
If[replacementRulesFinal == {}, | ||
templateDifferenceP1 = {};, | ||
templateDifferenceP1 = template1 /. replacementRulesFinal; | ||
]; | ||
exceptionTemplates = ExceptionTemplates[template2A]; | ||
templateDifferenceP2 = TemplateIntersection[template1A, #] & /@ exceptionTemplates; | ||
templateDifferenceP2 = #[["core"]] & /@templateDifferenceP2; | ||
templateDifference = Join[templateDifferenceP1, templateDifferenceP2]; | ||
]; | ||
templateDifference | ||
]; | ||
|
||
|
||
|
||
End[]; | ||
EndPackage[]; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid adding functions to
Basic
.#59 removes this namespace and we are gonna have conflicts.
If these functions are only used on
ExceptionTemplates
, you can leave them there.If you think these could be useful to other functions in the future, you can create a new namespace for them.