Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4083422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:18:39+00:00 2026-05-20T18:18:39+00:00

This discussion came up in a previous question and I’m interested in knowing the

  • 0

This discussion came up in a previous question and I’m interested in knowing the difference between the two. Illustration with an example would be nice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:18:40+00:00Added an answer on May 20, 2026 at 6:18 pm

    Basic Example

    Here is an example from Leonid Shifrin’s book Mathematica programming: an advanced introduction

    It is an excellent resource for this kind of question. See: (1) (2)

    ClearAll[a, b]
    
    a = RandomInteger[{1, 10}];
    
    b := RandomInteger[{1, 10}]
    
    Table[a, {5}]
      {4, 4, 4, 4, 4}
    Table[b, {5}]
    
      {10, 5, 2, 1, 3}

    Complicated Example

    The example above may give the impression that once a definition for a symbol is created using Set, its value is fixed, and does not change. This is not so.

    f = ... assigns to f an expression as it evaluates at the time of assignment. If symbols remain in that evaluated expression, and later their values change, so does the apparent value of f.

    ClearAll[f, x]
    
    f = 2 x;
    f
    
      2 x
    x = 7;
    f
    
      14
    x = 3;
    f
    
      6

    It is useful to keep in mind how the rules are stored internally. For symbols assigned a value as symbol = expression, the rules are stored in OwnValues. Usually (but not always), OwnValues contains just one rule. In this particular case,

    In[84]:= OwnValues[f]
    
    Out[84]= {HoldPattern[f] :> 2 x}
    

    The important part for us now is the r.h.s., which contains x as a symbol. What really matters for evaluation is this form – the way the rules are stored internally. As long as x did not have a value at the moment of assignment, both Set and SetDelayed produce (create) the same rule above in the global rule base, and that is all that matters. They are, therefore, equivalent in this context.

    The end result is a symbol f that has a function-like behavior, since its computed value depends on the current value of x. This is not a true function however, since it does not have any parameters, and triggers only changes of the symbol x. Generally, the use of such constructs should be discouraged, since implicit dependencies on global symbols (variables) are just as bad in Mathematica as they are in other languages – they make the code harder to understand and bugs subtler and easier to overlook. Somewhat related discussion can be found here.


    Set used for functions

    Set can be used for functions, and sometimes it needs to be. Let me give you an example. Here Mathematica symbolically solves the Sum, and then assigns that to aF(x), which is then used for the plot.

    ClearAll[aF, x]
    
    aF[x_] = Sum[x^n Fibonacci[n], {n, 1, \[Infinity]}];
    
    DiscretePlot[aF[x], {x, 1, 50}]
    

    enter image description here

    If on the other hand you try to use SetDelayed then you pass each value to be plotted to the Sum function. Not only will this be much slower, but at least on Mathematica 7, it fails entirely.

    ClearAll[aF, x]
    
    aF[x_] := Sum[x^n Fibonacci[n], {n, 1, \[Infinity]}];
    
    DiscretePlot[aF[x], {x, 1, 50}]
    

    If one wants to make sure that possible global values for formal parameters (x here) do not interfere and are ignored during the process of defining a new function, an alternative to Clear is to wrap Block around the definition:

    ClearAll[aF, x];
    x = 1;
    Block[{x}, aF[x_] = Sum[x^n Fibonacci[n], {n, 1, \[Infinity]}]];
    

    A look at the function’s definition confirms that we get what we wanted:

    ?aF
    Global`aF
    aF[x_]=-(x/(-1+x+x^2))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a discussion between me and me to understand an Isolated Storage issue.
I read some of the discussion in this question and thought to myself that
Inspired by the discussion in this question . We have all been taught that
This question arose from the discussion in the comments of this answer . First,
This question originates from a discussion on whether to use SQL ranking functionality or
This is perhaps more of a discussion question, but I thought stackoverflow could be
this is not a question as i think its discussion, i know you cant
Consider the following code (it came about as a result of this discussion ):
This question came to my mind while working on 2 projects in AI and
This is not a question about real code, it is just for discussion. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.