Ask Your Question
0

piecewise defined function via def

asked 2018-02-10 20:39:46 -0500

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.

edit retag flag offensive close merge delete

Comments

tmonteil gravatar imagetmonteil ( 2018-02-13 04:33:02 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-12 11:51:58 -0500

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
edit flag offensive delete link more

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 ( 2018-02-13 09:57:02 -0500 )edit

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: 2018-02-10 20:39:46 -0500

Seen: 66 times

Last updated: Feb 12