Files
Le-Compte-est-Bon/REDUCE-TREES.txt

256 lines
7.8 KiB
Plaintext

I thought about a way to drastically reduce the number of necessary trees. Does it make sense ?
For a 5 leaves (numbers) and 4 operators, I define following tree types:
;; Type A
o
/ \
o
/ \
o
/ \
o
/ \
;; type B
o
/ \
o o
/ \ / \
o
/ \
;; Type C
o
/ \
o
/ \
o o
/ \ / \
Normally, we have 14 trees for 5 numbers. But I categorize them within the 3 types above.
What I think is: 2 trees of same type will find the same solutions, given we permute all operators and numbers :
- It looks trivial for operators '+' and '-'.
- For '/' et '-', if we swap subtrees numbers to always have maximum on the left, we are left with always one operation (if possible), so the order does not matter.
My generated trees generated (in tree.c) for 5 numbers are :
1: (Op x (Op x (Op x (Op x x))))
2: (Op x (Op x (Op (Op x x) x)))
3: (Op x (Op (Op x x) (Op x x)))
4: (Op x (Op (Op x (Op x x)) x))
5: (Op x (Op (Op (Op x x) x) x))
6: (Op (Op x x) (Op x (Op x x)))
7: (Op (Op x x) (Op (Op x x) x))
8: (Op (Op x (Op x x)) (Op x x))
9: (Op (Op x (Op x (Op x x))) x)
10: (Op (Op x (Op (Op x x) x)) x)
11: (Op (Op (Op x x) x) (Op x x))
12: (Op (Op (Op x x) (Op x x)) x)
13: (Op (Op (Op x (Op x x)) x) x)
14: (Op (Op (Op (Op x x) x) x) x)
Categories:
;; 1 : type A
(Op x o
(Op x / \
(Op x o
(Op x / \
x)))) o
/ \
o
/ \
;; 2 : Type A
(Op x o
(Op x / \
(Op o
(Op x / \
x) o
x))) / \
o
/ \
;; 3 : Type C
(Op x o
(Op / \
(Op x o
x) / \
(Op x o o
x))) / \ / \
;; 4 : Type A
o
(Op x / \
(Op o
(Op x / \
(Op x o
x)) / \
x)) o
/ \
;; 5 : Type A
(Op x o
(Op / \
(Op o
(Op x / \
x) o
x) / \
x)) o
/ \
;; 6 : Type B
(Op o
(Op x / \
x) o o
(Op x / \ / \
(Op x o
x))) / \
;; 7 : Type B
(Op o
(Op x / \
x) o o
(Op / \ / \
(Op x o
x) / \
x))
;; 8 : Type B
(Op o
(Op x / \
(Op x o o
x)) / \ / \
(Op x o
x)) / \
;; 9 : Type A
(Op o
(Op x / \
(Op x o
(Op x / \
x))) o
x) / \
o
/ \
;; 10 : Type A
(Op o
(Op x / \
(Op o
(Op x / \
x) o
x)) / \
x) o
/ \
;; 11 : Type B
(Op o
(Op / \
(Op x o o
x) / / \
x) o
(Op x / \
x))
;; 12 : Type C
(Op o
(Op / \
(Op x o
x) / \
(Op x o o
x)) / \ / \
x)
;; 13 : Type A
(Op o
(Op / \
(Op x o
(Op x / \
x)) o
x) / \
x) o
/ \
;; 14 : Type A
(Op o
(Op / \
(Op o
(Op x / \
x) o
x) / \
x) o
x) / \
Below are all categories by input of N numbers, for N={2,3,4,5,6} :
w is max leaves on same level, and h is height (distance from root to lowest leaf).
2 leaves (1, Catalan=1):
o
/ \
width=2, height=1
serialization: 100
3 leaves (1, Catalan=2):
o
/ \
o
/ \
w=2, h=2
serial: 10100
4 leaves (2, Catalan=5):
o o
/ \ / \
o o o
/ \ / \ / \
o
/ \
w=2, h=3 w=4, h=2
serial: 1010100 serial: 1100100
5 leaves (3, Catalan=14):
o o o
/ \ / \ / \
o o o o
/ \ / \ / \ / \
o o o o
/ \ / \ / \ / \
o
/ \
w=2, h=4 w=3, h=3 w=4, h=3
serial: 101010100 serial: 110010100 serial: 101100100
6 leaves (6, Catalan=42):
o o o o
/ \ / \ / \ / \
o o o o o
/ \ / \ / \ / \ / \
o o o o o
/ \ / \ / \ / \ / \
o o o o o
/ \ / \ / \ / \ / \
o
/ \
w=2, h=5 w=3, h=4 w=3, h=4 w=4, h=4
serial: 10101010100 serial: 11001010100 serial: 10110010100 serial: 10101100100
o o
/ \ / \
o o o o
/ \ / \ / \ / \
o o o o
/ \ / \ / \ / \
w=4, h=3 w=4, h=3
serial: 11001100100 serial: 11010010100