6
votes
Accepted
How to force Mathematica to simplify in terms of half angles?
Clear["Global`*"]
expr = Sinh[x]/(Sqrt[2] Sqrt[1 + Cosh[x]])
(expr /. x -> 2 θ // TrigExpand //
Simplify) /. θ -> (x/2) // PowerExpand
Sinh[x/...
5
votes
Accepted
How to make ReplaceAll recognize what to be replaced in a situation like this?
Instead of x + y -> 1 replace only one of the variables x->1-y or y->1-x, it does ...
5
votes
Accepted
5
votes
Accepted
With function replace rule does not work in
try this:
sumT = TA + TE;
With[
{TA = 0.1, TE = 0.2},
Evaluate@{TA + TE, sumT}
]
4
votes
Accepted
ReplaceAll causing infinite recursion
$Version
(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)
Clear["Global`*"]
You can never Set a ...
4
votes
How to make ReplaceAll recognize what to be replaced in a situation like this?
ReplaceAll operates on the parts of the expression.
...
4
votes
Accepted
Different answers when attempting replacement of function argument
The /. infix form is just syntactic sugar. The expression that gets evaluated here is
...
4
votes
Different answers when attempting replacement of function argument
fib1 should be limited not to evaluate unless $n$ is an explicit integer number, so let's redefine it as such (in the following I've also used a version with ...
3
votes
Different answers when attempting replacement of function argument
Look at:
fib1[n]
-1 + n
fib1[n] /. n->10
9
And for fib2:
fib2[n]
2
Here the ReplaceAll does nothing.
3
votes
With function replace rule does not work in
In answer to
Could you give some explanation ?
Just follow the evaluation process
With[ {TA = 0.1, TE = 0.2}, {TA + TE, sumT} ]
...
3
votes
With function replace rule does not work in
Replace With with Block:
sumT = TA + TE;
Block[{TA = 0.1, TE = 0.2}, {TA + TE, sumT}]
{0.3,...
3
votes
How to make ReplaceAll recognize what to be replaced in a situation like this?
New answer based upon your revised question:
rep[f_] :=
Expand[f] /. Plus[Times[a_, _Symbol], Times[b_, _Symbol]] :> a
2 x + 2 y // rep
2
...
2
votes
Accepted
Why is replacement so slow for long sums?
I believe the code is slow because Integrate will try to evaluate the intermediate expressions before they are fully resolved. You may try using ...
2
votes
How to make ReplaceAll recognize what to be replaced in a situation like this?
Another way to do this is as follows:
rep = # /. s_Symbol /; Attributes[s] === {} -> 1 &;
rep@(2 x + 2 y)
(*4*)
rep@Exp[I Pi (2 a + 2 b + 5)]
(*-1*)
1
vote
How to make ReplaceAll recognize what to be replaced in a situation like this?
ReplaceAll simply replaces pattern, not the value. And you have no x+y pattern in that expression.
Try ...
1
vote
Accepted
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
replacement × 1593list-manipulation × 286
pattern-matching × 226
rule × 184
simplifying-expressions × 100
functions × 80
matrix × 74
expression-manipulation × 73
evaluation × 64
string-manipulation × 59
equation-solving × 57
calculus-and-analysis × 55
function-construction × 53
symbolic × 49
differential-equations × 40
performance-tuning × 36
algebraic-manipulation × 33
hold × 33
plotting × 27
syntax × 24
associations × 23
conditional × 23
scoping × 20
assignment × 19
output-formatting × 18