Friday 26 April 2013

Set up Java Development Environment for CZT (Community Z Tool) On Windows

Set up Java Development Environment for CZT (Community Z Tool) On Windows

Windows

Install JDK-1.7.0

  1. Install Directory
    • c:\Program Files\Java\jdk1.7.0_03
    • c:\Program Files\Java\jre7
  2. Set environment variables
    • Path=c:\Program Files\Java\jdk1.7.0_03\bin\;c:\Program Files\Java\jre7\bin\;
    • JAVA_HOME=c:\Program Files\Java\jre7\

Install maven-3.0.5 (>= 3.0.4)

  1. Download maven for Windows from http://maven.apache.org/download.cgi
  2. Unpack the tar package under d:\programs
  3. Add maven bin to environment variable PATH
    • PATH=d:\randall\Programs\apache-maven-3.0.5\bin\

Git clone czt code

    git clone git://git.code.sf.net/p/czt/code czt_code

Build CZT

  • Execute buildall.bat

Build Error

  1. Compilation Error #1
    ------- Error Log ------
    [INFO] -------------------------------------------------------------  
    [ERROR] COMPILATION ERROR :  
    [INFO] -------------------------------------------------------------  
    [ERROR] Unable to locate the Javac Compiler in:  
    c:\Program Files\Java\jre7\..\lib\tools.jar  
    Please ensure you are using JDK 1.4 or above and  
    not a JRE (the com.sun.tools.javac.Main class is required).  
    In most cases you can change the location of your Java  
    installation by setting the JAVA_HOME environment variable.  
    [INFO] 1 error  
    [INFO] -------------------------------------------------------------
    
    Solution: change JAVA_HOME to c:\Program Files\Java\jdk1.7.0_03\
  2. Build failed
    Line breaks (Windows only)
    On Windows, CZT expects Windows-style line breaks (CR+LF). The conversion is usually set by default (e.g. using msysgit) and nothing else is necessary. If, however, you encounter build problems with some CZT modules, try forcing the Windows line breaks using the following Git command in your repository:
    git config core.autocrlf true
    
    Then reset your Git repository to checkout correct line breaks:
    git rm --cached -r .
    git reset --hard
    
  3. Build Error

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 7:23.874s
    [INFO] Finished at: Tue Apr 23 10:45:24 BST 2013
    [INFO] Final Memory: 291M/784M
    [INFO] ------------------------------------------------------------------------
    [INFO] Scanning for projects...
    [WARNING] Error initializing: org.eclipse.tycho.p2.resolver.P2TargetPlatformReso lver@646d5273
    java.lang.RuntimeException: java.lang.IllegalStateException: Service is not regi
    stered class='interface org.eclipse.tycho.core.facade.ProxyServiceFacade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:301)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:275)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.p2.resolver.P2TargetPlatformResolver.initialize(P2T
    argetPlatformResolver.java:433)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.initializ
    e(PlexusLifecycleManager.java:338)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.manageLif
    ecycle(PlexusLifecycleManager.java:296)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.onProvisi
    on(PlexusLifecycleManager.java:148)
            at com.google.inject.internal.ProvisionListenerStackCallback$Provision.p
    rovision(ProvisionListenerStackCallback.java:108)
            at com.google.inject.internal.ProvisionListenerStackCallback.provision(P
    rovisionListenerStackCallback.java:55)
            at com.google.inject.internal.ProviderInternalFactory.circularGet(Provid
    erInternalFactory.java:68)
            at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(
    InternalFactoryToInitializableAdapter.java:45)
            at com.google.inject.internal.InjectorImpl$3$1.call(InjectorImpl.java:96
    5)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.ja
    va:1011)
            at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:961)
            at com.google.inject.Scopes$1$1.get(Scopes.java:59)
            at org.sonatype.guice.bean.locators.LazyBeanEntry.getValue(LazyBeanEntry
    .java:83)
            at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexus
    Bean.java:49)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:253)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:245)
            at org.eclipse.tycho.core.resolver.DefaultTargetPlatformResolverFactory.
    lookupPlatformResolver(DefaultTargetPlatformResolverFactory.java:74)
            at org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.setupP
    roject(DefaultTychoDependencyResolver.java:86)
            at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProj
    ectsRead(TychoMavenLifecycleParticipant.java:77)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:274)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:290)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:230)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:409)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    352)
    Caused by: java.lang.IllegalStateException: Service is not registered class='int
    erface org.eclipse.tycho.core.facade.ProxyServiceFacade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:291)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.osgi.configuration.OSGiProxyConfigurator.afterFrame
    workStarted(OSGiProxyConfigurator.java:30)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.doS
    tart(DefaultEquinoxEmbedder.java:180)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.sta
    rt(DefaultEquinoxEmbedder.java:67)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:299)
            ... 34 more
    [ERROR] Internal error: java.lang.RuntimeException: Could not instantiate requir
    ed component: com.google.inject.ProvisionException: Guice provision errors:
    [ERROR]
    [ERROR] 1) Error notifying ProvisionListener org.sonatype.guice.plexus.lifecycle
    s.PlexusLifecycleManager of org.eclipse.tycho.core.TargetPlatformResolver annota
    ted with @com.google.inject.name.Named(value=p2).
    [ERROR] Reason: java.lang.RuntimeException: java.lang.IllegalStateException: Ser
    vice is not registered class='interface org.eclipse.tycho.core.facade.ProxyServi
    ceFacade'
    [ERROR] while locating org.eclipse.tycho.core.TargetPlatformResolver annotated w
    ith @com.google.inject.name.Named(value=p2)
    [ERROR]
    [ERROR] 1 error
    [ERROR] role: org.eclipse.tycho.core.TargetPlatformResolver
    [ERROR] roleHint: p2
    [ERROR] -> [Help 1]
    org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeExcept
    ion: Could not instantiate required component
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:168)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:290)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:230)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:409)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    352)
    Caused by: java.lang.RuntimeException: Could not instantiate required component
            at org.eclipse.tycho.core.resolver.DefaultTargetPlatformResolverFactory.
    lookupPlatformResolver(DefaultTargetPlatformResolverFactory.java:76)
            at org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.setupP
    roject(DefaultTychoDependencyResolver.java:86)
            at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProj
    ectsRead(TychoMavenLifecycleParticipant.java:77)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:274)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
            ... 11 more
    Caused by: org.codehaus.plexus.component.repository.exception.ComponentLookupExc
    eption: com.google.inject.ProvisionException: Guice provision errors:

    1) Error notifying ProvisionListener org.sonatype.guice.plexus.lifecycles.Plexus
    LifecycleManager of org.eclipse.tycho.core.TargetPlatformResolver annotated with
     @com.google.inject.name.Named(value=p2).
     Reason: java.lang.RuntimeException: java.lang.IllegalStateException: Service is
     not registered class='interface org.eclipse.tycho.core.facade.ProxyServiceFacad
    e'
      while locating org.eclipse.tycho.core.TargetPlatformResolver annotated with @c
    om.google.inject.name.Named(value=p2)

    1 error
          role: org.eclipse.tycho.core.TargetPlatformResolver
      roleHint: p2
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:257)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:245)
            at org.eclipse.tycho.core.resolver.DefaultTargetPlatformResolverFactory.
    lookupPlatformResolver(DefaultTargetPlatformResolverFactory.java:74)
            ... 15 more
    Caused by: com.google.inject.ProvisionException: Guice provision errors:

    1) Error notifying ProvisionListener org.sonatype.guice.plexus.lifecycles.Plexus
    LifecycleManager of org.eclipse.tycho.core.TargetPlatformResolver annotated with
     @com.google.inject.name.Named(value=p2).
     Reason: java.lang.RuntimeException: java.lang.IllegalStateException: Service is
     not registered class='interface org.eclipse.tycho.core.facade.ProxyServiceFacad
    e'
      while locating org.eclipse.tycho.core.TargetPlatformResolver annotated with @c
    om.google.inject.name.Named(value=p2)

    1 error
            at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:974)
            at com.google.inject.Scopes$1$1.get(Scopes.java:59)
            at org.sonatype.guice.bean.locators.LazyBeanEntry.getValue(LazyBeanEntry
    .java:83)
            at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexus
    Bean.java:49)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:253)
            ... 17 more
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Service
    is not registered class='interface org.eclipse.tycho.core.facade.ProxyServiceFac
    ade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:301)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:275)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.p2.resolver.P2TargetPlatformResolver.initialize(P2T
    argetPlatformResolver.java:433)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.initializ
    e(PlexusLifecycleManager.java:338)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.manageLif
    ecycle(PlexusLifecycleManager.java:296)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.onProvisi
    on(PlexusLifecycleManager.java:148)
            at com.google.inject.internal.ProvisionListenerStackCallback$Provision.p
    rovision(ProvisionListenerStackCallback.java:108)
            at com.google.inject.internal.ProvisionListenerStackCallback.provision(P
    rovisionListenerStackCallback.java:55)
            at com.google.inject.internal.ProviderInternalFactory.circularGet(Provid
    erInternalFactory.java:68)
            at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(
    InternalFactoryToInitializableAdapter.java:45)
            at com.google.inject.internal.InjectorImpl$3$1.call(InjectorImpl.java:96
    5)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.ja
    va:1011)
            at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:961)
            ... 21 more
    Caused by: java.lang.IllegalStateException: Service is not registered class='int
    erface org.eclipse.tycho.core.facade.ProxyServiceFacade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:291)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.osgi.configuration.OSGiProxyConfigurator.afterFrame
    workStarted(OSGiProxyConfigurator.java:30)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.doS
    tart(DefaultEquinoxEmbedder.java:180)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.sta
    rt(DefaultEquinoxEmbedder.java:67)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:299)
            ... 34 more
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
    ch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorE
    xception
    Press any key to continue . . .


