dit- peter/expander2/exp2picpeter/expander2/exp2pic.pdf · text, tree (rooted graph) and picture...

64
Picture construction and animation with Expander2 fldit-www.cs.tu-dortmund.de/peter/Expander2/Exp2Pic.pdf Peter Padawitz TU Dortmund April 30, 2017 1

Upload: others

Post on 18-Mar-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Picture construction and animation with Expander2

fldit-www.cs.tu-dortmund.de/∼peter/Expander2/Exp2Pic.pdf

Peter Padawitz

TU Dortmund

April 30, 2017

1

Page 2: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

��

� Contents

1. Expander2 5

2. Swinging types 8

3. Picture generation 10

4. The Haskell types 14

5. Turtle actions 15

6. From turtle actions to a picture 17

7. Recursive drawing 18

8. Picture scanner 19

9. Oscillable widgets 20

10. Putting it all together 23

11. Examples 26

2

Page 3: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Expander2

• Horn axioms (p(t) ⇐ ϕ) and co-Horn axioms (p(t) ⇒ ϕ) defining functions, relations

or non-deterministic functions (transition systems),

• logical top-down derivations into True or another solved formula (constraint):

• prove ϕ: ϕ ` True

• solve ϕ: ϕ ` solved formula

• refute ϕ: ¬ϕ ` True

• verify p: p(x)⇒ ϕ ` True

• evaluate p: p(x)⇐ ϕ ` True

• evaluate t: t ≡ x ` c ≡ x

3

Page 4: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

• rewrite sequences that generate/manipulate/normalize functional terms or check

Kripke models,

• rules at 3 levels of automation/interaction:

• Simplifications are equivalence transformations that partially evaluate terms and

formulas.

• Narrowing and rewriting apply all or some axioms to goals,

exhaustively or selectively, interactively or automatically, stepwise or iteratively.

• Induction, coinduction and other proper expansions are applied interactively

and stepwise. (Fixpoint) induction and coinduction apply goals (as hypotheses) to

axioms and thus show the former by solving the latter.

4

Page 5: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Expander2

• The semantics is given by the initial resp. final model of the axioms.

• Relations and predicates are interpreted as the least or greatest solutions of their

Horn resp. co-Horn axioms.

• These dualities admit the uniform treatment of constructor- and destructor-based data

types, finite and infinite objects, positive and negative propositions.

• 3 representations of a formula/term:

text, tree (rooted graph) and picture (list of 2-dimensional widgets).

All representations can be edited, moved and scaled.

The pictorial ones can also be rotated and connected by arcs of different shapes.

5

Page 6: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

text tree(s) picture(s) graph(s)

eps file(s)

add arcs

Haskell term(s)of type Graph

compile

eps file(s)

compile

store

store

store

insert

tree(s)

tree(s)

derive

derive

tree(s)

deriveproof recordstore

proof termstore

execute

Expander’s representations of terms/formulas and derivations

6

Page 7: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Swinging types

• Sums∐

i∈I ti formalize/implement selection and case analysis.

Products∏

i∈I ti formalize/implement tupling and relationships.

• A recursively defined type T is created from

constructors

c : composed type→ T

(initial) algebras

context-free languages

or

destructors

d : T → composed type

(final) coalgebras

transition systems

Constructor-based types are called visible.

Destructor-based types are called hidden.

• More constructors lead to supertypes. More destructors lead to subtypes.

• Functions f : T → composed type on a visible type T

are defined by recursion.

Functions g : composed type→ T into a hidden type T

are defined by corecursion.

7

Page 8: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Swinging types

• Horn clauses r(t)⇐ ϕ define least relations

(least solution of r(t)⇐ ϕ in r).

Co-Horn clauses r(t)⇒ ϕ define greatest relations

(greatest solution of r(t)⇒ ϕ in r).

Properties of least relations are proved by induction.

Properties of greatest relations are proved by coinduction.

• Least or greatest congruences ≡: t× t and quotients A/≡A

formalize/implement (visible or hidden) abstraction.

Least or greatest invariants all : t and substructures allA ⊆ A

formalize/implement (visible or hidden) restriction.

8

Page 9: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

• The standard models are initial/least or final/greatest solutions

