Pattern matching repeated arguments of TimesA pattern involving TimesReplacing with pattern on built-in...
What does the behaviour of water on the skin of an aircraft in flight tell us?
What is the 中 in ダウンロード中?
Why did this prime-sequence puzzle not work?
Is floating in space similar to falling under gravity?
Future enhancements for the finite element method
What are the problems in teaching guitar via Skype?
What are these (utility?) boxes at the side of the house?
What caused the tendency for conservatives to not support climate change reform?
Looking after a wayward brother in mother's will
How to capture more stars?
Plot exactly N bounce of a ball
How to prevent bad sectors?
File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell
How many chess players are over 2500 Elo?
Different PCB color ( is it different material? )
What is the most important source of natural gas? coal, oil or other?
Tic-Tac-Toe for the terminal
shutdown at specific date
Preserving culinary oils
How do I subvert the tropes of a train heist?
SQL Server (JOIN) all from first with NULLs from 2nd
If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?
How does an ARM MCU run faster than the external crystal?
Smart people send dumb people to a new planet on a space craft that crashes into a body of water
Pattern matching repeated arguments of Times
A pattern involving TimesReplacing with pattern on built-in symbols?Commutativity of Times and pattern matchingPattern matching repeated structures with named subexpression componentsDeep Pattern matching with repeating argumentsPattern matchingStringExpression: pattern reapeted one or more times matches pattern repeated zero timesPattern matching: Times[a_] vs Times[a__]Pattern matching an expression involving TimesPattern matching and Plus, Times, Power etcDot confused with Times in pattern matchingRepeated pattern in XMLElementCommutativity of Times and pattern matching
$begingroup$
I am trying to match against products of elements with a specific pattern. Since a product of symbols A B C is just Times[A,B,C], I figured this could be done by treating Times like any other symbol (here f):
MatchQ[ f[a,b,c], f[_Symbol..] ]
>>> True
Woe, such a pattern doesn't seem to work for Times:
MatchQ[ a b c, Times[_Symbol..] ]
>>> False
MatchQ[ Times[a, b, c], Times[_Symbol..] ]
>>> False
I suspect this may be due to some property of Times related to its commutativity, though there's no auto-commuting in this example!
a b c // FullForm
>>> Times[a, b, c]
How can I produce the desired pattern for matching repeated-pattern arguments of Times?
pattern-matching
$endgroup$
add a comment |
$begingroup$
I am trying to match against products of elements with a specific pattern. Since a product of symbols A B C is just Times[A,B,C], I figured this could be done by treating Times like any other symbol (here f):
MatchQ[ f[a,b,c], f[_Symbol..] ]
>>> True
Woe, such a pattern doesn't seem to work for Times:
MatchQ[ a b c, Times[_Symbol..] ]
>>> False
MatchQ[ Times[a, b, c], Times[_Symbol..] ]
>>> False
I suspect this may be due to some property of Times related to its commutativity, though there's no auto-commuting in this example!
a b c // FullForm
>>> Times[a, b, c]
How can I produce the desired pattern for matching repeated-pattern arguments of Times?
pattern-matching
$endgroup$
1
$begingroup$
Related: (156282), (191133), (194131)
$endgroup$
– Michael E2
8 hours ago
add a comment |
$begingroup$
I am trying to match against products of elements with a specific pattern. Since a product of symbols A B C is just Times[A,B,C], I figured this could be done by treating Times like any other symbol (here f):
MatchQ[ f[a,b,c], f[_Symbol..] ]
>>> True
Woe, such a pattern doesn't seem to work for Times:
MatchQ[ a b c, Times[_Symbol..] ]
>>> False
MatchQ[ Times[a, b, c], Times[_Symbol..] ]
>>> False
I suspect this may be due to some property of Times related to its commutativity, though there's no auto-commuting in this example!
a b c // FullForm
>>> Times[a, b, c]
How can I produce the desired pattern for matching repeated-pattern arguments of Times?
pattern-matching
$endgroup$
I am trying to match against products of elements with a specific pattern. Since a product of symbols A B C is just Times[A,B,C], I figured this could be done by treating Times like any other symbol (here f):
MatchQ[ f[a,b,c], f[_Symbol..] ]
>>> True
Woe, such a pattern doesn't seem to work for Times:
MatchQ[ a b c, Times[_Symbol..] ]
>>> False
MatchQ[ Times[a, b, c], Times[_Symbol..] ]
>>> False
I suspect this may be due to some property of Times related to its commutativity, though there's no auto-commuting in this example!
a b c // FullForm
>>> Times[a, b, c]
How can I produce the desired pattern for matching repeated-pattern arguments of Times?
pattern-matching
pattern-matching
asked 9 hours ago
Anti EarthAnti Earth
22519
22519
1
$begingroup$
Related: (156282), (191133), (194131)
$endgroup$
– Michael E2
8 hours ago
add a comment |
1
$begingroup$
Related: (156282), (191133), (194131)
$endgroup$
– Michael E2
8 hours ago
1
1
$begingroup$
Related: (156282), (191133), (194131)
$endgroup$
– Michael E2
8 hours ago
$begingroup$
Related: (156282), (191133), (194131)
$endgroup$
– Michael E2
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
You need wrap the pattern Times[...] with HoldPattern or Verbatim to prevent Times[_Symbol ..] evaluating to _Symbol.. before MatchQ does its work:
MatchQ[a b c, HoldPattern[Times][_Symbol ..]]
True
MatchQ[a b c, Verbatim[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], HoldPattern[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], Verbatim[Times][_Symbol ..]]
True
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199196%2fpattern-matching-repeated-arguments-of-times%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You need wrap the pattern Times[...] with HoldPattern or Verbatim to prevent Times[_Symbol ..] evaluating to _Symbol.. before MatchQ does its work:
MatchQ[a b c, HoldPattern[Times][_Symbol ..]]
True
MatchQ[a b c, Verbatim[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], HoldPattern[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], Verbatim[Times][_Symbol ..]]
True
$endgroup$
add a comment |
$begingroup$
You need wrap the pattern Times[...] with HoldPattern or Verbatim to prevent Times[_Symbol ..] evaluating to _Symbol.. before MatchQ does its work:
MatchQ[a b c, HoldPattern[Times][_Symbol ..]]
True
MatchQ[a b c, Verbatim[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], HoldPattern[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], Verbatim[Times][_Symbol ..]]
True
$endgroup$
add a comment |
$begingroup$
You need wrap the pattern Times[...] with HoldPattern or Verbatim to prevent Times[_Symbol ..] evaluating to _Symbol.. before MatchQ does its work:
MatchQ[a b c, HoldPattern[Times][_Symbol ..]]
True
MatchQ[a b c, Verbatim[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], HoldPattern[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], Verbatim[Times][_Symbol ..]]
True
$endgroup$
You need wrap the pattern Times[...] with HoldPattern or Verbatim to prevent Times[_Symbol ..] evaluating to _Symbol.. before MatchQ does its work:
MatchQ[a b c, HoldPattern[Times][_Symbol ..]]
True
MatchQ[a b c, Verbatim[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], HoldPattern[Times][_Symbol ..]]
True
MatchQ[Times[a, b, c], Verbatim[Times][_Symbol ..]]
True
edited 9 hours ago
answered 9 hours ago
kglrkglr
194k10215436
194k10215436
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199196%2fpattern-matching-repeated-arguments-of-times%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
Related: (156282), (191133), (194131)
$endgroup$
– Michael E2
8 hours ago