Post Reply 
Suggestion for EXECON.
12-14-2014, 03:59 AM (This post was last modified: 12-18-2014 05:29 AM by John P.)
Post: #1
Suggestion for EXECON.
I was just playing with EXECON and found that if you have for ex. two lists l1:={1,2,3}, l2:={a,5,6} and if you do EXECON("&1-&2",l1,l2) I get the "Error:Syntax Error". I think because l2 has symbolic element in it and because l2 is accessed element by element using "&2". If there are no symbolic elements in l2 then there is no error and no problems. When I do for ex. sum(EXECON("abs(&1*l2)",l1,l2)) also there is no error even though l2 has symbolic element(s). My conclusion is that: the error occurs only when "&" finds in a list(s) symbolic element(s) ex. 'a', 'a*b' etc.. I do not know if it is at all possible to fix that and make EXECON to work when "&" also accesses list(s) with symbolic element(s) then, I think, the EXECON would be more versatile.
Find all posts by this user
Quote this message in a reply
12-14-2014, 05:28 PM (This post was last modified: 12-14-2014 06:01 PM by Snorre.)
Post: #2
RE: Sugdestion for EXECON.
Hello JohnP,

I think your assumption about EXECON not doing symbolic calculation, i.e. not firing up the CAS, is right. You could do it by yourself:
EXECON("CAS(\"&1-&2\")",l1,l2)
or -- easier to enter --
EXECON("CAS(""&1-&2"")",l1,l2)

It seems that EXECON is just repeatedly doing an EXPR(...) on the string after substituting each &n-pattern by the corresponding list's element. So you could put nearly arbitrary content (e.g. whole program chunks) into the pattern. For example, you could print out what's going on:
EXECON("LOCAL x; IFERR x:=EXPR(""&1-&2""); THEN x:=""Nah!""; END; PRINT(""&1-&2 → ""+x); x",l1,l2);

Greetings
Find all posts by this user
Quote this message in a reply
12-14-2014, 09:12 PM
Post: #3
RE: Sugdestion for EXECON.
(12-14-2014 05:28 PM)Snorre Wrote:  Hello JohnP,

I think your assumption about EXECON not doing symbolic calculation, i.e. not firing up the CAS, is right. You could do it by yourself:
EXECON("CAS("&1-&2")",l1,l2)
or -- easier to enter --
EXECON("CAS(""&1-&2"")",l1,l2)

It seems that EXECON is just repeatedly doing an EXPR(...) on the string after substituting each &n-pattern by the corresponding list's element. So you could put nearly arbitrary content (e.g. whole program chunks) into the pattern. For example, you could print out what's going on:
EXECON("LOCAL x; IFERR x:=EXPR(""&1-&2""); THEN x:=""Nah!""; END; PRINT(""&1-&2 → ""+x); x",l1,l2);

Greetings

Hello Snorre,

Thank you. Your suggestion works, but the question is: is that work around a problem or how the EXECON should work. If it is work around some problem in EXECON, I think they should fix it.

Cheers
Find all posts by this user
Quote this message in a reply
12-14-2014, 09:44 PM
Post: #4
RE: Sugdestion for EXECON.
(12-14-2014 09:12 PM)John P Wrote:  If it is work around some problem in EXECON, I think they should fix it.

I don't think so. The CAS is an independent subsystem which can be called form other places. EXECON is part of "the other places". It can call the CAS if told to do so but it is not automatic. The question is: Should the system call the CAS whenever it feels incapable to perform a specific task? This may lead to unexpected results when an error message would be the more appropriate answer to a problem. I concur that resorting to the CAS is a good idea whenever a function is called from the CAS command line, even if it is defined in "the other world".

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
12-15-2014, 12:13 AM
Post: #5
RE: Sugdestion for EXECON.
(12-14-2014 09:44 PM)Marcus von Cube Wrote:  
(12-14-2014 09:12 PM)John P Wrote:  If it is work around some problem in EXECON, I think they should fix it.

I don't think so. The CAS is an independent subsystem which can be called form other places. EXECON is part of "the other places". It can call the CAS if told to do so but it is not automatic. The question is: Should the system call the CAS whenever it feels incapable to perform a specific task? This may lead to unexpected results when an error message would be the more appropriate answer to a problem. I concur that resorting to the CAS is a good idea whenever a function is called from the CAS command line, even if it is defined in "the other world".

Hello Marcus von Cube,

"The question is: Should the system call the CAS whenever it feels incapable to perform a specific task?"
Not exactly and not in the sense: when the system is incapable to do something to call CAS. If I work in CAS or in HOME the system should be aware where it is and behave appropriately. In that sense the system is buggy.
Find all posts by this user
Quote this message in a reply
12-15-2014, 10:09 AM
Post: #6
RE: Sugdestion for EXECON.
Hello,

> l1:={1,2,3}; l2:={a,5,6}; EXECON("&1-&2",l1,l2) -> "Error:Syntax Error".

