Maple’s Evaluation Rules 教授 : 蔡桂宏 博士 學生 : 林佳慧 學號 : 統資軟體課程講義
Program Full evaluation Levels of evaluation Delayed evaluation
Program (continue) Last name evaluation Evaluating function definitions Evaluating function calls A no evaluation rule
Program (continue) Evaluating concatenated names Evaluating indexed names Online help for evaluation rules
Full evaluation Introducing the kinds of the data styles by normal programming : 文字 - 字元:『 ’ ’ 』或『 ’’ ’’ 』 數字 - 整數和浮點數: 5 、 5.0 邏輯值( boolean ):『 true 』或『 false 』 What is full evaluation? 一口氣計算完畢
Full evaluation(Continue) There are exceptions to this rule: delayed evaluation levels evaluation last name evaluation
1.Compare 『 : 』和『;』 2.Maple 語法的結尾是用『 : 』和 『;』 3. 交換變數
f := x -> f(x) f(x) 的資料會隨著變數 x 的值改變而 變
Solve 語法: solve( 函數,變數)
此處只有一個變數 (x) Plot 語法: plot( 函數,變數 1 range ,變數 2 range )
Seq 語法: seq( 數學式, i= 下界..上界 )
Levels of evaluation Purpose: How do we use the command? The command in levels of evaluation eval(expression , level )
Delayed evaluation Purpose : see the command’s output Compare 『 Delay 』 of evaluation with 『 Level 』 of evaluation Compare 『 eval(x) 』 with 『 eval(x,n) 』 What happened to the single quote in left equal sign
Delayed evaluation What happened to the double quote in left equal sign? Compare 『 % 』 with 『 eval(x,n) 』 Another mean about the command’s output in 『 ‘ ’ 』 Explain the function output in 『 rand( ) 』 Compare some different in 『 plot( ) 』
Delayed evaluation What is delayed evaluation? 沒有立即要計算變數時使用
Delayed evaluation(continue) The command’s output : 『 ’ 變數 ’ 』 : one delayed evaluation 『 ’’ 變數 ’’ 』 : a doubly delayed evaluation 『 ’’’ 變數 ’’’ 』 : a trebly delayed evaluation
expression X unassigned
function EX.1 C is a delayed parameter
EX.2 We can use delayed evaluation to prevent Maple from making the function call.
EX.3 Compare them…
Delayed evaluation(continue) Compare 『 Delay 』 of evaluation with 『 Level 』 of evaluation 『 Delay 』 - 由原來的表示式看 delay 幾次 『 Level 』 - 『 eval(x,n) 』 : 程式由前面開 始找到 x 後,逐行由上往下顯示
eval(x) 是 eval(eval(x,2))
Delayed evaluation(continue) Compare 『 eval(x) 』 with 『 eval(x,n) 』 The call eval(x) means: Two delayed evaluations.(the same of the eval(eval(x,2)) ) or evaluate x The call eval(x,n) means: To evaluate the n level of the name x
evaluate a
討論 eval(y,1)
Delayed evaluation(continue) What happened to the single quote in left equal sign The first x has its evaluation dealyed and the second x is evaluated right away
Delayed evaluation(continue) What happened to the double quote in left equal sign The first x has its evaluation dealyed and the second x is one delayed evaluated of x
Delayed evaluation(continue) the command’s output in 『 % 』、 『 % 』 『 % 』 :last expression 『 % 』 : second last expression i.e 『 %% 』 : third last expression
Delayed evaluation(continue) Compare 『 % 』 with 『 eval(x,n) 』 『 % 』 : 由此指令往前找一行 『 eval(x,n) 』 : 程式由前面開始找到 x 後, 逐行由上往下顯示
Delayed evaluation(continue) Another mean about the command’s output in 『 ‘ ’ 』 : It can get automatic simplification It is a very safe way to define y It is an often used trick in Maple Explain the command’s output in 『 plot( expression in independent variable x,the range of the x) 』
『 ‘ u+u ‘ 』 doesn ’ t evaluate to 2u, it simplifies to 2u.
『 u+u 』 is evaluated by u=5. 『 ’u+u’ 』 is a simplistic action.
Delayed evaluation(continue) Explain the function output in 『 rand( ) 』 : It can generate a random interger
You can find there do not return a random fracion. We can try it again by the common as following:
Another way to generate a random fraction:
Delayed evaluation(continue) Compare some different as following: plot(x^2,x=-5..5); v.s plot(x^2,'x'=-5..5); plot('x'^2,'x'=-5..5); v.s plot('x'^2, x=-5..5);
There have the same output
Last name evaluation Define: Maple 在計算函數時, 最後一步計算時的 變數
Last name is f
Last name is k(w) 此處未使用 last name evaluation
Evaluating function definitions Purpose: Learning how Maple evaluates function calls
If we define f as an expression in x. Now define g as a Maple function.
c is a parameter in the definition of g along with x.
Evaluating function definitions (continue) How do we define Maple function? use 『 -> 』 use 『 unapply 』 command
Exercise: Explain each the following three sequences of commands.
Evaluating function call If f is the name of a Maple function, then an expression of the form f(any-maple-expression) f was defined using by 『 -> 』 Here is an example of a function and several function calls
Evaluating function call (continue) Some of the function call: Case 1 : above this page Case 2 : unevaluated function call
g(2) is an unevaluated function call. Case 1 Case 2
Evaluating function call (continue) Compare this:
A no evaluation rule Purpose: There have many examples of how unevaluations are used Explain the command in 『 assigned( ) 』 What is recursion ?
assign(x=n); x;
Why? Because x:=‘x’
A no evaluation rule(continue) Explain the command in 『 assigned( ) 』 : The assigned function returns true if n has a value other than its own name, and returns false
這裡是因為遞迴 (x:=‘x’) 所引起
A no evaluation rule(continue) What is recursion? x=‘x’ f(0)=1 f(1)=1 f(x+2)=f(x+1)+f(x) EX. f(5)=8 f(x) x 電腦記憶體 x 的地方放 x 的位置
Evaluating concatenated names Purpose: find Maple’s rules for evaluating concatenated names What is a concatenated name? the concatenated name’s command is 『 || 』
evaln(expression)
使用 w||eval(x,n) 有無括號之差別
The next exercise shows that Maple does allow the use of parentheses for grouping around the right pair of vertical lines.
Evaluating indexed names Purpose: To understand what indexed name is it Compare 『 x||1:=0 』 with 『 x[1]:=0 』 『 x||1:=0 』 : Maple evaluates x||1 to the name x1 『 x[1]:=0 』 : x[1] is a name. Maple does not need to evaluate it
Online help for evaluation rules Purpose: Finding many ways to call for help
Online help for evaluation rules (continue) Ways: 『 ? 』 『 F1 』 (version 9) 『 Help/Search 』