of domain equations (A ≤ B iff ∃ A→ B),

constructed as suprema/colimits or infima/limits

of ascending or descending chains.

×

×

×

×

×

c1

+

+

+

+

+

d1

e3d2

e4

c2 c3

c4

+

+

+++

d1

d3d2

d4

An element of the initial model for constructors ci : si,1 × . . .× si,ni→ si (left)

versus an element of the final model for destructors di : si → si,1 + · · ·+ si,ni(right).

9

Page 10: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

��

� Picture generation

text

abstractsyntax tree

picture with state

compile

singlewidget

multiplewidget

position orientationcolor lightness

getState

move

rotate

mkWidg

mkPict

widget

widget 1

widget n

scale&

draw

fastor

slow

set lightness

modifysimplifyrewrite

picture

positions

add

cross points

convex hull

add

add

intersectionsunions

add add

compile

movescalerotate

edit arcs

design language

Haskell types & functions Tcl/Tk

wysiwyg

10

Page 11: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

• Several interpreters translate a tree into a picture:

• alignment, linear equations, matrices, matrix solution,

• partition, polygons, polygon solution, rectangles

• They create a widget in an initial state

(position (0,0), orientation 0, color, lightness 0)

• Some operations on a list of pictures ps, the contents of a file F,

a single widget w or a list of actions acts:

• color(c,ps), dark(ps), file(F), flipH/V(ps), gif(F), grow(ps),

grow5/R(n,ps), hframe(ps), light(i,ps), matrix(w), meet(n,ps), odots(ps),

outline(ps), place(w,points), rainbow(w,n,d,a), rainbow2(w,n), reverse(ps),

rframe(ps), shelves(n,d,ps), shineB/W(w,d,a), shuffle(ps), split(ps),

splitS(sc,ps), tabA/B(n,d,ps), tabAS/BS(n,d,sc,ps), turt(acts), turt(ps)

• animators: fadeB/W(w), fast(w), flash(w), new, old,

osciL/P/W(...), peaks(w,m), pulse(w), repeat(ps), rotate/C(w,a)

• Further operations on list terms are provided by the simplifier.

11

Page 12: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%The Haskell types

type Picture = [Widget_]

type Arcs = [[Int]]

data Widget_ = Arc Color ArcStyleType Point Float (Float,Float) |

Arc0 State ArcStyleType Float Float |

Arc0, Path0 and Tree0 are abstract versions of Arc, Path

resp. Tree which they are turned into before being displayed.

Bunch Widget_ [Int] |

Bunch w ns represents widget w together with arcs leading

from w to the widgets at positions ns.

ms++ns is the list of direct successors of Bunch w ms ns.

Circ State Float | CircA State Float | Dot Color Point |

CircA and RectA ignore the scale of enclosing turtles.

Fast Widget_ | File_ String | Gif String Point |

12

Page 13: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

New | Old | Path Color Int [Point] |

Path0 State Int Point [Point] |

Poly State Int [Float] Float |

Rect State Float Float | RectA State Float Float |

Repeat Widget_ | Snow State Int Float |

Text_ State [String] |

Tree Color Color (Term TNode) |

Tree0 State String Color [Term TNode] |

Tria State Float |

Turtle State Float [TurtleAct] | White

13

Page 14: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%The Haskell types

data TurtleAct = Move Float | MoveA Float | Jump Float | JumpA Float |

MoveA and JumpA ignore the scale of the enclosing turtle.

Turn Float | Open Color Int | Scale Float |

Close | Draw | Widg Widget_ | WidgB Widget_

Widg w ignores the orientation of the enclosing turtle,

WidgB w adds it to the orientation of w.

type State = (Point,Float,Color,Int)

type TNode = (String,Point)

type Point = (Float,Float)

14

Page 15: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Turtle actions

drawAt ps = f [open] p0 ps

where f acts p (q:ps) = f (acts++acts’) q ps

where acts’ = if p == q then [Widg w]

else [Turn a,Jump d,Turn (-a),Widg w]

(a,d) = (angle p q,distance p q)

f acts _ _ _ = acts++[Close]

15

Page 16: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%From turtle actions to a picture

mkPict (Turtle (p,a,c,i) sc acts) = g pict c’ n ps