Solution: ignore this error at that moment since all builds are successful

Import project into Eclipse

Reference: http://czt.sourceforge.net/dev/eclipse/index.html
  1. Download Eclipse Classic 4.2.0
  2. Install m2e connectors
    • install maven-jflex-plugin and xml-maven-plugin from http://czt.sourceforge.net/dev/eclipse/updates/
  3. Install m2e release for Eclipse
    • from http://download.eclipse.org/technology/m2e/releases
  4. Select the m2e repository cache directory. m2e has caches lucene index in two places
    • Per-workspace indexes are stored under .metadata/.plugins/org.eclipse.m2e.core/nexus
    • and there is also global cache in ~/.m2/repository/.cache/m2e/${m2e.version}
  5. The default cache directory on Windows in the department is the home directory h:\.WindowsProfile\.m2\. However, this folder has very strict limitation of disk volumn. Thus the cache directory has to be changed.
    • Open Eclipse preference, click Maven/Installation. Add external Maven d:\randall\Programs\apache-maven-3.0.5, and unselect the Embedded 3.0.4
    • The settings.xml file will be in d:\randall\Programs\apache-maven-3.0.5\conf. Open settings.xml, and change <localRepository> to <localRepository>d:\.m2\repository</localRepository>
    • Save the changes in Eclipse
  6. Open a command prompt window and rebuild the czt-code again
    • buildall.bat
    • Now all cached files are saved in the specified directory, and can build successfully
    • Thus the previous Build Error with long error log is due to the limited size of cache repository
  7. After the build, open Eclipse and import the czt projects into the Eclipse by File > Import > Existing Maven Projects
    • Select the czt-code root directory and import all necessary projects
    • After import, workspace will build automatically
    • Set CZT target platform
      • Open target definition file at /net.sourceforge.czt.eclipse.target/net.sourceforge.czt.eclipse.target.target within Eclipse and clock Set as Target Platform
    • If necessary, right click the project and Maven > Update Projects to update Maven projects
    • If necessary, clean all projects and build again

