Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Add doctests, import JConvex #70

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Expand Up @@ -68,6 +68,8 @@ jobs:
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- name: "Add Polymake for doctests" # FIXME: this is a workaround and should be removed eventually
run: julia --color=yes -e 'using Pkg ; Pkg.add(["Polymake"])'
- name: "Run doctests"
run: |
julia --project=docs --color=yes test/doctest.jl
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Expand Up @@ -2,7 +2,7 @@ push!(LOAD_PATH,"../src/")
using Documenter, JToric, DocumenterMarkdown

# ensure JToric is loaded for the doc tests
DocMeta.setdocmeta!(JToric, :DocTestSetup, :(using JToric, Random); recursive = true)
DocMeta.setdocmeta!(JToric, :DocTestSetup, :(using JToric, Random; using JToric.Oscar); recursive = true)

makedocs(sitename="JToric -- Toric Geometry in Julia")

Expand Down
90 changes: 90 additions & 0 deletions pkg/JConvex/PackageInfo.g
@@ -0,0 +1,90 @@
#############################################################################
##
## PackageInfo.g JConvex package
## Martin Bies
##
## Copyright 2021 University of Pennsylvania
##
## A Gap package for convex geometry via Polymake in Julia
##
#############################################################################

SetPackageInfo( rec(

PackageName := "JConvex",

Subtitle := "A Gap package for convex geometry via Polymake in Julia",

Version := Maximum( [
"2021.09.21",
] ),

Date := ~.Version{[ 1 .. 10 ]},
Date := Concatenation( ~.Date{[ 9, 10 ]}, "/", ~.Date{[ 6, 7 ]}, "/", ~.Date{[ 1 .. 4 ]} ),

License := "GPL-2.0-or-later",

Persons := [
rec(
LastName := "Bies",
FirstNames := "Martin",
IsAuthor := true,
IsMaintainer := true,
Email := "martin.bies@alumni.uni-heidelberg.de",
WWWHome := "https://martinbies.github.io/",
PostalAddress := Concatenation(
"Department of Mathematics\n",
"University of Pennsylvania\n",
"David Rittenhouse Laboratory\n",
"209 S 33rd St\n",
"Philadelphia\n",
"PA 19104\n",
"United States of America" ),
Place := "Pennsylvania",
Institution := "University of Pennsylvania"
),
],

Status := "dev",
PackageWWWHome := "https://github.com/homalg-project/ToricVarieties_project/tree/master/JConvex/",
ArchiveFormats := ".zip",
ArchiveURL := "https://github.com/homalg-project/ToricVarieties_project/releases/download/2021-09-05/JConvex",
README_URL := Concatenation( ~.PackageWWWHome, "README" ),
PackageInfoURL := Concatenation( ~.PackageWWWHome, "PackageInfo.g" ),

AbstractHTML := "JConvex provides functionality to perform convex geometry with Polymake in Julia.",

PackageDoc := rec(
BookName := "JConvex",
ArchiveURLSubset := ["doc"],
HTMLStart := "doc/chap0.html",
PDFFile := "doc/manual.pdf",
SixFile := "doc/manual.six",
LongTitle := "A Gap package for convex geometry via Polymake in Julia",
),


Dependencies := rec(
GAP := ">=4.9",
NeededOtherPackages := [ [ "AutoDoc", ">= 2019.05.20" ],
[ "NConvex", ">= 2020.11-04" ],
[ "JuliaInterface", ">= 0.5.2" ],
],
SuggestedOtherPackages := [ ],
ExternalConditions := [ ],
),

AvailabilityTest := ReturnTrue,

Keywords := [ "Convex geometry", "Polymake", "Julia" ],

AutoDoc := rec(
TitlePage := rec(
Copyright := """
This package may be distributed under the terms and conditions
of the GNU Public License Version 2 or (at your option) any later version.
"""
),
),

));
22 changes: 22 additions & 0 deletions pkg/JConvex/README.md
@@ -0,0 +1,22 @@
# JConvex
A `Gap4` package to do convex geometry by `Polymake` in `Julia`. This package is key to make the functionality of the `ToricVarieties_project` available in `Julia`.


## Installation this package

To get the latest version of this GAP 4 package pull the corresponding branch from github. This completes the installation of this package.


## Documentation and test

You can create the documentation for this package by issuing `make doc` inside the JConvex folder. Provided a running LaTeX installation, the documentation will subsequently be available inside the /doc subfolder as manual.pdf. After this step, you can also issue a test on this software by issuing `make test`.