where (pict,(_,_,c’,n,_,ps):_) = foldl f ([],[(p,a,c,0,sc,[p])]) acts

f (pict,(p,a,c,n,sc,ps):s) (Move d) =

(pict,(q,a,c,n,sc,ps++[q]):s)

where q = successor p a (d*sc)

f (pict,(p,a,c,n,sc,ps):s) (Jump d) =

(g pict c n ps,(q,a,c,n,sc,[q]):s)

where q = successor p a (d*sc)

f (pict,(p,a,c,n,sc,ps):s) (Turn b) =

(pict,(p,a+b,c,n,sc,ps):s)

f (pict,s@((p,a,c,m,sc,_):_)) (Open d n) =

(pict,(p,a,d,n,sc,[p]):s)

f (pict,s@((p,a,c,n,sc,ps):_)) (Scale sc’) =

(pict,(p,a,c,n,sc*sc’,ps):s)

16

Page 17: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%From turtle actions to a picture

f (pict,(_,_,c,n,_,ps):s) Close =

(pict++[Path (mkLight i c) n ps],

s)

f (pict,(p,a,c,n,sc,ps):s) Draw =

(pict++[Path (mkLight i c) n ps],

(p,a,c,n,sc,[p]):s)

f (pict,s@((p,a,_,_,sc,_):_)) (Widg w) =

(pict++[scaleWidg sc (moveWidg p a w)],

s)

17

Page 18: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Recursive drawing

drawPict pict = action

if fast || all isFast pict then mapM_ drawWidget pict

else let scan = head scans

run <- scan.isRunning

if run then scan.addScan pict

else scan.startScan0 delay pict

drawWidget (Circ ((x,y),_,c,i) r) = action

canv.oval (round2 (x-r,y-r)) (round2 (x+r,y+r))

[Outline (outColor c i), Fill (fillColor c i)]

done

...

drawWidget w | isWidg w = drawWidget (mkWidg w)

| isPict w = drawPict (mkPict w)

18

Page 19: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

��

� Picture scanner

struct Scanner = startScan0 :: Int -> Picture -> Action

...

scanner :: TkEnv -> (Widget_ -> Action) -> Template Scanner

scanner tk act =

template (as,run,running) := ([],undefined,False)

in let startScan0 n bs = action as := bs; startScan n

startScan n = action if running then run.stop

run0 <- tk.periodic n loop

run := run0; run.start; running := True

loop = action case as of a:s -> if noRepeat a then as := s

act a; if isFast a then loop

_ -> stopScan

addScan bs = action as := bs++as

stopScan = action if running then run.stop; running := False

isRunning = request return running

in struct ..Scanner

19

Page 20: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

'

&

$

%Oscillable widgets

struct Oscillable = maxheight :: Float

actseq :: Float -> [TurtleAct]

oscillate obj = f h++g 1

where f a = if a == 0 then [] else acts a++f (a-1)

g a = if a == h then [Fast (w h)]

else acts a++g (a+1)

acts a = [Fast v,wait,Fast (delWidg v)]

where v = w a

w = turtle . obj.actseq

h = obj.maxheight

20

Page 21: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

oleafF h c = struct maxheight = h

actseq a = leafF h a c

oplait n d c c’ = struct maxheight = 85

actseq a = f a c++f (-a) c’

where f = wave True 3 n d

owave n d c = struct maxheight = 85

actseq a = wave False 3 n d a c

leafF h d c = [open,Jump y,Turn 90,Jump (-x),Turn a,Widg w,Turn (-a),

Jump (x+x),Turn (-a),Widg (flipWidg False w),Close]

where p@(x,y) = ((h*h-d*d)/(d+d),h/2)

(dist,a) = (angle p0 p,distance p0 p)

w = Arc0 (p0,0,c,0) Chord dist (a+a)

wave b k n d a c = Open c k:

if b then right:Jump (-y/2):left:acts else acts

where right = Turn 90; left = Turn (-90)

acts = Jump (-fromInt n*x):right:Jump (-5):

left:border a++border (-a)++[Close]

21

Page 22: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

border a = foldl1 (<++>) (take n (repeat (step a)))++