how did you get 'a' in l1?
as a mater of fact, what is l1?
Are you working with user defined Home variables or program local or global variables?
These are important point of data to find what is happening...

What is sure is that execon will generate a series of strings with the proper data in it. Once it gets to "1-a", it seems that it can not parse it properly and errs on it...
it might not be due to symbolic, it might be due to the fact that execon is not aware of the existence of a in this case... This is what I Am trying to assert...

Cyrille
Find all posts by this user
Quote this message in a reply
12-15-2014, 10:57 AM
Post: #7
RE: Sugdestion for EXECON.
(12-15-2014 10:09 AM)cyrille de brébisson Wrote:  Hello,

> l1:={1,2,3}; l2:={a,5,6}; EXECON("&1-&2",l1,l2) -> "Error:Syntax Error".

how did you get 'a' in l1?
as a mater of fact, what is l1?
Are you working with user defined Home variables or program local or global variables?
These are important point of data to find what is happening...

What is sure is that execon will generate a series of strings with the proper data in it. Once it gets to "1-a", it seems that it can not parse it properly and errs on it...
it might not be due to symbolic, it might be due to the fact that execon is not aware of the existence of a in this case... This is what I Am trying to assert...

Cyrille

Hello,

1. I was working in CAS on command line. I did not yet try EXECON in program mode.
2. l1 is just a list with curly brackets. Just now I tried the same with square brackets and it also does not work.
3. I just put small 'a' in l2 as an element, but it does not matter where 'a' or any symbolic is it does not work, though it works with numbers only.
4. I defined l1 and l2 as user variables in CAS.
5. I tried another example sum(EXECON("abs(&1*l2)",l1,l2)) and it works as long as "&" does not refer to list with symbolic element(s).

Cheers
Find all posts by this user
Quote this message in a reply
12-15-2014, 12:31 PM (This post was last modified: 12-15-2014 12:33 PM by Snorre.)
Post: #8
RE: Sugdestion for EXECON.
Hi John P,

so, as Marcus pointed out, there are two worlds on the Prime: CAS and the rest.
EXECON is a command from the HOME-world and so get's executed in a non-CAS-environment even if called from the CAS (similiar to other PPL programs).

BTW: in CAS you normally wouldn't grub yourself with strings which contain expressions to be evaluated (like EXPR(), EXECON() etc., which is IMO a very BASIC approach -- simple, powerful, but a bit unaesthetic) since you've the full power of a functional system with "apply", "map", "seq", "zip" and all the implicit composite-type-handling of the other operators.

Greetings
Find all posts by this user
Quote this message in a reply
12-15-2014, 12:36 PM
Post: #9
RE: Sugdestion for EXECON.
It's treating the symbolic "a" as a variable, expecting it to contain a numeric value.
l1:={1,2,3}
l2:={a,5,6}

EXECON("&1-&2",l1,l2) ==> "Error: Syntax Error"

If:
a:=4
EXECON("&1-&2",l1,l2) ==> [-3,-3,-3]
Find all posts by this user
Quote this message in a reply
12-15-2014, 12:50 PM
Post: #10
RE: Sugdestion for EXECON.
(12-15-2014 12:36 PM)DrD Wrote:  It's treating the symbolic "a" as a variable, expecting it to contain a numeric value.
At least "a" should be defined. Here is what I tried in CAS:
  • Define l1
  • Define l2
  • Define a as a list
  • Execute EXECON => it works
[Image: 1czxn.png]

Now going to HOME:
  • Print l1
  • Print l2
  • Execute EXECON => it works as in CAS
[Image: 1czxm.png]
Find all posts by this user
Quote this message in a reply
12-15-2014, 12:57 PM
Post: #11
RE: Sugdestion for EXECON.
(12-15-2014 12:31 PM)Snorre Wrote:  Hi John P,

so, as Marcus pointed out, there are two worlds on the Prime: CAS and the rest.
EXECON is a command from the HOME-world and so get's executed in a non-CAS-environment even if called from the CAS (similiar to other PPL programs).

BTW: in CAS you normally wouldn't grub yourself with strings which contain expressions to be evaluated (like EXPR(), EXECON() etc., which is IMO a very BASIC approach -- simple, powerful, but a bit unaesthetic) since you've the full power of a functional system with "apply", "map", "seq", "zip" and all the implicit composite-type-handling of the other operators.

Greetings

Hello,

I have no problems what you and others say and I do not want be to picky at all ,but if EXECON works like it does, at least for me, it is a crippled funktion and if it could be fixed, why not.

Cheers
Find all posts by this user
Quote this message in a reply
12-15-2014, 01:15 PM
Post: #12
RE: Sugdestion for EXECON.
(12-15-2014 12:50 PM)Didier Lachieze Wrote:  
(12-15-2014 12:36 PM)DrD Wrote:  It's treating the symbolic "a" as a variable, expecting it to contain a numeric value.
At least "a" should be defined. Here is what I tried in CAS:
  • Define l1
  • Define l2
  • Define a as a list
  • Execute EXECON => it works
