NTU-Exam 板


LINE

課程名稱︰程式語言理論與型態系統 (FLOLAC) 課程性質︰資管系 (所) 選修 課程教師︰穆信成 (與教學團隊的其他講師) 開課學院:管理學院 開課系所︰資管系 (所) 考試日期(年月日)︰2018 年 7 月 20 日 考試時限(分鐘):9:10 ~ 12:10 (最後有延長時間到 12:30) 試題 : Part (A) - Functional Programming Final Examination, July. 2018 Important: note before you start the exam: * Algebraic proofs need not be carried out in gory details -- you may skip some steps that you think are trivial. Do label the important steps, however, especially the step(s) where you use induction, or be explicit where you use fold fusion. * You can use all Haskell functions in the standard prelude, mentioned in the lectures. * You lost 1 point for each syntactical mistakes (e.g. writing f g x when it should be f (g x), or the other way round), up to 5 points. 1. (25 points) Assume the following definitions: maximum [] = -∞ maximum (x:xs) = x↑maximum xs , minimum [] = ∞ minimum (x:xs) = x↓minimum xs . Prove the following property maximum (map (x-) xs) = x - minimum xs . (1) You may use all properties regarding arithmetics, in particular laws regard- ing addition, subtraction, and minimum, and some silly ones such as x - ∞ = -∞. 2. (25 points) The function allpairs returns all pairs of elements in a given list, in their order: allpairs::List a → List (a,a) allpairs[] = [] allpairs(x:xs) = map (λy → (x,y)) xs ++ allpairs xs . For example, allpairs [1,2,3,4] evaluates to [(1,2),(1,3),(1,4),(2,3),(2,4), (3,4)]. Furthermore, the function maxdiff computes the maximum difference of these pairs: maxdiff::List Int → Int maxdiff = maximum.map minus.allpairs , minus (x,y) = x - y . Apparently, maxdiff as defined uses a O(n^2) algorithm. Define: mdm xs = (maxdiff xs,???) Find out what ??? should be, and construct a linear-time implementation of mdm. You may need properties such as: map f (xs ++ ys) = map f xs ++ map f ys , (2) maximum (xs ++ ys) = maximum xs↑maximum ys , (3) plus property (1), and other essential properties such as map-fusion. 3. Recall that map and minimum are both folds (definitions omitted... find out by yourself!): map f = foldr ? ? minimum = foldr ? ? Another way to prove (1) is to show that both sides equal the same fold. (a) (12 points) Turn maximum.map (x-) into a single foldr, using the foldr- fusion theorem. (b) (12 points) Turn (x-).minimum into a single foldr, using the foldr- fusion theorem. If they turn out to be the same foldr, you have proved (1). 4. (26 points) Given xs::List Int, the function call pure i xs checks whether there exists an element x in the j-th position such that x = i + j: pure i [] = False pure i (x:xs) = if i == x then True else pure (1+i) xs . For example, if xs = [1,4,2,5], pure 0 xs = True because xs!!2 = 2 = 0 + 2. People might be more used to do the same task imperatively. If we define: imp::MonadState Int m => List Int → m Bool imp [] = return False imp (x:xs) = get >>= λi → if i == x then put (1+i+length xs) >> return True else put (1+i) >> imp xs , where (>>) is defined by m >> n = m >>= λ() → n, the same computation can be done by put i >> imp xs. (There is an awkward put (1+i+length xs) before return True. You might see why we need it later.) Show that put i >> imp xs = put (i+length xs) >> return (pure i xs) . You may need monad laws, laws regarding get and put, and the if rule we have used a lot: f (if p then x else y) = if p then f x else f y for terminating p. Part (B) - Logic: Exam 12th Formosan Summer School on Logic, Language, and Computation, 2018 1. (20%) Give two different derivations of |- A → A. 2. (20%) Derive A V (B Λ C) |- (A V B) Λ (A V C). 3. (20%) Derive A → -A, -A → A |- ⊥. 4. (20%) Derive ∀x. P x → Q |- (∃x. P x) → Q. (P and Q are predicate symbols of arities 1 and 0 respectively.) 5. (20%) Prove that for all Γ⊆PROP, φ∈PROP, and Ψ∈PROP, if Γ|=φ and Γ|=Ψ, then Γ|=φΛΨ. Part (C) - Lambda Calculus and Types: Exam 12th Formosan Summer School on Logic, Language, and Computation In the following questions, you do not need to write down every step. 1. (20pt) Write the set of free variables for each of the following terms. (a) (λx.x y x) (λy.x) (b) λy.(λx.x y x) (c) λxyz.(λx.z) (d) (λy.λx.y x) x 2. (25pt) Give two untyped λ-terms N and M such that N ≠ M (no α equivalent), N /→ M, M /→ N (cannot β reduction) but there exists some L with N → L and M → L (can β reduction). Explain why. 3. (20pt) Recall that True = λxy.x and False = λxy.y. Reduce the following term to its normal form using →β* (β reduction with or without any intermediate step). (λn.n (λb.λxy.b y x)(λxy.x)) c_100 4. (20pt) Derive the following typing judgement for any type τ in simply typed lambda calculus. |- λb.λxy.b y x : (τ→(τ→τ)) → (τ→(τ→τ)) 5. (15pt) In Haskell, Maybe a is a type with constructors Nothing::Maybe a and Just::a → Maybe a for any type a. Consider a function defined by maybe :: b → (a→b) → Maybe a → b maybe b f Nothing = b maybe b f (Just a) = f a In System F, we can encode Maybe σ for any type σ as Maybe σ := ∀t.t → (σ → t) → t and Nothing as Nothing := Λt.λ(x:t)(f:σ→t).x Define the corresponding λ-terms Just : σ → Maybe σ maybe: ∀t.t → (σ → t) → Maybe σ → t in System F such that maybe τ b f (Just a) → f a (β reduction) maybe τ b f Nothing → b (β reduction) Part (D) - Models of concurrent computation and session types: Exam Marks: Each question below is 20% of the overall mark for the exam. 1. What are the free names and free variables of the following processes? (a) Q = (μb) ( b(x).Q_1 | b_bar<c> | x(y).Q_2 ) (b) R = (μa) (!a(x).c_bar<y>) | a(x).R_1 | b(y).0 ) 2. Are these processes structually congruent? Write the justification: (a) (μa)Q | P | !(P|(μa)Q) and (μa)(P|Q)|(!((μa)(P|Q))) (b) (μa)(c_bar<a> | a(x).a_bar<a>) and (μa)(c_bar<a> | b(x).b_bar<b>) 3. Write the reduction step by step using the rules in the lecture notes (you can omit some steps, such as the structural congruence). (a) (μb)(a(x).x_bar<b>) | !(a_bar<b> | b(x).0) (b) a_bar<e> | a_bar<b> | a(x).(b_bar<x> | c_bar<x>) 4. Give the dual types: (a) μt.(?[string];![string];?[boolean];t) (b) &{inc:?[nat];![boolean];end, dec:![string];end} 5. Give the type derivation: __________________________________________________________________ Ø;Ø|- s(x).s(y).s_bar< x<y >.0 |> s:?[int];?[int];![boolean];end Note that we assume the expression x < y evaluates to boolean. ------------------------------------------------------------------------------ 圖片連結: Part(A) - 1st page: https://goo.gl/ouGv17 Part(A) - 2nd Page: https://goo.gl/1Sj3LB Part(B): https://goo.gl/pKbBr6 Part(C): https://goo.gl/s1Deod Part(D): https://goo.gl/nAJ8vK --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.83.213.167
※ 文章網址: https://webptt.com/m.aspx?n=bbs/NTU-Exam/M.1533324166.A.86E.html
1F:推 m24639297 : QQ看到就難過 08/04 18:30
2F:→ alan23273850: 蠻好奇大家成績都怎麼樣QQ 來個自我統計 08/04 19:42
※ 編輯: alan23273850 (36.235.34.5), 08/04/2018 21:14:00
3F:推 ffone : 推FLOLAC! 08/15 03:11







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP