Ask Your Question
0

piecewise defined function via def

asked 2018-02-11 03:39:46 +0100

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 11:33:02 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-02-12 18:51:58 +0100

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 16:57:02 +0100 )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-11 03:39:46 +0100

Seen: 578 times

Last updated: Feb 12 '18