## Contact

E-mail me if there are any questions, remarks, suggestions. Also, I would like to hear about applications of this package: `Martin Bies, martin.bies@alumni.uni-heidelberg.de`.


## Funding

Martin Bies acknowledges support by NSF grant DMS 2001673, the Simons Foundation Collaboration grant #390287 on “Homological Mirror Symmetry" and the SimonsFoundation Collaboration grant #724069 on “Special Holonomy in Geometry, Analysisand Physics”.
5 changes: 5 additions & 0 deletions pkg/JConvex/doc/Doc.autodoc
@@ -0,0 +1,5 @@
@Chapter Introduction

@Section What is the goal of the JConvex package?

**JConvex** aims to perform convex geometry by Polymake (and eventually also Cdd and Normaliz) in Julia. This is key to make the functionality of the ToricVarieties_package available in Julia.
4 changes: 4 additions & 0 deletions pkg/JConvex/doc/clean
@@ -0,0 +1,4 @@
#!/bin/bash
rm -f *.{six,aux,lab,log,dvi,ps,pdf,bbl,ilg,ind,idx,out,html,tex,pnr,txt,blg,toc,six,brf,xml,xml.bib,css,js}
rm -f ../maketest.g ../VERSION ../public_html.version

88 changes: 88 additions & 0 deletions pkg/JConvex/examples/Cones.g
@@ -0,0 +1,88 @@
#! @Chapter Cones

#! @Section Examples

LoadPackage( "JConvex" );

#! The following demonstrates cone operations performed with Polymake:

#! @Example
P:= Cone( [ [ 2, 7 ], [ 0, 12 ], [ -2, 5 ] ] );
#! <A cone in |R^2>
d:= DefiningInequalities( P );
#! [ [ -7, 2 ], [ 5, 2 ] ]
Q:= ConeByInequalities( d );
#! <A cone in |R^2>
DefiningInequalities( Q );
#! [ [ -7, 2 ], [ 5, 2 ] ]
RayGenerators( P );
#! [ [ -2, 5 ], [ 2, 7 ] ]
RayGenerators( Q );
#! [ [ -2, 5 ], [ 2, 7 ] ]
IsPointed( P );
#! true
IsPointed( Q );
#! true
P=Q;
#! true
HilbertBasis( P );
#! [ [ -2, 5 ], [ -1, 3 ], [ 0, 1 ], [ 1, 4 ], [ 2, 7 ] ]
HilbertBasis( Q );
#! [ [ -2, 5 ], [ -1, 3 ], [ 0, 1 ], [ 1, 4 ], [ 2, 7 ] ]
P_dual:= DualCone( P );
#! <A cone in |R^2>
RayGenerators( P_dual );
#! [ [ -7, 2 ], [ 5, 2 ] ]
Dimension( P );
#! 2
List( Facets( P ), RayGenerators );
#! [ [ [ 2, 7 ] ], [ [ -2, 5 ] ] ]
IsRegularCone( P );
#! false
IsRay( P );
#! false
R:= Cone( [ [ 4, 5 ], [ -2, 1 ] ] );
#! <A cone in |R^2>
T:= IntersectionOfCones( P, R );
#! <A cone in |R^2>
RayGenerators( T );
#! [ [ -2, 5 ], [ 2, 7 ] ]
W:= Cone( [ [-3,-4 ] ] );
#! <A ray in |R^2>
I:= IntersectionOfCones( P, W );
#! <A cone in |R^2>
RayGenerators( I );
#! [ ]
Contains( P, I );
#! true
Contains( W, I );
#! true
Contains( P, R );
#! false
Contains( R, P );
#! true
LinealitySpaceGenerators( P );
#! [ ]
P:= Cone( [ [ 1, 1, -3 ], [ -1, -1, 3 ], [ 1, 2, 1 ], [ 2, 1, 2 ] ] );
#! < A cone in |R^3>
IsPointed( P );
#! false
Dimension( P );
#! 3
IsRegularCone( P );
#! false
P;
#! < A cone in |R^3 of dimension 3 with 4 ray generators>
RayGenerators( P );
#! [ [ -1, -1, 3 ], [ 1, 1, -3 ], [ 1, 2, 1 ], [ 2, 1, 2 ] ]
d:= DefiningInequalities( P );
#! [ [ -5, 8, 1 ], [ 7, -4, 1 ] ]
facets:= Facets( P );
#! [ <A cone in |R^3>, <A cone in |R^3> ]
DualCone( P );
#! < A cone in |R^3>
RayGenerators( DualCone( P ) );
#! [ [ -5, 8, 1 ], [ 7, -4, 1 ] ]
LinealitySpaceGenerators( DualCone( P ) );
#! [ ]
#! @EndExample
120 changes: 120 additions & 0 deletions pkg/JConvex/examples/Polytopes.g
@@ -0,0 +1,120 @@
#! @Chapter Polytopes

