Ticket #3431: trac3431-qepcad-interface-part2.patch

File trac3431-qepcad-interface-part2.patch, 5.7 kB (added by cwitty, 5 months ago)
  • a/sage/interfaces/qepcad.py

    old new  
    208208with.  We'll start by finding a point on our ellipse. 
    209209 
    210210sage: p = qepcad(ellipse == 0, solution='any-point'); p 
    211 {'y': [0.96850196850295267 .. 0.96850196850295279], 'x': [-1.4685019685029528 .. -1.4685019685029525]
     211{'y': 0.9685019685029527?, 'x': -1.468501968502953?
    212212 
    213 (Note that despite appearances, these are really exact numbers.) 
     213(Note that despite the decimal printing and the question marks, these 
     214are really exact numbers.) 
    214215 
    215216We can verify that this point is a solution.  To do so, we create 
    216217a copy of ellipse as a polynomial over QQ (instead of a symbolic  
     
    223224For cell-points, let's look at points \emph{not} on the ellipse. 
    224225 
    225226sage: pts = qepcad(ellipse != 0, solution='cell-points'); pts 
    226 [{'y': 0, 'x': 4}, {'y': 1, 'x': [2.4685019685029523 .. 2.4685019685029528]}, {'y': -9, 'x': [2.4685019685029523 .. 2.4685019685029528]}, {'y': 9, 'x': 1/2}, {'y': -1, 'x': 1/2}, {'y': -5, 'x': 1/2}, {'y': 3, 'x': [-1.4685019685029528 .. -1.4685019685029525]}, {'y': -1, 'x': [-1.4685019685029528 .. -1.4685019685029525]}, {'y': 0, 'x': -3}] 
     227[{'y': 0, 'x': 4}, {'y': 1, 'x': 2.468501968502953?}, {'y': -9, 'x': 2.468501968502953?}, {'y': 9, 'x': 1/2}, {'y': -1, 'x': 1/2}, {'y': -5, 'x': 1/2}, {'y': 3, 'x': -1.468501968502953?}, {'y': -1, 'x': -1.468501968502953?}, {'y': 0, 'x': -3}] 
    227228 
    228229For the points here which are in full-dimensional cells, QEPCAD has the 
    229230freedom to choose rational sample points, and it does so. 
     
    239240sage: F = qf.exactly_k(3, y, circle * ellipse == 0); F 
    240241(X3 y)[(y^2 + x^2 - 3) (y^2 + 2 x y + y + 3 x^2 - x - 7) = 0] 
    241242sage: pts = qepcad(F, solution='all-points'); pts 
    242 [{'x': [1.7320508075688771 .. 1.7320508075688775]}, {'x': [1.7310549134625334 .. 1.7310549134625338]}, {'x': [0.67891138420800389 .. 0.67891138420800401]}, {'x': [-0.94177273774171678 .. -0.94177273774171665]}, {'x': [-1.4681935599288210 .. -1.4681935599288207]}, {'x': [-1.4685019685029528 .. -1.4685019685029525]}] 
     243[{'x': 1.732050807568878?}, {'x': 1.731054913462534?}, {'x': 0.6789113842080040?}, {'x': -0.9417727377417167?}, {'x': -1.4681935599288208?}, {'x': -1.468501968502953?}] 
    243244 
    244245Since $y$ is bound by the quantifier, the solutions only refer to $x$. 
    245246 
     
    248249sage: pt = pts[0] 
    249250sage: pcombo = QQ['x,y'](circle * ellipse) 
    250251sage: intersections = pcombo(y=polygen(AA, 'y'), **pt); intersections 
    251 y^4 + [4.4641016151377543 .. 4.4641016151377553]*y^3 + [0.26794919243112269 .. 0.26794919243112276]*y^2 
     252y^4 + 4.464101615137755?*y^3 + 0.2679491924311228?*y^2 
    252253 
    253254and verify that it does have three roots: 
    254255 
    255256sage: intersections.roots() 
    256 [([-4.4032490056009586 .. -4.4032490056009576], 1), ([-0.060852609536796533 .. -0.060852609536796525], 1), ([0.00000000000000000 .. 0.00000000000000000], 2)] 
     257[(-4.403249005600958?, 1), (-0.06085260953679653?, 1), (0, 2)] 
    257258 
    258259Let's check all six solutions. 
    259260 
     
    407408as \sage algebraic real numbers. 
    408409 
    409410sage: c.sample_point() 
    410 (0, [1.7320508075688771 .. 1.7320508075688775]
     411(0, 1.732050807568878?
    411412sage: c.sample_point_dict() 
    412 {'y': [1.7320508075688771 .. 1.7320508075688775], 'x': 0} 
     413{'y': 1.732050807568878?, 'x': 0} 
    413414 
    414415We've seen that we can get cells using the \method{cell} method. 
    415416There are several QEPCAD commands that print lists of cells; we can 
     
    10101011 
    10111012        EXAMPLES: 
    10121013            sage: qe = qepcad(x^2 < 0, interact=True) # optional 
    1013             sage: len(qe.trait_names()) # optional 
    1014             95 
     1014            sage: len(qe.trait_names()) # optional, random 
     1015            97 
    10151016            sage: 'd_cell' in qe.trait_names() # optional 
    10161017            True 
    10171018        """ 
     
    14871488    Return a string containing the current QEPCAD version number. 
    14881489 
    14891490    EXAMPLES: 
     1491        sage: qepcad_version() # optional, random 
     1492        'Version B 1.48, 25 Oct 2007' 
     1493 
     1494    TESTS: 
    14901495        sage: qepcad_version() # optional 
    1491         'Version B 1.48, 25 Oct 2007
     1496        'Version B ..., ...
    14921497    """ 
    14931498    banner = str(qepcad_banner()) 
    14941499    lines = banner.split('\n') 
     
    20382043    EXAMPLES: 
    20392044        sage: from sage.interfaces.qepcad import _eval_qepcad_algebraic 
    20402045        sage: x = _eval_qepcad_algebraic('the unique root of 8 x^2 - 8 x - 29 between -47/32 and -1503/1024'); x 
    2041         [-1.4685019685029528 .. -1.4685019685029525] 
     2046        -1.468501968502953? 
    20422047        sage: 8*x^2 - 8*x - 29 == 0 
    20432048        True 
    20442049    """ 
     
    23962401            QEPCAD object has moved to phase 'Before Choice' 
    23972402            QEPCAD object has moved to phase 'Before Solution' 
    23982403            sage: v1 = qe.cell(2).sample_point()[0]; v1 # optional 
    2399             [-0.61803398874989491 .. -0.61803398874989479] 
     2404            -0.6180339887498948? 
    24002405            sage: v2 = qe.cell(4).sample_point()[0]; v2 # optional 
    2401             [1.6180339887498946 .. 1.6180339887498950] 
     2406            1.618033988749895? 
    24022407            sage: v1 + v2 == 1 # optional 
    24032408            True 
    24042409        """ 
     
    24402445            QEPCAD object has moved to phase 'Before Choice' 
    24412446            QEPCAD object has moved to phase 'Before Solution' 
    24422447            sage: qe.cell(4).sample_point_dict() # optional 
    2443             {'x': [1.6180339887498946 .. 1.6180339887498950]
     2448            {'x': 1.618033988749895?
    24442449        """ 
    24452450        points = self.sample_point() 
    24462451        # from sage.calculus.calculus.var import var