problems with integration
01-09-2015, 07:46 AM
Post: #41
 danielmewes Junior Member Posts: 29 Joined: Dec 2014
RE: problems with integration
GDB suggests some infinite recursion. The last few lines of the backtrace:
Code:
 #16016 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16017 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16018 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16019 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16020 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16021 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16022 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16023 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16024 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16025 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16026 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16027 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16028 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16029 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16030 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16031 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16032 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16033 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16034 0x00007fd53f57bb94 in giac::is_algebraic_program(giac::gen const&, giac::gen&, giac::gen&) () from /usr/lib/libgiac.so.0 #16035 0x00007fd53febff25 in giac::gen::operator()(giac::gen const&, giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16036 0x00007fd53fec0336 in giac::gen::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16037 0x00007fd53fe04c32 in giac::_of(giac::gen const&, giac::context const*) () from /usr/lib/libgiac.so.0 #16038 0x00007fd53fdff050 in giac::unary_function_eval::operator()(giac::gen const&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16039 0x00007fd53fed7e3d in giac::gen::in_eval(int, giac::gen&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16040 0x00007fd53f86513d in giac::symbolic::eval(int, giac::context const*) const () from /usr/lib/libgiac.so.0 #16041 0x00007fd53fed7a8a in giac::gen::in_eval(int, giac::gen&, giac::context const*) const () from /usr/lib/libgiac.so.0 #16042 0x00007fd53fed809d in giac::gen::eval(int, giac::context const*) const () from /usr/lib/libgiac.so.0 #16043 0x00007fd53fd6a5dd in giac::protecteval(giac::gen const&, int, giac::context const*) () from /usr/lib/libgiac.so.0 #16044 0x00007fd53fb33683 in ?? () from /usr/lib/libgiac.so.0 #16045 0x00007fd53d6a9e9a in start_thread (arg=0x7fd531df1700) at pthread_create.c:308 #16046 0x00007fd53ac2f2ed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
01-09-2015, 07:53 AM
Post: #42
 danielmewes Junior Member Posts: 29 Joined: Dec 2014
RE: problems with integration
@resolved:

Thankfully parisse's comment also shows how to avoid the problem:

Define y3 like this:
y3:=(x)->y1(x) - 48.9047619048*x

and it should work.

(x)->expression is the format for a function of parameter x in the Prime's CAS.
01-09-2015, 12:40 PM
Post: #43
 parisse Senior Member Posts: 1,243 Joined: Dec 2013
RE: problems with integration
Actually the right definition of y3 should be
y3:=y1 -(x-> 48.9047619048*x)
or
y3:=unapply(y1(x) - 48.9047619048*x,x)
unless you want to see y3 modified if y1 is modified.
I have fixed the crash in source. Indeed an infinite recursion while trying to evaluate a mixed function/expression. It was not a very good idea to add code to evaluate expressions like if they are function...
01-10-2015, 10:30 AM
Post: #44
 resolved Member Posts: 55 Joined: Jun 2014
RE: problems with integration
sorry but I am new to all this jargon, but to help me avoid creating this kind of problem in the future, how do I know or how can I tell when I am working with a function versus an expression???? what I gather is "f" is a function but "f(x)" is an expression?? and how should they be used differently????
01-10-2015, 01:34 PM
Post: #45
 rprosperi Super Moderator Posts: 5,527 Joined: Dec 2013
RE: problems with integration
(01-10-2015 10:30 AM)resolved Wrote:  sorry but I am new to all this jargon, but to help me avoid creating this kind of problem in the future, how do I know or how can I tell when I am working with a function versus an expression???? what I gather is "f" is a function but "f(x)" is an expression?? and how should they be used differently????

I'm so glad you asked this question; I thought I was the only one confused on these seemingly small (but effectively big) issues.

While CAS designers and math teachers seem to easily keep these things straight, the number of posts about this confusion suggests that many of us lowly calculator users appear to need help keeping track.

