<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4820154385615627530</id><updated>2012-02-16T01:20:57.783-08:00</updated><category term='virtual memory'/><category term='CSC369'/><category term='memory management'/><category term='Operating System'/><category term='os161'/><category term='fork'/><title type='text'>Wake Up！Davidson！</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-6791941246533274535</id><published>2012-02-05T18:03:00.000-08:00</published><updated>2012-02-05T18:19:05.829-08:00</updated><title type='text'>[IMPORTANT] Davidson's Blog is moved to mszheng.com</title><content type='html'>&lt;b&gt;&lt;span  &gt;Please notice that my blog is moved, &lt;/span&gt;&lt;/b&gt;&lt;div&gt;&lt;b&gt;&lt;span  &gt;for further update, please refer to &lt;a href="http://mszheng.com/"&gt;mszheng.com&lt;/a&gt;.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span &gt;&lt;b&gt;&lt;span &gt;此部落格将停止更新，&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span  &gt;&lt;b&gt;&lt;span&gt;请关注&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span&gt;&lt;a href="http://mszheng.com/"&gt;mszheng.com&lt;/a&gt;获取更多信息。&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span  &gt;&lt;b&gt;&lt;span&gt;このブログは&lt;/span&gt;&lt;/b&gt; &lt;span&gt;&lt;a href="http://mszheng.com/" style="font-family: arial; font-weight: bold; "&gt;mszheng.com&lt;/a&gt;&lt;/span&gt;&lt;b&gt;&lt;span&gt;に移転しました&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span&gt;よ。&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span &gt;&lt;b&gt;&lt;span &gt;ぜひご覧になってください！&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-6791941246533274535?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/6791941246533274535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=6791941246533274535' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/6791941246533274535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/6791941246533274535'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2012/02/important-davidsons-blog-is-moved-to.html' title='[IMPORTANT] Davidson&apos;s Blog is moved to mszheng.com'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-4357313484256618648</id><published>2011-10-13T17:15:00.000-07:00</published><updated>2011-10-13T18:00:57.097-07:00</updated><title type='text'>Memory Management, Paging</title><content type='html'>&lt;b&gt;Page frames or frames:&lt;/b&gt; memory is partitioned into equal, fixed-size chunks&lt;div&gt;&lt;b&gt;Pages&lt;/b&gt;: memory of processes are divided into chunks with same size&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Pages fit into any free page frame.&lt;/div&gt;&lt;div&gt;Benefits: No external fragmentation. Relatively little internal fragmentation(a part of a page).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For each process, a &lt;b&gt;page table&lt;/b&gt; is associated with it. It records the information about which&lt;/div&gt;&lt;div&gt;page is in which page frame. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Virtual Address = Page number + Page offset = vaddr /  page size + vaddr % page size&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Some calculations:&lt;/div&gt;&lt;div&gt;Suppose a logical address is 32 bits and a page is 8 kbytes&lt;/div&gt;&lt;div&gt;Bits of the logical address are used to address bytes within a page:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;8kbytes = 2^10 * 2^3 = 2^13; least significant 13 bits&lt;/div&gt;&lt;div&gt;Number of bytes can be addressed with a logical address:&lt;/div&gt;&lt;div&gt;2^32&lt;/div&gt;&lt;div&gt;Number of logical pages:&lt;/div&gt;&lt;div&gt;2^20&lt;/div&gt;&lt;div&gt;If a PTE is 4 bytes, space required for the page table:&lt;/div&gt;&lt;div&gt;2^20*2*2 = 2*22 bytes, 22 bits to represent&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-4357313484256618648?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/4357313484256618648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=4357313484256618648' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4357313484256618648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4357313484256618648'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/10/memory-management-paging.html' title='Memory Management, Paging'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-5630923079207339882</id><published>2011-10-13T16:26:00.000-07:00</published><updated>2011-10-13T17:15:22.537-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Operating System'/><category scheme='http://www.blogger.com/atom/ns#' term='CSC369'/><category scheme='http://www.blogger.com/atom/ns#' term='virtual memory'/><title type='text'>Memory Management, part 2</title><content type='html'>Another way to partition memory is &lt;b&gt;Dynamic Partition&lt;/b&gt;.&lt;div&gt;Partitions vary depending on the size of a process. The placement with dynamic allocation&lt;/div&gt;&lt;div&gt;is to allocate exactly the size of a process in the memory.&lt;/div&gt;&lt;div&gt;However, when processes exit, holes might be created between every two processes.&lt;/div&gt;&lt;div&gt;This is called &lt;b&gt;External Fragmentation&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;When OS move processes down to eliminate holes, larger free space are created.&lt;/div&gt;&lt;div&gt;This action is called &lt;b&gt;Memory Compaction&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;We need to know what is the maximum size of a process at load time. Otherwise, we&lt;/div&gt;&lt;div&gt;must be able to add to its partition, potentially relocating it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To keep track of memory allocation, we can use &lt;b&gt;Bitmaps&lt;/b&gt;. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Placement Heuristics: &lt;/div&gt;&lt;div&gt;Memory compaction is time-consuming. We can reduce compaction if we systematically&lt;/div&gt;&lt;div&gt;allocate memory. The following techniques give us an idea how this can be achieved.&lt;/div&gt;&lt;div&gt;&lt;b&gt;First-fit, &lt;/b&gt;allocate the first block large enough, appears to be the BEST choice, leave &lt;/div&gt;&lt;div&gt;external fragmentation at start of memory&lt;/div&gt;&lt;div&gt;&lt;b&gt;Next-fit, &lt;/b&gt;allocate the block where previous search ends at, a variation of first-fit,&lt;/div&gt;&lt;div&gt;free space becomes fragmented more rapidly&lt;/div&gt;&lt;div&gt;&lt;b&gt;Best-fit, &lt;/b&gt;scans through the blocks and finds the most suitable block in size,&lt;/div&gt;&lt;div&gt;small, unusable fragments&lt;/div&gt;&lt;div&gt;&lt;b&gt;Worst-fit, &lt;/b&gt;find the largest block&lt;/div&gt;&lt;div&gt;&lt;b&gt;Quick-fit,&lt;/b&gt; keep multiple free lists for common block sizes,&lt;/div&gt;&lt;div&gt;fast allocation, harder to coalesce&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Relocation:&lt;/div&gt;&lt;div&gt;a way to change the physical memory reference&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Dynamic relocation:&lt;/div&gt;&lt;div&gt;execution-time binding of addresses, hardware translates to physical addresses as instructions are executed.&lt;/div&gt;&lt;div&gt;base address + relative address = physical address &amp;lt;= limit address&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Basic problems that cause internal fragmentation and external fragmentation and so on...:&lt;/div&gt;&lt;div&gt;we assume processes are allocated to contiguous block of memory&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Solution: Paging&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To be continued...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-5630923079207339882?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/5630923079207339882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=5630923079207339882' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/5630923079207339882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/5630923079207339882'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/10/memory-management-part-2.html' title='Memory Management, part 2'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-4309332352009336747</id><published>2011-10-12T22:21:00.000-07:00</published><updated>2011-10-12T23:16:03.535-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='memory management'/><category scheme='http://www.blogger.com/atom/ns#' term='CSC369'/><category scheme='http://www.blogger.com/atom/ns#' term='virtual memory'/><title type='text'>Memory Management</title><content type='html'>The Quiz 1 is coming soon I am kind of falling behind the schedule. I decide to spend some times&lt;div&gt;to go over the concepts that have been covered in the lecture so hopefully I won't "fail" this course the second time.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I've been dealing with the memory management problems all the time when I implementing&lt;/div&gt;&lt;div&gt;the thread sub-system and system call functions. &lt;/div&gt;&lt;div&gt;Why should each process has its own address space? Why do we even come to this abstraction?&lt;/div&gt;&lt;div&gt;First, we want to protect the OS from being modified or trashed or whatever easily because of easy access to physical memory. &lt;/div&gt;&lt;div&gt;Second, we want to run multiple programs at once.&lt;/div&gt;&lt;div&gt;When multiple programs are running, two programs present: &lt;b&gt;protection &lt;/b&gt;and &lt;b&gt;relocation&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Address space&lt;/b&gt; creates a kind of abstract memory for programs. &lt;/div&gt;&lt;div&gt;It is a set of addresses for processes to address memory.&lt;/div&gt;&lt;div&gt;Each process then owns its private address space, continuous and contiguous. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;An important  concept to remember is "&lt;b&gt;Address Translation&lt;/b&gt;". It is the process of mapping addresses in the programs, mostly referred to the variables or symbolic addresses  that&lt;/div&gt;&lt;div&gt; programmers use, into physical addresses. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To deal with memory problems, two strategies are commonly used: &lt;b&gt;swapping&lt;/b&gt; and &lt;b&gt;virtual memory&lt;/b&gt;. &lt;/div&gt;&lt;div&gt;Swapping means to swap process in and out from memory and to put the inactive process&lt;/div&gt;&lt;div&gt;on the disk. Virtual memory allows program to run even when they are partially in main memory. This is insane technology! I will go over it later since there's quite a few things.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the lecture, we discussed about the &lt;b&gt;Partition &lt;/b&gt;problem. Process will grow as they run.&lt;/div&gt;&lt;div&gt;We must determine whether to partition the memory into fixed-size chunks or dynamically&lt;/div&gt;&lt;div&gt;allocate the memory. We want to allocate extra memory for a process to reduce the overhead&lt;/div&gt;&lt;div&gt;associated with swapping processes that no longer fit in out from the memory. &lt;/div&gt;&lt;div&gt;It is somewhat complicated here. Let's start over again.&lt;/div&gt;&lt;div&gt;When the space is no longer large enough for a process, it will be swapped out and it has&lt;/div&gt;&lt;div&gt;to wait until a lager hole in the memory becomes available. The static/fixed-size allocation &lt;/div&gt;&lt;div&gt;is simpler to implement, but it creates &lt;b&gt;Internal Fragmentation&lt;/b&gt;. In this case, memory&lt;/div&gt;&lt;div&gt;is wasted if process in a partition is smaller. For programs that are larger than the partitions,&lt;/div&gt;&lt;div&gt;we have &lt;b&gt;Overlay&lt;/b&gt; problems. Then those programs have to get the hell out of the memory. (:&amp;lt;)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Gotta sleep now.&lt;/div&gt;&lt;div&gt;To be continued...&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-4309332352009336747?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/4309332352009336747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=4309332352009336747' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4309332352009336747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4309332352009336747'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/10/memory-management.html' title='Memory Management'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-682402162751860992</id><published>2011-10-10T02:26:00.000-07:00</published><updated>2011-10-10T04:25:44.577-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Operating System'/><category scheme='http://www.blogger.com/atom/ns#' term='fork'/><category scheme='http://www.blogger.com/atom/ns#' term='os161'/><title type='text'>os161 - fork(), part 2</title><content type='html'>&lt;div&gt;If a process is running a user program in user mode and needs a system service, such as reading&lt;/div&gt;&lt;div&gt;data from a file, it has to execute a "trap" instruction to transfer control to the OS. &lt;/div&gt;&lt;div&gt;When an interrupt signal occurs, there has to be some reasons for the occurrence. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The information needed to be handled are pushed onto the stack  in user space. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The system handler is just a function in os161 that takes a pointer to trapframe as argument.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In os161, we define a structure called trapframe, which describe what is saved on the stack&lt;/div&gt;&lt;div&gt;during entry to the exception handler. The first 4 32-bit arguments are passed in the 4&lt;/div&gt;&lt;div&gt;argument registers a0-a3 by convention. 64-bit arguments are passed in aligned pairs of&lt;/div&gt;&lt;div&gt;registers, either a0/a1 or a2/a3. The system call number is passed in the v0 register.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;On success, the return value is passed in the v0 register. a3 is set to 0.&lt;/div&gt;&lt;div&gt;For example, 0 is returned to the child process after fork() succeed.&lt;/div&gt;&lt;div&gt;On failure, error code is passed in v0 and a3 is set to 1.&lt;/div&gt;&lt;div&gt;Upon syscall return, the PC stored in the trapframe (tf_epc) must be incremented by 4 bytes,&lt;/div&gt;&lt;div&gt;which is the length of one instruction. Otherwise the return code restart at the same point.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Look closely inside syscall() in kern/arch/mips/syscall/syscall.c, we shall see how it works. &lt;/div&gt;&lt;div&gt;In the case of fork(), the OS will pass the trapframe pointer and PID into sys_fork.&lt;/div&gt;&lt;div&gt;For the parent process, the syscall function will examine the return value(a PID or error code) &lt;/div&gt;&lt;div&gt;of sys_fork to set the register values. Then the parent process shall proceed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In sys_fork(), the parent process will allocate some memory in the heap and make a copy&lt;/div&gt;&lt;div&gt;of the trapframe on the stack for the child process. A pointer to this trapframe will be passed into thread_fork(). &lt;/div&gt;&lt;div&gt;Later the child will free the memory allocated previously by the parent on the heap.&lt;/div&gt;&lt;div&gt;Then the thread_fork() is called to create the a new thread structure for the child process. &lt;/div&gt;&lt;div&gt;What thread_fork() will do first is to allocate a new stack, get a new PID of the child, do some&lt;/div&gt;&lt;div&gt;address space copy from its parent, and it also copies the working directory.&lt;/div&gt;&lt;div&gt;After the new thread structure is set up, it will initialize the switch frame for the new thread.&lt;/div&gt;&lt;div&gt;But what the hell is a switchframe? This is actually the PCB(process control block) of&lt;/div&gt;&lt;div&gt;a thread. The sf registers of this "switchframe" will hold the arguments from&lt;/div&gt;&lt;div&gt;thread_fork(): a function poiner "entrypoint", the trapframe copied from the address space&lt;/div&gt;&lt;div&gt;of the parent process to the child process's, and some garbage "data2".&lt;/div&gt;&lt;div&gt;Then we call thread_make_runnable() to make the new thread runnable.&lt;/div&gt;&lt;div&gt;The funnction "entrypoint" will be implemented in syscall.c.&lt;/div&gt;&lt;div&gt;The child process will start at this function and free the trapframe passed to it.&lt;/div&gt;&lt;div&gt;It will create its own trapframe on the stack in its address space and sets up the&lt;/div&gt;&lt;div&gt;return values in the registers. It finally increment the program counter by 4 bytes and&lt;/div&gt;&lt;div&gt;calls mips_usermode to warp to user space.&lt;/div&gt;&lt;div&gt;Eventually, we will see fork returns twice:&lt;/div&gt;&lt;div&gt;0 and PID of child process.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is my understanding so far, after a night without sleep. The next thing I will do is to&lt;/div&gt;&lt;div&gt;implement execv(), which is quite similar to runprogram().&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-682402162751860992?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/682402162751860992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=682402162751860992' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/682402162751860992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/682402162751860992'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/10/os161-fork-part-2.html' title='os161 - fork(), part 2'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-2377221841242485312</id><published>2011-10-09T19:46:00.000-07:00</published><updated>2011-10-09T21:51:39.756-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Operating System'/><category scheme='http://www.blogger.com/atom/ns#' term='fork'/><category scheme='http://www.blogger.com/atom/ns#' term='os161'/><category scheme='http://www.blogger.com/atom/ns#' term='CSC369'/><title type='text'>OS161-Writing Fork(), part 1</title><content type='html'>In assignment 2, we are asked to implement fork in the system os161. &lt;div&gt;It has been said that implementing fork() is the most difficult part in this assignment and is very crucial to understand how new process are created.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Despite the very details of the thread subsystem in os161, we will step through the process of the implementation of fork() in order to deepen our understanding of system calls.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;fork() does the following things:&lt;/div&gt;&lt;div&gt;- it makes a copy of the invoking process and makes sure that the parent and child processes&lt;/div&gt;&lt;div&gt;  each observe the correct return value.&lt;/div&gt;&lt;div&gt;- it returns  0 to the child and a new PID to the parent.&lt;/div&gt;&lt;div&gt;- the core of the fork() system call will invoke "thread_fork()" in kern/thread/thread.c&lt;/div&gt;&lt;div&gt;  to create a new kernel thread&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The child process should inherit exactly the same state of the parent at the time the parent&lt;/div&gt;&lt;div&gt;had when it made the system call.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;By inspecting the code of "runprogram()" in /kern/syscall/runprogram.c, we can get some&lt;/div&gt;&lt;div&gt;insights of how fork() can be implemented. &lt;/div&gt;&lt;div&gt;runprogram() will show us how a program returns user space after a system call.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;runprogram() takes a "string" (or char *) program_name and return an integer(EINVAL if error). loadexec() is the core code to load an executable into memory.&lt;/div&gt;&lt;div&gt;loadexec() will &lt;/div&gt;&lt;div&gt;- call kstrdup() to make a new name for the process&lt;/div&gt;&lt;div&gt;- call vfs_open() to load the program / open the file, &lt;/div&gt;&lt;div&gt;- call as_create() to make a new address space ,&lt;/div&gt;&lt;div&gt;- replace the old address spaces of the current thread with the new address spaces, &lt;/div&gt;&lt;div&gt;- call as_activate to make the new address space "seen" by the processor,&lt;/div&gt;&lt;div&gt;- call load_elf() to load the executable indicated by its argument "entrypoint", a virtual address&lt;/div&gt;&lt;div&gt;- call as_define_stack() to set up the user stack region in the address space, which make the &lt;/div&gt;&lt;div&gt;  stack pointer point back to USERSTACK, the initial stack pointer for the new process,&lt;/div&gt;&lt;div&gt;- wipe out the old address space,&lt;/div&gt;&lt;div&gt;- change the current thread's name to reflect the new process.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;After this, enter_new_process(), in /kern/arch/mips/locore/trap.c, &lt;/div&gt;&lt;div&gt;is called to warp to user mode. This function is used to go to user mode after loading an executable. It creates an ersatz (what the heck is this, figure it out later) trapframe, &lt;/div&gt;&lt;div&gt;sets the program counter to a virtual address, &lt;/div&gt;&lt;div&gt;stores the "argc" into register tf_a0, stores the pointer to arguments&lt;/div&gt;&lt;div&gt;into register tf_a1, and sets the stack pointer. Finally it calls mips_usermode(&amp;amp;tf) to enter&lt;/div&gt;&lt;div&gt;user mode.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now we will go through the code of fork() step by step.&lt;/div&gt;&lt;div&gt;fork() takes two arguments: a pointer to trapframe an integer (the PID of the parent process).&lt;/div&gt;&lt;div&gt;It will first malloc some spaces in the heap to copy the trapframe, because we might return&lt;/div&gt;&lt;div&gt;to user level and make another system call, which might change the trapframe, before the&lt;/div&gt;&lt;div&gt;child runs. The child will free the copy of the trapframe in the heap. Then we call thread_fork().&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Honestly, I have no idea how to implement thread_fork() from scratch. This is super duper hard for me. But...so what? I am going to get the jobs done anyway.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To create a new thread, call thread_create().&lt;/div&gt;&lt;div&gt;We will stick some magic numbers on the bottom end of the stack to catch kernel stack overflow.&lt;/div&gt;&lt;div&gt;Then we need to allocate some memory to the new thread and create a new PID for it.&lt;/div&gt;&lt;div&gt;Then we need to set up various fields associated with the new thread.&lt;/div&gt;&lt;div&gt;For example, we need to copy the virtual address space and current working directory from&lt;/div&gt;&lt;div&gt;its parent. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To be continued...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-2377221841242485312?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/2377221841242485312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=2377221841242485312' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2377221841242485312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2377221841242485312'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/10/os161-writing-fork-part-1.html' title='OS161-Writing Fork(), part 1'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-4966506580054902342</id><published>2011-04-07T16:41:00.000-07:00</published><updated>2011-04-07T17:40:21.574-07:00</updated><title type='text'>CSC300 Service Learning: Website for the Global Roots Garden</title><content type='html'>I met with our service partner Sara and another classmate Andrew yesterday.&lt;br /&gt;Up to this point, we have built a prototype of the website for the Global Roots Garden.&lt;br /&gt;Andrew and I were both super busy during these two weeks. Fortunately, the website&lt;br /&gt;does not require any fancy function. Web users can listen to the stories of the gardeners&lt;br /&gt;by using the Google reader mp3 player embedded in the web page. Inspired from the website&lt;br /&gt;http://mycitylives.com/, people can view the gardeners' profiles by clicking on a "seed" icon&lt;br /&gt;spread on a image. They then will see the photo of the gardener who is telling the story so that people feel more connected to the story as if they are told by the gardener himself/herself.&lt;br /&gt;I am also responsible for creating a different language version of the website, allowing people from different countries to access.&lt;br /&gt;&lt;br /&gt;As a result, our contribution to the community and the neighborhood is positive. We can not see any change or consequence right away since the website is not online and the stories have not been uploaded to the server yet. However, our service partner Sara is quite satisfied with our cooperation. Due to the deadline of this course, our service also comes to an end. I hope this project will help foster the improvement of the cultural diversity  within the city.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-4966506580054902342?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/4966506580054902342/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=4966506580054902342' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4966506580054902342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4966506580054902342'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/04/csc300-service-learning-website-for.html' title='CSC300 Service Learning: Website for the Global Roots Garden'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-6412340601309218127</id><published>2011-04-05T18:10:00.001-07:00</published><updated>2011-04-05T18:52:41.562-07:00</updated><title type='text'>CSC300 Service Learning: Storytelling</title><content type='html'>This should be posted a two weeks ago but I was too busy to write the thing down. I went to the the garden at St.Clair West &amp;amp; Bathurst to help our service partner, Sara, with interviewing a Chinese Woman, from Dongbei province in China. Surprisingly Sara learned Chinese before when she was teaching as a TA in Shanghai Jiao Tong University, in Shanghai.&lt;br /&gt;Since Sara had difficulties fully understanding her words, she asked me to help translate the story and any questions/answers from the Chinese woman. This is very helpful for the story recording because there may be a chance the woman tell the story without understanding Sara's question. We still spent a whole afternoon to make sure the woman's telling the story relevantly. She mentioned her experience of growing food fifty years ago in China. She also told us what is her life like after she moved to Canada. She told us how different was the food grew locally in Toronto from the food she grew in Beijing. Eventually these stories will be visible to the public through the web. I was pleased that I helped collect the story and build the interface for more people to access to the story in this project. It was quite an amazing experience.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-6412340601309218127?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/6412340601309218127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=6412340601309218127' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/6412340601309218127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/6412340601309218127'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/04/csc300-service-learning-storytelling.html' title='CSC300 Service Learning: Storytelling'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-7263729270860193345</id><published>2011-03-16T02:26:00.000-07:00</published><updated>2011-03-16T03:38:11.645-07:00</updated><title type='text'>CSC300 Service Learning: Second Meeting</title><content type='html'>The second meeting was on Wednesday 2pm, March 9. The attendants were Andrew, Mariyam, Sara and I.  Prior to the meeting, I had a chance to read part of Sara's paper about the Global Roots Project. She also gave us a few links to the websites that record stories told about specific geographic locations. One similar project is known as the "murmur" project. People listen to the stories and get to know the histories and ancedotes of the local people. The "murmur" project unveiled the private truths and tales that make up the city. Information hidden from eyes and things being forgotten by the new generation are picked up and translated into the form of voices. I think this is something that people nowadays don't usually find in someone's blog or social networking spaces.  Hence I'm provided a great opportunity to help improve the situation.&lt;br /&gt;&lt;br /&gt;Our objective again is to help Sara with the project The Global Roots Project and get the audio recordings of the gardeners' narratives displayed within the garden and on the internet. More precisely, the Global Roots garden we provide services for is one of the two locations in Toronto that the Stop Community Food Center operates. People from different ethnic communities are given a 20-by-13 ft plot to grow non-local vegetables. There are different events going on each week for them to socialize. The design of the garden and the diversity of the plants tell the story of how people share their cultures. Inspired by the "murmur" project, the Global Roots Project will also record the stories of all the gardeners in all languages. The stories told in other languages other than English will be translated. Although it's suggested to listen to the story throughout the garden, we still need to build a website for the larger public.&lt;br /&gt;&lt;br /&gt;During the meeting we discussed the rough idea of the website we are going to build. Andrew and I will be responsible for it. We consider to put a image of the garden with plots. Stories are wrapped in a tag or label or button scattered throughout the image like a geographic location in a map. By clicking the the tag/label/button, people get access to the audio files of the stories.&lt;br /&gt;We still need to design the different level of the website. We also considered the possibilities to have interactive feature such as providing comments or feedback. However, such interaction may require a database in the back-end to store all the information sent by users and add more&lt;br /&gt;complexity to the project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-7263729270860193345?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/7263729270860193345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=7263729270860193345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/7263729270860193345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/7263729270860193345'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/03/csc300-service-learning-second-meeting.html' title='CSC300 Service Learning: Second Meeting'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-3419367495566086227</id><published>2011-03-03T15:12:00.000-08:00</published><updated>2011-03-03T16:25:04.450-08:00</updated><title type='text'>CSC300 2011 Winter Service Learning, First Meeting</title><content type='html'>Today Andrew, Mariyam and I  met with our service partner, Sara, at Noir Cafe near The Stop Community Food Center. She briefly introduced The Global Root Project to us and brought us to the Stop Green Barn, located at St. Clair and Christie.&lt;br /&gt;&lt;br /&gt;Our main duties associated with this project include building a website that host the oral histories of the gardeners in the neighborhood and creating the audio installation within the garden. The primary goal is to allow people in the community to get more familiar with the history and background of the local green food and urban agriculture. People may hear about the concept but they seldom have the chances to directly access to the stories behind the scenes. People get the source of information directly through listening to a short storytelling audio clip, which is more reliable.&lt;br /&gt;&lt;br /&gt;The gardeners being interviewed by our service partner Sara come from all over the world such as Canada, India, China, Kenia, and etc. Most of them is able to speak English. People with different cultural background share their knowledge of food, gardening here.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-3419367495566086227?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/3419367495566086227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=3419367495566086227' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/3419367495566086227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/3419367495566086227'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2011/03/csc300-2011-winter-service-learning.html' title='CSC300 2011 Winter Service Learning, First Meeting'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-1857076864549898515</id><published>2008-12-04T20:12:00.000-08:00</published><updated>2008-12-04T21:27:26.403-08:00</updated><title type='text'>Test 3 Q3 review - Problem Solving</title><content type='html'>Below is the last question in test 3 i did hours ago. I wrote down the proof briefly which may not be that convincible, so i decide to prove it again.&lt;br /&gt;&lt;br /&gt;Prove L(1*(0+e)1*(0+e)1*) = L2, the language has at most two zeros.&lt;br /&gt;&lt;br /&gt;To prove the equivalence, we actually prove that for any element x , it can be represented by&lt;br /&gt;L(1*(0+e)1*(0+e)1*) or L2.  The former one looks a little bit complicated but actually it is possible to simplify it to make the proof much easier and shorter. By applying the distributivity, the transformation is going to be like:&lt;br /&gt;L(1*(0+e)1*(0+e)1*) &lt;=&gt; L((1*0+1*e)(1*0+1*e)1*) , apply identity and annihilator for concatenation here, we get L((0+1*)(0+1*)1*), then apply idempotence of Kleene star, the simplest form is L((0+1*)(0+1*)).&lt;br /&gt;Now, we are really just proving L((0+1*)(0+1*)) = L2.&lt;br /&gt;&lt;br /&gt;In first part, we prove L((0+1*)(0+1*)) is a subset of L2.&lt;br /&gt;L2 tells us how we rewrite L((0+1*)(0+1*)), that is to say, the number of zero is crucial.&lt;br /&gt;It's definitely true by just looking at L((0+1*)(0+1*)),  but we need demonstrate it with stronger reason. All cases include zero-free, one zero and two zeros. (0+1*) has either one zero or repetition of 1 or e. Then the concatenation of two (0+1*) has two zeros at most which satisfies L2. Then x \in L((0+1*)(0+1*)) implies x \in L2.&lt;br /&gt;&lt;br /&gt;In second part, we prove L2 is a subset of L((0+1*)(0+1*)).&lt;br /&gt;In this part, the setting for the typical elemtent x depends on L((0+1*)(0+1*)).&lt;br /&gt;Since there are at most two zeros, i don't think there are too much things to worry about.&lt;br /&gt;We just ensure x can be zero-free or with one zero or with two zeros.&lt;br /&gt;x = (0+1/e/1*)(0+1/e/1*), (0+1*) is satisfying the language L((0+1*)(0+1*)) here.&lt;br /&gt;Hence, the proof is done.&lt;br /&gt;&lt;br /&gt;For such questions, once the languages on both sides are well understood, the proof will be just following the formal procedure.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-1857076864549898515?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/1857076864549898515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=1857076864549898515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/1857076864549898515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/1857076864549898515'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/12/test-3-q3-review-problem-solving.html' title='Test 3 Q3 review - Problem Solving'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-2055225189874053086</id><published>2008-12-04T10:22:00.000-08:00</published><updated>2008-12-04T13:00:54.049-08:00</updated><title type='text'>Chapter Seven Review</title><content type='html'>#############&lt;br /&gt;Formal Language:&lt;br /&gt;#############&lt;br /&gt;Any set of strings can be empty, finite, or infinite.&lt;br /&gt;Length of string: s, number of symbols in s, ex: "+"=1, "e"=0.&lt;br /&gt;&lt;br /&gt;#############&lt;br /&gt;Regular Expressions(Regex):&lt;br /&gt;#############&lt;br /&gt;Basis : empty, empty string, one-symbol character;&lt;br /&gt;Kleene star can be used to restrict the pattern of a regex:&lt;br /&gt; even or odd numbers of some characters;&lt;br /&gt;Idempotence of Kleene star: R** = R*&lt;br /&gt;Distributivity: (A(B+C)) = (AB+AC), ((B+C)A) = (BA + BC)&lt;br /&gt;&lt;br /&gt;Proving equality of two languages =&gt; Prove mutual inclusion:&lt;br /&gt;1. Analyze the pattern of a language and divide into pieces if possible;&lt;br /&gt;2. Transformations: in general case, expand some terms to make up the equality;&lt;br /&gt;3. Check from both directions, conclusion.&lt;br /&gt;&lt;br /&gt;###&lt;br /&gt;FSA&lt;br /&gt;###&lt;br /&gt;Proof procedure, induction:&lt;br /&gt;Basis: x=e, &amp;amp;*(q_e,x)=q_e. P(e) true.&lt;br /&gt;Induction Step: Assume x = x'a, assume P(x'). Analyze the cases.&lt;br /&gt;In all cases, x = x'a and &amp;amp;*(s,x) = &amp;amp;*(q_e,x'a)=&amp;amp;(&amp;amp;*(q_e,x'),a)&lt;br /&gt;according to our induction hypothesis.&lt;br /&gt;Then using the transistions functions, we prove P(x') =&gt; P(x), in all cases.&lt;br /&gt;&lt;br /&gt;####&lt;br /&gt;NFSA&lt;br /&gt;####&lt;br /&gt;Difference: Each transition takes the machine to a subset of states rather than a unique&lt;br /&gt;state.&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;Every regex has equivalent NFSA.&lt;br /&gt;Every NFSA has equivalent DFSA.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-2055225189874053086?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/2055225189874053086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=2055225189874053086' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2055225189874053086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2055225189874053086'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/12/chapter-seven-review.html' title='Chapter Seven Review'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-4475931338209675720</id><published>2008-11-24T12:17:00.000-08:00</published><updated>2008-11-24T12:55:39.902-08:00</updated><title type='text'>DFSA</title><content type='html'>In some degree, the most challenging question in assignment 3 may be the last one.&lt;br /&gt;I once got stuck on combing the two machines representing binary string with odd length and multiple of five respectively.  I wasn't sure what were the exact steps using cartesian product. So i considered all the combinations of the cases of the third machine i want to construct.&lt;br /&gt;That is exactly the result of cartesian product. Excluding the initial state, there are 5*2 = 10 states&lt;br /&gt;for x = n mod 5 with odd/even length. These are the state invariants. Then We can see directly from some binary numbers and derive the transitions.  Then the desired machine is fulfilled.&lt;br /&gt;The proof of a DFA is straightforward. For me it is kind of a process of verifying each state go to the correct place via a path or an edge. Graphically, each state is a node with inputs and outputs.&lt;br /&gt;Thus the transitions explain the correctness of traversals in a machine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-4475931338209675720?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/4475931338209675720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=4475931338209675720' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4475931338209675720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4475931338209675720'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/11/dfsa.html' title='DFSA'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-8861593654419071588</id><published>2008-11-15T19:19:00.000-08:00</published><updated>2008-11-17T12:40:12.617-08:00</updated><title type='text'>review of Week 10</title><content type='html'>The annoying assignments, exercises, quizzes and term tests seem to be paused except for CSC236. This weekend i have to engage into the second last assignment with my partner. I also have a somehow big project of csc207 to worry about. Insipte of the workload of a computer science student, i now write for my 6%~11% of the final mark.&lt;br /&gt;These two week we saw pretty much things about finite state automata and regular expressions. Regular expression is a descriptive way to express the language. We can design our own language with different alphabet using regular expressions. Through the example in the lecture, such as an alphabet of binary numbers containing even or odd zeros, i learned a logical procedure to analyze the syntax between various languages. The interesting part for me is the algebra on regexes. Without changing the language, one can apply some principles such as: commutativity, distributivity to the regular expressions. This simplifying process allows more variations on a language and it provides some interesting design patterns of a language.&lt;br /&gt;Another thing is the DFA, or DFSA. The first time i saw it was in CSC148 when we were doing the graph algorithm. It seems there is quite a few connection from the DFA to graph algorithm. Machines of DFA accept their unique pattern of strings. We can easily find out  whether a string is valid to the machine by traversing between the states. The hard part is how we construct a desired machine for a particular collection of strings. By observing the pattern of some strings, we need to derive some crucial parts of the machine like the state invariants and the transition functions. A graph is usually helpful to verify the state the next character heads is correct, which is to say, we need to carefully set our initial state, final state, states between and all the edges. Such things is really thoughtful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-8861593654419071588?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/8861593654419071588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=8861593654419071588' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/8861593654419071588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/8861593654419071588'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/11/review-of-week-10.html' title='review of Week 10'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-2017670665192965194</id><published>2008-11-08T10:19:00.000-08:00</published><updated>2008-11-08T10:42:08.286-08:00</updated><title type='text'>After Test 2..</title><content type='html'>Since there is always a lot of people there in the day section, i wrote the night section test.&lt;br /&gt;I don't know how big the difference between the day section and night section test. They may follow the same patter pretty much. I didn't work out satisfying answers on the test.&lt;br /&gt;About the palindrome, i remembered well that i did the same thing in CSC108 lab. But one thing&lt;br /&gt;to regret is that i forgot the prove structure. I tried using complete induction but i didn't organize the frame well.&lt;br /&gt;Related to the last question in the test, i really got a mess in my mind during the test.&lt;br /&gt;I got frustrated when i could not figure out right away the main purpose of the function downward(n). Things happened and i got all blank in my brain. When i got calm down and refreshed my mind, i tried out some typical examples. Unfortunatley, i didn't realize that the loop invairant was sth like the floor of lgn until hours after the test. Anyway i cannot say i fail the test, at least i failed getting an insight on the subtle things.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-2017670665192965194?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/2017670665192965194/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=2017670665192965194' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2017670665192965194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2017670665192965194'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/11/after-test-2.html' title='After Test 2..'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-312525097143261954</id><published>2008-10-30T18:24:00.000-07:00</published><updated>2008-10-30T19:09:30.714-07:00</updated><title type='text'>More on iteration</title><content type='html'>The 3-hour night version lecture is a real torture.  For the example counter(m,n), i can't relate the loop invariant directly to the correctness of the program. It's weird that the b value is set to 6.&lt;br /&gt;I tried pick two non-zeros natural numbers for m and n randomly. And the loop has to execute 6 more times to terminate after a and b decrease to 0 since b is assigned to 6 and c has to counter 6 more times. It may be necessary to use the loop invariant c = 7m + n to go to the postcondition,  but it seems not to be that straightforward to be understood. Now i realize the importance of code design that make other people's life easier, for people who are learning how to prove loop invariant. Back to the loop invariant, i usually trace algorithm on simple example, like iterates for a few times and see what kind of changes are caused. As to me it's more helpful than just thinking of some fancy relationship between precondition and postcondition.&lt;br /&gt;For more complicated loops, like nested loops, these things have to be done inside out. Prove termination and loop invariant in the very inside, then for any value of the loop outside, prove termination and loop invariant for outside loop. In the selection_sort example, the inside loop is going from index j=i+1 to the end of the list. Selection_sort is basically "selecting" a proper position for an element in the unsorted section of that list. I take a [4,2,3,1] as an example to run the loop. The inside loop actually helps me to evaluate a position by comparing the value of 4 to 2,3 and 1, then the outer loop moves to the next index and this easily sorts the whole list. But the inside loop may have k+1 iteration or may not. Since the value of the number could be equivalent. These "special" cases happened because of the postcondition, which is non-decreasing order here. Then it's not hard to prove the program "moves" and "compares" in some range.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-312525097143261954?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/312525097143261954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=312525097143261954' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/312525097143261954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/312525097143261954'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/more-on-iteration.html' title='More on iteration'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-8499862716139766849</id><published>2008-10-29T10:16:00.000-07:00</published><updated>2008-10-29T10:48:42.060-07:00</updated><title type='text'>Busy Week 8</title><content type='html'>A2 was submitted a few days ago, but i didn't work out the first problem, neither did my partner.&lt;br /&gt;I  didn't derive a valid recursive formula for the 3rd problem as well. So i just proved it without a valid formula, which might lose some marks probably.&lt;br /&gt;Luckily the 207 midterm was over this afternoon, i now have more time to review the materials Danny had talked about iterative programs.&lt;br /&gt;It's again easy to start with, and more interesting than the previous sections. Obviously, we will use a lot of simple induction stuff here, for proving correctness of iterative programs. It's tricky to seek for a proper loop invariant, and it always takes times to go through the loop and see how this 'incomplete solution' works. Again, to prove the correctness, we carefully trace the loop and the changes each time it caused. This helps us to fulfill the implication from the ith to the (i+1)th loop.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-8499862716139766849?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/8499862716139766849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=8499862716139766849' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/8499862716139766849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/8499862716139766849'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/busy-week-8.html' title='Busy Week 8'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-2865246219732030955</id><published>2008-10-24T20:52:00.000-07:00</published><updated>2008-10-24T22:55:18.372-07:00</updated><title type='text'>the end of week 7</title><content type='html'>Proving program correctness is always an annoying part, especially dealing with searching items and sorting items in an array or list. There are many conditions to consider for the program(most of them we have seen during this week were recursive programs) correctness.&lt;br /&gt;&lt;br /&gt;The proof of correctness may be like: by induction, for size of the input,&lt;br /&gt;prove precondition -&gt; termination&amp;amp;postcondition. It seems the structure of&lt;br /&gt;complete induction is well following recursive structure.&lt;br /&gt;&lt;br /&gt;Then we go through the first few lines and if lucky enough we can proceed to the&lt;br /&gt;annoying part of the recursive function.  In this case, the recursive step leads us&lt;br /&gt;to examine the whole function again with different input size, a smaller size.&lt;br /&gt;We don't stop checking until we get the expected result - the post condition.&lt;br /&gt;But how to split up the size so that it will look more straightforward and easier to&lt;br /&gt;be checked? For the binary search, the way is to break into the middle of a list.&lt;br /&gt;So there may be various ways and algorithms for various problems to shrink the&lt;br /&gt;searching or sorting range.  The next thing is to continue on executing. The case&lt;br /&gt;must be carefully chosen otherwise some unexpected errors may cause the crush&lt;br /&gt;of the program.&lt;br /&gt;&lt;br /&gt;The proof is complicated at most of the time so as to ensure all the codes work from the&lt;br /&gt;first line with the initial input. It saves us a lot of time to complement any cases or to fix&lt;br /&gt;up any mistakes afterwards.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-2865246219732030955?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/2865246219732030955/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=2865246219732030955' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2865246219732030955'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2865246219732030955'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/end-of-week-7.html' title='the end of week 7'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-7928781797907948542</id><published>2008-10-20T15:55:00.000-07:00</published><updated>2008-10-20T16:33:27.756-07:00</updated><title type='text'>Lecture about Program Correctness</title><content type='html'>Monday came, Danny didn't come.&lt;br /&gt;A lecturer named Nick presented us a lecture about program correctness.&lt;br /&gt;Nick started by the sentence "My program is correct." He talked about how correct a program&lt;br /&gt;would be from different points of view. He spent some minutes on explaining the definition of conditions, the relationship between precondition and input, postcondition and output.&lt;br /&gt;This helps us to recall what we have learned in CSC165.&lt;br /&gt;Then he gave the very familiar example, binary research, to reinforce the concept on how a program would be correct in each step. One question(maybe just for fun, maybe not) he mentioned during the lecture was 'how do you crush a program', which sounds very illegal.&lt;br /&gt;But at the same time, this is just the way to prove the program correctness backwards.&lt;br /&gt;I believe if one can crush a program easily, then it wouldn't be too hard to prove correctness.&lt;br /&gt;That is where you see right from wrong. So yes, let's enjoy crushing our programs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-7928781797907948542?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/7928781797907948542/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=7928781797907948542' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/7928781797907948542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/7928781797907948542'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/lecture-about-program-correctness.html' title='Lecture about Program Correctness'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-4341475550296279080</id><published>2008-10-18T21:41:00.000-07:00</published><updated>2008-10-18T22:57:06.965-07:00</updated><title type='text'>Week 6</title><content type='html'>This week we focused on analyzing the complexity of mergesort and did some unwinding and proof.  The repeating substitution procedure is simple. In most cases, when n&gt;some integer, according to the definition, we can easily get a formula from the right hand side. Since we want the f(n) or g(n) or whatever to decrease to f(0)/g(0)=1, the formula we eventually derive will be like a constant to the power of something plus something else. To make a conjecture, we just carefully define n, which is usually natural numbers with some restrictions. The divide-and-conquer strategy provides us a way of breaking big problems into smaller and smaller parts. Then the size will be small enought for us to directly solve. Well, at least with spliting up and solving one of the subproblems, the base cases, we can always get a few marks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-4341475550296279080?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/4341475550296279080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=4341475550296279080' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4341475550296279080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/4341475550296279080'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/week-6.html' title='Week 6'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-9053713796537246035</id><published>2008-10-10T10:27:00.000-07:00</published><updated>2008-10-10T10:41:02.574-07:00</updated><title type='text'>term test 1</title><content type='html'>i used simple induction for all the three questions. Since i guess it would be easier to prove P(n)=&gt;P(n=1) for the predicate in the three questions, except the last question. it seems it would be proper if i used complete induction to prove it. Similar problem i had seen before. since i was writing in a hurry, i just picked the most familiar technique for me to solve, which is simple induction. I was stuck when i was dividing the set into a part that can be applied with IH. The n+1 element took me a lot of time to derive the subsets containing it. I might be wrong on the answer since the induction step wasn't that successful. if there were 5 more minutes maybe i could do the induction step one more time and find out which number of subsets is going wrong.&lt;br /&gt;Luckily the first two questions required less cases to analyze. i think i did well in the recursive one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-9053713796537246035?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/9053713796537246035/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=9053713796537246035' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/9053713796537246035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/9053713796537246035'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/term-test-1.html' title='term test 1'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-3822465600781682143</id><published>2008-10-07T17:43:00.000-07:00</published><updated>2008-10-07T19:30:58.849-07:00</updated><title type='text'>review for week 4</title><content type='html'>The algorithm complexity part is usually thoughtful-provoking.&lt;br /&gt;I didn't see big differences when i run a program on my laptop or some computers, but i did see the way that much fewer steps generated by applying recursion. Well, iterative functions come more naturally for me though great efficiency recursion has. Everytime i'm analyzing recursive functions, my sight jumps back and forth. Thought it makes my codes neat, it usually takes time for me to solve a problem recursively. We also did a bit of unwinding, estimating the time complexity of binary search and the proof of it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-3822465600781682143?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/3822465600781682143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=3822465600781682143' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/3822465600781682143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/3822465600781682143'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/10/review-for-week-4.html' title='review for week 4'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-2076873805032420239</id><published>2008-09-26T08:13:00.000-07:00</published><updated>2008-09-26T08:40:05.889-07:00</updated><title type='text'>how wrong would a proof be</title><content type='html'>I'm given some ideas of how a induction "traps" is raised by today's lecture. As to me, this happens that i write down the proof before convincing myself that each step follows the previous steps rigorously. We know that there are base case, induction hypothesis and induction step in a formal induction proof. The subtle may be made by missing one of them or by saying something that mismatching the fact. I sometimes make mistakes by making implicit assumption, and the result is that i couldn't reach the conclusion since it is incorrect at the beginning. To understand the statement is also important since the predicate is chosen from the statement. For the last problem on assignment 1, we should carefully remain the property of a ternary tree when we make our assumption. Good luck for the assignment 1.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-2076873805032420239?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/2076873805032420239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=2076873805032420239' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2076873805032420239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/2076873805032420239'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/09/how-wrong-would-proof-be.html' title='how wrong would a proof be'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-5962256671935513473</id><published>2008-09-16T17:46:00.000-07:00</published><updated>2008-09-16T19:01:10.720-07:00</updated><title type='text'>working on practices</title><content type='html'>By reading the textbook, the simple induction and complete induction seem not that confusing. To make sure that i understand the definition and examples, i redid the proof  in lecture and in the textbook. It's really important to find the right base case: is this case the very fundamental of the problem? do we need more base cases?&lt;br /&gt;The scratch work helps a lot because it's always convinent to make changes when i look backwards in the problem. All of the mathematical problems we've encountered in this course are solvable. The key is always to know what kind of strategy to use corresponding to the problem and follow it step by step.&lt;br /&gt;For example, we want to find out the possible unit digit that 3^n can have by using simple induction. The method is specified as simple induction. Then we just need to figure out the base case and the induction step. It's easy to find the P(0).  Then we have to determine P(n) and let it imply to P(n+1). There are different predicates in different questions. We must make sure we understand how does P(n) work here so that it leads exactly to P(n+1).  It's really helpful to correspond our assumption to its inductive case and understand the property. When transforming 3^(n+1)  into 3*3^n, slight change is made but huge differnce occurs. We now can see the answers explicitly because 3^n had been extracted.  This means we have proved our inductive case correctly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-5962256671935513473?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/5962256671935513473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=5962256671935513473' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/5962256671935513473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/5962256671935513473'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/09/working-on-practices.html' title='working on practices'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4820154385615627530.post-593993017855515788</id><published>2008-09-15T16:57:00.000-07:00</published><updated>2008-09-15T17:32:05.075-07:00</updated><title type='text'>Week 1 in CSC236</title><content type='html'>Since i took CSC165 in the summer, this is my first time to use SLOG.&lt;br /&gt;After reading the SLOG handout, i kinda understand what is it now. Compared with the bulletin board, SLOG is a better platform to post one's opinions, with more details and informations.&lt;br /&gt;It's an exciting thing that we can record what we've learned and what we've doubted. By viewing others' blog we can try to explore a different way to think the same problem. That's a good thing.&lt;br /&gt;&lt;br /&gt;The materials in the first week were not too much and not that confusing. So far we took a review about the simple induction and strong induction by dealing with some mathematical statements. They seem quite familiar, but the problems are always tricky.&lt;br /&gt;The proof of recursive program and program correctness might get harder in the future. For now, i will try my best to conquer any difficulties in the most basic part.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4820154385615627530-593993017855515788?l=nadavidson.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nadavidson.blogspot.com/feeds/593993017855515788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4820154385615627530&amp;postID=593993017855515788' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/593993017855515788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4820154385615627530/posts/default/593993017855515788'/><link rel='alternate' type='text/html' href='http://nadavidson.blogspot.com/2008/09/week-1-in-csc236.html' title='Week 1 in CSC236'/><author><name>DavidsoNisDifferentiable</name><uri>http://www.blogger.com/profile/04003470639906407247</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
