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/cn.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灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP