Grammars, L-Systems Jim Whitehead UC Santa Cruz School of Engineering courses.soe.ucsc.edu/courses/cmps265/Spring14/01 23 Apr 2014.

Slides:



Advertisements
Similar presentations
Formal Languages: main findings so far A problem can be formalised as a formal language A formal language can be defined in various ways, e.g.: the language.
Advertisements

Jason Stredwick, MSU 2004 L-Systems Lindenmayer Systems algorithmicbotany.org.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
ATEC Procedural Animation Introduction to Procedural Methods in 3D Computer Animation Dr. Midori Kitagawa.
L-System Aristid Lindenmayer (1968), biologist. L-System A method of constructing a FRACTAL that is also a MODEL for plant growth. The Computational Beauty.
Cosc 1P02 Week 2 Lecture slides
So far we’ve done… Dynamics and chaos Thermodynamics, statistical mechanics, entropy, information Computation, Turing machines, halting problem Evolution,
Introduction to Computability Theory
L systems (Aristid Lindenmayer)
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
L-systems Presented by Luv Kohli COMP258 October 30, 2002 Images copyright © 1992 D. Fowler, P. Prusinkiewicz, and J. Battjes.
Amirkabir University of Technology Computer Engineering Faculty AILAB Efficient Parsing Ahmad Abdollahzadeh Barfouroush Aban 1381 Natural Language Processing.
Procedural Modeling L-Systems Procedural Terrain Procedural Behavior Based on the slides from Spring 2007.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Lindenmayer Systems . Lindenmayer systems There is no distinction between terminal and non-terminal symbols. All the words derived from a given word.
CS39N The Beauty and Joy of Computing Lecture #11 Recursion III It has been a challenge to power electronic components implanted within a body.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Morphogenesis and Lindenmayer Systems (L-systems) Gabriela Ochoa
IlliDOL: A Framework for Exploration of L- Systems in Three Dimensions Vilas Dhar Math 198 Spring 2003.
Dragon Curve Drawn in Project 4… How to generate the string of drawing commands? How does the dragon curve come about? 1.
L-Systems and Procedural Plants CSE 3541 Matt Boggus.
Some Probability Theory and Computational models A short overview.
College of Computer and Information Science, Northeastern UniversityOctober 13, CS U540 Computer Graphics Prof. Harriet Fell Spring 2007 Lecture.
The Artificial Life of Plants Przemyslaw Prusinkiewicz, Mark Hammel, Radom´ır Mˇech Department of Computer Science University of Calgary Calgary, Alberta,
Examining the World of Fractals. Myles Akeem Singleton Central Illinois Chapter National BDPA Technology Conference 2006 Los-Angeles, CA.
Pushdown Automata (PDAs)
Grammars CPSC 5135.
L-Systems Lindenmayer Systems Prusinkiewicz and Lindenmayer
Summer School „Modelling and Simulation with GroIMP“ / Tutorial for beginners University of Göttingen (Germany), September, 2010 Winfried Kurth Some.
Lindenmayer systems Martijn van den Heuvel May 26th, May 26th, 2011.
L-system and SVG 2D SVG Tree 2002/10/16.
Evolutionary Robotics Using A Formal Grammar To Evolve Robot Bodies and Brains Hornby, G.S., Pollack, J. (2001) Creating high-level components with a generative.
How to Draw a Tree L-Systems in Computer Graphics Steven Janke.
Final Review Zhicheng Yan. Over Operator  Two formulas  Alpha Slides  C A over B = a A C A + (1 – a A ) a B C B and a A over B = a A + (1 – a A ) a.
ISBN Chapter 3 Describing Syntax and Semantics.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Copyright © by Curt Hill Grammar Types The Chomsky Hierarchy BNF and Derivation Trees.
1 10/27/ :26 UML Simplicity in Complexity. 2 10/27/ :26 UML Rewriting Systems Classic Example: Koch 1905 Initiator Generator.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Special Models.
LINDFERN Lindenmayer Systems in VPython Nick Langhammer.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Top-down Parsing lecture slides from C OMP 412 Rice University Houston, Texas, Fall 2001.
Chapter 7 Pushdown Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
ATEC Procedural Animation Introduction to Procedural Methods in 3D Computer Animation Dr. Midori Kitagawa.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Parsing and Code Generation Set 24. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program,
Experimenting with Grammars to Generate L-Systems October 29, 2007
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
Experimenting with Grammars to Generate L-Systems – in JFLAP March 31, 2011 Prof. Susan Rodger Computer Science Dept.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
L-systems L-systems are grammatical systems introduced by Lyndenmayer to describe biological developments such as the growth of plants and cellular organisms.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chapter 7 PUSHDOWN AUTOMATA.
ATCM 3310 Procedural Animation
CSE322 The Chomsky Hierarchy
Intro to Data Structures
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Prof. Susan Rodger Computer Science Dept
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Normal Forms for Context-free Grammars
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Grammars, L-Systems Jim Whitehead UC Santa Cruz School of Engineering courses.soe.ucsc.edu/courses/cmps265/Spring14/01 23 Apr 2014

UC SANTA CRUZ Grammars as Rewrite Systems  In Computer Science, grammars are most often thought of as defining rules for accepting strings in a language.  I.e., use in programming languages  However, a grammar can be used to generate strings in a language, as well as accept strings in a language  The way grammars do this is by creating a system of rewriting rules  Start with an initial string, and then successively apply rules to it to create new strings.

UC SANTA CRUZ Generative Grammar  A grammar is a set of production rules  Each production rule gives instructions for how to rewrite a string  That is, how to turn one string into another  Production rules  Symbol(s)  other symbols  Mechanics  Start with an initial string  Each time a symbol (or symbols) is found that matches the left hand side (LHS) of a production rule…  The LHS symbols are replaced by the right hand side (RHS) symbols

