ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 21 Jul 2017 18:23:17 +0200Piecewise Symbolic Function with Conditional Statementhttps://ask.sagemath.org/question/38347/piecewise-symbolic-function-with-conditional-statement/I wish to incorporate a conditional Python expression (`if ... else ...`) in a symbolic function.
Suppose I have a piecewise function *k(n)* defined for *n* = 1,2,3... as in the following pseudocode:
k(n) =
2 if n = 1
n otherwise
I compose this with another function *g(x)* and wish to integrate the result. For example,
f(x)=g(x)/k(n)
f(n=...).integrate(x, 0, 1)
How can implement a non-evaluating conditional in a symbolic Sage function?terrygarciaFri, 21 Jul 2017 18:23:17 +0200https://ask.sagemath.org/question/38347/assume certain properties of the output of a functionhttps://ask.sagemath.org/question/33865/assume-certain-properties-of-the-output-of-a-function/Hi,
I've just started using SAGE and I want to "declare" a symbolic function *f(t)* and to be able to hint that *f(t) > 5* && *f(t) < 100*, for any value of *t* (the values are just for the purpose of example).
I know I can use assume for variables, but it seems it doesn't also work on functions, so I'm trying to see what alternatives I have left.
I have thought of "defining" the function f(t), with some mock values which don't contradict my assumptions(I don't actually know f(t), I only know some of it's properties), but I'm not sure how to force sage not to expand the function. I have tried *f(t, hold=True)* but it didn't seem to work(while this works for the default functions like sin).
Edit:
Upon the comment made by @eric_g I add the following information:
f = function('f') ; t = var('t')
(f(t) > 4).assume()
assume(f(3)>5)
assume(t>1)
assume(f(t)>5)
print(assumptions())
print('a) bool(f(3)>5) : '+str(bool(f(3)>5)))
print('b) bool(f(3)>4) : '+str(bool(f(3)>4)))
print('c) bool(f(2)>5) : '+str(bool(f(2)>5)))
print('d) bool(f(t)>5) : '+str(bool(f(t)>5)))
Output
[f(t) > 4, f(3) > 5, t > 1, f(t) > 5]
a) bool(f(3)>5) : True
b) bool(f(3)>4) : False
c) bool(f(2)>5) : False
d) bool(f(t)>5) : False
Two things puzzle me:
- How to get "c)" and "d)" to return true
- While "a)" returns true probably due to the second assumption, I would expect "b)" to also be true
Is the behavior I'm seeing incorrect, or am I just using SAGE wrong?
Thanks
twosanTue, 21 Jun 2016 00:11:32 +0200https://ask.sagemath.org/question/33865/