Tag Info

Hot answers tagged

18

Try this: Map[If[#==1,Unevaluated@Sequence[],#]&,{1,2,3}] Note the output. The 1 is gone. That's because Unevaluated@Sequence[] puts the empty sequence there, that is, "nothing". ##&[] is a shorthand that can be used in most places for same - ## is the sequence of arguments, & makes it a function to apply to something, [] is that something - ...


7

The r.h.s of the assignments are evaluated sequentially. However, the symbols don't actually assume these OwnValues until the the evaluation of the body of Block begins. Example: In[8]:= Block[{a = (Print[{a, b, c}]; 1), b = (Print[{a, b, c}]; 2), c = (Print[{a, b, c}]; 3)}, {a, b, c}] During evaluation of In[8]:= {a,b,c} During evaluation of In[8]:= ...


7

You need to set the CellLabelAutoDelete option to False. You can do that in the Option Inspector in the Format menu.


7

I believe it is important to get a fundamental understanding of what Pure Functions are that goes beyond the understanding using of a syntax. Hereafter an non-exhaustif summary of a few key understandings: 1) Pure Functions have they roots in Lambda calculus that forms the basis of functional programming paradigm implemented in Mathematica. 2) In ...


5

Looking at your code, the problem occurs when you're trying to return {node-1, Transpose[{xn,phi}]}. If instead you run the following code, which only returns Transpose[{xn,phi}], calU=Compile[{{x,_Real,1},{energy,_Real},{m,_Real},{a,_Real}}, Module[{i,node,xn,nn,phi,V,h,f,temp}, h=x[[3]]; xn=Range[x[[1]],x[[2]],h]; nn=Length@xn; ...


5

Behavior you're describing is briefly mentioned in last paragraph of "Controlling Infinite Evaluation" tutorial and very similar example is shown in documentation of Update function. It's related to how Mathematica optimizes evaluation, how it decides that expression has not changed since last evaluation and whether it needs to be re-evaluated. For what ...


5

Sequence is treated a bit specially. It does not get "evaluated to a result", but instead as the documentation explains: Sequence objects will automatically be flattened out in all functions except those with attribute SequenceHold or HoldAllComplete. This means that even though If has attribute HoldRest, the expression If[1 == 0, x, Sequence[]] will ...


4

You need to construct your desired expression without unwanted evaluation of its constituent parts. Here is one approach to do that: makeTest[{tests__}] := Replace[And[tests] &, fn_ :> fn[#], {2}] This works because the surrounding Function prevents evaluation before and after the Replace operation. Example: f1[x_] := (Print["First"]; x > ...


3

Sequence has non-standard evaluation rules. You can work around them like so. seq := Sequence {a, b, If[False, x, seq[]], c} {a, b, c} {a, b, If[True, x, seq[]], c} {a, b, x, c} Updated to conform with the observation made by Szabolcs in his comment below.


3

first = {1 + a, 2 + a, 3 + a, 4 + a}; t = {0, 1, 2, 3}; MapThread[#1 /. a -> #2 &, {first, t}] (* {1, 3, 5, 7}*) or #[[1]] /. a -> #[[2]] & /@ Transpose@{first, t} (* {1, 3, 5, 7}*)


2

So much wrong there... a = 2; tx = 2^(3/2); x[t_] := a Cos[2 Pi t/tx] - Cos[2 Pi t]; y[t_] := a Sin[2 Pi t/tx] - Sin[2 Pi t]; f[t_] := x[t] + I y[t]; f[20] (* -1 + 2 Cos[10 Sqrt[2] π] + 2 I Sin[10 Sqrt[2] π] *) Don't use uppercase initials for your symbols - you might clash with built-ins. Don't use some external user-defined global symbol inside a ...


2

Perhaps you can adapt something like this partial = Reap[CheckAbort[full=Table[Sow[expr]; expr, {i,1,1000}], Null]][[2,1]]


1

This is not a complete answer, but it is too long to post in a comment. I have made some modifications in your code, but due to insufficient information given, I cannot completely correct it (I don't know economics). I will put the code here and possibly make other's work easier. boptval[stock_, time_, vol_, int_, expn_, payoff_, strike_, nas_] := ...


1

I'm guessing you are looking for the list of replacements that need to be made going down to level 0 instead of just showing the level 0 results. Are you looking for something like this? assignments[d] = a + b; assignments[e] = b c; assignments[f] = d e; assignments[x_] := x; FixedPointList[Map[assignments, #, {-1}] &, {f}][[;; -2, 1]] {f, d e, b ...


1

Maybe I missed the point, but if you just copy and paste your expressions (and insert spaces to give multiplication) you get: d = a + b; e = b c; f = d e which gives you b (a + b) c, which is equivalent to your given f. Is this all you were asking?


1

This kind of problem is the reason I sought and found a solution to: How do I evaluate only one step of an expression? Here is an example of how the step function defined in my answer there is used: var1 = "init-val1"; var2 = "init-val2"; mapping := {var1 -> "val1", var2 -> "val2"} (* note use of := *) step[mapping][[{1}, 1, 1]] % // ...


1

This might be what you want: myfullsimplify[expr_, assum_] := Module[ {pat, tmp, seq}, pat = FirstCase[Level[assum, Infinity], p[_]] /. p[x_] -> x; tmp = FirstCase[Level[expr, Infinity], pat]; seq = {expr, assum} /. {pat -> #, p[_] -> #}; FullSimplify @@ seq /. # -> tmp ] It's used as follows: myfullsimplify[entry[1, 2, 3] < 0, ...


1

Did you try DistributeDefinitions[evolve] before running ParallelTable ?



Only top voted, non community-wiki answers of a minimum length are eligible