Wednesday 24 April 2013

Setup of a notes writing environment (markdown + Voom + markdown2.py) on Windows

This is a note to write down how to set up a working environment for notes writing efficiently on Windows

Environment Requirement

  • VIM editor
  • markdown syntax
  • Voom outline
  • markdown2.py to convert from mkd to html for easily publishing on blog

Install markdown syntax

Install Voom

Install python27 on Windows

  • Install python27 to C:\python27
  • Add this directory to the PATH environment variable

Install distribute package to have the packages installation capability (such as pip, easy_install )

Install markdown2

markdown2.py is used to convert the mkd file to html file - Open a command prompt window, and type
easy_install markdown2 - Then markdown2.py is installed in the c:/python27/scripts

Test it

  • Create a mkd file and write a sample markdown note by VIM
  • You should see the syntax works for this file. If not, add "syntax on" vimrc file
  • Type command ":Voom markdown" within VIM, and another outline window is opened
  • Quit Vim and open a command prompt window, and type
    markdown2.py hello.mkd
  • Error
    close failed in file object destructor: sys.excepthook is missing lost sys.stderr
  • Solution: use "python c:\python27\Scripts\markdown2.py hello.mkd > hello.html" instead of "markdown2.py hello.mkd > hello.html"

Saturday 20 April 2013