The conceptual difference is clear, but the pragmatic difference when writing and transposing equations seems far more subtle.

--Bob Prosperi
01-10-2015, 02:16 PM (This post was last modified: 01-10-2015 03:29 PM by Snorre.)
Post: #46
 Snorre Member Posts: 101 Joined: Dec 2013
RE: problems with integration
(01-10-2015 10:30 AM)resolved Wrote:  sorry but I am new to all this jargon, but to help me avoid creating this kind of problem in the future, how do I know or how can I tell when I am working with a function versus an expression???? what I gather is "f" is a function but "f(x)" is an expression?? and how should they be used differently????

It may be a bit long offtopic post, but I'll try to explain:

"f" is a function, i.e. a variable which contains a mapping rule, e.g. "x->x²".
"f(x)" is an expression, it evaluates to the value (a mapping) of f when applied on an argument x, e.g. (x->x²)(x). Its result is x² where the current value (if any) of variable x will be inserted.
I used different colors to visualize distinct(!) variables (despite having the same name).

In the first case "x" is locally bound, which means it is independent of any global variable "x". It doesn't matter if it was renamed to "y" or whatsoever ("x->x²" and "foo->foo²" are totally equivalent) and will be substituted by whatever you put within the parentheses of "f(...)".
In the second case "x" is a free variable and is something very different from "x" within the function definition. It will be substituted immediately by whatever value it currently has. If it has no value, it will be simply substituted by 'x'.

So, if you define a function "g(x):=f-1" (which means "g:=(x->f-1)") and call "g(x)" (which is an expression) you're actually evaluating "(x->f-1)(x)" which results in "x->x²-1".
I don't know the Prime's internals, but in principle this can be examined step by step (from outer to inner):
(1) "x" has no value, so it gets substituted just by 'x'. Thus your expression "(x->f-1)(x)" evaluates to "(x->f-1)(x)".
(2) This expression is further evaluated (applied): parameter "x" is substituted by the argument 'x', so that the result becomes "f-1". As you can see our black 'x' vanished since the parameter "x" didn't occur in the right hand side of the mapping.
(3) The (global) variable "f" is substituted by its value (our mapping "x->x²"), so we get "(x->x²)-1".
(4) Now the CAS does some functional magic: it is capable of operating on mappings, e.g. subtracting a number "1" from the mapping "x->x²", which results in a mapping "x->(x²-1)", our final result.
Even if you initially set x to a value, it won't appear here, because local "x" is different from global "x".

As the Prime doesn't have colored variables, you may clarify this to yourself by renaming. For example if "x:=v", "f(x):=x²", "g(y)=f-1", and "z:=w", then "g(z)" will still evaluate to "x->x²+1".

Simply put: The arrow "->" makes the difference.
An expression is just a term whose variables will be replaced by their content immediately.
A function is a variable containing a mapping rule. The mapping rule itself can be seen as a single term too, but whose variables (wether local or global) won't get evaluated immediately (so recursive definitions become possible).
If you apply "f(...)" you're actually evaluating an expression (the right side of "->" in the mapping rule) where all (local) parameters (as defined left of "->") become substituted by their corresponding arguments (what you put within the parentheses of your call) and then all global variables (even if given as arguments) become substituted by their current values.

Greetings
01-10-2015, 02:19 PM
Post: #47
 Han Senior Member Posts: 1,882 Joined: Dec 2013
RE: problems with integration
(01-10-2015 10:30 AM)resolved Wrote:  sorry but I am new to all this jargon, but to help me avoid creating this kind of problem in the future, how do I know or how can I tell when I am working with a function versus an expression???? what I gather is "f" is a function but "f(x)" is an expression?? and how should they be used differently????

I'm sure parisse has more to say, but as I understand it, a mathematical function $$f(x)$$ is represented in the CAS as f(x):=x^2 or f:=(x)->x^2. Typing f(x):=x^2 is the same as typing f:=(x)->(x^2). On the other hand, if we use f:=x^2 then we have simply created a variable named f whose content is the expression x^2.

