Re: Avoid iteration in pattern test?
- To: mathgroup at smc.vnet.net
- Subject: [mg132173] Re: Avoid iteration in pattern test?
- From: Carl K Woll <carlw at wolfram.com>
- Date: Thu, 9 Jan 2014 03:51:25 -0500 (EST)
- Delivered-to: email@example.com
- Delivered-to: firstname.lastname@example.org
- Delivered-to: email@example.com
- Delivered-to: firstname.lastname@example.org
- References: <20140106073034.2A31D69D3@smc.vnet.net>
You could try:
x /: HoldPattern[Times][f__, x] /; ! FreeQ[Hold[f], d] := "matched"
On 1/6/2014 1:30 AM, Yi Wang wrote:
> Dear all,
> I wonder if one can stop pattern test from unnecessary iteration. For example
> ClearAll[x, a, b, c, d, f]
> x /: f_ x := "matched" /; !FreeQ[f, d]
> Trace[a b c x]
> One can find that Mathematica first tests if a*b*c is free of d. Then it tests if a*b is free of d, if a*c is free of d, ...
> However, we know that if a*b*c is free of d, all the sub-sequences are free of d. Thus is it possible to rewrite the above rule, to stop Mathematica from wasting the efforts?
> Thanks a lot!
> PS: currently, I have a workaround -- to hold evolution of x when no match. However, it makes things complicated and less automatic.
> x /: f_ x := If[!FreeQ[f, d], "matched", f Hold[x]]
Prev by Date:
Re: Intersect Point of a 3D Parametric Line & B-Spline
Next by Date:
Re: Plot in manipulate
Previous by thread:
Avoid iteration in pattern test?
Next by thread:
Benchmarking Mathematica on the Raspberry Pi