Skip to main content

simplifying expressions - What is a "generic case"?


Introduction


With this question I am coming back to a long-standing issue I have with Mma's concept of a "generically correct" result. The basic idea seems to be, vaguely, that if a result is true in the vast majority of cases, then the Wolfram Language decides that it is o.k. to just substitute such a result instead of alerting the user to the fact that this result may be wrong "sometimes". I note in passing that, in the fields of mathematics I am most familiar with, the concept of "generically true" is rigorously defined as "true with the exception of a set of measure zero", after appropriate definition of the measure(s) one is talking about, and that no such definition seems to exist for the Wolfram Language.


Example 1: Let's look at the expression e1, defined via


e1 = Sin[2 Pi j]/j

If we ask Mathematica to simplify the expression for the case of integer j, we get 0:


Assuming[j ∈ Integers, Simplify[e1]]


Given what I said above, I am not particularly happy about the concept of "generically correct" revealed by this choice. Yes, this result is incorrect only for one single value of the integer, j=0, and correct for an infinite number of other cases. However, if we consider the important case of finite subsets of the integers, then the case of a set with just one element is not particularly small. Note also that, if we ask for, say


Assuming[j ∈ Integers ∧ 0 <= j <= 1, Simplify[e1]]

we will get the same answer of 0, which clearly makes no sense at all now. By the way, the mathematically equivalent


Assuming[j == 0 ∨ j == 1, Simplify[e1]]

happens to produce a correct result of sin(2 π j)/j.


Now, one might argue that it would be asking too much to expect Mathematica to go through all possible cases of a finite set designated similarly to the above before producing an answer, but consider my


Example 2:



e2 = Sin[2 Pi (j - k)]/(j - k)

and ask for


Assuming[j ∈ Integers ∧ k ∈ Integers, Simplify[e2]]

Again, Mathematica claims the result is zero, even though in this case it is clear that there can be no mathematical justification for doing so. Notice that the set of pairs {i, j} for which this result is correct (the set that has i<>j) contains exactly as countably infinite many elements as the set where it is false.


So, here is my question: Given the difficulties revealed by the above examples, is there any safe way to use assumptions in Mathematica, or should they just be avoided, period? Note that, in the above trivial cases, it's easy to see when we receive a wrong answer. However, imagine us having Assumptions hidden in some piece of code that accepts arbitrary expressions as its input. The consequence will be that in general we cannot know if such code will produce a valid answer.


Alternatively, is there a way to know exactly what conclusions the various Mathematica functions that accept assumptions might draw from such assumptions? In other words, is there, at least in principle, any way to rationally test code that contains assumptions?


P.S.: I will say that I find the statement in Mathematica's documentation that "It is however often not practical to try to get formulas that are valid for absolutely every possible value of each variable" thoroughly unconvincing. I frankly don't see an issue with not returning a definite result when such a result does not exist. I would very much prefer Mathematica to force me to state assumptions such that a definite result can be obtained, rather than it silently and implicitly introducing assumptions that may turn out to be false. I guess ideally there would be a way to tell Mathematica to switch to a "rigorous mode", where no assumptions are introduced surreptitiously.




Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[ {Total@((vec1[[#]] - Indexed[vec2, u[#]])^2 & /@ R...

What is and isn't a valid variable specification for Manipulate?

I have an expression whose terms have arguments (representing subscripts), like this: myExpr = A[0] + V[1,T] I would like to put it inside a Manipulate to see its value as I move around the parameters. (The goal is eventually to plot it wrt one of the variables inside.) However, Mathematica complains when I set V[1,T] as a manipulated variable: Manipulate[Evaluate[myExpr], {A[0], 0, 1}, {V[1, T], 0, 1}] (*Manipulate::vsform: Manipulate argument {V[1,T],0,1} does not have the correct form for a variable specification. >> *) As a workaround, if I get rid of the symbol T inside the argument, it works fine: Manipulate[ Evaluate[myExpr /. T -> 15], {A[0], 0, 1}, {V[1, 15], 0, 1}] Why this behavior? Can anyone point me to the documentation that says what counts as a valid variable? And is there a way to get Manpiulate to accept an expression with a symbolic argument as a variable? Investigations I've done so far: I tried using variableQ from this answer , but it says V[1...