Concurrency, Parallel, Synchronization and Reactive. How to distinguish them?

Parallel and Concurrent

Parallel

Parallel computing is a form of computation in which many calculations are carried out simultaneously,[1] operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently ("in parallel"). (from Wikipedia)

Key points of Parallel:

  • Usually for time saving and speeding up the calculation
  • Decompose the big problem into smaller ones
  • The smaller ones run in different processors at the same time
  • Reference: https://computing.llnl.gov/tutorials/parallel_comp/#Whatis

Three-level Parallelisms:

  • Bit-level (4-bit, 8-bit, 16-bit, 32-bit and 64-bit microprocessors)
  • Instruction-level (pipelining (CISC, RISC), superscalar)
  • Task-level (multi-processors, tasks running on different processors simultaneously)

Task Parallelism and Data Parallelism:

  • Task Parallelism (processes, or threads of execution)

"entirely different calculations can be performed on either the same or different sets of data"

  • Data Parallelism

"the same calculation is performed on the same or different sets of data"

Concurrent

Concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other. (from Wikipedia)

a program is typically factored into multiple threads of control with distinct responsibilities and purposes, which may run simultaneously or take turns. This is often about dealing with concurrency and nondeterminism in the world, or about reducing latency.

Key points of concurrent programming:

  • It may run simultaneously on different processors or multithreads on single processor
  • the number of possible execution paths in the system can be extremely large and the resulting outcome can be nondeterministic
  • Concurrent access of shared resources with nondeterminism may lead to issues such as deadlock and starvation
  • What differentiates concurrent system from sequential system most is the fact that their subprocesses communicate with each other

The difference between parallel and concurrency programming

Parallel and concurrent are synonyms in most cases, but in programming, it's not the case. They are totally different concepts.

Example (Parallel and Concurrent programming in Haskell)

A parallel program

  • utilize the more powerful and computational hardware (e.g. multiple processors or cores) to make it quickly and achieve more efficiency
  • A big task is splitted into several smaller tasks, and each of them is executed in different processor or core at the same time (in parallel). Thus the whole delivery time will be shorter than sequentially performed task

Concurrent program

  • concurrency is a progarm-structuring technique in which there are multiple threads of control.
  • From the user level, threads are executed "at the same time" because their effects interleaved. But whether they actually execute at the same time or not is not a design problem, and just an implementation detail.
  • concurrency can be implemented on one single process with multithreads or on multiple processors
  • concurrent programming also concerns program-structuring to interact with multiple independent external agents (for example, one thread responsible for the user, one for database server, and another for external clients)