[right,Move 10,right]

step a = [Turn a,Move d,Turn (-a-a),Move d,Turn a]

(x,y) = successor p0 a d

22

Page 23: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

��

� Putting it all together

scaleAndDraw = action

mapM_ (.stopScan) scans

scan <- scanner tk drawWidget

scans := [scan]

let pict = pictures!!curr

sizes <- mkSizes font (stringsInPict pict)

(ns,ws) <- getEnclosed pict

let (pict1,(x1,y1,x2,y2)) = f pict 0

f (w:pict) i = (w’:pict’,minmax4 (widgFrame sizes w’) bds)

where w’ = scaleWidg (sc i) w

(pict’,bds) = f pict (i+1)

f _ _ = ([],(0,0,0,0))

sc i = if just rect && i ‘elem‘ ns then rscale else scale

23

Page 24: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

pict2 = map (transXY (5-x1) (5-y1)) pict1

pict3 = filter (not . isRedDot) pict2

compl = map (hullLines sizes) . minus1 pict3

anchor w = Dot c p where p = coords w

c = if any (interior p) (compl w)

then RGB 150 150 150 else black

(hull,rs) = convexPath sizes qs pict3

qs = if just rect then filter (‘inRect‘(get rect)) ps else ps

where ps = map coords pict3

hullNos = zipWithIndices addNo rs

where addNo i p = Text_ (p,0,dark red,0) [show i]

hulls = concatMap (hullPoints sizes) (removeSingles sizes pict3)

24

Page 25: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

pictures := updList pictures curr

(zipWithIndices (scaleWidg (recip (sc pict2))))

widthX := max 100 (round (x2-x1+10))

widthY := max 100 (round (y2-y1+10))

canv.set [ScrollRegion (0,0) (widthX,widthY)]

if partBit then drawPict pict2

else case drawMore of

0 -> drawPict pict2

1 -> drawPict (pict3++map anchor pict3)

2 -> drawPict (pict3++hull++hullNos)

3 -> drawPict (pict3++markCross hulls)

4 -> drawPict (pict3++meetHulls (showStrands True) hulls)

5 -> drawPict (pict3++meetHulls (showStrands False) hulls)

n -> drawPict (pict3++uniquePaths (meetHulls f hulls))

where f = mergeStrands Path (n-6)

mapM_ drawArrow (getArcs sizes pict2 (edges!!curr))

if just rect then drawWidget (get rect)

25

Page 26: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

��

� Examples

Example: NDA (Examples/TRANS0)

defuncts: states

fovars: n

axioms: states = [0..10] &

(n < 6 & n ‘mod‘ 2 = 0 ==> n -> [n,n+1]) &

(n < 6 & n ‘mod‘ 2 =/= 0 ==> n -> n+1) &

6 -> [1,3,5,7..10]

26

Page 27: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

<+>

0 []

1 () ()

2 0

()

[] 1

()

2 2

()

3 0

[] 3

()

1

4 4

4

2

[] 5

3

6

4

5

5

6

7 8 9 10

27

Page 28: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

0 1 2 3 4 5 6

0

1

2

3

4

5

&

=

X0

=

X1

=

0 X2

=

X0

1 X3

=

X1 X2

2 X4

=

X2

3 X5

=

X3 X4

4 X6

X4

5

X5 X6

6

X1 X3 X5 7 8 9 10

28

Page 29: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Five queens (Examples/QUEENS)

preds: cmp loop queens

fovars: n x y xs ys ps s s’

axioms: (x =/= y+n & x =/= y-n ==> cmp(x)(y,n)) &

(xs ‘gives‘ x & zipAll(cmp(x))(ys)[1..length(ys)]

==> (xs,ys) -> (xs-x,x:ys)) &

loop(xs,([],ys),zip(xs)(ys)) &

(s -> s’ ==> (loop(xs,s,ps) <=== loop(xs,s’,ps))) &

(xs = [1..n] ==> (queens(n,ps) <=== loop(xs,(xs,[]),ps)))

29

Page 30: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

conjects: queens(5,ps)

ps = [(1,4),(2,2),(3,5),(4,3),(5,1)]

| ps = [(1,3),(2,5),(3,2),(4,4),(5,1)]

