CompA - Complex Analyzer

Similar documents
EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

MiniMat: Matrix Language in OCaml LLVM

Computer Science Introductory Course MSc - Introduction to Java

A High Level Programming Language for Quantum Computing

COMS 6100 Class Notes

DARN: A Matrix Manipulation Language

Introduction to Programming (Java) 3/12

Google Go illustrated on the basis of Fibonacci numbers

GRIDLang. Move-Driven Game Programming Language Final Report. May 10, 2017

Introduction to functions

CS Exam 1 Study Guide and Practice Exam

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

ITI Introduction to Computing II

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Functional Programming with F# Overview and Basic Concepts

QLang: Qubit Language

ITI Introduction to Computing II

Vector Spaces. 1 Theory. 2 Matlab. Rules and Operations

1. Write a program to calculate distance traveled by light

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

Python. chrysn

Octave. Tutorial. Daniel Lamprecht. March 26, Graz University of Technology. Slides based on previous work by Ingo Holzmann

CS 221 Lecture 9. Tuesday, 1 November 2011

Copyright 2018 Dan Dill 1

Outline. policies for the first part. with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014

Matlab Instruction Primer; Chem 691, Spring 2016

Recurrence Relations and Recursion: MATH 180

Information Flow Inference for ML

Chapter 5. Finite Automata

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

The quantum state as a vector

Reasoning About Imperative Programs. COS 441 Slides 10b

Clock Analysis of X10 Programs

Predictive parsing as a specific subclass of recursive descent parsing complexity comparisons with general parsing

Programming Language Concepts, CS2104 Lecture 3

Contents. 6.1 Conditional statements 6.2 Iteration 6.3 Procedures and flow control

(a) Definition of TMs. First Problem of URMs

2 Getting Started with Numerical Computations in Python

Lab 2: Static Response, Cantilevered Beam

Chapter 4 Number Representations

Math 56 Homework 1 Michael Downs. ne n 10 + ne n (1)

Meta-programming & you

Computing with Semigroup Congruences. Michael Torpey

Matrix-Vector Operations

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

CS 163/164 - Exam 1 Study Guide and Practice Exam

Chem 467 Supplement to Lecture 19 Hydrogen Atom, Atomic Orbitals

Decision Procedures. Jochen Hoenicke. Software Engineering Albert-Ludwigs-University Freiburg. Winter Term 2016/17

Additive Numbering Systems and Numbers of Different Bases MAT 142 RSCC Scott Surgent

Introduction. How to use this book. Linear algebra. Mathematica. Mathematica cells

Lecture Notes on Inductive Definitions

CS 314 Principles of Programming Languages

Introduction to lambda calculus Part 2

Automatic Reverse-Mode Differentiation: Lecture Notes

AFEM USER GUIDE R. VERFÜRTH

Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3

pixelman Final Report Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

Design of Embedded Systems: Models, Validation and Synthesis (EE 249) Lecture 9

Applied C Fri

ECE 102 Engineering Computation

CSE 311: Foundations of Computing. Lecture 26: Cardinality

CA Compiler Construction

Manual of Time Scales Toolbox for MATLAB

Constructors - Cont. must be distinguished by the number or type of their arguments.

MATLAB Ordinary Differential Equation (ODE) solver for a simple example 1. Introduction

LAB 1: MATLAB - Introduction to Programming. Objective:

Matrix-Vector Operations

Functional Big-step Semantics

Lecture Notes on Inductive Definitions

Software Engineering

Linear Algebra and TI 89

Simulation of Gene Regulatory Networks

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.

Basic Principles of Algebra

Plan for Today and Beginning Next week (Lexical Analysis)

CHM Physical Chemistry II Chapter 9 - Supplementary Material. 1. Constuction of orbitals from the spherical harmonics

Apache Quarks for Developers April 13, 2016

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Relation of Pure Minimum Cost Flow Model to Linear Programming

QLang: Qubit Language (Final Report) Christopher Campbell Clément Canonne Sankalpa Khadka Winnie Narang Jonathan Wong

Relational Algebra and Calculus

Introduction to ANTLR (ANother Tool for Language Recognition)

Introduction to Python

On-the-Fly Model Checking for Extended Action-Based Probabilistic Operators

Pattern Matching. a b a c a a b. a b a c a b. a b a c a b. Pattern Matching 1

4th year Project demo presentation

BCMB/CHEM 8190 Lab Exercise Using Maple for NMR Data Processing and Pulse Sequence Design March 2012

Operational Semantics

R: A Quick Reference

A An Overview of Complexity Theory for the Algorithm Designer

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

MAT1332 Assignment #5 solutions

(1.1) In particular, ψ( q 1, m 1 ; ; q N, m N ) 2 is the probability to find the first particle

Hidden Markov Methods. Algorithms and Implementation

Jointly Learning Python Programming and Analytic Geometry

1 Java Night Countdown (30%)

CMSC 132, Object-Oriented Programming II Summer Lecture 11:

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

Transcription:

