Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] Two bugs in evalapply()

Search email archive for  

[MUG] Two bugs in evalapply()
Author: Helmut Kahovec    Posted: Wed, 11 Dec 2002 13:35:11 +0100

>> From: Helmut Kahovec "helmut.kahovec"

Dear Maple users,

There are two bugs in the procedure evalapply(), which behave
differently in Maple7 and Maple8. The first one was discovered by Carl
Devore, the second by myself. Following are short Maple7 and Maple8
sessions that show the two bugs and their fixes.

Maple7:
=======

Carl's bug:

> f[1]:=x->sin(2*x);

f[1] := x -> sin(2 x)

> `@`(g,f[1])(1); %;

g(f[1](1))

g(sin(2))

> map(evalf@f[1],[1,2,3]); %;

[f[1](1), f[1](2), f[1](3)]

[sin(2), sin(4), sin(6)]

> `@`(f[1],g)(1); %;

f[1](g(1))

sin(2 g(1))

> map(f[1]@evalf,[1,2,3]); %;

[f[1](1.), f[1](2.), f[1](3.)]

[.9092974268, -.7568024953, -.2794154982]

My bug:

> `@`(g,''F'')(1);

g('F'(eval(LOC[3], 1)))

> map(g@'''F''',[1,2,3]);

[g('F'(eval(LOC[3], 1))), g('F'(eval(LOC[3], 1))),

g('F'(eval(LOC[3], 1)))]

> `@`(''F'',g)(1);

'F'(eval(LOC[3], 1))

> map('''F'''@g,[1,2,3]);

['F'(eval(LOC[3], 1)), 'F'(eval(LOC[3], 1)), 'F'(eval(LOC[3], 1))]

My bug can be found very easily by executing the following procedure
test(), which also shows the fix for Maple7.

> test:=proc(F)
local r,_r,_F;
r:=1;
F(r),F(%),subs(_r=r,F(_r)),subs(_r=%,F(_r)),subs(_F=eval(F),_F(r));
end proc:

> test(F);

F(1), F(1), F(1), F(1), F(1)

> test('F');

F(1), F(1), F(1), F(1), F(1)

> test(''F'');

'F'(LOC[1]), 'F'(%), 'F'(LOC[2]), 'F'(LOC[2]), F(1)

> test('''F''');

''F''(LOC[1]), ''F''(%), ''F''(LOC[2]), ''F''(LOC[2]), 'F'(1)

Thus -- and in order to fix Carl's bug, too -- unprotect evalapply(),
add the names _r,_f to the locals of evalapply(), replace line 10

r := op(i,f)(eval(r,1))

(cf. the code that showstat(evalapply); returns) by the lines

op(i,f);
if type('%',uneval) then
r:=subs(_r=r,_f='%',_f(_r));
elif type(op(i,f),procedure) then
r:=eval(op(i,f))(eval(r,1))
else
r:=op(i,f)(eval(r,1))
end if

and protect the new evalapply() again. Now you get in turn:

> `@`(g,f[1])(1);

g(sin(2))

> map(evalf@f[1],[1,2,3]);

[.9092974268, -.7568024953, -.2794154982]

> `@`(f[1],g)(1);

sin(2 g(1))

> map(f[1]@evalf,[1,2,3]);

[.9092974268, -.7568024953, -.2794154982]

> `@`(g,''F'')(1);

g('F'(1))

> map(g@'''F''',[1,2,3]);

[g('F'(1)), g('F'(2)), g('F'(3))]

> `@`(''F'',g)(1);

'F'(g(1))

> map('''F'''@g,[1,2,3]);

['F'(g(1)), 'F'(g(2)), 'F'(g(3))]


Maple8:
=======

Carl's bug appears to be the same as in Maple7. My bug behaves
differently in Maple8:

> `@`(g,''F'')(1);

g('F'(eval(r, 1)))

> op([1,1,1],'%');

r

> %;

g(F(g('F'(eval(r, 1)))))

> %;

g(F(g(F(g('F'(eval(r, 1)))))))

> r-'%%%';

r - r

> map(g@'''F''',[1,2,3]);

[g('F'(eval(r, 1))), g('F'(eval(r, 1))), g('F'(eval(r, 1)))]

> `@`(''F'',g)(1);

'F'(eval(r, 1))

> map('''F'''@g,[1,2,3]);

['F'(eval(r, 1)), 'F'(eval(r, 1)), 'F'(eval(r, 1))]

My bug can be found very easily by executing the following procedure
test(), which also shows the possible fixes for Maple8.

> test:=proc(F)
local r,_r;
r:=1;
F(r),F(%),subs(_r=r,F(_r)),subs(_r=%,F(_r))
end proc:

> test(F);

F(1), F(1), F(1), F(1)

> test('F');

F(1), F(1), F(1), F(1)

> test(''F'');

'F'(r), 'F'(1), 'F'(1), 'F'(1)

Thus -- and in order to fix Carl's bug, too -- unprotect evalapply(),
add the name _r to the locals of evalapply(), replace line 10

r := op(i,f)(eval(r,1))

(cf. the code that showstat(evalapply); returns) by the lines

if type(op(i,f),uneval) then
r:=subs(_r=r,op(i,f)(_r))
elif type(op(i,f),procedure) then
r:=eval(op(i,f))(eval(r,1))
else
r:=op(i,f)(eval(r,1))
end if

and protect the new evalapply() again. Now you get the same correct
results that were shown in the Maple7 session above.


Kind regards,

Helmut

Previous by date: [MUG] Forcing Maple Output with Simplifying, Fraser Murray
Next by date: [MUG] Evaluation problem, Colin Campbell - IST
Previous thread: [MUG] Logplot to file, Emilio Sanchez
Next thread: [MUG] Evaluation problem, Colin Campbell - IST



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055