Calling Functions using Default Values

I’ve gotten a lot of help (and criticism) from other users of this forum and I have one question left:

How do I run a function using default parameters?
What do I import?
How do I use it?

Thanks,
Oliver

If the function has default parameters, you can omit passing values for them unless you want different values to those defaults.

How have you been learning Python? Any decent book or tutorial should show you examples of functions with default parameters. For example: 4. More Control Flow Tools — Python 3.10.4 documentation.

i = 5

def f(arg=i):
    print(arg)

i = 6
f()

will print 5.

Interesting…

You know what? I forgot to call all the functions.
Thank you ndc

Edit: I’m getting an error saying it needs a positional argument (1)

What is the difference in what I am doing and what ndc posted?

In the following REPL example, foo is a required positional
parameter, while bar and baz have default values. We call the
function by passing positional values for foo (required) and bar
(overridden), but the function uses the default value for baz since
we don’t override that:

>>> def my_func(foo, bar='xyzzy', baz='quux'):
...     print(foo, bar, baz)
... 
>>> my_func('gralpy', 'plugh')
gralpy plugh quux

I’m using typing to say

def omniscience(  p : Ninf_map)
#omniscience()

It seems like ( p : Ninf_map) would work as default parameters

Why don’t they?

This is because your def f() block comes after i=5 and contains a local variable arg, which is assigned the value of i at that point.

Edit: Given the rest of this thread, this now seems to be out of context.

That’s the type of the parameter, not its default value.

Can the type of parameter be a default value?

Why? What are you actually trying to achieve? You’re not making any more sense than your other threads, despite being asked to ask clear questions.

As you’ve already been told, this omniscient thing is not possible. Perhaps you need to find a simpler project to work on?

No, typing and function parameter defaults are pretty much entirely
unrelated concepts.

Ok yeah that’s what I thought…

They aren’t even related about to have a mutual exclusion….

As for the context of the current discussion, it was initiated after my question, quoted below, that was posed within a previous discussion, I need an expert:

For the sake of completeness, here is a simple example of references to imported function definitions as default values for function parameters:

# source of the function definitions
import math 

# function, with references to imported functions as default values for its parameters
def sum_of_function_results(val, f1=math.sin, f2=math.cos, f3=math.tan):
    return f1(val) + f2(val) + f3(val)

print(sum_of_function_results(math.pi / 4))

Output:

2.414213562373095

However, it now appears that the OP might actually be interested in typing instead. If that be the case, see:

1 Like

We’ll I’m not sure where to start.
I have an algorithm made for me by Mark Dickinson that follows an LPO (with its input) Here. It is a decision making algorithm designed to reference (or in any case output) the “best” possible solution under any condition. It uses an indirect, but reliable pattern to make this output, and though not omniscient, can imitate it seamlessly.

The program has three parts, one of which, the function call, needs to be addressed in a proficient manner; it doesn’t make sense to use conventional arguments, but it is not suited for default value

Part one is the algorithm:

import typing
Ninf = typing.Callable[[int], bool]
Ninf_map = typing.Callable[[Ninf], bool]
def inj(k: int) -> Ninf:
 return lambda n: n < k
def eps(p : Ninf_map) -> Ninf:
 return lambda n: min(p(inj(k)) for k in range(n + 1))
def omniscience(  p : Ninf_map) -> typing.Optional[Ninf]:
 return None if p(x := eps(p)) else x

Part two is an output loop:

x = True
#replace with function call below

o = ""
while True:
 l = 11
 while l  < 126:
  l = l  + 1
  m = chr(l)
  #omniscience()
  if x:
   o = o + m
  else:
   o = o
 if o == o + "":
  break
print (o)
``

The third part is a function call, which so far has nothing to do with the equation:

i = 5

def f(arg=i):
print(arg)

i = 6
f()


As you can see the project is nearly finished, and hiding in some library is the answer to the question of how to call these functions.

The best possible solution to what question?

The best possible solution to each of these questions are different, and need different algorithms:

  • What is the trigonometric sine of 2.0 radians?

  • What is the square root of 45?

  • Is 27 divisible by 7?

  • What are the factors of 60?

I fear that you have been fooled by the “Omniscience” name into thinking that the Limited Principle of Omniscience is an algorithm to answer every possible question, or at least every possible question related to mathematics.

It really isn’t. It is a stupidly pretentious name for a principle of extremely narrow purpose, namely to prove by construction that either a proposition P is true, or it is not true.

So we ask again. What specific problem are you trying to solve?

In Python, default values are bound to the function parameter when the function is created. This is called early binding, as opposed to late binding (when the default value isn’t evaluated until it is needed).

When you have this function:


value = 5



def f(arg=value):

    print(arg)

when the interpreter creates the function f(), it looks up the name “value” to get its current value, and squirrels that value away somewhere deep inside the function for later use.

Once that is done, the function f() never again looks at or cares about the variable value. So you can change the variable, or delete it, and f() with no arguments will always print 5.

If you want the function to delay evaluation of the global variable until it is needed, you can write this instead:


value = 5



def f(arg=None):

    if arg is None:

        arg = value

    print(arg)

1 Like

Wikipedia: Limited principle of omniscience states:

LPO : For any sequence a0, a1, … such that each ai is either 0 or 1, the following holds: either ai = 0 for all i , or there is a k with ak = 1.

The limited principle of omniscience can be used to confirm or refute statements that make claims about all elements within an infinite series, when an element is found within the series that either confirms or refutes the claim. However, the principle is nowhere near as powerful a device as the term omniscience suggests. The term limited is perhaps more applicable there than is the term omniscience.

A lot of people seem to be missing the point of the generic convergent sequence

LPO is trivial
(Without the generic convergent sequence)

I did mention that it was indirect…

Basically the GCS sees whether the upmost certainty is x and if it is, it outputs a letter correspondent to x

If that correspondence is of the upmost certainty, the GNC says “ooh! I must be true” and outputs the value

Why does “omniscience( p : Ninf_map)” not have a default value?