| ps = [(1,5),(2,3),(3,1),(4,4),(5,2)]

| ps = [(1,4),(2,1),(3,3),(4,5),(5,2)]

| ps = [(1,5),(2,2),(3,4),(4,1),(5,3)]

| ps = [(1,1),(2,4),(3,2),(4,5),(5,3)]

| ps = [(1,2),(2,5),(3,3),(4,1),(5,4)]

| ps = [(1,1),(2,3),(3,5),(4,2),(5,4)]

| ps = [(1,3),(2,1),(3,4),(4,2),(5,5)]

| ps = [(1,2),(2,4),(3,1),(4,3),(5,5)]

30

Page 31: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Labelled transition relation (Examples/TRANS1)

constructs: a b

defuncts: states

axioms: states = [1,2,3,4] & labels = [a,b] &

(2,b) -> [1,3] & (3,b) -> 3 & (3,a) -> 4 & (4,b) -> 3

<+>

[] 2

()

&

() b

2

() =

b 3

()

1 X2

=

[] a 3 3 X3

=

4 b 4 2 X4

1

3 b

a

3

3

3

b b

4

4

a

1 X3 X4

b b

b

X3 X3

a b

2

1

3

3 4 3

4 3

31

Page 32: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Turtle (Examples/turt)

turt

OS T

dark red

M

40

rect

22

M

11

snow

16 45

M

red 3

tria

22 45

T

magenta -22

M

dark green -40

pie

55

M

6

T

22 22

M

50

grow

35

M

grow

tree

trunk 35

M

trunk

turt

slice

trunk

25

T

M

22

M

rect

60 -50

text

55

light blue 55

22

peter hans peter hans

11

32

Page 33: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Table (Examples/polytab)

tabA

5 66 []

turt text

polyR

turt

flip horizontally:

text

7

flipH

turt

[]

flip vertically:

turt

polyR

flipV

text

33

polyR

turt

11 7

polyR

flip horizontally:

text

[]

7

flipH

turt

7

[]

flip vertically:

33

[]

polyR

flipV

11

-33

33

-11 7

polyR

11

[] 7

-33

[]

-11 -33 -11

33

Page 34: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Shelves (Examples/shelvesA)

tabAS

5 93 2 $

fun ()

()

x

[] rect

y x

rect

x 22 11 11rect 22text x

5

y

55 hanspeter

y

blue

y polyF y y

5

x

[]

y

red

y

44

y

11

y x y y circ x y

11 green

34

Page 35: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Shelves (Examples/shelvesB)

tabBS

5 5 2 $

fun ()

()

x

[] rect

y x

rect

x 22 11 11rect 22text x

5

y

55 hanspeter

y

blue

y polyF y y

5

x

[]

y

red

y

44

y

11

y x y y circ x y

11 green

35

Page 36: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Decorations (Examples/hull)

tabB

5 5 $

tup grow

id outline trunkodots growhframe rframe

grow trunk

trunk grow

trunk trunk

36

Page 37: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Rainbows (Examples/raintabB)

tabB

3 0 $

map []

rframe turt polyR

rainbow

turt

51

circ

[] rainbow

33

33 polyR

yellow 51 []

33

37

Page 38: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Pathfinder (Examples/ROBOT)

preds: loop

constructs: turt path place circ red

defuncts: cs

fovars: x’ y’ p q ps pa

38

Page 39: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

axioms:

cs = [(2,6),(6,2)] &

((p = (x+2,y) | p = (x,y+2)) & p ‘NOTin‘ cs ==> (x,y) -> p) &

loop((8,12),path(ps),path(ps++[(8,12)])) &

(p < (8,12) & p -> q

==> (loop(p,path(ps),pa) <=== loop(q,path(ps++[p]),pa))) &

((x,y) < (x,y’) <=== y < y’) &

((x,y) < (x’,y) <=== x < x’) &

((x,y) < (x’,y’) <=== x < x’ & y < y’)

conjects:

Any pa: (loop((0,0),path[],pa) & turt(pa:place(circ(2,red),cs)) = z)

39

Page 40: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Plan formation (Examples/ROBOTACTS)

preds: loop

constructs: turt pathS place circ red O C blue M R L

