Innovative Produktentwicklung durch

Similar documents
Implicit Evaluation of auto Variables and Arguments

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Chapter 3 Function Overloading

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

Object Oriented Design

Implicit Evaluation of auto Variables and Arguments

Cpt S 122 Data Structures. Templates

COS 320. Compiling Techniques

15. Pointers, Algorithms, Iterators and Containers II

0. Overview of this standard Design entities and configurations... 5

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli

CS 161 Computer Security

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Functions and Recursion

14. Pointers, Algorithms, Iterators and Containers II

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Lambdas in unevaluated contexts

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Types and Type Inference

Formal Semantics of Programming Languages

Polymorphism and Type Inference

Formal Semantics of Programming Languages

INF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

Review of the C Programming Language for Principles of Operating Systems

GridKa School 2013: Effective Analysis C++ Templates

Chapter 3 (part 3) Describing Syntax and Semantics

use static size for this buffer

Introduction to Lexical Analysis

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

CSCE 314 Programming Languages. Type System

Chapter 17. Templates

Lesson 13 - Vectors Dynamic Data Storage

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Expansion statements. Version history. Introduction. Basic usage

Introduction to Lexical Analysis

These are notes for the third lecture; if statements and loops.

C The new standard

Goals of this Lecture

Intermediate Code Generation

Introduction to C++ with content from

Fundamental Algebraic Concepts in Concept-Enabled C++ Peter Gottschling

An introduction introduction to functional functional programming programming using usin Haskell

G Programming Languages - Fall 2012

Chapter 3. Describing Syntax and Semantics

C:\Temp\Templates. Download This PDF From The Web Site

Cpt S 122 Data Structures. Introduction to C++ Part II

C++ Modern and Lucid C++ for Professional Programmers

Auto - a necessary evil?

Axioms: Semantics Aspects of C++ Concepts

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

Defining Languages GMU

Overload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018

An introduction to C++ template programming

array Indexed same type

W3101: Programming Languages C++ Ramana Isukapalli

Chapter 3. Describing Syntax and Semantics ISBN

M.EC201 Programming language

QStringView. everywhere. Marc Mutz, Senior Software Engineer at KDAB

ENGINEERING 1020 Introduction to Computer Programming M A Y 2 6, R E Z A S H A H I D I

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Fibonacci in Lisp. Computer Programming: Skills & Concepts (CP1) Programming Languages. Varieties of Programing Language

On the correctness of template metaprograms

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Templating functions. Comp Sci 1570 Introduction to C++ Administrative notes. Review. Templates. Compiler processing. Functions Overloading

Overload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019

[[assert: std::disjoint(a,na, B,nB)]]: Contract assertions as an alternate spelling of restrict

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Numerical computing. How computers store real numbers and the problems that result

Lambdas in unevaluated contexts

Types and Type Inference

CPSC 427: Object-Oriented Programming

VS 3 : SMT Solvers for Program Verification

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

Review of the C Programming Language

Proposal for Extending the switch statement

CMSC 330: Organization of Programming Languages

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Outline. 1 About the course

Expression Evaluation and Control Flow. Outline

Advanced C++ Topics. Alexander Warg, 2017

Parameter Binding. Value: The formal parameter represents a local variable initialized to the value of the corresponding actual parameter.

C++ Programming Fundamentals

Fast Introduction to Object Oriented Programming and C++

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

A Fast Review of C Essentials Part I

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

Programming Languages Third Edition

CS11 Advanced C++ Spring 2018 Lecture 2

Object-Oriented Programming

Other C++11/14 features

The Structure of a Syntax-Directed Compiler

C++ For Science and Engineering Lecture 15

Transcription:

The benefits of concepts PETER GOTTSCHLING SMARTSOFT/TU DRESDEN SmartSoft TU Dresden Autor@smartsoft-computing.com Tel.: +49 (0) 351 463 34018 Finite-Elemente-Methode Goals for (FEM) Concepts More concise and meaningful error messages Retroactive interface adaption Expressing semantic behavior Semantic verification (Bergen team) Language support for full formal specification? Generic Optimization Compiler support (responsibility) for a higher quality of software development Instead of external specification/verification tools 1

CURRENT CONCEPT SUPPORT Finite-Elemente-Methode More concise error (FEM) message conceptg++ sort_and_concepts.cpp -o sort_and_concepts sort_and_concepts.cpp: cpp: In function 'int main(int, char**)': sort_and_concepts.cpp:19: error: no matching function for call to 'sort( gnu_cxx:: normal_iterator<const int*, std::vector<int, std::allocator<int> > >, gnu_cxx:: normal_iterator<const int*, std::vector<int, std::allocator<int> > >)' /Users/pgottsch/software/conceptgcc-config-darwin/powerpcapple-darwin7.3.1/libstdc++-v3/include/bits/stl_algo.h:2913: note: candidates are: void std::sort(_iter, _Iter) [with _Iter = gnu_cxx:: normal_iterator<const int*, std::vector<int, std::allocator<int> t t> > >] <where clause> sort_and_concepts.cpp:19: note: no concept map for requirement 'std::mutablerandomaccessiterator< gnu_cxx:: normal_it erator<const int*, std::vector<int, std::allocator<int> > > >' sort_and_concepts.cpp:19: note: no concept map for requirement 'std::assignable<const int&, const int&>' 2

