Questions tagged [rule]

Questions about transformation rules in Mathematica--constructs that let you set, or programmatically modify, local values for expressions.

Useful links:

356 questions
10
votes
4 answers

Is there a simple way to apply a function to the RHS of a substitution?

Suppose I have solved a system of equations, resulting in a solution of the form: sol = {{f[a1] -> SomeComplicatedFunction[x, a1]}, {f[a2] -> SomeComplicatedFunction[x, a2]}, {f[a3] -> SomeComplicatedFunction[x, a3]}} I want to use the list of…
user366202
  • 451
  • 2
  • 8
6
votes
4 answers

Add the values in the rule

{ a -> 1, a -> 2, b -> 3, b -> 4 } You can see that both a and b have two values, so how do I add these two vaule?Like this {a->3,b->7}
我心永恒
  • 1,488
  • 6
  • 9
4
votes
0 answers

Applying Inversed Rules

If I have {x->2,y->3,z->19} and make many calculations and finaly get First/@FactorInteger[57] {3, 19} how can I apply the inversed rules to get {y,z} without using /.{2->x,3->y,19->z}
ZaMoC
  • 6,697
  • 11
  • 31
4
votes
3 answers

Applying rules to expressions

I'm trying to write a rule that acts on any number, lists, expression and so on to turn any negative numbers positive. The simple r = n_ -> Abs[n] works perfectly well for numbers, lists and nested lists, but does not work expressions, such as…
Pablo
  • 155
  • 5
3
votes
1 answer

Remove duplicate rules in a list?

Replace and ReplaceAll apply rules only once, so multiple (redundant) rules can be given as input and the first instance of a rule is the only one that is applied. How can I go about creating a function simplifyRules that can be given a list of…
dionys
  • 4,321
  • 1
  • 19
  • 46
2
votes
2 answers

A rule to transpose pattern and target of a rule?

I am trying to write a Mathematica function that will take a rule such as a->b to `b->a'. Can this be done?
Yossi Gil
  • 121
  • 2
1
vote
1 answer

How to combine multiple rules?

I have 2 rules: Rule[#, SomeFunction[#]] &/@ SomeFunctionArgs; Rule[#, OtherFunction[#]] &/@ OtherFunctionArgs; I want to have one function that combines the 2 results in 1. I have tried to do: MainFunction[] =: ( Rule[#, SomeFunction[#]] &/@…
SuTron
  • 1,708
  • 1
  • 11
  • 21
1
vote
1 answer

using rules to look up values

I have a lookup table with about 30 rows. Column 1 has the value I want to search for and column 2 has the value I want returned. It seemed like I should be able to use rules to do this, but clearly I don't know what I'm doing. Oh, the values are…
Mitchell Kaplan
  • 3,696
  • 22
  • 34
1
vote
2 answers

How to implement this simple product rule in mathematica

Firstly i have defined a simple function below. dotPro[a_, b_] := a[1]*b[1] + a[2]*b[2]; Then i create two terms using the above function. t1=dotPro[q,σ]; t2=dotPro[ϵ,σ]; Then i have some rules regarding how these parameters multiply r1 =…
Hubble07
  • 3,614
  • 13
  • 23
1
vote
1 answer

Delayed rule at StringReplace

In the StringReplace example(chaging two letter to uppercase) below, delayed rule is used. However, the result is the same even if rule is used. 1)The delayed rule must be uesd in this case? 2)In what cases should delayed rule should be used when…
Soon
  • 648
  • 3
  • 8
1
vote
1 answer

How to replace variables with functions in an expression?

I have an expression: KK = -(2*b *(c + 6) *(b + a) *d /(b + d) *(c + d)) a, b, c, d - are variables, a[i_]:=i^2; b[i_]:=i; c[i_]:=i-2; d[i_]:=i^3; - are functions. I would like to change the variables to the functions in this way: a -> a[i_], b ->…
Mam Mam
  • 1,843
  • 2
  • 9
1
vote
2 answers

How to use a rule and its derivative on an equation?

I generated a very simple rule that is of the type {a[0] -> 0, a[1] -> 0, a[2] -> 8/3*pi} And I want to impose this set of rules on an equation. The problem is that in this equation there are some derived terms like a'[0]. How can I use the rule…
Ramos
  • 11
  • 2
1
vote
0 answers

How to substitute values of multiple variables into an expression

Brand new user here. How to substitute values of multiple variables into an expression? I try: n + m /. {n, m} -> {2, 4} # produces `m+n` as output # or alternatively n + m /. n->2, m->4 # gives blank output n+5 ./ n->2 works and produces 7 as…
Smithey
  • 121
  • 4
1
vote
3 answers

Pattern with two lists

I have two lists with multiple array elements: myList = {{myArray[1, 0, 0], myArray[1, 0, 1], myArray[1, 0, 2], myArray[1, 1, 0], myArray[1, 1, 1], myArray[1, 1, 2], myArray[1, 2, 0], myArray[1, 2, 1], myArray[1, 2, 2]}, {myArray[2, 0, 0],…
Mark R
  • 1,589
  • 5
  • 10
1
vote
1 answer

a problem of substitution with a rule

I would to make this substitution with 2 rules. Nothing is happening. (Sin[η2] ((Cos[θ2]* Cos[ψ1])/Sin[ψ1] + Cos[ψ2] Sin[θ2]) == Cos[η2] Sin[ψ2]) /. Sin[ψ1] -> (Cos[ϕ2] Sin[η2])/Sin[ψ2] /. Cos[ψ1] -> Cos[η2] Cos[θ2] Cos[ϕ2] - …
Bendesarts
  • 1,099
  • 5
  • 12
1
2