defuncts: cs

fovars: x’ y’ s s’ act act’ acts acts1 acts2

axioms:

(s = (x+2,y) & s ‘NOTin‘ cs ==> (x,y) -> (s,[M(2)])) &

(s = (x,y+2) & s ‘NOTin‘ cs ==> (x,y) -> (s,[R,M(2),L])) &

loop((8,12),acts,acts) &

(s < (8,12) & s -> (s’,acts)

==> (loop(s,acts1,acts2) <=== loop(s’,acts1++acts,acts2))) &

conjects:

Any acts: (loop((0,0),[],acts) &

turt(O(blue):acts++[C,place(circ(2,red),cs)]) = z)

40

Page 41: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Pythagorean trees (Examples/PYTREE)

fovars: x y

axioms: trunk -> flipV(trunk) &

trunk -> grow(trunk,trunk) &

flipV(flipV(x)) -> x

conjects: trunk <+>

flipV(trunk) <+>

grow(trunk,trunk) <+>

grow(trunk,flipV(trunk)) <+>

pytree1 <+>

pytree2 <+>

file(pytree1code)

41

Page 42: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

trunk c = path0 c 2 [p0,(-15,0),(-15,-30),(-3,-45),(15,-30),(15,0),p0]

grow c acts1 acts2 =

Widg (trunk c):Turn 180:open:Jump 15:Turn 90:Jump 30:Turn 38.6598:

Scale 0.640313:Jump 15:acts1++close2++open:Jump 3:Turn 90:Jump 45:

Turn 129.806:Scale 0.781023:Jump 15:acts2++close2

fractal "pytree" n c = open:f n c++[Close]

where f 0 c = []

f n c = grow c acts acts where acts = f (n-1) (nextCol n c)

fractal "pytree" 12 blue;

42

Page 43: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Various trees (Examples/NICETREE)

fovars: n x

axioms: rhomb -> leaf(1.5,20) &

rhomb -> leafF(15,6) &

rhomb -> turt(blosF(10,5,2,red),blosF(5,3,1,yellow)) &

rhomb -> polyR(5,[9,3]) &

rhomb -> rhomb5(1) &

rhomb -> flipV(rhomb) &

rhomb -> grow5(1,rhomb,rhomb,rhomb,rhomb,rhomb) &

rhomb -> growR(1,rhomb,rhomb,rhomb,rhomb,rhomb) &

... &

flipV(flipV(x)) -> x

43

Page 44: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

$

fun

x

growR

$ 2 rhomb

fun

rhomb5

y

growR

rhomb5

3

rhomb

$ 1

2

rhomb

rhomb x

fun

z

growR

rhomb5 x x

growR 2

3

rhomb y

1 y

rhomb5

growR y

rhomb

z 2

rhomb

2

x

rhomb rhomb5 z

3

rhomb rhomb

44

Page 45: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Tattoo (Examples/tattoo)

meet

2 flipV waveS

turt

waveS

3

turt

R

60 3

turt

J

-45 60 J

turt

L

red 45 R J

-10

waveS

red

-22

waveS R R

22

waveS J

2

2

L

50

50 2 10

waveS

-45

45 50

blue

green -45 2green 50 45 blue

45

Page 46: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Stars (Examples/shinepoly3)

tabA

3 44 $

map []

fun ()

()

()

turt shineW

()

F x

dark yellow fun

F y

light blue shineW blue

polySF

shineW

y

8 [] x

0 22.5

32 12

46

Page 47: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Shuttles (Examples/shuttles2)

$

fun ()

() turt .

F x

[]

F turtJ . 22

1 x

O 12

22

T

shineW

0

dark cyan

J

polySF

0

-90

flipV 22

22

C 5

F

O 22T 0

1 x

J 0

90

flipV 12

dark yellow

22

C

F

J flipV

1 x

22 F

dark magenta 1 x green

47

Page 48: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Windmill (Examples/shineplait4)

$

map []

fun

x

0 60

shineB

120

turt 0

:

SC :

0.9 T

x

$

map []

fun ()

()

()

y

plaitS 45

()

z

yellow -45

()

6

yellow 40

50 y

red -40

z

red

48

Page 49: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Carpet (Examples/CARPET)

