First time here? Check out the FAQ!

Ask Your Question
0

piecewise defined function via def

asked 7 years ago

anonymous user

Anonymous

I've made the following experiment with Sage:

    def f(x):

        if (0<= x<= 1/2):
            return 1
        else:
            return 0 
assume(0<= x<= 1/2)  
show(f(x))  
show(f(1/3))

However I get outputs 0 and 1 respectively. Can someone clarify please? Thanks.

Preview: (hide)

Comments

tmonteil gravatar imagetmonteil ( 7 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 7 years ago

nbruin gravatar image

Looks like double inequalities aren't parsed properly by "assume":

sage: assume(0<= x<= 1/2)
sage: bool(0<=x<=1/2)
False
sage: assume(0<=x)
sage: assume(x<=1/2)
sage: bool(0<=x<=1/2)
True
Preview: (hide)
link

Comments

1

Note that assume does not parse anything, it takes a symbolic expression that silently fails, see my answer to the duplicate question

tmonteil gravatar imagetmonteil ( 7 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 7 years ago

Seen: 754 times

Last updated: Feb 12 '18