Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In Mathematica 9:

I have two functions f[v] and g[v]. When I do f[g[0]], I get the correct value. However, when I copy the expression for f[g[v]], let's call it R, and then do

t[v_]:=R; t[0]

I get an incorrect value. That is,

t[0]==f[g[0]]

returns false. No idea what is going wrong here. In other words, Mathematica seems to incorrectly compute (or output) the symbolic expression for f[g[v]]. Here are the two functions:

f[v_]:=Sqrt[(1 - 2 v + 8 v^2 + Sqrt[-3 + 12 v + 4 v^2 - 32 v^3 + 64 v^4])/(-1 + 2 v)]/Sqrt[2]

and

g[v_]:=3/8 + 1/8 Sqrt[25 + 16 v] + Sqrt[ 5 + 8 v - 25/Sqrt[25 + 16 v] - (16 v)/Sqrt[25 + 16 v]]/(4 Sqrt[2])

EDIT

However, it seems that if I do

f[v_]:=Sqrt[(1 - 2 v + 8 v^2 + Sqrt[-3 + 12 v + 4 v^2 - 32 v^3 + 64 v^4])/(-1 + 2 v)]/Sqrt[2]

followed by

f[3/8 + 1/8 Sqrt[25 + 16 v] + Sqrt[ 5 + 8 v - 25/Sqrt[25 + 16 v] - (16 v)/Sqrt[25 + 16 v]]/(4 Sqrt[2])]

then I get the correct expression.

share|improve this question

closed as off-topic by m_goldberg, bobthechemist, rm -rf Feb 21 at 22:01

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Are there typos in the question? The pattern of your function definitions will only match an argument of the literal symbol v, or if v had a value when the definitions are evaluated, only the pattern of f[<that value>] will match. –  rasher Feb 21 at 2:03
    
Capital E is the base of the natural log./exp. function. I suggest you not call f[g[0]] E. –  Michael E2 Feb 21 at 2:08
    
I've edited the question accordingly. No, no typos. –  William Feb 21 at 2:11
    
@Nasser: Thank you, corrected. In the working notebook it was correct. –  William Feb 21 at 2:16
2  
This question appears to be off-topic because the problem the user is experiencing can not be reproduced. –  m_goldberg Feb 21 at 15:56

1 Answer 1

After your comment showed that I misunderstood your problem, I cannot reproduce the issue you have. Let me copy and evaluate your complete example and show you that I get the correct behavior:

f[v_]:=Sqrt[(1-2 v+8 v^2+Sqrt[-3+12 v+4 v^2-32 v^3+64 v^4])/(-1+2 v)]/Sqrt[2]
g[v_]:=3/8+1/8 Sqrt[25+16 v]+Sqrt[5+8 v-25/Sqrt[25+16 v]-(16 v)/Sqrt[25+16 v]]/(4 Sqrt[2])

Now I evaluate f[g[v]] and copy the result the the right hand side of the following definition

t[v_]:=(1/Sqrt[2])*Sqrt[(1 - 2*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
       Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/Sqrt[25 + 16*v]]/
        (4*Sqrt[2])) + 8*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
        Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/Sqrt[25 + 16*v]]/
         (4*Sqrt[2]))^2 + 
     Sqrt[-3 + 12*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
         Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/
             Sqrt[25 + 16*v]]/(4*Sqrt[2])) + 
       4*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
          Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/
              Sqrt[25 + 16*v]]/(4*Sqrt[2]))^2 - 
       32*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
          Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/
              Sqrt[25 + 16*v]]/(4*Sqrt[2]))^3 + 
       64*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
          Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/
              Sqrt[25 + 16*v]]/(4*Sqrt[2]))^4])/
    (-1 + 2*(3/8 + (1/8)*Sqrt[25 + 16*v] + 
       Sqrt[5 + 8*v - 25/Sqrt[25 + 16*v] - (16*v)/Sqrt[25 + 16*v]]/
        (4*Sqrt[2])))];

Doing now

t[0] == f[g[0]]
(* True *)

returns True as expected. Can you please try this with a fresh Mathematica session?

share|improve this answer
    
I am probably missing something, but I didn't literally set R to f[g[v]]. R was a place holder in the OP, so that I didn't have to paste the entire code. What I did was this: I copied the expression for f[g[v]], and then pasted it in the definition of t[v_]. If you'd like, I can paste the entire code into the original post. –  William Feb 21 at 15:27
    
@William Then I have misread your question. Unfortunately, pure copying should work as expected and I edited my answer to show you that I get indeed True as result here. –  halirutan Feb 21 at 16:49
    
Thank you! Yes, strangely, in the new notebook it all works correctly, while in my original notebook it doesn't. I must have a bug buried deep in my work somewhere. –  William Feb 21 at 16:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.