# Need help debugging

I have written a short script to prove well founded output as it relates to the equation of well founded ness

What errors do you see here?
How can I fix them?

Anything helps so thanks in advance

``````
#Amend

n = set()
i = set()
k = [n]
N = set()
q = 0
Q = []

while q >= float('inf'):
N = set(N)
q = q + 1
def J ():
Q = Q.insert(N)

for n in N:
a = set((k[n]) == k[n] in set(0, 1))

while h <= float('inf') or h >= float('inf'):
while m <= float('inf') or m >= float('inf'):
h = set(h)
m = set(m)
x = [h, i, m]

y = Q[float('inf')] is set(x in a == all(i) in J(x[i] >= x[i+1])

def p(y):
def T ():
X = 0
while X < 2:
X = X + 1
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))

output = ""
while True:
l =11
while l  < 126:
l = l  + 1
a = chr(l)
p ()
v = p ()
if v == 1:
o = o + a
elif v == 0:
o = o
if o == o + "":
break
print ()

``````
1 Like

I have written a short script to prove well founded output as it relates to the equation of well founded ness

Iâm afraid I donât know what that means. Well founded in what aspect?

What errors do you see here?

That depends on what you want it to do. We can help you if youâre having problems implementing a specific concept in python. But we canât necessarily debug your program for you. As written, I have no idea of what any part is supposed to do, so I canât tell you if itâs working correctly or not.

But just looking at the first stanza, several things seem odd:

``````while q >= float('inf'):
N = set(N)
q = q + 1
def J ():
Q = Q.insert(N)
``````

`q` at this point is 0. This means the loop will not be entered. This section will never be run. Also, you have the definition of J inside the loop. Since the loop is not run, J will not be defined and cannot be called later. I canât see any reason youâd want to put the definition inside this loop.

You use a lot of single-letter variable names. In a math context where each of the variables have specific meanings, this might be okay. But otherwise it makes it hard to follow what anything is doing.

Youâre checking the values of h and m before ever setting them. That will cause an error. If h and m are supposed to be sets, comparing them with a numeric value is not allowed. You have a conditional that succeeds when something is less than or equal to a value OR greater than or equal to that same value. Under what conditions could that ever be false?

1 Like

Line 12 q was supposed to be <= not => lol

So this needs done work:

``````
while h <= or >= float('inf'):
while m <= or >= float('inf'):
h = set(h)
m = set(m)
x = [h, i, m]

``````

Here I mean to say len(h) and len(m) but Iâm confused about what type of value uses len()

You can use len() on a set to tell the number of members. But python sets are implemented with real computer memory. As that resource is finite, the program will exhaust memory and crash at some finite number of set members. It is not possible for the length of a python set to be >= float(âinfâ). Executing that check is not useful.

Please donât assume that we will be able to intuit what your code is
intended to do, or what it actually does.

What do you mean by âprove well-founded outputâ? Whatâs âthe equation of
well-foundednessâ?

I can only guess that you are trying to prove something about
cardinalities of infinite sets or something mathematical. If thatâs the
case, you wonât be able to do it this way.

âWhat errors do you see here?â

Thatâs not how this forum works. If you want to hire an expert Python
programmer to review your code, and pay actual money for their time, you
get to tell them what to do. Otherwise, weâre volunteers, doing this to
give back to the community which helped us. So you tell us what errors
are you having, and weâll try to help if we can.

But having said that, Iâm now going to undercut my own message by
telling you the errors I see o_O

``````n = set()
i = set()
k = [n]
N = set()
q = 0
Q = []
``````
``````while q >= float('inf'):
N = set(N)
``````

Integers are never greater than or equal to infinity. The `while` loop
will never run.

Python sets cannot contain sets. The line `N = set(N)` does not create a
set containing N, but effectively copies the set N. So this is just a
waste of processing effort, every loop turning N into a copy of N and
throwing away the original.

``````    q = q + 1
def J ():
Q = Q.insert(N)
``````

Again, more wasted effort: every loop you define a new function J that
doesnât work and never gets used, over-writing the previous function J.

Even if you tried to call the function J, which you donât, it wouldnât
work. I donât know how to fix it because I donât understand what you are
actually trying to do.

``````for n in N:
a = set((k[n]) == k[n] in set(0, 1))
``````

More code I donât understand what you are trying to do.

``````while h <= or >= float('inf'):
``````

That will be a SyntaxError, which means that the Python interpreter
canât work out what you are trying to do. And neither can I. I think
that you might be trying to say:

