Ask Your Question

wwang314159's profile - activity

2022-07-11 13:16:04 +0200 received badge  Famous Question (source)
2021-04-23 11:22:24 +0200 received badge  Notable Question (source)
2020-12-19 01:57:58 +0200 received badge  Popular Question (source)
2020-04-26 22:51:48 +0200 received badge  Scholar (source)
2020-04-26 22:51:46 +0200 received badge  Supporter (source)
2020-04-26 22:16:38 +0200 received badge  Student (source)
2020-04-24 21:54:41 +0200 asked a question How to ask the user for legal inputs?

Suppose we have the following code for the Taylor expansion.

 @interact
def Taylor(
    f = input_box(default=e^x ),
    n = slider(vmin=0, vmax=10, step_size=1, default=3, label="Select the order n: ")):
    print (f, " = " , f.taylor(x, 0, n))

Then we will get a Sage Interact. We can change the function e^x to any function of x and get the Taylor expansion.

However if we input something like e^y, we will get an error from Sage.

Is there some way that we can modify the code so that if someone input something which is not a function of x, it will print "illegal input" instead of returning an error?

More generally, if I require the input to be an element of a polynomial ring, for example Q[x,y,z], then how to ask Sage to print "illegal input" if someone input something like t^2.