Graph 3D | QPI | SolveSys
01-10-2015, 03:17 PM
Post: #48
 parisse Senior Member Posts: 1,243 Joined: Dec 2013
RE: problems with integration
I would explain the difference like this.
An expression is a symbolic value, it's almost the same as 1 or 2/3, but the value is symbolic, not numeric. x^2 is an expression. You can store an expression in a CAS variable, for example g:=x^2. You can not use g like if it was a function, g(2) is invalid, instead you must substitute x by 2 in g: subst(g,x=2) (with recent Xcas version, you can use the shortcut g(x=2))
A function is a mathematical object that eats one (or more) argument, process it then returns a value (that's why we use a ->). x->x^2 is a function. You can store a function in a CAS variable, for example f:=x->x^2 (or with the shortcut f(x):=x^2). Then f is a function, f(2) will return 4, f(x) will return the expression x^2. You can do arithmetic operations on functions, for example h:=f*f is a function such that h(x)==f(x)*f(x), you can also compose functions e.g. h:=f@f is a function such that h(x)=f(f(x)), or even give a function as argument to a CAS program.
Many students are confused by the difference between function and expression, because most of the time the math teachers do not make a clear distinction between the two different mathematical objects because there is no confusion thanks to the context, but that's much harder to do that on a computer : I recently introduced some syntaxic "sugar", e.g. g(3) will evaluate to 9 in recent Xcas with a warning. That's precisely because I added this that the infinite recursion happened in the example ((x->x)+x)(3) where x has two different meanings (mute variable of the x->x function and expression). Now I fixed it in Xcas, I hope it's behind...
01-10-2015, 03:58 PM (This post was last modified: 01-10-2015 04:29 PM by Snorre.)
Post: #49
 Snorre Member Posts: 101 Joined: Dec 2013
RE: problems with integration
(01-10-2015 03:17 PM)parisse Wrote:  [...] You can not use g like if it was a function, g(2) is invalid, [...]
Numbers seem to be treated like constant functions: If "g:=2" then "g", "g(x)", "g(x,y,z)" evaluate to "2".
Your explanation makes me doubt this was intention. Maybe there should pop up a warning too, especially to avoid confusion with implicit multiplication "2(x)". Or maybe the implicit multiplication shoud be abandoned (IMO preferable).
Another case are the results of "f(x)" while "f:=2/3", "f:=π", "f:=∞".

P.S. How will "((x->x)+x)(3)" be handled after your fix? Does it differ from "((y->y)+x)(3)"?
01-10-2015, 07:58 PM
Post: #50
 parisse Senior Member Posts: 1,243 Joined: Dec 2013
RE: problems with integration
Numeric constants and numeric constant functions are less confusing: g:=x+1, g(3) could be the constant function x+1 evaluated at 3, value x+1, or the function x->x+1 evaluated at 3, value 4 (current returned value with a warning). If g:=1, there is nothing to replace, g(3) is less confusing, hence no warning. 1(x) is parsed as 1*x with a warning since nobody would enter 1 as 1(x).
Implicit multiplication is *not* supported by the CAS parser, a few shortcuts are supported like 2x, 2x^3, 2sin(x), and some syntaxic sugar (with warning) happens for expressions like (x+1)(x+2) where * is guessed from context since x can not be a function and a variable in the same time.
With the fix, ((x->x)+x)(3) will return like ((y->y)+x)(3), i.e. x(3)+3, with a warning.
01-12-2015, 06:18 AM
Post: #51
 jte Member Posts: 191 Joined: Feb 2014
RE: problems with integration
When writing / reading mathematics, (plain / straight / unbarred) arrows are often used to indicate function domains and codomains (e.g., f:A→B states that f is a function that maps elements of A to elements of B) with barred arrows (↦) used to indicate function rule(s) (e.g., f:ℝ→ℝ, x↦2x) or to state anonymous functions (e.g., x↦2x).
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)