UC SANTA CRUZ Generative Grammar Example  Example production rules:  1. A  AB  2. B  b  Application  Initial String: A A A  AB AB ABb A  AB B  b ABbb A  AB B  b Typically lower case letters are terminals, and cannot be expanded any further Rewrite step 1 Rewrite step 2 Rewrite step 3 … Rewriting will continue on indefinitely…

UC SANTA CRUZ Choices in Applying Rewrite Rules (1)  Deterministic vs. Nondeterministic  Deterministic: Exactly one rule that applies to each symbol, or sequence of symbols  Completely unambiguous which rule to use to rewrite the string  For a given initial string, the output string is always the same  Nondeterministic (stochastic): Multiple rules can apply to a given string  Each rewrite step involves a choice among applicable rules  Random  Make a random choice among the matching rules  Grammar could have probabilities for selecting each rule  Example: Context Free Art  Parameters  Use some parameters for deciding which rule to apply

UC SANTA CRUZ Nondeterministic Grammar Example  Example production rules:  1. A  AB  2. [0.5] B  b  3. [0.25] B  c  4. [0.25] B  d  Initial string: A A A  AB AB ABb A  AB B  b ABcb A  AB B  c Rewrite step 1 (only 1 choice, deterministic) Rewrite step 2 (chose rule 2 to apply) Rewrite step 3 (chose rule 3 to apply) … Numbers in brackets are probabilities Other possible output strings after 3 steps: ABcd, ABdd, ABbb, ABcc, ABbc, etc.

UC SANTA CRUZ Choices in Applying Rewrite Rules (2)  Context sensitive grammars  When the rule to be applied depends on the symbols appearing before and after the symbol to be rewritten  Example: B b  AB  Only rewrite A to AB if A is preceded by B, and followed by b  Rewriting rule application  Parallel: simultaneous application of rules  Go through the input string and apply every rule at the same time  Can think of having a second string that is created by application of rules to the initial string  Sequential: apply one rule at a time  Typical Chomsky grammar approach

UC SANTA CRUZ Lindenmayer Systems (L Systems)  Deterministic, parallel, context-free  Known as D0L  D – deterministic  0 – context free  L - Language  First explored by Aristid Lindenmayer in 1968  Had interest in developing axiomatic theory for how plants grow  Deterministic application of rules  Turtle Graphics interpretation of strings  See:  Algorithmic Beauty of Plants book   Many examples of using L systems to model plant growth  Introduction to L systems 

UC SANTA CRUZ Interpretation of Strings  Generating sequences of characters isn’t that interesting  To create interesting content for games, need to give meaning:  To characters (terminals)  To proximity of characters (what does it mean to be next to each other in sequence)  Some approaches  Turtle graphics  Strings are commands in a simple language  Map directly to geometric primitives (or more complex shapes)  Map directly to elements in a level  Example: platforms, gaps, portals (2D platform games)

UC SANTA CRUZ Turtle graphics  An imaginary turtle starts at position 0,0  When it moves, a pen attached to the turtle draws a line  Developed by Seymour Papert for Logo in late 1960s  Commands  F – move forward a step of length d  f – move forward a step of length d without drawing a line  Can also have pen up and pen down commands  + turn left by angle   - turn right by angle   [ - push current turtle state (x, y, angle) onto pushdown stack  ] – pop current turtle state from the stack  Use of the stack makes L-systems “bracketed”

UC SANTA CRUZ Koch Curve  Example L-System  1. F  F +F − F − F +F  Starting this system with the axiom F  Round 0: F  Round 1: F +F − F − F +F  Round 2: F +F − F − F +F +F +F − F − F +F − F +F − F − F +F − F +F − F − F +F +F +F − F − F +F  Not so interesting as a string. But, apply a Turtle graphics interpretation:   Round 1Round 2 Round 3

UC SANTA CRUZ Impact of the stack  Consider the same production, with the addition of stack pushes and pops  Rule 1: F  F[ − F]F[+F][F]  If the angle is 30 degrees, instead of 90 degrees:

UC SANTA CRUZ Shape Grammars  So far, Turtle graphics have worked with lines and points  But, what if you have squares, triangles, circles, (or cubes, cones, and cylinders) etc. as basic geometric primitives?  Would want basic operations like: rotate rectangle 90 degrees and attach to center of right face of square  Stiny and Gips (1971) developed the notion of Shape Grammars  Can express complex shapes via rewrite rules  Has built in notion of faces, orientation, attachment points, spatial area (volume)

UC SANTA CRUZ Shape Grammars  In Shape Grammars, symbols are shapes  Rules generally:  Substitute one shape for another shape  Attach a shape to an existing shape (at an attachment point, or along a wall)  Transform an existing shape (e.g., rotation)  Modify attribute information associated with a shape (e.g., intended use information for spaces in a house)  Introduction to shape and shape grammars, G. Stiny, Environment and Planning B, vol. 7, 1980, pp From Prairie House grammar. Note encoding of attachment points and orientation

UC SANTA CRUZ Split Grammar  Shape grammars are good for building up a novel shape…  …but they are not as good for refining an existing shape  Example: creating a building façade requires refining an existing surface  Split grammars are a type of shape grammar  Transformation rules:  Split: Take an existing shape and split it (decompose it) into other shapes (with the total space consumed being the same)  Transform: Replace an existing shape a with another shape b  Where b has to be contained in the volume of a  Instant Architecture, Peter Wonka, Michael Wimmer, François Sillion, William Ribarsky, ACM SIGGRAPH 2003

UC SANTA CRUZ Split Grammar Example