Finite-Elemente-Methode Express (FEM) semantics concept VectorSpace<typename Vector, typename Scalar = Vector::value_type> : AdditiveAbelianGroup<Vector>, Multiplicable<Scalar, Vector>, Multiplicable<Vector, Scalar> VectorSpace<typename AddOp, typename MultOp, typename Element> { requires Field<Scalar>; axiom Distributivity(Scalar a, Scalar b, Vector v, Vector w) { a * (v + w) == a * v + a * w; (v + w) * a == v * a + w * a; (a + b) * v == a * v + b * v; v * (a + b) == v * a + v * b; } } auto concept BanachSpace<typename N, typename Vector, typename Scalar = Vector::value_type > : Norm<N, Vector, Scalar>, VectorSpace<Vector, Scalar> {} auto concept HilbertSpace<typename I, typename Vector, typename Scalar = Vector::value_type > : InnerProduct<I, Vector, Scalar>, BanachSpace<induced_norm_t<I, Vector, Scalar>, Vector, Scalar> {} Finite-Elemente-Methode Explicit vs. implicit (FEM) concepts Compiler cannot recognize semantics Models of semantic concepts must be declared by programmer Not always distinguishable syntactically 3

Finite-Elemente-Methode Optimize on (FEM) semantics template <RandomAccessIterator Iter, typename T, typename Op> requires Monoid<Op, T> && Commutative<Op, T> T accumulate(iter first, Iter last, T s, Op op) { T s1= identity(op, s), s2= s1, s3= s2; for (last_block= ;first!= last_block; first+= 4) { s = op(s, *first); s1 = op(s1, *(first+1)); s2 = op(s2, *(first+2)); s3 = op(s3, *(first+3)); } for (;first!= last; ++first) s = op(s, *first); return op(op(s, s1), op(s2, s3)); } Or in compiler based on axioms (Jaakko/Jeremiah) Finite-Elemente-Methode Accelerated accumulate (FEM) Addition of integer 4

Finite-Elemente-Methode Challenges (FEM) Innovative Produktentwicklung Anisomorphisms durch Between mathematics and C++ Math set can be multiple types E.g. float, double Infinite number with expression templates C++ type can be multiple sets Vector for each set C++ functions are sets of mathematical functions Due to overloading and templates DESIRED CONCEPT EXTENSIONS 5

Finite-Elemente-Methode Dynamic (FEM) concepts Are concepts on objects Motivation: for function arguments only property of object matters not of whole type, e.g. template <typename LinearOperator, > requires void conjugate_gradient(const LinearOperator& A, ) requires Symmetric(A) && PositiveDefinite(A) {} Finite-Elemente-Methode Dynamic concepts (FEM) (cont) Allow for (dynamic) overloading Opposed to assertion-based preconditions template <T> requires st1<t> void f(const T& x) {} template <T> requires st1<t> void f(const T& x) {} template t <T> template <T> requires st1<t> && st2<t> requires st1<t> && st2<t> void f(const T& x) void f(const T& x) { requires dyn(x) // use other assert(dyn(x)); // crash {} } 6

Finite-Elemente-Methode Dynamic Concepts (FEM) (cont) Are extensions of static concepts A type modeling a concept all values/objects are dynamic models Can replace run-time by compile-time check template <typename LinearOperator, > requires void cg(const LinearOperator& A, ) requires Symmetric(A) && PositiveDefinite(A) {} Finite-Elemente-Methode Dynamic concepts (FEM) (cont) Innovative Produktentwicklung Property conservation durch Allow for requiring pre- and declaring post-conditions Properties are valid as long as objects are not modified exploring const 7

Finite-Elemente-Methode Dynamic concepts (FEM) (cont) Innovative Produktentwicklung Increasing durch constancy Axiom-based optimizations allowed within validity range of property Maximizing constancy in arguments extents validity Result-dependent argument type ordering template<class T> T f(const T& x); matrix_type A; const double x= A[i][j]; y= f(a[i][j]); We could use const version of operator[] For constant result prioritize constant arguments Increases reliability even without dynamic concepts Finite-Elemente-Methode Inferring syntactic concepts (FEM) from Innovative Produktentwicklung missing durch constraints Syntactical ti constraints t are already contained in source Often much longer than code itself Distract from semantic constraints Can be generated by the compiler Parser-based documentation tools needed 8

Finite-Elemente-Methode Example (FEM) for Innovative Produktentwicklung inferring syntactic durch concepts template <typename Op, std::semiregular Element, Integral Exponent> requires Group<Op, Element> && std::convertible<std::callable2<op, Element, Element>::result type, Element> && std::semiregular<math::inversion<op, Element>::result type> && std::hasnegate<exponent> && math::monoid<op, math::inversion<op, Element>::result type> && Integral< std::hasnegate<exponent>::result type> && std::callable2<op, math::inversion<op, Element>::result type, math::inversion<op, Element>::result type> && std::convertible<std::callable2<op, math::inversion<op, Element>::result type, math::inversion<op, Element>::result type>::result type, math::inversion<op, Element>::result type> inline Element power(const Element& a, Exponent n, Op op) { return n < 0? multiply and square(inverse(op, a), -n, op) : multiply and square(a, n, op); } Finite-Elemente-Methode What is code complexity? (FEM) int m,u,e;float g,s,f;char f;char* _= =")xx.xxx@xxx(rezneumxxx@xxx(rezneum drahnreb\n";main(){for( ;e<1944;){u=s=f=0;do{g=s*s-f*f-2.1+.035*(m=e%81);f=2*s*f+e/81*.088-1.1;s =g;}while(++u<19&&g*s+f*f<4);putchar(_[++e>1863&&m<28?27- m:m>79?28:u]);}} If you can write this correctly you don t need: Concepts Concepts Specification/verificatin Type systems Sometimes more is less 9

Finite-Elemente-Methode Open (FEM) questions Innovative Produktentwicklung (to leave you durch puzzled) What properties can we prove? Which ones do we want to? Interface to Coq or alike? Do we want/need? Easier renaming/aliasing Magne Transitivity of axioms (categories) Marcin template <typename T, concept C> class c; Concepts of concepts, e.g. UnaryConcept Which feedback what the compiler did? 10