Why is lisa[i_, j_] :> Nothing un-evaluated?

Anyone know how to correct it with minor change?

Input(i = {1, 3, 5, 7, 9}; j = {1, 3, 5, 7, 9}; (Tuples[lisa[i, j]] /. lisa[i_, j_] :> i/j)/. lisa[i_, j_] :> Nothing

Output{1, 1/3, 1/5, 1/7, 1/9, 3, 1, 3/5, 3/7, 1/3, 5, 5/3, 1, 5/7, 5/9, 7, \ 7/3, 7/5, 1, 7/9, 9, 3, 9/5, 9/7, 1}

• I'm not sure what you're expecting to see - you replace all lisa[i_,j_] by something else, and then you replace list[i_,j_] by something again - obviously the second one will not find anything – Lukas Lang Oct 16 at 15:49
• @Lucas How can you add lisa[i_,j_];>Nothing ? I mean by not changing the first oneTuples[lisa[i, j]] /. lisa[i_, j_] :> i/j – kile Oct 16 at 15:52
• But what do you want to get in the end? Because list[i_,j_]:>Nothing will just replace all the elements by Nothing, giving an empty list – Lukas Lang Oct 16 at 15:55
• How can you add i!=j? – kile Oct 16 at 15:57
• So you want Tuples[list[i,j]] /. {lisa[i_, i_] :> Nothing, lisa[i_,j_] :> i/j}? – Lukas Lang Oct 16 at 15:59

Lucas's Method

1st

i = {1, 3, 5, 7, 9}; j = {1, 3, 5, 7, 9}; Tuples[lisa[i,j]] /. {lisa[i_, i_] :> Nothing, lisa[i_,j_] :> i/j}

This lisa[i_, i_] :> Nothing will delete the circumstance when i!=j(Mathematica will automatically interpret != into ) , which will produce 1 in the output.

{lisa[i_, i_] :> Nothing, lisa[i_,j_] :> i/j} will be treated as a whole when lisa[i_, i_] :> Nothing and lisa[i_,j_] :> i/j will be evaluated simultaneously.

2nd

i = j={1, 3, 5, 7, 9}; Tuples[lisa[i, j]] /. lisa[i_, j_] /; i != j :> i/j /. lisa[i_, i_] :> Nothing

The other method Lucas provide here is to use Condition to make sure i!=j is a constraint here. Fuction lisa[i_, j_] /; i != j :> i/j will be evaluated only when i!=j happens. After that, lisa[i_, i_] :> Nothing will be evaluated.

BobHanlon's Method

1st

i = j={1, 3, 5, 7, 9}; (Tuples[lisa[i, j]] /. lisa[i_, j_] :> i/j) /. (1 -> Nothing)

Bob's method here is more direct in the output. Since we know know that if i=j then the output is will be 1. In order to delete 1 in the output, Bob delete 1 with 1 -> Nothing. It first produce an output with 1 , /. (1 -> Nothing) will definitely delete 1

2nd

f[i_List,j_List] := (Tuples[lisa[i, j]] /. lisa[x_, y_] :> x/y) /. (1 -> Nothing);
i = j = {1, 3, 5, 7, 9};
f[i, j]

I think f[i_List, j_List] can be substituted for f[i_,j_]. Cause it will generate the same result. In the second method here Bob choose function f as the highest rank function in this code.

3rd

i = j = {1, 3, 5, 7, 9};
f[i_List, j_List] = Flatten[Outer[#1/#2 &, i, j] /. (1 :> Nothing)]

Or since the function lisa is only used as a placeholder, #1 and #2 simply mean that #1 and #2 is a arbitrary number of {1, 3, 5, 7, 9}