if h is less than or equal to infinity, or greater than or equal to infinitryâŚ

In other words, it doesnât matter what h is.

But surely thatâs not what you mean?

And at that point Iâm just giving up.

I canât work out what you think the code will do, and it is so full of
syntax errors and other errors that I know it wonât do anything. But I
have no clue how to make it do what you want, or even what you want it
to do. (Except that I think it might have something to do with set
theory and mathematics.)

1 Like

Heat Jack said:

âIĂ˘ÂÂm confused about what type of value uses len()â

https://docs.python.org/3/library/functions.html#len

I think it might help if you do a Python tutorial.

https://docs.python.org/3/tutorial/index.html

1 Like
``````
q <= float(âinfâ)

``````

I actually do call J on line 35

``````
y = Q[float('inf')] is set(x in a == all(i) in J(x[i] >= x[i+1])

``````

The point is to just have the last version of J

``````
for n in N:
a = set((k[n]) == k[n] in set(0, 1))

``````

This is cantors set, a topological statement

Yes that is what I mean
To have h be any length
I rewrote this as

``````
while len(h) >= float('inf') or len(h) <= float('inf'):
while len(m) >= float('inf') or len(m) <= float('inf'):
h = set(h)
m = set(m)
x = x.insert(h+1, h)
x = x.insert(m+1, m)
x = x.insert(h+1, i)

``````
1 Like

I rewrote this as

``````while h >= float('inf') or h <= float('inf'):
while m >= float('inf') or m <= float('inf'):
``````

This seems silly. Setting aside the fact that you canât directly compare a set and a float, if you could compare them, how would either of these conditionals ever fail?

Why not just rewrite them as:

``````while True:
``````

Are you expecting something to happen to h or m to make the loops terminate? If so, what?

1 Like

Itâs not true because true only outputs the last value

1 Like

âTrueâ doesnât output anything. Itâs a value. Likewise your loop conditionals donât output anything. Theyâre checked to see if the loop should continue running.

Iâm saying you have a relatively complex expression there that takes both computer and human time to look at, but which can never be false. If it can never be false, why bother with it? If you think it can be false in some situation, would you explain how?

1 Like

Heat Jack, have you actually tried running your code?

Programming is an incremental process. You write some code, then run it,
see what the errors are, fix those errors, run it again, when there are
no more errors you write a bit more code, run the new code, fix those
errors, and so on.

If you think that programming goes:

• write some code
• it works perfectly the first time you run it

then you will be disappointed.

You are right, I missed the fact that you do call J. That wonât work:
your function J takes no arguments, but you are calling it with an
argument.

If you fix that, you have another error: J doesnât return a result that
you can iterate over.

If you fix that, you have another error: your attempt to insert an item
into a list wonât work, because you arenât calling the insert method
with the right number of arguments. You provide one argument, the method
needs two.

If you fix that, you have another error: you replace the list with the
special None value.

Iâm sure there are other issues, but thereâs a more fundamental problem.
You say:

âThis is cantors set, a topological statementâ

Nice! However:

• Python sets are not mathematical sets
• Python floats are not mathematical Real numbers
• Python ints are not mathematical integers

(although Python ints are closer to integers than the others).

You are not going to be able to experimentally test the truth of
statements about infinite sets like the Cantor Set using Python.

There are only 4607182418800017407 Python floats between 0 and 1, they
are not evenly spaced, and none of them are exactly divisible by 3.
4607182418800017407 might seem like a lot of numbers, but compared to
the uncountably infinite elements of the Cantor Set, its nothing.

You have a while loop:

``````while h >= float('inf') or h <= float('inf'):
``````

What possible h value do you imagine will be greater than infinity?

What possible h value do you imagine will be neither less than, equal
to, or greater than infinity?

1 Like

This is what I have so far
(Minus Stephens last post, which I am still in the process of comprehending)

``````#sentience

n = set()
i = set()
k = [n]
N = set()
m = set()
h = set()
x = []
q = 0
Q = []

while q <= float('inf'):
N = set(N)
q = q + 1
def J ():
Q = Q.insert(N)

for n in N:
a = set((k[n]) == k[n] in set(0, 1))

while len(x) >= float('inf') or len(x) <= float('inf'):
h = set(h)
m = set(m)
x = x.insert(h+1, h)
x = x.insert(m+1, m)
x = x.insert(h+1, i)

y = Q[float('inf')] is set(x in a == all(i) in J(len(x[i]) >= len(x[i+1]))

def p():
def T ():
X = 0
while X < 2:
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
X = X + 1

output = ""
while True:
l =11
while l  < 126:
l = l  + 1
a = chr(l)
p ()
v = p ()
if v == 1:
o = o + a
elif v == 0:
o = o
if o == o + "":
break
print () n
``````

block 6 seems to be broken

def p (): is a syntax errorâŚ

The error appears at X = X + 1 when the code is isolatedâŚ

1 Like
``````y = set()
def p():
def T ():
X = 0
while X < 2:
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
X = X + 1

``````

block 6 is clearly where to problem lies, as errors occur in block 6 when isolated from the rest of the code

1 Like

I deleted my text as it contained several errors. Sent it too fast.

1 Like

"So now N is a different set with one set as the content. Do you

really want that?"

I imagine that if Heat-Jack is trying to work with the fundamentals of

algebra, that is precisely what he wants: a set containing a set.

But thatâs not what Python will do.

``````>>> N = set([1, 2, 3, 4])

>>> print(N)

{1, 2, 3, 4}

>>> N = set(N)

>>> print(N)

{1, 2, 3, 4}
``````

In Python, calling set on a set argument just makes a copy of the

original set.

My guess is that Jack is thinking along the lines of the fundamental

definition of algebra, where we have

``````0 = the empty set {}

1 = the set containing one element, the empty set: {{}}

2 = the set containing two elements: {{}, {{}}}
``````

and so on. (Or something like that â Iâm too lazy to look it up to

check the details.)

Jack then has the code:

``````a = set((k[n]) == k[n] in set(0, 1))
``````

"So a is now a set containing `False`, if it werenât for the type error

in `set(0, 1)` . Is that really what you want?"

Thatâs not the only type error. Fixing this error:

``````set(0, 1)  # TypeError: set takes a single argument.
``````

will just reveal the next error:

``````set(False)  # TypeError: False is not iterable.
``````

Itâs not clear how to fix these errors in Jackâs code, because they are

conceptual errors: Python simply doesnât work the way he appears to

think it does. Python is not a language that operates with pure

mathematical concepts like the Real numbers and infinite sets.

We would need to understand what he is trying to do to fix them, if they

can be fixed.

1 Like

Heat Jack said:

âN is a compilation of set inclusions like it should beâ

No it isnât.

You have:

``````N = set()
q = 0

while q <= float('inf'):
N = set(N)
q = q + 1
``````

Letâs get rid of the infinite loop. Your loop will never finish, so all
the code following it will never be executed. But even if we make it a
little shorter, we can see that N will always be an empty list:

``````N = set()
q = 0
while q <= 5:
N = set(N)
print("N =", N)
q = q + 1
``````

That prints:

``````N = set()
N = set()
N = set()
N = set()
N = set()
N = set()
``````

Jack said:

âYour type error is coming up because you didnât assign a
table to k or did not assign a set to N or nâ

No, thatâs not correct:

``````>>> set(0, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: set expected at most 1 argument, got 2``````
1 Like

(post deleted by author)

Iâm getting a type error on this

``````N = set()
n = set()
k = [n]
for n in N:
a = set((k[n]) == k[n] in set(0, 1))
print(a)

``````

Itâs the second to last problem in my code

The last problem is how to reference [-1] with float(âinfâ)
Iâll post that after

Syntax and name errors are entirely resolvable at your end, normally.
But Iâll have a look.

You seem to have both spaces and TAB characters for indenting; that is
usually a bad mix. TABs are interpreted as 8 spaces of indent, but often
are not rendered that way, depending on your editor. You should use all
spaces or all TABs, and try not to mix them. Youâre using spaces almost
everywhere, so Iâd stick with spaces.

Youâve got TABs here:

``````while X < 2:
``````

and also on the line directly below it.

Fixing then (and guessing about your intent with the line above), the
first syntax error is line 44, âX = 0â. That is itself fine, so the
actual error is before that:

``````y = Q[float('inf')] is set(x in a == all(i) in J(len(x[i]) >= len(x[i+1]))
``````

Thereâs no closing â)â for the opening one in âset(â. The âJ(âŚ)â part
goes right to the end of the line. If (guessing again about your intent)
I put a closing bracket at the end, thus:

``````y = Q[float('inf')] is set(x in a == all(i) in J(len(x[i]) >= len(x[i+1])))
``````

you then have legal Python syntax. But other problems remain. Poinitng

``````% python3 -m pyflakes p1.py
p1.py:41:48 undefined name 'J'
p1.py:49:17 local variable 'X' defined in enclosing scope on line 44 referenced before assignment
p1.py:49:13 local variable 'X' is assigned to but never used
p1.py:63:16 undefined name 'o'
``````

Letâs a look:

``````p1.py:41:48 undefined name 'J'
``````

This is again the line above. Your programme defines no function named âJâ.

Then these:

``````p1.py:49:17 local variable 'X' defined in enclosing scope on line 44 referenced before assignment
p1.py:49:13 local variable 'X' is assigned to but never used
p1.py:63:16 undefined name 'o'
``````

are all the same issue from this code:

``````X = 0
def p():
def T():
while X < 2:
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
X = X + 1
``````

The first line defines âXâ in the global scope. Since you do not use âXâ
below this code, maybe âXâ was meant to be used only for the function
âTâ, which is the only place it is used. If so, you want this instead:

``````def p():
def T():
X = 0
while X < 2:
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
X = X + 1
``````

which defines âXâ in the local scope of âTâ.

What was happening before? You had defined an âXâ in the global scope.
It looked like you then wanted to use âXâ inside the T() function as a
counter. You might do that if you wanted to use âXâ later in the main
global programme. (This isnât a great way to do that - better to return
a value from the function.)

But Python has a feature about scopes that is not obvious to new
programmers: since you do not (normally) declare variables, how does
Python decide what scope holds the variable.

In functions, if the function assigns to a variable anywhere, then
variable is held to be a local variable. This lets you write:

``````def f():
x = 0
for i in range(4):
x = x + 2
return x
``````

and x is a local variable, affecting nothing outside the function. But
if you only use âXâ in the functionm Python looks for it in an outer
scope:

``````def f():
for i in range(4):
print(y)
``````

Here âyâ is not a local variable because it is never assigned to.

Your T() function assigns to âXâ, so thatâs local to T(). The âXâ in the
global scope is unaffected and unrelated.

Letâs go back to the modified function from your programme:

``````def p():
def T():
X = 0
while X < 2:
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
X = X + 1
``````

This still does not make a great deal of sense. Firstly, T() computed X
but never returns it. Maybe you did intend it to affect the global X?
You can do that like this:

``````X = 0

def p():
def T():
global X
while X < 2:
any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
X = X + 1
``````

which tells T() that âXâ is from the global scope, not the local scope
of the function.

There are other problems here:

The function T() is called only by itself. Functions can call
thenselves, but there should be something which make the initial call to
T(), otherwise it never runs at all. Nothing else calls T().

The function p() defines T() but never calls it. A function definition
is a local assignment, just like assigning to a variable, so T() is
known only inside p(). Nothing outside can use it.

Inside T(), this line:

``````any(y) in T(p(y).eq(0)) or all(y) in T(p(y).eq(1))
``````

just does some logical tests, not assigning the result to anything. It
does call T() and P() internally, so if they had side effects this might
result in something. But they donât.

This expression:

``````p(y).eq(0)
``````

might be intended to test of p(y)==0, but that it actually means is
âcall p(), then call the âeqâ method of what p() returnedâ. I doubt that
is what you intend.

Also, because p() has no explicit âreturnâ statement, it returns None.
None has no .eq() method.

Just looking at your code, I think youâre trying to do symbolic set
expressions. But Python functions are not thqt - they are procedural
actions. FOr example, writing:

``````any(y) in ....
``````

Means:

• call the any() function with âyâ; the Python âany()â function tests
where any of the values in it argument are true; it returns true if so
and false otherwise.
• takes the result of any(y) and tests if it in âinâ what follows. SO it
is taking a true or false value, and seeing if that value is in what
follows.

I do not think that is what you intended. I suspect you meant was âfind
values from y such that âŚâ. WHich you can do, but you donât write it
that way. You might write:

``````for y0 in y:
if y0 in ...:
do something with y0 here ...
``````

The largest âprogrammingâ problem with your code is that you have a
bunch of variable with single letter names and no comments at all
describing what their purpose is.

Others have pointed out various logic errors, such as expressions like:

``````len(x) >= float('inf')
``````

which can never be true (len(x) is an int, a finite integer).

Also, the larger test:

``````if len(x) >= float('inf') or len(x) <= float('inf'):
``````

is always true because the second part is always true. This is
probably not what you intend.

Cheers,
Cameron Simpson cs@cskk.id.au