Skip to content

Commit

Permalink
Merge pull request #23 from rhennigan/feature/custom-rule-specifications
Browse files Browse the repository at this point in the history
Custom rule specifications and misc Bug fixes
  • Loading branch information
rhennigan authored Jun 22, 2023
2 parents 9e368fe + 6f3e251 commit 472fa11
Show file tree
Hide file tree
Showing 28 changed files with 3,999 additions and 2,655 deletions.
26 changes: 22 additions & 4 deletions Data/RuleSets/Arithmetic.wl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "Arithmetic-deiVLm",
"Name" -> "Plus-0",
"Description" -> "Transform using basic arithmetic rules",
"Usage" -> { "EquivalenceTesting", "Simplification", "Optimization" },
"Symbols" :> { Plus },
Expand All @@ -52,7 +52,16 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "Arithmetic-cJntVW",
"Name" -> "Plus-1",
"Description" -> "Simplify Plus expressions with one argument",
"Usage" -> { "EquivalenceTesting", "Simplification", "Optimization" },
"Symbols" :> { Plus },
"Rule" :> Verbatim[ Plus ][ x_ ] :> x
|>

(**********************************************************************************************************************)
<|
"Name" -> "Times-0",
"Description" -> "Transform using basic arithmetic rules",
"Usage" -> { "EquivalenceTesting", "Simplification", "Optimization" },
"Symbols" :> { Times },
Expand All @@ -61,8 +70,17 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "Arithmetic-bjzLyg",
"Description" -> "Transform using basic arithmetic rules",
"Name" -> "Times-1",
"Description" -> "Simplify Times expressions with one argument",
"Usage" -> { "EquivalenceTesting", "Simplification", "Optimization" },
"Symbols" :> { Times },
"Rule" :> Verbatim[ Times ][ x_ ] :> x
|>

(**********************************************************************************************************************)
<|
"Name" -> "Power-1",
"Description" -> "Simplify Power expressions with one argument",
"Usage" -> { "EquivalenceTesting", "Simplification", "Optimization" },
"Symbols" :> { Power },
"Rule" :> Power[ x_ ] :> x
Expand Down
2 changes: 2 additions & 0 deletions Data/RuleSets/Attributes.wl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SetRuleDefaults @ <|
(**********************************************************************************************************************)
<|
"Description" -> "Resolve single-argument forms of functions with the OneIdentity attribute",
"Usage" -> { Inherited, "Simplification", "Optimization" },
"Symbols" :> { Attributes, OneIdentity },
"Rule" :>
(f_Symbol? SymbolQ)[ x: Except[ _Symbol? SymbolQ, _? UAtomQ ] ] /; MemberQ[ Attributes @ f, OneIdentity ] :>
Expand All @@ -53,6 +54,7 @@ SetRuleDefaults @ <|
<|
(* TODO: this doesn't quite belong in attribute rules *)
"Description" -> "Resolve Apply when the specified function is not holding",
"Usage" -> { Inherited, "Simplification", "Optimization" },
"Symbols" :> { Attributes, HoldFirst, HoldRest, HoldAll, HoldAllComplete, Apply },
"Rule" :>
(f_? SymbolQ) @@ { a___ } /; And[
Expand Down
39 changes: 20 additions & 19 deletions Data/RuleSets/Internal.wl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "StripTempHoldWrappers",
"Description" -> "Strip TempHold wrappers",
"Symbols" :> { TempHold },
"Priority" -> -Infinity,
Expand All @@ -32,6 +33,7 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "PreserveTransformHold",
"Description" -> "Prevent transformation of TransformHold contents",
"Symbols" :> { TransformHold },
"Priority" -> -10000,
Expand All @@ -41,6 +43,7 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "HandlePacletSymbol",
"Description" -> "Handle PacletSymbol wrappers for pasted documentation examples",
"Symbols" :> { PacletSymbol },
"Internal" -> True,
Expand All @@ -58,32 +61,17 @@ SetRuleDefaults @ <|
|>

(**********************************************************************************************************************)
(* TODO: combine these rules: *)
<|
"Name" -> "SimplifyTrivialIntegerOperations",
"Description" -> "Simplify trivial integer operations",
"Usage" -> { "EquivalenceTesting", "Optimization", "Simplification" },
"Symbols" :> { Ceiling },
"Rule" :> Ceiling[ i_? IntTypeQ ] :> i
|>

(**********************************************************************************************************************)
<|
"Description" -> "Simplify trivial integer operations",
"Usage" -> { "EquivalenceTesting", "Optimization", "Simplification" },
"Symbols" :> { Floor },
"Rule" :> Floor[ i_? IntTypeQ ] :> i
|>

(**********************************************************************************************************************)
<|
"Description" -> "Simplify trivial integer operations",
"Usage" -> { "EquivalenceTesting", "Optimization", "Simplification" },
"Symbols" :> { Round },
"Rule" :> Round[ i_? IntTypeQ ] :> i
"Symbols" :> { Ceiling, Floor, Round, IntegerPart },
"Rule" :> (Ceiling|Floor|Round|IntegerPart)[ i_? IntTypeQ ] :> i
|>

(**********************************************************************************************************************)
<|
"Name" -> "MaskGraphicsIntegerLists",
"Description" -> "Hide large integer lists in graphics from transformations",
"Usage" -> { "EquivalenceTesting", "Optimization" },
"Symbols" :> { Graphics, Graphics3D },
Expand All @@ -102,6 +90,7 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "FlattenTypedSymbol",
"Description" -> "Flatten TypedSymbol expressions",
"Symbols" :> { TypedSymbol },
"Internal" -> True,
Expand All @@ -111,6 +100,17 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "ApplyHoldApply",
"Description" -> "Apply HoldApply expressions",
"Symbols" :> { HoldApply },
"Internal" -> True,
"Priority" -> 10000,
"Rule" :> HoldApply[ f_, { v___ } ] :> f @ v
|>

(**********************************************************************************************************************)
<|
"Name" -> "LoopTest-1",
"Description" -> "Generate a cycle detection warning for testing",
"Symbols" :> { },
"Internal" -> True,
Expand All @@ -122,6 +122,7 @@ SetRuleDefaults @ <|

(**********************************************************************************************************************)
<|
"Name" -> "LoopTest-2",
"Description" -> "Generate a cycle detection warning for testing",
"Symbols" :> { },
"Internal" -> True,
Expand Down
Loading

0 comments on commit 472fa11

Please sign in to comment.