meet

1 $

map shuffle

fun []

()

x

turt $

y

$

z R mapJ [] map

x

L

fun

[]meet

n

0 fun40

n

202

()

80 60plaitS

n

120

()

100plaitS

n

3

red

60 3

green green

60 y 60

red

-60 z

49

Page 50: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Yin & Yang (Examples/yinyang)

$

fun fun

F xturt y z

:

[]

circ :

J

120

B

blue R

60

circ

:

circ

60 x

O

slice

12 y

J

++

R

120

32

J

180 F

text

red :

52 z

C

red

y

blue JYang F

60 blue red Yin

turt

[]

circ R

120

slice

blue

J

120

B

180 60

circ

red

circ

60

O

red 12

J

blue

R

32

J text

52

C

Yang

J

blue

B

120.0

circ circ

60

O

blue 12

J

red

R

32

J text

52

C

Yin red

50

Page 51: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

51

Page 52: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Yin & Yang (Examples/yinyangR)

tabB

4 0 rainbow

$ 16

fun

0

fun

0

F x

0.7

turt y z

:

[]

circ :

J

120

B

blue R

60

circ

:

circ

60 x

O

slice

12 y

J

++

R

120

32

J

180 F

text

red :

52 z

C

red

y

blue JYang F

60 blue red Yin

52

Page 53: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

53

Page 54: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Yin & Yang (Examples/yinyangRR)

tabB

4 0 rainbow

$ 16

fun

0

fun

360

F x

0.7

turt y z

:

[]

circ :

J

120

B

blue R

60

circ

:

circ

60 x

O

slice

12 y

J

++

R

120

32

J

180 F

text

red :

52 z

C

red

y

blue JYang F

60 blue red Yin

54

Page 55: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

YinYang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

Yin

Yang

YinYang

Yin

55

Page 56: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Yin & Yang (Examples/yinyangRR2)

tabB

12 0 rainbow

turt 144

[]

0 360

circ

0.25

R

120

slice

blue

J

120

B

180 60

circ

red

circ

60

J

red 12

B

blue 120.0

circ circ

60 blue 12 red

56

Page 57: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

57

Page 58: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Concatenation (Examples/circtab)

tabA

26 22 $

map []

fun

z

0 5

light

10 15

-

20

z

rainbow

25 30

circ

35

26

40

51

0

35

yellow

0

30

1

25 20 15 10 5 0

58

Page 59: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Concatenation (Examples/circtabA)

tabA

26 22 $

map []

fun

z

0 5

light

10 15

-

20

z

rainbow

25 30

circ

35

26

40

51

35

yellow

30 25 20 15 10 5 0

59

Page 60: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Shuffling (Examples/circtabAS)

tabA

17 22 shuffle

$

map []

fun

z

0 5

light

10 15

-

20

z

rainbow

25 30

circ

35

26

40

51

35

yellow

30 25 20 15 10 5 0

60

Page 61: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Concatenation (Examples/circtabB)

tabB

26 0 $

map []

fun

z

0 5

light

10 15

-

20

z

rainbow

25 30

circ

35

26

40

22

35

yellow

30 25 20 15 10 5 0

61

Page 62: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Shuffling (Examples/circtabBS)

tabB

17 0 shuffle

$

map []

fun

z

0 5

light

10 15

-

20

z

rainbow

25 30

circ

35

26

40

26

35

yellow

30 25 20 15 10 5 0

62

Page 63: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Shuffling (Examples/circtabBR2S)

tabB

17 0 shuffle

$

map []

fun

z

0 5

light

10 15

-

20

z

rainbow2

25 30

circ

35

26

40

26

35

yellow

30 25 20 15 10 5 0

63

Page 64: dit- peter/Expander2/Exp2Picpeter/Expander2/Exp2Pic.pdf · text, tree (rooted graph) and picture (list of 2-dimensional widgets). All representations can be edited, moved and scaled

Example: Reversal and shuffling (Examples/circtabBSR)

tabB

17 0 shuffle

$

map []

fun

z

0 5

light

10 15

-

20

z

reverse

25 30

rainbow

35 40

circ

35

26

30

26

25

yellow

20 15 10 5 0

64