#! @Section Examples

LoadPackage( "JConvex" );

#! The following demonstrates polytope operations performed with Polymake:

#! @Example
P := Polytope( [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1, 2 ] ] );
#! <A polytope in |R^3>
ine := FacetInequalities( P );
#! [ [ 0, 0, 0, 1 ], [ 0, 0, 2, -1 ], [ 0, 2, 0, -1 ], [ 2, -2, -2, 1 ] ]
P2 := PolytopeByInequalities( ine );
#! <A polytope in |R^3>
Vertices( P2 );
#! [ [ 0, 0, 0 ], [ 0, 1, 0 ], [ 1, 0, 0 ], [ 1, 1, 2 ] ]
IsNormalPolytope( P );
#! false
IsVeryAmple( P );
#! false
Q := Polytope( [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1, 1 ] ] );
#! <A polytope in |R^3>
IsNormalPolytope( Q );
#! true
IsVeryAmple( Q );
#! true
Q;
#! <A normal very ample polytope in |R^3 with 4 vertices>
T := Polytope( [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1, 4 ] ] );
#! <A polytope in |R^3>
I := Polytope( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
#! <A polytope in |R^3>
J := T + I;
#! <A polytope in |R^3>
Vertices( J );
#! [ [ 0, 0, 0 ], [ 0, 0, 1 ], [ 1, 0, 0 ], [ 1, 0, 1 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 1, 1, 4 ], [ 1, 1, 5 ] ]
FacetInequalities( J );
#! [ [ 0, 0, 0, 1 ], [ 0, 0, 1, 0 ], [ 0, 1, 0, 0 ], [ 1, -1, 0, 0 ], [ 1, 0, -1, 0 ], [ 1, 0, 4, -1 ], [ 1, 4, 0, -1 ], [ 4, -4, -4, 1 ] ]
IsVeryAmple( J );
#! true
IsNormalPolytope( J );
#! false
J;
#! <A very ample polytope in |R^3 with 8 vertices>
#! @EndExample

#! We now compute example 2.2.20 in the book Toric Varieties by Cox, Little, Schenk:

#! @Example
A:= [ [1,1,1,0,0,0], [1,1,0,1,0,0], [1,0,1,0,1,0], [ 1,0,0,1,0,1],
[ 1,0,0,0,1,1], [ 0,1,1,0,0,1], [0,1,0,1,1,0], [0,1,0,0,1,1],
[0,0,1,1,1,0], [0,0,1,1,0,1] ];
#! [ [ 1, 1, 1, 0, 0, 0 ], [ 1, 1, 0, 1, 0, 0 ], [ 1, 0, 1, 0, 1, 0 ],
#! [ 1, 0, 0, 1, 0, 1 ], [ 1, 0, 0, 0, 1, 1 ], [ 0, 1, 1, 0, 0, 1 ],
#! [ 0, 1, 0, 1, 1, 0 ], [ 0, 1, 0, 0, 1, 1 ], [ 0, 0, 1, 1, 1, 0 ],
#! [ 0, 0, 1, 1, 0, 1 ] ]
H:= Polytope( A );
#! <A polytope in |R^6>
IsVeryAmple( H );
#! true <- we receive false!
IsNormalPolytope( H );
#! false
H;
#! <A very ample polytope in |R^6 with 10 vertices>
#! @EndExample

#! More applications include:

#! @Example
l:= [ [ 0, 0, 1 ], [ 0, 0, 0 ], [ 1, 0, 0 ], [ 1, 0, 1 ], [ 0, 1, 0 ],
[ 0, 1, 1 ], [ 1, 1, 4 ], [ 1, 1, 5 ] ];;
P:= Polytope( l );
#! <A polytope in |R^3>
IsNormalPolytope( P );
#! false
lattic_points:= LatticePoints( P );
#! [ [ 0, 0, 0 ], [ 0, 0, 1 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 1, 0, 0 ], [ 1, 0, 1 ],
#! [ 1, 1, 4 ], [ 1, 1, 5 ] ]
u:= Cartesian( lattic_points, lattic_points );;
k:= Set( List( u, u-> u[1]+u[2] ) );
#! [ [ 0, 0, 0 ], [ 0, 0, 1 ], [ 0, 0, 2 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 0, 1, 2 ],
#! [ 0, 2, 0 ], [ 0, 2, 1 ], [ 0, 2, 2 ], [ 1, 0, 0 ], [ 1, 0, 1 ], [ 1, 0, 2 ],
#! [ 1, 1, 0 ], [ 1, 1, 1 ], [ 1, 1, 2 ], [ 1, 1, 4 ], [ 1, 1, 5 ], [ 1, 1, 6 ],
#! [ 1, 2, 4 ], [ 1, 2, 5 ], [ 1, 2, 6 ], [ 2, 0, 0 ], [ 2, 0, 1 ], [ 2, 0, 2 ],
#! [ 2, 1, 4 ], [ 2, 1, 5 ], [ 2, 1, 6 ], [ 2, 2, 8 ], [ 2, 2, 9 ], [ 2, 2, 10 ] ]
Q:= 2*P;
#! <A polytope in |R^3 with 8 vertices>
LatticePoints( Q );
#! [ [ 0, 0, 0 ], [ 0, 0, 1 ], [ 0, 0, 2 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 0, 1, 2 ],
#! [ 0, 2, 0 ], [ 0, 2, 1 ], [ 0, 2, 2 ], [ 1, 0, 0 ],
#! [ 1, 0, 1 ], [ 1, 0, 2 ], [ 1, 1, 0 ], [ 1, 1, 1 ], [ 1, 1, 2 ], [ 1, 1, 3 ],
#! [ 1, 1, 4 ], [ 1, 1, 5 ], [ 1, 1, 6 ], [ 1, 2, 4 ], [ 1, 2, 5 ], [ 1, 2, 6 ],
#! [ 2, 0, 0 ], [ 2, 0, 1 ], [ 2, 0, 2 ], [ 2, 1, 4 ],
#! [ 2, 1, 5 ], [ 2, 1, 6 ], [ 2, 2, 8 ], [ 2, 2, 9 ], [ 2, 2, 10 ] ]
P:= Polytope( [ [ 1, 1 ], [ 1, -1 ], [ -1, 1 ], [ -1, -1 ] ] );
#! <A polytope in |R^2>
Q:= PolarPolytope( P );
#! <A polytope in |R^2>
Vertices( Q );
#! [ [ -1, 0 ], [ 0, -1 ], [ 0, 1 ], [ 1, 0 ] ]
T := PolarPolytope( Q );
#! <A polytope in |R^2>
Vertices( T );
#! [ [ -1, -1 ], [ -1, 1 ], [ 1, -1 ], [ 1, 1 ] ]
P:= Polytope( [ [ 0, 0 ], [ 1, -1], [ -1, 1 ], [ -1, -1 ] ] );
#! <A polytope in |R^2>
#! @EndExample

#! @BeginLatexOnly
#! Let us now find out if the vertices of the polytope defined by the following inequalities:
#! $$x_2\geq 0,1-x_1-x_2\geq 0,1+x_1-x_2\geq 0.$$
#! @EndLatexOnly

#! @Example
P := PolytopeByInequalities( [ [ 0, 0, 1 ], [ 1, -1, -1 ], [ 1, 1, -1 ] ] );
#! <A polytope in |R^2>
Vertices( P );
#! [ [ -1, 0 ], [ 0, 1 ], [ 1, 0 ] ]
#! @EndExample
24 changes: 24 additions & 0 deletions pkg/JConvex/gap/Cone.gd
@@ -0,0 +1,24 @@
#############################################################################
##
## Cone.gd JConvex package
## Martin Bies
##
## Copyright 2021 University of Pennsylvania
##
## A Gap package to do convex geometry by Polymake
##
#! @Chapter Cones
##
#############################################################################

###############################
##
#! @Section Attributes of Cones
##
###############################

#! @Arguments C
#! @Returns a polymake cone
#! @Description
#! Converts the cone to a Polymake cone.
DeclareAttribute( "ExternalPolymakeCone", IsCone );