New answers tagged expression-manipulation
1
Maybe this
Replace[Expand@expr, Times[terms__ /; Count[{terms}, _f | _g, Infinity] > 1] -> 0, 1]
1
Try this
First harvest the terms:
terms = Cases[expr, (_f | _g) | Conjugate[_g | _f], Infinity]//Union
and then
(D[expr, {terms}] /. {f -> (0 &), g -> (0 &)}).terms + (expr/.Thread[terms -> 0])
Note:
For a faster alternative use CoefficientArrays:
#1 + #2.terms & @@ (Take[CoefficientArrays[expr, terms], 2] // Normal)
3
How about this:
(Series[Simplify[expr/.{forg_[x_] -> m forg[x]}, m \[Element] Reals], {m, 0, 1}] // Normal) /. m -> 1
Edit:
If there are other functions within the expression that are not f or g then you have to be a bit more explicit:
(Series[Simplify[expr/.{f[x_] -> m f[x],g[x_]->m g[x]}, m \[Element] Reals], {m, 0, 1}] // Normal) /. m ...
11
Implementation
The following implementation is based on expression serialization and SequenceAlignment built-in function. The idea is to break expressions into constituent parts, then align these part sequences, and then determine the positions where the expressions are different.
The auxiliary heads we will need are inert heads diff and myHold, the latter ...
0
Found one way to do this. If f is the function you're interested in, the following will give you a list of lists of argument types, so long as the definitions are of the form f[firstParam_Integer, secondParam_Real, ...].
Cases[DownValues[f], RuleDelayed[func_, _] :> Level[func, {4}]]
2
For diff'ing code fragments/expressions, you can copy-and-paste as "Plain Text" into Quick Diff (online) or into WinMerge (PC-based), ref. http://stackoverflow.com/q/15655828/879601 (also mentions a Mac-based method using Bash).
E.g. WinMerge:-
(For diff'ing packages and notebooks I favour CSDiff.)
5
If you can convert expressions to text form, there's a possible answer here. I sometimes use it to compare notebooks:
notebook1 =
StringJoin[
Import["/tmp/freaky-illusion.nb", "Plaintext"]];
notebook2 =
StringJoin[
Import["/tmp/freaky-illusion-1.nb", "Plaintext"]];
System`Dump`showStringDiff[notebook1, notebook2]
3
Let that you have the variables
vars= {Subscript[1, a],Subscript[1, b],Subscript[2, a],Subscript[2, b],Subscript[3, a],
Subscript[3, b]}
and
expr=(3 Subscript[1, b] Subscript[2, a])/8+1/8 E^(I [Theta]) Subscript[1, b] Subscript[2, a]+1/8 E^(2 I [Theta]) Subscript[1, b] Subscript[2, a]+3/8 E^(3 I [Theta]) Subscript[1, b] Subscript[2, a]-(3 ...
Top 50 recent answers are included
