-- MATH 531 -- Sept 20 -- Area formulas for polygons -- lab3.m2 -- Heron's formula R = QQ[x,y,a,b,c,S, MonomialOrder=>Eliminate 2] -- Let our triangle with sides of lengths a,b,c -- have vertices at A=(0,0),B=(a,0), and C=(x,y) I = ideal {x^2+y^2-c^2, -- |AC| = c (x-a)^2+y^2-b^2, -- |BC| = b 4*S^2 - y^2*a^2} -- 2S = |ya| G = gb I -- Grobner basis is a separate type in M2 transpose gens G -- "gens G" makes a matrix containing the elements of G M = selectInSubring(1, gens G) -- select elements in the subring QQ[a,b,c,S] << "S^2 = " << 1/16*factor(-M_(0,0)+16*S^2) -- Computing the image of a polynomial map: -- let f(t) = (t^2,t^3,t^5) be a map from k->k^3 R = QQ[t,x,y,z, MonomialOrder=>Eliminate 1] I = ideal {x-t^2, y-t^3, z-t^5} -- the graph of f (in k^4 = k^1 X k^3) is the variety V(I) selectInSubring(1, gens gb I) -- its projection onto k^3, the variety V(I_1), is the image of f -- Pythagorean theorem: -- you might have heard of it... R = QQ[x,y,a,b,c, MonomialOrder => Eliminate 2] I = ideal {a*b-(c-x)*y-x*y, a*y-(c-x)*b, a*x-y*b} selectInSubring(1, gens gb I) factor oo_(0,0) -- Area of a cyclic quadrilateral: -- Consider a quadrilateral with sides a,b,c,d inscribed in a circle. -- Make extra assumptions: let the circle be centered at (0,0) and of radius r , -- and let the vertices be A=(r,0), B=(x_1,y_1), C=(x_2,y_2), D=(x_3,y_3). restart R = QQ[x_1..x_3,y_1..y_3,r,a,b,c,d,S, MonomialOrder=>Eliminate 7]; I = ideal apply(1..3,i->x_i^2+y_i^2-r^2) -- B,C,D are on the circle I = I + ideal{ -- one equation per side (x_1-r)^2+y_1^2-a^2, (x_2-x_1)^2+(y_2-y_1)^2-b^2, (x_3-x_2)^2+(y_3-y_2)^2-c^2, (x_3-r)^2+y_3^2-d^2 } matrix{{r,0},{x_1,y_1},{x_2,y_2},{x_3,y_3}} minors(2,oo) -- the ideal generated by all 2x2 minors gens oo entries oo l = flatten oo I = I + ideal{(l#0+l#2-l#3+l#5)^2-4*S^2} -- 4S = |the sum of certain minors| gbTrace 3 -- monitor the progress of "gb" time G = gb I; -- use "time" to read the timing selectInSubring(1,gens G) f = oo_(0,0) ff = factor f -- we get 2 factors -- ff is a "Product" expression, its zeroth operand ff#0 -- is a nontrivial expression as well, but the zeroth operand of f#0 -- is a polynomial factor(-ff#0#0+16*S^2) -- this implies the generalized Heron's formula factor(-ff#1#0+16*S^2) -- here is another formula for the area of -- the self-intersecting quadrilateral