-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
170 lines (141 loc) · 5.5 KB
/
example.c
File metadata and controls
170 lines (141 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/***************************************************************************************
* The Patterns of Resemblance Arithmetic Library *
* *
* (By Samuel Alexander) *
* (Department of Mathematics) *
* (The Ohio State University) *
***************************************************************************************
* As seen in the Online Patterns of Resemblance Ordinal Calculator *
* For documentation, see http://www.semitrivial.com/patterns *
***************************************************************************************
* This library implements basic arithmetic for Timothy J. Carlson's Patterns of *
* Resemblance ordinal notation system. Patterns of resemblance are a combinatorial *
* way of notating very large ordinals (up to the ordinal of Pi^1_1-CA_0, to be *
* precise). The PORAL (Patterns of Resemblance Arithmetic Library) is a patterns *
* implementation in C. *
***************************************************************************************
* example.c *
***************************************************************************************
* A bare-bones example file showing the multiplication of the ordinal Gamma_0 by the *
* ordinal epsilon_0. *
* *
* To compile this simple example program (using GCC): *
* gcc -Wall example.c por.c core.c arith.c simp.c patterns.c -o example *
**************************************************************************************/
/*
* For sake of minimizing namespace overlap, the user
* of the arithmetic library needs only include patterns.h,
* the other header files are only used internally.
*/
#include "patterns.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
pattern *Gamma0, *epsilon0, *product, *simplified;
node *a,*b,*c,*d;
node **decomposition;
printf( "This example program will compute Gamma_0 times epsilon_0.\n" );
printf( "--------------------------------\n\n" );
printf( "Initializing basic patterns...\n" );
patterns_initialize();
printf( "--------------------------------\n\n" );
printf( "Creating Gamma_0... ...\n" );
printf( "(See http://www.xamuel.com/geometric-patterns-of-resemblance/ for a picture of Gamma_0)\n" );
/*
* The pattern notating Gamma_0 has four nodes
*/
Gamma0 = new_pattern( 4 );
/*
* This wouldn't happen, but it's here to illustrate error handling:
*/
if ( !Gamma0 )
{
printf( "Creating Gamma_0 failed: %s\n\n", global_pattern_error );
abort();
}
if ( Gamma0 == pattern_too_large )
{
printf( "Gamma_0 has too many nodes.\n\n" );
abort();
}
/*
* Direct some pointers at the nodes of Gamma0
*/
a = Gamma0->first_node;
b = a->next;
c = b->next;
d = c->next;
/*
* Create an arc from node b to node d
*/
b->less1 = d;
/*
* Create an arc from node c to node d
*/
c->less1 = d;
/*
* Decompose node d into the sum c+b.
* Decompositions are expressed as NULL-terminated
* strings of node *'s.
*/
decomposition = malloc( sizeof(node*) * (1+strlen("cb")) );
decomposition[0] = c;
decomposition[1] = b;
decomposition[2] = NULL;
d->decomposition = decomposition;
/*
* Designate b as the pattern's point (so the pattern notates Gamma_0)
*/
Gamma0->point = b;
printf( "...Gamma_0 successfully created.\n" );
printf( "--------------------------------\n\n" );
printf( "Creating epsilon_0... ...\n" );
/*
* epsilon_0 has three nodes
* (See http://www.xamuel.com/geometric-patterns-of-resemblance/ for picture)
*/
epsilon0 = new_pattern( 3 );
if ( !epsilon0 || epsilon0 == pattern_too_large )
{
printf( "Failed: %s\n\n", global_pattern_error[0] ? global_pattern_error : "too many nodes" );
abort();
}
/*
* Get convenient pointers for the nodes
*/
a = epsilon0->first_node;
b = a->next;
c = b->next;
/*
* Create an arc from b to c
*/
b->less1 = c;
/*
* Decompose c into c=b+b
*/
decomposition = malloc( sizeof(node*) * (1+strlen("bb")) );
decomposition[0] = b;
decomposition[1] = b;
decomposition[2] = NULL;
c->decomposition = decomposition;
/*
* Designate b as the pattern's point (so the pattern notates epsilon_0)
*/
epsilon0->point = b;
printf( "...epsilon_0 successfully created.\n" );
printf( "--------------------------------\n\n" );
printf( "Multiplying Gamma_0 times epsilon_0... ...\n" );
printf( "--------------------------------\n\n" );
product = pattern_product( Gamma0, epsilon0 );
if ( !product || product == pattern_too_large )
{
printf( "Failed: %s\n\n", global_pattern_error[0] ? global_pattern_error : "too many nodes" );
abort();
}
printf( "...Multiplication succeeded, yielding a pattern with %d nodes.\n", product->nodes );
simplified = pattern_simplify( product );
printf( "That product simplifies to a pattern with %d nodes.\n\n", simplified->nodes );
return 1;
}