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.Mon, 20 Nov 2023 16:31:33 +0100What is the algorithm used for polyhedra intersection?https://ask.sagemath.org/question/74396/what-is-the-algorithm-used-for-polyhedra-intersection/ What is the algorithm used for polyhedra intersection and what is its time complexity?
Is the algorithm based on a research paper? If so, which one?muha123Mon, 20 Nov 2023 16:31:33 +0100https://ask.sagemath.org/question/74396/Finding subset of lists with common entrieshttps://ask.sagemath.org/question/65732/finding-subset-of-lists-with-common-entries/ Suppose I have a list of lists. For example,
[ [1, 2, 3, 4], [1, 3, 1, 3], [4, 1, 4, 1], [1, 3, 2, 1], [4, 1, 2, 4] ]
I want SageMath to give me a sub-list of this list that consist of lists where any two have at least one common entry. For example,
[ [1, 2, 3, 4], [1, 3, 1, 3], [1, 3, 2, 1] ]
or
[ [4, 1, 4, 1], [1, 3, 2, 1], [4, 1, 2, 4] ] .
What would be even more amazing is if SageMath could find the largest possible such sub-list. How could I get SageMath to do this? Thank you in advance!merluzaWed, 04 Jan 2023 19:32:45 +0100https://ask.sagemath.org/question/65732/Why am I getting a type error when I attempt to take the projective closure of this intersection?https://ask.sagemath.org/question/56448/why-am-i-getting-a-type-error-when-i-attempt-to-take-the-projective-closure-of-this-intersection/I am attempting to take the projective closure of the intersection of the following affine polynomials (not the intersection of the closure!):
$$y^3-y-x^2= 0 $$
$$w^3-w+y^7-y^5-x^4y^3+x^4y = 0.$$
This affine intersection is a curve of dimension one. Unfortunately, I haven't been able to enter this lovely affine curve defined by this intersection into sage. When I attempt as follows:
A.<x,y,w> = AffineSpace(QQ, 3)
P.<u,v,t,s>=ProjectiveSpace(QQ,3)
C = Curve([y^3-y-x^2, w^3-w+y^7-y^5-x^4*y^3+x^4*y], A)
D=C.projective_closure(1,P)
I get an error at the definition of C due to the second polynomial:
TypeError: F (=[-x^4*y^3 + y^7 + x^4*y - y^5 + w^3 - w]) must be a list or tuple of polynomials of the coordinate ring of A (=Affine Space of dimension 3 over Finite Field of size 3)
I am so confused because this is absolutely in the coordinate ring of $A$. Why am I getting this type error? How can I enter this affine intersection into sage, so that I may take its closure?
_______________
As an aside, I can enter the intersection of the closure, which is not what I want, as follows:
x,y,z,w = GF(3)['x,y,z,w'].gens()
C = Curve([y^3-y*z^2-x^2*z, w^3*z^4-w*z^6+y^7-y^5*z^2-x^4*y^3+x^4*y*z^2]); C
The intersection of the closure has an extra irreducible component $[x: 0: w: 0]$,
tzeentchThu, 01 Apr 2021 05:08:59 +0200https://ask.sagemath.org/question/56448/plot of sine, parabola intersection works but solve makes no sensehttps://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/When I plot a sine and parabola I get two obvious intersections
plot(x^2-5,-10,10,ymax=20) + plot(sin(x),-10,10)
But when I solve to get the two numeric x values, the answer makes no sense.
solve(x^2-5==sin(x),x)
[x == -sqrt(sin(x) + 5), x == sqrt(sin(x) + 5)]
![image description](/upfiles/16030024791456171.png)cybervigilanteSun, 18 Oct 2020 08:14:31 +0200https://ask.sagemath.org/question/53958/plotted real intersection but solve only shows imaginaryhttps://ask.sagemath.org/question/53835/plotted-real-intersection-but-solve-only-shows-imaginary/I plotted `x^3 - x` and its derivative `3*x^2 - 1` to get two intersections in the real plane.
plot([x^3-x,3*x^2 - 1],-3,3,color=['blue','green'],legend_label=["f","derivative"])
![intersection](/upfiles/16024461625093012.png)
However, when I solved the two with `solve(x^3-x == 3*x^2 - 1, x)`, all I get are imaginary values.
solve(x^3-x == 3x^2 - 1,x)
[x == -1/2*(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3)*(I*sqrt(3) + 1) - 2/3*(-I*sqrt(3) + 1)/(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 1, x == -1/2*(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3)*(-I*sqrt(3) + 1) - 2/3*(I*sqrt(3) + 1)/(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 1, x == (1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 4/3/(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 1]
Shouldn't `solve` show me the two intersections or am I disastrously confused?cybervigilanteSun, 11 Oct 2020 21:39:24 +0200https://ask.sagemath.org/question/53835/Set-Intersection Iterationhttps://ask.sagemath.org/question/53246/set-intersection-iteration/Suppose I have two sets with integral elements $A$ = {$a_1, a_2, ... , a_n$} and $B$ = {$b_1, b_2, ... , b_m$}, the cardinalities of which are arbitrarily large, and $a_n > a_{n - 1} > a_{n - 2} > ... > a_1$ and $b_m > b_{m - 1} > b_{m - 2} > ... > b_1$ with $n$ ≠ $m$. Suppose, also, that the intersection of sets $A$ and $B$ is the singleton set {$c$}, and there exists an index $i$ such that $b_{i + 1} > a_n > b_i > b_{i - 1} > ... > b_1$ where $a_n = \sup(A)$.
I want to create a for-loop iteration (or whatever the best approach might be!) that finds the set intersection without generating all the elements of both sets and then determining the set {$c$}. (This is possible because the generating functions I've created yield explicit formulas I can use to calculate specific elements of both sets.)
I wrote some basic code in Sage to calculate elementary set intersection, but for even moderately large cardinalities, the halt time was incredibly long. I'm thinking the following approach might be faster, but I don't know how to write the program using for-/while-loops and if/else constructions (or even if I should do so):
(1) Check if $a_{n - 1}$ ≤ $b_i$. If $a_{n - 1} > b_i$, keep checking conterminous decreasing indices for elements of $A$ (i.e., $a_{n - 2}$, $a_{n - 3}$, etc.) until $a_j$ ≤ $b_i$ for some index $j < n - 1$. If $a_j = b_i$, break and print($a_j$). If not, go to step (2).
(2) When $a_j < b_i$, check conterminous decreasing indices for elements of $B$ (i.e., $b_{i - 1}$, $b_{i - 2}$, etc.) until $a_j$ ≥ $b_k$ for some index $k < i$. If $a_j = b_k$, break and print($b_k$). If not, go to step (3).
(3) Repeat the process in steps (1) and (2) until $a_r = b_s$ for some indices $r$ ≠ $s$; then, break and print($b_s$).
Thanks in advance.u220eTue, 01 Sep 2020 01:38:15 +0200https://ask.sagemath.org/question/53246/intersection of two free submoduleshttps://ask.sagemath.org/question/49966/intersection-of-two-free-submodules/ I have two modules found as follows
F=GF(2);R.<x,y,z> = PolynomialRing(F)
f1 = 1+z;g1=1+y;h1=0;
I1 = Ideal([f1,g1,h1])
M1 = I1.syzygy_module(); M1
[ 0 0 1]
[y + 1 z + 1 0]
F=GF(2);R.<x,y,z> = PolynomialRing(F)
f2 = 0;g2=1+y;h2=1+x;
I2 = Ideal([f2,g2,h2])
M2 = I2.syzygy_module(); M2
[ 1 0 0]
[ 0 x + 1 y + 1]
Is it possible to find the intersection of two such submodules $M_1$ and $M_2$ in sage? Another possibility would be to find the syzygy of the module generated by vectors (f1,g1,h1) and (f2,g2,h2). arpitTue, 18 Feb 2020 19:30:48 +0100https://ask.sagemath.org/question/49966/Intersection of polynomial Ideals over $\mathbb{R}$https://ask.sagemath.org/question/46258/intersection-of-polynomial-ideals-over-mathbbr/I am trying to compute the intersection of Ideals over $\mathbb{R}[x,y]$, but I get problems from the coefficient $\frac{1}{\sqrt{2}}$. This is my code:
R.<x,y>=PolynomialRing(RR,order='lex')
I=Ideal([(x^2+y^2-1),(x*y),(y^3-y)])
I5=Ideal([x-1/sqrt(2),y-1/sqrt(2)])
I6=Ideal([x+1/sqrt(2),y-1/sqrt(2)])
I7=Ideal([x+1/sqrt(2),y+1/sqrt(2)])
I8=Ideal([x-1/sqrt(2),y+1/sqrt(2)])
J=I.intersection(I5,I6,I7,I8)
and this is the error I get:
TypeError: Intersection is only available for ideals of the same ring.
So when I ask if
I5 in R
the answer is False. I also tried with QQbar but same result, can someone explain this?
Thanks!
EDIT: I also tried with $\frac{\sqrt{2}}{2}$ instead of $\frac{1}{\sqrt{2}}$ and I get the same error.LeghThu, 18 Apr 2019 17:29:09 +0200https://ask.sagemath.org/question/46258/Trouble finding intersection of two functionshttps://ask.sagemath.org/question/44019/trouble-finding-intersection-of-two-functions/ Hi all,
I'm still pretty new using SageMath, but I'm trying to duplicate functionality that I've been able to do in wolfram alpha
Wolfram Input:
Intersection points of [//math:90000 1.03^x//] and [//math:63000 1.095^x//]
So far I've been able to recreate and graph these functions very easily using SageMath, but I'm having a difficult time using the solve function to actually return a numerical value for the intersection point itself.
My SageMath code looks like:
x = var('x')
f1 = (63000*((1.095)^x))
f2 = (90000*((1.03)^x))
ans=solve(f2==f1,x)
print ans
print n(ans[0].rhs())
ans prints as
"[
219^x == 1/35*200^(x - 1)*103^x*100^(-x + 2)
]"
And I get an error "TypeError: cannot evaluate symbolic expression numerically" in my attempts to resolve it to an approximate number.
Can anyone tell me what I'm doing wrong?lgushurstMon, 22 Oct 2018 07:51:55 +0200https://ask.sagemath.org/question/44019/Finding intersection of two lists?https://ask.sagemath.org/question/36829/finding-intersection-of-two-lists/Hello, guys. First of all, I'm very new to Sage and also to this forum, so please be generous for my question...
So, suppose we have
c=[[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 3, 4], [0, 2, 3, 4], [1, 2, 3, 4]],
d=[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4], [9, 8, 7, 6]]
I would like to get
[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4]]
which is intersection of c and d. Is there a way to do this?
Thank you for any help.sssageeeeSat, 04 Mar 2017 21:48:54 +0100https://ask.sagemath.org/question/36829/Plot the intersection of two surfaces (or solutions of a system of eqs)https://ask.sagemath.org/question/33418/plot-the-intersection-of-two-surfaces-or-solutions-of-a-system-of-eqs/ Hi everybody,
I'd like to plot the solutions of the system
$$(X + Y )(X − Z^3)=0,$$
$$XY + Y^2=0.$$
in 3D, I mean, the set of points (X,Y,Z) in IR^3 that verify the system. I don't know how to do it. I was searching how to plot the intersection of both surfaces, but neither I could. ¿Could anyone tell me how to do it?
Thanks in advanceMinkowskiMon, 16 May 2016 18:03:59 +0200https://ask.sagemath.org/question/33418/Constructing subgroups by intersectionhttps://ask.sagemath.org/question/25955/constructing-subgroups-by-intersection/ I'd like to construct a subgroup of $Sp\left(4,\mathbb{Z}\right)$ of the form:
$$G_0\left(N\right) = M\left(N\right)
\cap {Sp}\left(4,\mathbb{Z}\right)$$
where $M\left(N\right)$ is a $4\times4$ matrix over the integer ring with elements that are multiples of the integer $N$. I think I know how to construct such an $M\left(N\right)$ for a given $N$, but how does one then construct such a subgroup $G_0\left(N\right)$? Thanks!JimereeFri, 27 Feb 2015 19:03:03 +0100https://ask.sagemath.org/question/25955/curves in a plane, find intersecting points?https://ask.sagemath.org/question/24353/curves-in-a-plane-find-intersecting-points/can anyone please help???
Let n be your ID number and consider the curves in the plane R2 that are defined by the equations, y2 = x3 − nx and xy = 1. At how many points do these curves intersect?fionaTue, 30 Sep 2014 23:49:15 +0200https://ask.sagemath.org/question/24353/Error intersecting polyhedrahttps://ask.sagemath.org/question/10202/error-intersecting-polyhedra/I have a dictionary of polyhedra which I want to consider various intersections and unions of. For now, my dictionary has four polyhedra in it. When running the following for loop:
v={} # contains coordinates of the tetrahedron, centered at (0,0,0)
v[1] = vector([1,0,-1/sqrt(2)])
v[2] = vector([-1,0,-1/sqrt(2)])
v[3] = vector([0,1,1/sqrt(2)])
v[4] = vector([0,-1,1/sqrt(2)])
V = {1,2,3,4}
b={} # will contain coordinates of vertices of the subdivision of the tetrahedron
for X in powerset(V):
q = len(X)
if q > 0:
b[tuple(X)] = (1/q)*sum([v[i] for i in X])
poly_int = Polyhedron([b[key] for key in b.keys()]) # this is a tetrahedron containing
# all of my polyhedra
for i in [1,2,3,4]:
poly_int = poly[i] & poly_int
I get a very nasty error:
AttributeError: 'Polyhedra_RDF_cdd_with_category.element_class'
object has no attribute '_Vrepresentation'
(The traceback for the error is quite long. I can include it if needed.)
Manually computing
poly[1] & poly[2] & poly[3] & poly[4]
gives the same error. HOWEVER, if instead I compute
(poly[1] & poly[2]) & (poly[3] & poly[4])
I get no errors. While this is a fine workaround for this particular case, I'm scripting these intersections and need some way to actually compute these intersections automatically. Using something like
poly[1].intersection(poly[2]) # etc.
doesn't help either. Any thoughts?BillThu, 06 Jun 2013 17:13:30 +0200https://ask.sagemath.org/question/10202/Intersection of a line and a planehttps://ask.sagemath.org/question/9855/intersection-of-a-line-and-a-plane/Hi,
I have a line described by points (1, 0, 1), (4, -2, 2) and a plane x + y + z = 6. If solve by hand I get the point of intersection as (7, -4, 3). But in sage, I don't find any intersection point. My code in sage is as follows:
P = Polyhedron(eqns=[(-6,1,1,1)])
L = [[1, 0, 1], [4, -2, 2]]
L1 = Polyhedron(L)
intersect = L1.intersection(P)
Output is "The empty polyhedron in QQ^3". Whats wrong here? my calculation by hand or my code?
assadabbasiWed, 27 Feb 2013 00:03:37 +0100https://ask.sagemath.org/question/9855/Intersection of a hyperplane with a polytope (intersection in 9D)https://ask.sagemath.org/question/9829/intersection-of-a-hyperplane-with-a-polytope-intersection-in-9d/Hi,
I have a hyperplane given by equation:
2/3*x1 + 2/3*x2 + 2/3*x3 - 1/3*x4 - 1/3*x5 - 1/3*x6 - 1/3*x7 -1/3*x8 - 1/3*x9 = 1
and a polytope with nine vertices:
P = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [-8/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9, 1/9], [-7/9, -7/9, 2/9, 2/9, 2/9, 2/9, 2/9, 2/9, 2/9], [-2/3, -2/3, -2/3, 1/3, 1/3, 1/3, 1/3, 1/3, 1/3], [-5/9, -5/9, -5/9, -5/9, 4/9, 4/9, 4/9, 4/9, 4/9], [-4/9, -4/9, -4/9, -4/9, -4/9, 5/9, 5/9, 5/9, 5/9], [-1/3, -1/3, -1/3, -1/3, -1/3, -1/3, 2/3, 2/3, 2/3], [-2/9, -2/9, -2/9, -2/9, -2/9, -2/9, -2/9, 7/9, 7/9], [-1/9, -1/9, -1/9, -1/9, -1/9, -1/9, -1/9, -1/9, 8/9]]
Each vertex in this polytope is connected to other eight vertices with a line.
I have tried with the following approach but I am unable to get the correct result.
First I created a polyhedron from the equation of the hyperplane as follows:
Hplane1 = Polyhedron(eqns=[(-3,2,2,2,-1,-1,-1,-1,-1,-1)])
Next I used this code to find the intersection between hyperplane and the line connected by every two vertices of the Polytope 'P'
for j in range(len(P)):
for i in range(len(P)):
if i != j:
a = Polyhedron( vertices = [P[i], P[j]])
b = a.intersection(Hplane1)
print(b)
I know the this hyperplane and the polytope have some intersection points but I am unable to calculate them. Any help/suggestion will be highly appreciated.
ThanksassadabbasiFri, 22 Feb 2013 00:27:14 +0100https://ask.sagemath.org/question/9829/Intersection of a Cube with two planes and resulting polyhedronhttps://ask.sagemath.org/question/9818/intersection-of-a-cube-with-two-planes-and-resulting-polyhedron/Hi,
I am new to sage and trying to solve a problem where I have two planes cutting a cube. How can I find the resulting polytope/polyhedron as a result of this cut.
cube = polytopes.n_cube(3)
cube.Hrepresentation()
plane1 = Polyhedron(eqns=[(0,1,0,0)])
plane2 = Polyhedron(eqns=[(1,0,0,-1)])
Please also tell me that what is meant by `eqns=[(0,1,0,0)]` in sage? what equality it represent? similarly `eqns=[(1,0,0,-1)]` ?
Thanks
assadabbasiTue, 19 Feb 2013 00:21:51 +0100https://ask.sagemath.org/question/9818/