Distributed, Reactive and Concurrent System

Distributed System

A distributed system consists of multiple computers that communicate through a computer network, and the computers interact with each other in order to achieve a common goal

For example,

  • a lithography has several subsystems, and each subsystem runs on its individual embedded system. They are working with central workstation together to achieve the function of the lithography

Reactive System

A system that responds or reacts to external events

For example,

  • a motor control driver: it gets the input from the caller or user, then move the motor forward or backward to specified position, and stop
  • interactive system is a kind of typical reactive system, which reacts to its user and operators, and provides the feedback

Concurrent System

several computations are running simultaneously and may interact with each other while they are executing.

Architectural Aspect

  • Each computer in distributed system has the individual processor and memory
  • A parallel system will have the tasks on different processors with shared memory, such as SMP or AMP system
  • A concurrent system may have the multiple threads on a single processor or multiple processors with shared memory

Synchronization

Synchronization refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, in order to reach an agreement or commit to a certain sequence of action. Data synchronization refers to the idea of keeping multiple copies of a dataset in coherence with one another, or to maintain data integrity. (from Wikipedia)

CSP (Communicating Sequential Processes)

is a formal language for modelling and reasoning the patterns of interaction in concurrent system

  • interaction by synchronous message passing

Parallel

  • Synchronous Parallel (P || Q)
  • Alphabetised Parallel (P [ Ap || Aq ] Q)
  • Generalised Parallel (P [ | a | ] Q, such as P [| {| in, out |} |] Q)
  • Interleaving |||

Friday 12 April 2013

Use VIM to make notes [markdown]

Sometimes you will face a situation that you want to write down some notes, but you can not have a suitable tool on handle. For example, you only have VIM to edit and don't have the "Notes" like Evernote, OneNote etc. So how can you make writing down a note easy? Here's one solution: VIM + Voom + markdown syntax highlight

Source file of this post is reference to markdown.mkd, One screen show:

 

Markdown

Markdown is intended to be as easy-to-read and easy-to-write as is feasible. Markdown’s syntax is intended for one purpose: to be used as a format for writing for the web.
Reference: <http://daringfireball.net/projects/markdown/syntax>

Syntax

Header

Two types of header: Setext and atx
  • Setext
    = for 1st level
    • for 2nd level
  • atx
    # for H1
    ## for H2
    ### for H3
    #### for H4
    ##### for H5
    ###### for H6

Block Quotes

  • Use the > for each line or only > for each paragraph
Quote Block or
  • can be nested
Quote
Block

Bullets

  • *, - and + all do the same

Numbering

  1. 1 Use the number
  2. 2
  3. 3

Codeblocks

Indent with 4 spaces or one tab. C Example: for(i = 0; i \< 5; i++) { printf("%d\n", i); }

Horizontal Rules

  • three or more (*, -, or _)



Links

Emphasis

Text wrapped in * and _
  • Markdown is very helpful to make notes
  • Markdown is very helpful to make notes

Code

Wrap the code with backtick quotes (`) * printf() function will print on the stardard output 0

Special characters

The special characters (\, `, *, _, -, {}, ], (), #, +, ., !) can be inputted by a prefix backslash \

Markdown syntax highlight

Installation

  • It's very easy to install it. Just download the latest the markdown-.vba.gz, then
    $ vim makedown-.vba.gz +":so %"
    Reference: http://www.vim.org/scripts/script.php?script_id=2882
  • Make sure the syntax highlight is on and can be set in .vimrc syntax on filetype on

Usage

Just create a new file with extension 'mkd', for example $ vim hello.mkd

Voom - Two-pane outliner

Installation

Usage

  • Load the markdown format file, such as hello.mkd
  • Open Voom markdown markup formats within VIM : Voom markdown

Markups supported

