Specification of Chemical Formulæ in XL with Operator Overloading

Similar documents
Compiling Techniques

Computer Science Introductory Course MSc - Introduction to Java

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Compiling Techniques

ITI Introduction to Computing II

ITI Introduction to Computing II

A brief introduction to Logic. (slides from

Introduction to Programming (Java) 3/12

Analysis and Design of Sequential Circuits: Examples

Sharing Objects. Pieter van den Hombergh. Fontys Hogeschool voor Techniek en Logistiek. February 15, 2017

Logic as a Tool Chapter 1: Understanding Propositional Logic 1.1 Propositions and logical connectives. Truth tables and tautologies

One Year Later. Iliano Cervesato. ITT Industries, NRL Washington, DC. MSR 3.0:

THe use of mixed data-type expressions, although not

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


6.001 Recitation 22: Streams

Enzyme Reactions. Lecture 13: Kinetics II Michaelis-Menten Kinetics. Margaret A. Daugherty Fall v = k 1 [A] E + S ES ES* EP E + P

Michaelis-Menten Kinetics. Lecture 13: Kinetics II. Enzyme Reactions. Margaret A. Daugherty. Fall Substrates bind to the enzyme s active site

Syntax Directed Transla1on

Introduction to Arti Intelligence

Binary Logic and Gates

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

Automatic Reverse-Mode Differentiation: Lecture Notes

An Introduction to Z3

A Logic Primer. Stavros Tripakis University of California, Berkeley. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 1 / 35

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

A Logic Primer. Stavros Tripakis University of California, Berkeley

Implementation of a simple dimensionality checking system in Ada 2012

1. Introduction to Chemical Kinetics

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

Chemical kinetics and catalysis

Modeling Biological Systems in Stochastic Concurrent Constraint Programming

Künstliche Intelligenz

Elementary Sorts 1 / 18

Knowledge representation DATA INFORMATION KNOWLEDGE WISDOM. Figure Relation ship between data, information knowledge and wisdom.

CSCI Compiler Construction

Bringing machine learning & compositional semantics together: central concepts

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

Chapter 5 Synchronous Sequential Logic

ELCT201: DIGITAL LOGIC DESIGN

Introduction to Computational Linguistics

ChemLab Project Proposal COMS W4115

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010

The TLA + proof system

Propositional Logic: Methods of Proof (Part II)

ICS141: Discrete Mathematics for Computer Science I

CS415 Compilers Syntax Analysis Top-down Parsing

Adders, subtractors comparators, multipliers and other ALU elements

Inf2D 06: Logical Agents: Knowledge Bases and the Wumpus World

Automata-based Verification - III

Lab: Conservation of Linear Momentum There is a quantity called linear momentum defined as the mass of an object times its velocity, i.e.

An Introduction to Modal Logic III

MiniMat: Matrix Language in OCaml LLVM

Axiomatic Semantics. Operational semantics. Good for. Not good for automatic reasoning about programs

Learning Goals of CS245 Logic and Computation

Algorithms for NLP. Language Modeling III. Taylor Berg-Kirkpatrick CMU Slides: Dan Klein UC Berkeley

n logical not (negation) n logical or (disjunction) n logical and (conjunction) n logical exclusive or n logical implication (conditional)

Lambda Calculus! Gunnar Gotshalks! LC-1

Logic. Introduction to Artificial Intelligence CS/ECE 348 Lecture 11 September 27, 2001

Introduction to Z3. Bow-Yaw Wang. December 19, Institute of Information Science Academia Sinica, Taiwan

Module 6 : Reaction Kinetics and Dynamics Lecture 28 : Elementary Reactions and Reaction Mechanisms

Notes. Corneliu Popeea. May 3, 2013

In this chapter, we explore the parsing problem, which encompasses several questions, including:

Logic and Computer Design Fundamentals. Chapter 8 Sequencing and Control

d(ν) = max{n N : ν dmn p n } N. p d(ν) (ν) = ρ.

First-Order Theorem Proving and Vampire. Laura Kovács (Chalmers University of Technology) Andrei Voronkov (The University of Manchester)

Reasoning About Imperative Programs. COS 441 Slides 10b

A First Course on Kinetics and Reaction Engineering. Class 9 on Unit 9

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Artificial Intelligence Chapter 7: Logical Agents

CS560 Knowledge Discovery and Management. CS560 - Lecture 3 1

Sharpening the empirical claims of generative syntax through formalization

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

Solution suggestions for examination of Logic, Algorithms and Data Structures,

Compiling Techniques

Computational Study of System Dynamics (Chemical Kinetics)

Principles of Program Analysis: Control Flow Analysis

Data Converter Fundamentals

HYBRIDIZATION THEORY

UNIT-I: Propositional Logic

Verifying Properties of Parallel Programs: An Axiomatic Approach

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Functional Programming with F# Overview and Basic Concepts

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts

CONTEXT FREE GRAMMAR AND

RELATION OF WHITEHEAD AND RUSSELL'S THEORY OF DEDUCTION TO THE BOOLEAN LOGIC OF PROPOSITIONS*

Satisfiability Modulo Theories (SMT)

The Logical Meeting Point of Multiset Rewriting and Process Algebra

CSCI 2670 Introduction to Theory of Computing

Syntax Analysis, VII The Canonical LR(1) Table Construction. Comp 412

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Lecture 11: Enzyme Kinetics, Part I

Combinational Logic. Lan-Da Van ( 范倫達 ), Ph. D. Department of Computer Science National Chiao Tung University Taiwan, R.O.C.

Measuring Goodness of an Algorithm. Asymptotic Analysis of Algorithms. Measuring Efficiency of an Algorithm. Algorithm and Data Structure

Prioritized Garbage Collection Using the Garbage Collector to Support Caching

Denotational semantics

CSE 20. Lecture 4: Introduction to Boolean algebra. CSE 20: Lecture4

CMPT-825 Natural Language Processing. Why are parsing algorithms important?

Transcription:

Formulæ in with Specification of Formulæ in with University of Göttingen 28 February 2012

Formulæ in with Outline 1 2 3 4 5

Formulæ in with ultimately we want to specify reactions like 2H 2 + O 2 k f kb 2H 2 O use operator overloading to enable this in automatically derive differential equations from this and solve these numerically possible for elementary reactions via law of mass action

Formulæ in with Functions like in C++ define function with special name name is operator<symbol>, where <symbol> is one of +, -, *, /, %,... unary vs. binary operators count parameters of function plus one extra for non-static functions (left operand is this)

Formulæ in with Functions Example class Complex { double real, imag ; public Complex ( double real, double imag ) { this. r e a l = r e a l ; this. imag = imag ; public s t a t i c Complex operator+ ( Complex a, Complex b ) { return new Complex ( a. r e a l + b. real, a. imag + b. imag ) ;...

Formulæ in with Functions Conclusion allows: but not yet: Complex a = new Complex ( 1, 2 ) ; Complex b = new Complex ( 3, 4 ) ; Complex c = a + b ; Complex d = 1 + a ; Complex e = a + 1; could be resolved by providing additional operator overloads better solutions are implicit conversions

Formulæ in with Implicit Conversion like in C++ extends autoboxing from primitive to reference types can be defined in any of the following ways: class C { C(S source ) ; s t a t i c C valueof (S source ) ; T tot ( ) ; t tvalue ( ) ; follows existing patterns like tostring(), intvalue(), etc.

Formulæ in with Implicit Conversion Example class Complex {... @de. grogra. x l. lang. ConversionConstructor public C( double d ) { r e a l = d ; imag = 0;

Formulæ in with Introduction reaction equation: reaction rate: r = 1 ν 1 d[a] dt ν 1 A + ν 2 B +... ν 1A + ν 2B +... = 1 ν 2 d[b] dt = 1 ν 1 d[a ] dt = 1 ν 2 d[b ] dt =... rate law: r = k[a] ν 1 [B] ν 2...

Formulæ in with Parse Tree Generation Reaction left right Expression Expression Term Term Term 2H 2 O 2 2H 2 O in : 2*H2 + O2 <=> 2*H2O;

Formulæ in with Molecule / / each e n t i t y i n the r e a c t i o n i s a molecule class Molecule { / / predefine some instances of Molecule so t h a t they / / can be s t a t i c a l l y imported i n t o c u r r e n t scope public s t a t i c f i n a l Molecule H2 = new Molecule ( "H2" ) ; public s t a t i c f i n a l Molecule H2O = new Molecule ( "H2O" ) ; public s t a t i c f i n a l Molecule O2 = new Molecule ( "O2" ) ; S t r i n g name ; public Molecule ( S t r i n g name) { this. name = name ; public S t r i n g t o S t r i n g ( ) { return name ;

Formulæ in with Reaction Arrow / / stores the whole r e a c t i o n class Reaction { Expression l e f t, r i g h t ; double kf, kb ; / / i n f e r r e a c t i o n from l e f t and r i g h t side public s t a t i c Reaction operator <=> ( Expression lhs, Expression rhs ) { Reaction r e s u l t = new Reaction ( ) ; r e s u l t. l e f t = l h s ; r e s u l t. r i g h t = rhs ; return r e s u l t ;

Formulæ in with Expressions / / an expression i s a l i s t of terms class Expression { f i n a l ArrayList <Term> terms = new ArrayList <Term > ( ) ; public void add ( Term term ) { terms. add ( term ) ; / / terms are combined by + operator public s t a t i c Expression operator+ ( Expression expr, Term term ) { expr. add ( term ) ; return expr ;

Formulæ in with Term / / f a c t o r i s s t o i c h i o m e t r i c c o e f f i c i e n t f o r molecule class Term { double f a c t o r ; Molecule m; public Term ( Molecule m) { this ( 1, m) ; public Term ( double factor, Molecule m) { this. f a c t o r = f a c t o r ; this.m = m; public s t a t i c Term operator ( double factor, Term term ) { term. f a c t o r = f a c t o r ; return term ;

Formulæ in with Implicit Conversions Some implicit conversions are needed to cover remaining cases: 1) Molecule Term 2) Molecule Expression 3) Term Expression

Formulæ in with Application put all reactions into a Model derive ODEs from reaction equation for numerical integration use law of mass action need to assign indices to each Molecule map Molecule int with java.util.hashmap can then use any standard method for integration

Formulæ in with Example 1 Reaction A k 1 B k 2 C const Molecule A = new Molecule ( "A" ) ; const Molecule B = new Molecule ( "B" ) ; const Molecule C = new Molecule ( "C" ) ; public void run ( ) { Reaction r1 = A <=> B ; / / f i r s t reaction : A > B r1. setforwardrateconstant ( 2 ) ; f i n a l Model model = new Model ( ) ; model. addslope ( r1 ) ; model. add (B <=> C, 1 ) ; / / second r e a c t i o n : B > C...

Formulæ in with Example 1 Reaction A k 1 B k 2 C 10 8 concentration 6 4 A B C 2 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time

Formulæ in with Example 2 Michaelis-Menten reaction: in : E + S k f kr ES k cat E + P f i n a l Model model = new Model ( ) ; model. add (E + S <=> ES, 3, 0. 1 ) ; model. add (ES <=> E + P, 2 ) ;

Formulæ in with Example 2 Michaelis-Menten 10 8 concentration 6 4 E S ES P 2 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time

Formulæ in with operator overloading very versatile makes chemical reactions part of the language syntax checking included also other applications right-hand sides of rules iostreams-like input/output retrofit existing classes like BigInteger and BigDecimal with overloaded operators

Formulæ in with Thank you for your attention.

Formulæ in with

Formulæ in with Backup Slides

Formulæ in with Example 1 Reaction A k 1 B k 2 C... / / assign i n d i c e s f i n a l HashMap m = new HashMap ( ) ; i n t count = model. assignindices ( 0, m) ; / / a l l o c a t e memory double [ ] y0 = new double [ count ] ; double [ ] y = new double [ count ] ; / / set i n i t i a l c o n d i t i o n s setvalue (m, y0, A, 10);...

Formulæ in with Example 1 Reaction A k 1 B k 2 C... / / prepare d i f f e r e n t i a l equations / / getrate ( ) w i l l be c a l l e d by the i n t e g r a t o r ODE ode = new ODE( ) { public void getrate ( double [ ] out, double t, double [ ] y ) { Arrays. f i l l ( out, 0 ) ; model. eval ( out, t, y ) ; ;...

Formulæ in with Example 1 Reaction A k 1 B k 2 C... / / create numerical s o l v e r Solver s o l v e r = new F i r s t O r d e r I n t e g r a t o r A d a p t e r ( new C l a s s i c a l R u n g e K u t t a I n t e g r a t o r ( 0. 0 0 1 ) ) ;...

Formulæ in with Example 1 Reaction A k 1 B k 2 C... / / setup monitor f u n c t i o n to p l o t s t a t e over time solver. setmonitor ( 1, new Monitor ( ) { public void g ( double [ ] out, double t, double [ ] y ) { / / t r i g g e r at 20Hz out [ 0 ] = s i n ( PI t 2 0 ) ; public boolean handleevent ( i n t i, double t, double [ ] y ) { / / p l o t data or whatever return false ; ) ;...

Formulæ in with Example 1 Reaction A k 1 B k 2 C... / / perform i n t e g r a t i o n s o l v e r. i n t e g r a t e ( ode, 0, y0, 5, y ) ;