CompA - Complex Analyzer Xiping Liu(xl2639), Jianshuo Qiu(jq2253), Tianwu Wang(tw2576), Yingshuang Zheng(yz3083), Zhanpeng Su(zs2329) Septembee 25, 2017 1 Introduction The motivation for writing this language is that complex numbers are an indispensable part of mathematics and they are widely used to solve many real world engineering and physics problems. Moreover, it also possesses computational rules and properties that are consistent with real numbers. Hence, computer s great power in computing real numbers can also be used to solve complex number related problems. In most cases, computations involving complex numbers tend to require more time and techniques. Thus, a language that can support complex computations will be handy. Furthermore, it also supports matrix operations which can work with complex numbers to solve problems in areas like quantum mechanics. Our language, CompA stands for Complex Analyzer and we plan to compile it to LLVM. The following proposal details some of the specifics of our language. 2 Language Overview Our language is designed to conveniently and concisely support complicated scientific and engineering projects that are built upon functions and primitive operations in Linear Algebra and Complex Analysis. The syntax of our language resembles C language (without allowing pointers), except that the mathematical representations are absorbed from MATLAB. 1

2.1 Datatypes in the Language The 6 data types in the above table are all the built-in data types in our language. Our language is statically-typed. Namely, you must declare the data types of your variables before you use them. According to the examples in the above table, declaring variables in our language is fairly simple. Declaration of integer, float, boolean, and string is similar to mainstream programming languages such as C and Java. The specification of declaring complex number and matrix is shown as follows. We use a 2-tuple surrounded by parentheses to declare complex number, where the first tuple is real part, the second tuple is imaginary part. Both parts can be either integer or float. For matrix, we include all entries in square brackets. Inside the square brackets, rows are separated by semicolon, while entries of the same row are separated by comma. Integers, float numbers, and complex numbers can be put into the same matrix. There are also some built-in constants in our language. 2

2.2 Operators Assume all numbers written in the form z = a + ib which we call it regular form. For all real numbers, b is simply 0. Our language also supports matrix operations: 3

2.3 Control Flow a. if statement Handles conditional statements i f (< condition >) { <statements> e l s e i f (< condition >) { <statements> e l s e { <statements> b. for loop Handles loop operations f o r ( i n t i = 0 ; i < 2 0 ; i++) { <statements> c. while loop Another way to handle loop operations i n t i = 0 ; while ( i < 10) { <statements >; i ++; 4

d. break Terminate a loop(usually with a condition), and the program resumes at the next statement following the loop i n t i = 0 ; while ( i < 10) { <statements >; i ++; i f ( i > 6) { break ; e. continue When a continue statement is encountered inside a loop, control jumps to the beginning of the loop for next iteration, skipping the execution of statements inside the body of loop for the current iteration f o r ( i = 0 ; i < 1 0 ; i++) { i f ( i == 6) { continue ; // when i = 6, <statements> w i l l be skipped and the c o n t r o l w i l l return to the loop with i = 7 <statements >; 2.4 Built-in function 5

6

2.5 User Defined Function Users can create their own functions by using primitive data types and built-in functions. The syntax is C-like. Example1 i n t g e t z e r o ( ) { r eturn 0 ; Example2 bool age compare ( i n t age1, i n t age2 ){ i f ( age1 >= age2 ){ r eturn true ; e l s e { r eturn f a l s e ; Example3 mx add matrix (mx matrix1, mx matrix2 ){ r eturn matrix1 + matrix2 ; Example4 void printtrace (mx m){ i n t t r a c e = t r (m) ; p r i n t ( t r a c e ) ; 3 A Sample Program Below is an example program in our language CompA, which solves a problem in Quantum Mechanics. It uses a user defined function spinxexpectation(int t) to calculate the expectation value of the spin angular momentum in x direction of a wave function at time t. In the main() function, spinxexpectation(int t) is calculated at t = 0 and 5 and the results are printed out to the console window using the built-in function print(). / s t a r t o f the program / / g l o b a l v a r i a b l e s / s t a t i c f l o a t h bar = 1.05457 e 34; s t a t i c f l o a t B 0 = 1e 5; s t a t i c f l o a t alpha = PI / 6 ; s t a t i c f l o a t gamma = 1.6e 19/9.11 e 31 7

/ main f u n c t o i n / i n t main (mx arg ) { p r i n t ( Spin angular momentum in x d i r e c t i o n at time t = 0 ) ; mx expectationvalue = spinxexpectation ( 0 ) ; p r i n t ( expectationvalue ) ; p r i n t ( Spin angular momentum in x d i r e c t i o n at time t = 5 ) ; expectationvalue = spinxexpectation ( 5 ) ; p r i n t ( expectationvalue ) ; r eturn 0 ; / user d e f i n e d f u n c t i o n / mx spinxexpectation ( f l o a t t ) { mx wavefunction = [ cos ( alpha /2) exp ( ( 0, 1 ) gamma B 0 t / 2 ) ; s i n ( alpha /2) exp ( (0,1) gamma B 0 t / 2 ) ] ; / complex matrix d e c l a r a t i o n / mx S x = [ 0, 1 ; 1, 0 ] ; r eturn tp ( conj ( wavefunction ) ) S x wavefunction ; / complex matrix m u l t i p l i c a t i o n / / end o f the program / 8