Voom can support a variety of markups - fmr, fmr1, fmr2 -- start fold markers with levels (variations of the default mode);
- wiki -- MediaWiki, headlines are surrounded by '=';
- vimwiki -- vimwiki plugin (vimscript #2226);
- viki -- Viki/Deplate plugin (vimscript #861);
- org -- Emacs Org-mode;
- rest -- reStructuredText section titles;
- markdown -- Markdown headers, both Setext-style and Atx-style;
- hashes -- #, ##, ###, etc. (Atx-style headers, a subset of Markdown format);
- txt2tags -- txt2tags titles and numbered titles;
- asciidoc -- AsciiDoc document and section titles, both styles;
- latex -- LaTeX sectioning and some other commands;
- taskpaper -- TaskPaper (vimscript #2027);
- thevimoutliner -- The Vim Outliner plugin (vimscript #517);
- vimoutliner -- VimOutliner plugin (vimscript #3515);
- cwiki -- vimscript #2176;
- html -- HTML heading tags, single line only;
- python -- Python code browser, blocks between 'class' and 'def' are also nodes.

Convert to html

Installation of python-markdown

  • MAC OS: $ sudo easy_install Markdown

Command line

$ markdown_py -f hello.html hello.mkd
Notes: two spaces in the end of line means EOL

Friday 5 April 2013

Function and its Properties

A function is a relation between input X and output Y with the property that there is at most one element in Y corresponding to each element in X. For example, relation {(1, 2), (1, 3)} is not a function since 1 has two corresponding elements 2 and 3.
If \(f: X \to Y\), X is called the domain of function \(f\), and Y codomain or range

If \(A \subseteq X\), then \(f(A)\) is called the image of \(A\) under \(f\). Refer to the below diagram, the yellow area is image.

If \(B \subseteq Y\), then \(f^{-1}(B)\) is called the preimage of \(B\) under \(f\).

From Wikipedia

Identity function
$$id: X \to X \land \forall x: X \bullet id(x)=x$$

Injective function, or one-to-one function
$$\forall a,b:X \bullet f(a)=f(b) \implies a=b$$
For example,
  • identity function
  • inclusion function
  • \(f(x)=2x+1\)
  • \(f(x)=e^x\)

Inclusion function
$$\forall a:X, b:Y \bullet X \subset Y \implies f(a)=a$$

Surjective function (Onto)
$$\forall y:Y \bullet \exists x:X \bullet f(x)=y$$
From Wikipedia

For example,
  • identity function
  • \(f(x)=2x+1\)
  • \(f: \mathbb{R} \to \mathbb{R}, f(x)=e^x\) is not surjective since there is no x such that f(x) is negative
  • \(f: \mathbb{R} \to \mathbb{R}, f(x)=x^2\) is not surjective since there is no x such that f(x) is negative
  • \(f: \mathbb{R} \to \mathbb{R}^{nn}, f(x)=x^2\) is surjective since for each y there is a x that \(x^2=y\)
Partial Function
A function f from X to Y is partial if it doesn't map every element in X to Y. Formally,
$$\exists x:X \bullet f(x) \text{ is undefined}$$
For example,
  • \(f: \mathbb{N} \to \mathbb{N}\), and \(f(x)=\sqrt{x}\)

Total Function
Every element in X is defined.
$$\forall x:X \bullet \exists y:Y \bullet f(x)=y$$
For example,
  • \(f: \mathbb{N} \to \mathbb{N}\), f(x)=x

Monotonic
$$\forall x_1,x_2:X \bullet x_1 < x_2 \implies f(x_1) < f(x_2)$$

Idempotent
$$\overbrace{f(f(...f}^n(x))=f(x)$$

Associative
$$f(f(x,y), z) = f(x, f(y, z))$$

Distributive
$$f(g(x,y), z) = g(f(x, z), f(y, z))$$
f is distributive in g.
For example,
  • \(f(x, y) = x \times y, g(x,y)=x+y \), \(x \times (y+z)=(x \times y + x \times z)\)




Binary Relations and its Properties

Symmetric
$$\forall a, b \bullet a R b \implies b R a$$
where \(R\) is a relation. For example,
  • = relation on \(\mathbb{R}\)
  • is equal to
  • is married to 
  • {(1,2), (2,1)}
Antisymmetric
$$\forall a,b:X \bullet a R b \land b R a \implies a = b $$
For example,
  • \(\leq\)
  • \(\geq\)
  • \(\subseteq\)
  • {(1, 2), (2, 3), (1, 1)}
Asymmetric
$$\forall a,b:X \bullet a R b \implies \lnot(bRa) $$
For example,
  • {(1,2), (3,4)}
Reflexive
$$\forall x:X \bullet xRx$$
For example,
  • =
  • \(\leq\)
Irreflexive (strict)
$$\forall x:X \bullet \lnot(xRx)$$
For example,
  • \(>\), \(<\)

Coreflexive (a subset of Identity Relation)
$$\forall x,y:X \bullet x R y \implies x= y)$$
For example,
  •  equal to and odd, such as {(1,1), (3,3)}
Identity
$$\{(x,x) | x \in X\}$$

Transitive
$$\forall x,y,z:X \bullet x R y \land y R z \implies x R z$$
For example,
  • \(<\), =, \(\leq\)



Number Sets in Latex

Include the package amsfonts or amssymb
$\usepackage{amsfont}$ or $\usepackage{amssymb}$

  •     Prime Numbers \( \mathbb{P} \) ($\mathbb{P}$): No positive divisors other than 1 and itself: 1, 3, 5, 7, 11, ...
  •     Natural Numbers \( \mathbb{N} \) ($\mathbb{N}$): 0, 1, 2, 3
  •     Integers \(\mathbb{Z}\) ($\mathbb{Z}$): ..., -3, -2, -1, 0, 1, 2, 3
  •     Irrational Numbers \(\mathbb{I}\) ($\mathbb{I}$): \(\pi\), 1.3333...
  •     Rational Numbers \(\mathbb{Q}\) ($\mathbb{Q}$): any real number can be expressed by ration of two integers, such as 0.5 (1/2), 1.6 (8/5)
  •     Real Numbers \(\mathbb{R}\) ($\mathbb{R}$):
  •     Complex Numbers \(\mathbb{C}\) ($\mathbb{C}$)

Latex enabled in Google Blogger

1. Mathjax
http://www.mathjax.org/

2. Getting Started with Mathjax
http://docs.mathjax.org/en/latest/start.html

3. Open your google blogger and click "Design" on the top right of your home page
Design
4. Click "Edit Html" and paste the following scripts after the first <head> tag
<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

The default math delimiters are $ $...$ $ and \ [...\ ] for displayed mathematics, and \(...\) for in-line mathematics. Note in particular that the $...$ in-line delimiters are not used by default. If you want to use single-dollars for in-line math mode, you must enable that explicitly in your configuration:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>

5. Test in new post

Display Math:
  • $ $a^2+b^2=c^2$ $
$$a^2+b^2=c^2$$

  • \ [ a^2+b^2=c^2 \ ]
\[ a^2+b^2=c^2 \]

Inline Math:
  • \ ( a^2+b^2=c^2 \ )      \( a^2+b^2=c^2 \)





Axiom, Theorem, Lemma, Corollary, Proposition ... The differences!

 Axiom
Generally accepted and recognized as truth. It's self-evident without proof.  For example, A and B implies A

Theorem (http://en.wikipedia.org/wiki/Theorem)
a theorem is a statement that has been proven on the basis of previously established statements, such as other theorems, and previously accepted statements, such as axioms.

Theorem Example


Lemma
usually it's small and used to support the proof of the larger theorem. And no interests of itself.
Proof of Theorem with support of Lemma

The Lemma A.1 used to prove above Theorem
Corollary
follows a Theorem, and easily deduced from the Theorem with little or no proof. Secondary result of the theorem

Corollary Example





Proposition
a generic term for a theorem of no particular importance and a theorem is regarded as the important result