[Image: 1czxn.png]

Now going to HOME:
  • Print l1
  • Print l2
  • Execute EXECON => it works as in CAS
[Image: 1czxm.png]

Hello,

Fine, but I want 'a' to be 'a' with no value for now and I want it in the final result as an 'a' and then to use it if I need to. In your example you showed elements of 'a' were subtracted from the first element of l1 and then 5 from 2 and 6 from 3. What your example shows is that EXECON when using "&" with symbolic element in a list does not use CAS and this is exactly what Snorre explained in his first post.

Cheers
Find all posts by this user
Quote this message in a reply
12-15-2014, 07:47 PM
Post: #13
RE: Sugdestion for EXECON.
(12-15-2014 01:15 PM)John P Wrote:  Fine, but I want 'a' to be 'a' with no value for now and I want it in the final result as an 'a' and then to use it if I need to.
What you are asking for is an execon (lower case is intentional) function in the CAS. What you are using by now is EXECON, a Home function. Even if you use it from the CAS command line it is still executed in the non symbolic environment and thus is incapable of handling symbolic input.

It shouldn't be rocket science to create your own implementation as a CAS program.

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
12-16-2014, 06:58 AM (This post was last modified: 12-16-2014 07:20 AM by cyrille de brébisson.)
Post: #14
RE: Sugdestion for EXECON.
Hello,

Sorry OP, but EXECON, as stated by other is a numerical command.
What is means is that EXECON, when executed from the CAS, or with CAS arguements will 'transport' all the CAS stuff into the HOME/Numerical world and will execute there...

Now, in some cases, such as purely numerical data in your list, it will all happen with no issues...

BUT if you are using items which as CAS only, then it will, unfortunately not...

They are 2 similar (but not fully equivalent) functions in the CAS: apply and map. you should have a look at them.

Cyrille
Find all posts by this user
Quote this message in a reply
12-16-2014, 07:55 AM
Post: #15
RE: Sugdestion for EXECON.
(12-16-2014 06:58 AM)cyrille de brébisson Wrote:  Hello,

Sorry OP, but EXECON, as stated by other is a numerical command.
What is means is that EXECON, when executed from the CAS, or with CAS arguements will 'transport' all the CAS stuff into the HOME/Numerical world and will execute there...

Now, in some cases, such as purely numerical data in your list, it will all happen with no issues...

BUT if you are using items which as CAS only, then it will, unfortunately not...

They are 2 similar (but not fully equivalent) functions in the CAS: apply and map. you should have a look at them.

Cyrille

Hello, and thank you all for your explanations. I certainly learned something from the discussion.

Cheers
Find all posts by this user
Quote this message in a reply
12-16-2014, 08:01 AM
Post: #16
RE: Sugdestion for EXECON.
For the example above, you can use the zip command, e.g.
zip('+',[a,b,c,d], [1,2,3,4])
Find all posts by this user
Quote this message in a reply
12-16-2014, 09:01 AM
Post: #17
RE: Sugdestion for EXECON.
(12-16-2014 08:01 AM)parisse Wrote:  For the example above, you can use the zip command, e.g.
zip('+',[a,b,c,d], [1,2,3,4])

Hello,

I do not want to extend this discussion indefinitely. What I like very much about EXECO is that by using "&" I can use in "expression" element(s) of the same list(s) many times over for example "(&2-&1)/&1" or somethin like that. OK, EXECON works as numerical function that is clear, but in the light what Snorre wrote in his first post I thought that porting it to CAS would not be very big problem and EXECON would be much more versatile. There is no problem at all because I can always write my own function using Snorre suggestion with slightly different name and get what I want and if I need. Thanks.

Cheers
Find all posts by this user
Quote this message in a reply
12-16-2014, 09:48 AM
Post: #18
RE: Sugdestion for EXECON.
You can also do that with zip, like this
zip((a,b)->(b-a)/b,l1,l2)
Find all posts by this user
Quote this message in a reply
12-16-2014, 09:36 PM
Post: #19
RE: Sugdestion for EXECON.
(12-16-2014 09:48 AM)parisse Wrote:  You can also do that with zip, like this
zip((a,b)->(b-a)/b,l1,l2)

Hello,

If I have: zip((a,b,c)->(a+b)/(b+c),l1,l2,l3) I get "Error: Bad Argument Value", but if I do:
EXECON("CAS(\"(&1+&2)/(&2+&3)\")",l1,l2,l3) I get what I want. It looks as "zip" takes only two arguments and this is what I mean "EXECON" is, could be, more versatile.
Thank you.

Cheers
Find all posts by this user
Quote this message in a reply
12-17-2014, 06:54 AM
Post: #20
RE: Sugdestion for EXECON.
Yes, EXECON is more versatile. zip and apply work for 2 or 1 arg function. Otherwise just write a loop yourself if you need it in the CAS.
Find all posts by this user
Quote this message in a reply
Post Reply 




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