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

Thanks for the heads up about “h”
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.

You ask:

“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’)

Sorry about the confusion

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.

Some other comments:

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?

2 Likes

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. :roll_eyes:

1 Like

Menno asked:

"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))

and Manno asks:

"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

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
pyflakes at your programme:

% 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

Incorrect usage of scope

Wow Cameron you really know what you’re taking about. Can I get examples of these things in proper coding?

It’d really speed things up