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.Wed, 16 Aug 2023 15:58:20 +0200max_symbolic with assumptions?https://ask.sagemath.org/question/72595/max_symbolic-with-assumptions/I am in need of a symbolic engine for Python to calcultate max expressions. It is important that we can pass assumptions like "x is a positive symbol" and "y is greater than x" to the engine (the latter is why sympy does not suffice AFAIK).
I am currently testing sage and ran into some disappointing results... Am I doing something wrong here or is this sage's limit?
import sage.all as sage
x = sage.var('x')
y = sage.var('y')
myMax = sage.max_symbolic(x, 2*x)
print(sage.simplify(myMax)) # gives max(x, 2*x) as expected
sage.assume(x, 'integer')
sage.assume(x > 0)
print(sage.simplify(myMax)) # simplifies to 2*x (nice!)
sage.assume(y > 0)
sage.assume(y, 'integer')
myMax = sage.max_symbolic(x, y)
print(sage.simplify(myMax)) # gives max(x, y) as expected
sage.assume(y > x)
print(sage.simplify(myMax)) # now gives y (nice!)
print(sage.simplify(sage.max_symbolic(20*x, 20*y))) # gives 20*y (nice!)
print(sage.simplify(sage.max_symbolic(19*x, 20*y))) # gives max(19*x, 20*y)... why?
print(sage.simplify(sage.max_symbolic(19*x, 20*x))) # gives 20*x, so the above should be deducable
We tell sage that x and y are positive integers and that y > x. Sage can deduce that 20*y > 20*x (and also 20*x > 19*x), but it cannot deduce that 20*y > 19*x? :(
Do I need to do somehing differently or is this how things are in sage?
Thanks for the much appreciated help!new_to_sageWed, 16 Aug 2023 15:58:20 +0200https://ask.sagemath.org/question/72595/max_symbolic, polynomial expressions, assumptionshttps://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/ The following works as expected:
var('b')
with assuming(b>1):
v = max_symbolic(7*b-5,0).full_simplify()
print(v)
yields 7*b - 5
The following does not (maybe my expectations are unrealistic)
with assuming(b>1):
v = max_symbolic(b^2-b+1,0).full_simplify()
print(v)
yields max(0, b^2 - b + 1), even though the latter expression is always > 3/4
I have a bunch of expressions such as the one below, that I want to analyze, to get a piecewise-defined function:
print(myexpr,"\n\n")
print(myexpr.full_simplify(),"\n\n")
with assuming(a>2):
print(myexpr.full_simplify(),"\n\n")
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(5*a + 7, a^2 + 3*a + 3)
This is good, however:
with assuming(a>2000):
print(myexpr.full_simplify())
yields max(5*a + 7, a^2 + 3*a + 3)
Can such expressions, as above, in max_symbolic be converted into piecewise defined functions? (I would also be interested in having
more than one parameter, and having SAGE partition the parameter space appropriately and automatically).
JTSThu, 11 Mar 2021 13:39:33 +0100https://ask.sagemath.org/question/56120/find maximum value of Fhttps://ask.sagemath.org/question/53907/find-maximum-value-of-f/ F = (4*x+4*y+9*z-2*w),
G = (2*x+2*y +z+ w)==0,
H = (x^2+y^2+z-4)==0,
* x ,y, z, w is symbolic expressions in 4 variables.
* The symbolic expressions G and H represent constraints.
* find the maximum value of F , subject to the constraints G=0 and H=0 ?????????
* please help meDalin ArangaWed, 14 Oct 2020 11:45:51 +0200https://ask.sagemath.org/question/53907/Particular solve: find values of variables which will solve equation for any values of other variableshttps://ask.sagemath.org/question/35609/particular-solve-find-values-of-variables-which-will-solve-equation-for-any-values-of-other-variables/ Hi, this is my first time using Sage, so I hope my questions aren't too trivial.
I have to solve the following problem: find (if they exist) values of real variables x,u,v (with x,v>0) such that the following equality
Maximum{2 a/x, 2 (u*b + v*c)/(u^2 + v^2),
2 ((u - x)*(b - a) + v*c)/(v^2 + (u - x)^2)} = (a/x + c/v) + (1/v*x)*sqrt(
a^2 (u^2 + v^2) - 2 a*x*(b*u + c*v) + (b^2 + c^2)*x^2)
is verified for every value of the real values a, b, c.
It is my understanding that to evaluate the maximum I should use max_symbolic, am I right?
Let me emphasize that I don't need to find values of x,u,v with respect to a,b,c, but fixed values of x,u,v which will verify the equality for any given a,b,c. This means that I need to find x, u, v which will verify all the infinite equations we will get for any different triple of values of a, b, c.
For this reason writing
x,u,v,a,b,c=var('x u v a b c')
s1=solve([max_symbolic(2 a/x, 2*(u*b + v*c)/(u^2 + v^2), 2 ((u - x)*(b - a) + v*c)/(v^2 + (u - x)^2)) == (a/x + c/v) +(1/v*x)*sqrt(a^2 (u^2 + v^2) - 2 a*x*(b*u + c*v) + (b^2 + c^2)*x^2)],x,u,v)
show(s1)
will not work. I've thought of solving for all 6 variables, but then an error occurred saying solve() could only use 5 positional arguments..
Can you suggest me any way to proceed? Also, I fear this kind of computation will be very heavy for my cpu.. Any ideas on how to make It lighter?
Thank you very much!nibWed, 16 Nov 2016 12:12:07 +0100https://ask.sagemath.org/question/35609/max_symbolic and distributive law with multiplicationhttps://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/Minimum and maximum are distributive over multiplication of non-negative numbers, i.e., if a,b,c >= 0 then
a * max{ b, c } = max { ab, ac }
and the same works for min{}. How can I exploit this in sagemath? Consider the followiing:
n=5
x=var(['x_'+str(i+1) for i in range(n)])
# (x_1, x_2, x_3, x_4, x_5)
assume([x[i] >= 0 for i in range(n)])
assumptions()
# [x_1 >= 0, x_2 >= 0, x_3 >= 0, x_4 >= 0, x_5 >= 0]
This does **not** work as expected:
y = max_symbolic( x[4] * max_symbolic(x[0],x[1]), x[0] * max_symbolic(x[2],x[3]) )
# y == max(x_5*max(x_1, x_2), x_1*max(x_3, x_4))
simplify(y)
# max(x_1*max(x_3, x_4), x_5*max(x_1, x_2))
Simplify does not do the simplification I want it to do, which should yield
## max(max(x_1*x_3, x_1*x_4), max(x_5*x_1, x_5*x_2))
or even better
## max(x_1*x_3, x_1*x_4, x_5*x_1, x_5*x_2)
Needless to say, I have also tried `expand` and `full_simplify`. None of them does the trick.
So, I wonder, am I missing out on some other fancy function here, or is there a (hopefully easy) way to add a distributive law-feature to the max_symbolic function?BjornTue, 17 Mar 2015 06:12:56 +0100https://ask.sagemath.org/question/26214/Recursive max_symbolic???https://ask.sagemath.org/question/8921/recursive-max_symbolic/Hi
Over a (x,y) space, I have n functions resp f_1(x,y), f_2(x,y), ..., f_n(x,y) and I would like to create g(x,y) =max(f_1(x,y), f_2(x,y), ..., f_n(x,y), constant)
I now know it is possible to use max_symbolic with 2 functions, but then if I have say 100 of them, it gets clumpsy.
Does anyone know a way to do that?
ThankssagembTue, 24 Apr 2012 15:25:47 +0200https://ask.sagemath.org/question/8921/