├── .gitignore ├── APACHE-2.0.txt ├── README.md ├── RMarkdown ├── README.Rmd ├── basic.Rmd ├── beamer-demo.Rmd ├── html-document.Rmd ├── prettydoc-architect.rmd ├── python3.Rmd ├── readme.bib └── rticles │ ├── acm_article │ ├── Makefile │ ├── README.md │ ├── acm_article.Rmd │ ├── acm_proc_article-sp.cls │ ├── sensys-abstract.cls │ └── sigproc.bib │ ├── acs_article │ ├── acs_article.Rmd │ └── acstest.bib │ ├── aea_article │ ├── AEA.cls │ ├── BibFile.bib │ ├── aea.bst │ ├── aea_article.Rmd │ ├── multicol.sty │ ├── references.bib │ └── setspace.sty │ ├── amq_article │ ├── amq_article.Rmd │ ├── authorcommands.tex │ ├── authorpackages.tex │ ├── mybibliography.tex │ └── pics │ │ ├── Figure1.jpg │ │ └── Figure2.pdf │ ├── ams_article │ ├── ams_article.Rmd │ ├── amstest.bib │ └── figure01.pdf │ ├── asa_article │ ├── agsm.bst │ ├── asa_article.Rmd │ └── bibliography.bib │ ├── ctex.Rmd │ ├── elsevier_article │ ├── elsarticle.cls │ ├── elsevier_article.Rmd │ ├── mybibfile.bib │ └── numcompress.sty │ ├── generate.ipynb │ ├── ieee_article │ ├── IEEEtran.bst │ ├── IEEEtran.cls │ ├── ieee_article.Rmd │ └── mybibfile.bib │ ├── jss_article │ ├── jss.bst │ ├── jss.cls │ ├── jss_article.Rmd │ └── jsslogo.jpg │ ├── mdpi_article │ ├── appendix.tex │ ├── chicago2.bst │ ├── logo-ccby.eps │ ├── logo-mdpi.eps │ ├── mdpi.bst │ ├── mdpi.cls │ ├── mdpi_article.Rmd │ └── mybibfile.bib │ ├── mnras_article │ ├── README.md │ ├── example.png │ ├── mnras.cls │ ├── mnras_article.Rmd │ └── references.bib │ ├── peerj_article │ ├── peerj_article.Rmd │ ├── sample.bib │ ├── view.jpg │ └── wlpeerj.cls │ ├── plos_article │ ├── PLOS-submission.eps │ ├── mybibfile.bib │ ├── plos.csl │ └── plos_article.Rmd │ ├── pnas_article │ ├── frog.png │ ├── pnas-new.cls │ ├── pnas-sample.bib │ ├── pnas.csl │ ├── pnas_article.Rmd │ ├── pnasinvited.sty │ ├── pnasmathematics.sty │ ├── pnasresearcharticle.sty │ └── widetext.sty │ ├── rjournal_article │ ├── RJournal.sty │ ├── RJreferences.bib │ ├── Rlogo.png │ ├── preamble.tex │ └── rjournal_article.Rmd │ ├── rsos_article │ ├── OPENSCIENCE.pdf │ ├── OpenAccesslogo_bw.pdf │ ├── RS.bst │ ├── RSOS_Pubs_Logo_Line_CMYK.pdf │ ├── RS_crossmark_logo.pdf │ ├── rsos.cls │ ├── rsos_article.Rmd │ └── sample.bib │ ├── rss_article │ ├── amssym.def │ ├── amssym.tex │ ├── bibliography.bib │ ├── natbib.sty │ ├── rss.bst │ ├── rss_article.Rmd │ └── statsoc.cls │ ├── sim_article │ ├── WileyNJD-AMA.bst │ ├── WileyNJD-v2.cls │ ├── bibfile.bib │ └── sim_article.Rmd │ └── springer_article │ ├── bibliography.bib │ ├── spbasic.bst │ ├── spmpsci.bst │ ├── spphys.bst │ ├── springer_article.Rmd │ ├── svglov3.clo │ └── svjour3.cls ├── d3 └── d3-tutorial.sagews ├── fortran ├── cylinder.f90 ├── run.sh └── run.term ├── gap ├── gap.sagews └── gap_directly.sagews ├── go ├── go.pdf └── go.sagews ├── index.yaml ├── julia ├── batman-demo-300.png ├── julia-first-steps.ipynb └── julia-logo-325-by-225.png ├── latex ├── .gitignore ├── README.md ├── multiple-files │ ├── 10-make.tex │ ├── 20-subfiles.tex │ ├── 30-komascript.tex │ ├── 40-sagetex.tex │ ├── bibliography.bib │ ├── latexmkrc │ ├── makefile │ ├── master.tex │ └── run-sagetex.py ├── presentation │ └── presentation.tex ├── pythontex │ └── pythontex.tex └── sagetex │ ├── README.md │ └── minimal.tex ├── linux └── Introduction.sagews ├── markdown ├── markdown-in-jupyter.ipynb ├── markdown-in-sage-worksheet.sagews └── markdown-intro.md ├── ocaml ├── Readme.md ├── compile.term └── example1.ml ├── octave ├── myfirst.m ├── octave-ipython.ipynb └── octave-sage.sagews ├── pydata └── OLSvsRLM.sagews ├── r ├── .gitignore ├── basics.sagews ├── r-plotting.sagews ├── rmagic.ipynb ├── rpy2.sagews └── rpy2talk │ ├── rpy2talk.pdf │ └── rpy2talk.tex ├── sage ├── 2dSphere.sagews ├── 3dplot.sagews ├── MagicCommandsDoc.sagews ├── RiemannSumSampler.sagews ├── SageBeginnerTutorial.sagews ├── SageManifolds │ ├── SM_AdS.sagews │ ├── SM_Carter-Penrose_diag.sagews │ ├── SM_Friedmann_equations.sagews │ ├── SM_Kerr.sagews │ ├── SM_Kerr_Newman.sagews │ ├── SM_Schwarzschild.sagews │ ├── SM_Simon-Mars_3p1_Kerr.sagews │ ├── SM_Simon-Mars_3p1_TS2.sagews │ ├── SM_Simon-Mars_Curzon-Chazy.sagews │ ├── SM_Tolman-Oppenheimer-Volkoff_equations.sagews │ ├── SM_Tomimatsu-Sato_3p1.sagews │ ├── SM_de_Sitter.sagews │ ├── SM_hyperbolic_plane.sagews │ ├── SM_projective_plane_RP2.sagews │ ├── SM_sphere_S2.sagews │ ├── SM_tensors_modules.sagews │ └── SM_tutorial.sagews ├── basics.sagews ├── interact │ ├── Algebra │ │ └── ideal.sagews │ ├── Bioinformatics │ │ └── coalescent.sagews │ ├── Calculus │ │ ├── contourMap.sagews │ │ ├── deltaEpsilon.sagews │ │ ├── differentialApprox2Var.sagews │ │ ├── graph3DPointCurve.sagews │ │ ├── latSurfaceArea.sagews │ │ ├── midpointTwoVar.sagews │ │ ├── multivarLimit.sagews │ │ ├── newtonMethod.sagews │ │ ├── numericalIntegral.sagews │ │ ├── parametricSurfaceArea.sagews │ │ ├── polarCurve.sagews │ │ ├── quadricSurface.sagews │ │ ├── symbolicFunction.sagews │ │ ├── taylorApprox2Var.sagews │ │ └── volumeNonRectangDomain.sagews │ ├── DiffEq │ │ ├── diffEqBoundary.sagews │ │ ├── eulerBaroque.sagews │ │ ├── eulerMarayumaBrownian.sagews │ │ ├── eulerVectorField.sagews │ │ ├── heatFourier.sagews │ │ ├── picardIter.sagews │ │ └── rungaKuttaFehlberg.sagews │ ├── DynamicalSystems │ │ └── cobweb.sagews │ ├── Fractals │ │ ├── digitSetDilationMatrix.sagews │ │ ├── juliaVariableExp.sagews │ │ ├── mandelbrotBinomDistrib.sagews │ │ ├── mandlebrotVariableExp.sagews │ │ ├── sierpinskiTri.sagews │ │ ├── twinDragon.sagews │ │ └── twinDragon3D.sagews │ ├── Games │ │ ├── nim.sagews │ │ ├── queens.sagews │ │ └── zeros.sagews │ ├── Geometry │ │ ├── banchoffPohl.sagews │ │ ├── croftonFormula.sagews │ │ ├── evolutes.sagews │ │ ├── geodesicsParamSurf.sagews │ │ └── tetReflect.sagews │ ├── Graph │ │ ├── automorphism.sagews │ │ └── graphMinor.sagews │ ├── Graphics │ │ ├── 3DParametricPlot.sagews │ │ ├── interactive2DPlot.sagews │ │ ├── interactive3DPlot.sagews │ │ ├── interactiveMatPlotLib.sagews │ │ ├── paintEgg.sagews │ │ ├── plotColor.sagews │ │ ├── plt.png │ │ ├── pursuitCurve.sagews │ │ ├── rotateRayTrace.sagews │ │ └── spirograph.sagews │ ├── LinearAlgebra │ │ ├── determTranspose.sagews │ │ ├── discreteFourier.sagews │ │ ├── gerschgorinCircle.sagews │ │ ├── linearTransform.sagews │ │ └── sVD.sagews │ ├── LoopQuantumGravity │ │ ├── holomorphicFactorQuantTetra.sagews │ │ ├── quantumTetAreaEig.sagews │ │ └── quantumTetNumbers.sagews │ ├── Miscellaneous │ │ ├── beatFreq.sagews │ │ ├── cellularAutomata.sagews │ │ ├── interactiveVenn.sagews │ │ ├── karplusStrong.sagews │ │ ├── minkowskiSum.sagews │ │ ├── snippetProfile.sagews │ │ └── unreadable.sagews │ ├── NumberTheory │ │ ├── Cryptography │ │ │ └── cryptography.sagews │ │ ├── IntegerFactorization │ │ │ ├── divisibilityPoset.sagews │ │ │ └── factorTrees.sagews │ │ ├── ModularForms │ │ │ ├── charpodyHecke.sagews │ │ │ ├── computeCuspidalSubgroup.sagews │ │ │ ├── computeModForm.sagews │ │ │ ├── ellipticCurve.sagews │ │ │ └── ellipticCurveFinite.sagews │ │ ├── Other │ │ │ ├── computeBernoulli.sagews │ │ │ ├── fundDomainSL2.sagews │ │ │ └── plotContinueFrac.sagews │ │ └── PrimeNumbers │ │ │ ├── primeNumbrThrm.sagews │ │ │ └── primeSpiralPolar.sagews │ ├── Statistics │ │ ├── dishonestCasino.sagews │ │ └── randomWalk.sagews │ ├── Topology │ │ └── winding.sagews │ └── WebApp │ │ └── pieChart.sagews ├── interactive.sagews ├── pi.sagews ├── xkcd.sagews ├── yoda.sagews └── yodapose.mat ├── sagews-jupyter ├── bash.sagews ├── jupyter-python3.sagews ├── r-completion.png ├── r.sagews ├── sage.png └── simpleLoop.wav ├── sympy ├── sympy-code.sagews └── sympy-intro.sagews ├── thumbs ├── latex-beamer-in-cocalc.png ├── latex-multiple-documents.png ├── markdown-in-cocalc.png ├── pythontex.png ├── r-in-cocalc.png ├── rmd.png ├── sage-in-cocalc.png └── sagetex-in-cocalc.png ├── web-app-worksheet ├── app.css ├── app.html ├── app.js └── app.sagews └── webservice ├── Readme.md ├── main.py └── run.term /.gitignore: -------------------------------------------------------------------------------- 1 | index.js 2 | octave/octave-workspace 3 | cmdline.term 4 | sage-plots-for*.tex 5 | *.sout 6 | *.scmd 7 | *.sage-backup 8 | *.synctex.gz 9 | .bashrc 10 | fortran/cylinder 11 | *.bak 12 | .bup/ 13 | .cache/ 14 | .forever/ 15 | .gitconfig 16 | .sage/ 17 | .sagemathcloud/ 18 | .ssh/ 19 | *.term 20 | *~ 21 | \.* 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CoCalc Templates 2 | ================ 3 | 4 | [](https://cocalc.com/github/sagemathinc/cocalc-example-files) 5 | 6 | This is a collection of some templates for worksheets or scripts 7 | in [CoCalc](https://cocalc.com). 8 | 9 | Just clone them into your working directory via 10 | 11 | 1. Open the [+ New] tab, 12 | 1. Enter `https://github.com/sagemathinc/cocalc-example-files.git` in the text box, 13 | 1. Then click on `Download from Internet` to download and clone the entire project. 14 | 15 | Go back to `Files`, open the `cocalc-example-files` directory and you are ready to start exploring CoCalc! 16 | 17 | Authors 18 | ------- 19 | 20 | * Harald Schilly 21 | * William Stein 22 | * Theron Hitchman (SageBeginnerTutorial) 23 | * Gustav Delius 24 | * Hal Snyder 25 | 26 | License 27 | ------- 28 | 29 | Unless otherwise noted in the respective source file: Apache 2.0. 30 | -------------------------------------------------------------------------------- /RMarkdown/README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "RMarkdown in CoCalc" 3 | bibliography: readme.bib 4 | --- 5 | 6 | ## Introduction 7 | 8 | RMarkdown allows you to write a HTML document, a scientific article, a presentation (interactive website or LaTeX beamer), or even a book by just using [Markdown](https://bookdown.org/yihui/rmarkdown/markdown-syntax.html) syntax and embedded programming code. 9 | The "**R**" in RMarkdown stands for the [R statistical computing](https://www.R-project.org/) language, 10 | but it also supports [Python](https://www.python.org) and many other langauges. 11 | 12 | To make full use of this approach, look at the included example documents, 13 | the [articles](./rticle) and make sure to check out advanced concepts like the "frontmatter" -- which you can see at the top between the triple dashes -- to configure the document. 14 | 15 | For example, you can use a [bibtex file](readme.bib) to collect other documents. 16 | Use it to include a reference in your file like for R (@R-base), SageMath (@sagemath) and CoCalc [@cocalc]. 17 | 18 | Of course, you can include formulas like $$f(k) = {n \choose k} p^{k} (1-p)^{n-k}$$ and much more ... 19 | 20 | ## Included documents 21 | 22 | - [Basic.Rmd](basic.Rmd) -- this shows how to produce a simple HTML with some R code and plots. 23 | - [html-document.Rmd](html-document.Rmd) -- shows how to customize an HTML document. 24 | - [python3.Rmd](python3.Rmd) -- showcase how to use Python 3 for code and plots. 25 | - [beamer-demo.Rmd](beamer-demo.Rmd) -- a LaTeX beamer presentation (produces as PDF!) 26 | 27 | ## Learn more 28 | 29 | - [Website](https://rmarkdown.rstudio.com) 30 | - [Tutorial](https://rmarkdown.rstudio.com/lesson-1.html) 31 | - [The Definitive Guide](https://bookdown.org/yihui/rmarkdown/) 32 | -------------------------------------------------------------------------------- /RMarkdown/basic.Rmd: -------------------------------------------------------------------------------- 1 | # Test 2 | 3 | ``` 4 | just code formatted 5 | ``` 6 | 7 | and some R code 8 | 9 | ```{r} 10 | xx <- rnorm(2000) 11 | paste("length of xx:", length(xx)) 12 | plot(xx) 13 | ``` 14 | 15 | **ok** _italic_ and $\tfrac{1}{997} = `r 1/997`$. 16 | 17 |
right hand side
18 | 19 | link to [google](https://google.com). 20 | 21 | ## and a table 22 | 23 | ```{r echo = FALSE, results = 'asis'} 24 | library(knitr) 25 | kable(mtcars[1:15, ], caption = "this is a knitr kable.") 26 | ``` 27 | -------------------------------------------------------------------------------- /RMarkdown/beamer-demo.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Beamer Demo" 3 | author: "John Doe" 4 | date: March 22, 2005 5 | fontsize: 10pt 6 | output: 7 | beamer_presentation: 8 | theme: "Copenhagen" 9 | colortheme: "dolphin" 10 | --- 11 | 12 | # In the morning 13 | 14 | Just a simple calculation: $123+234 = `r 123+234`$. 15 | 16 | --- 17 | 18 | ## Getting up 19 | 20 | - Turn off alarm 21 | - Get out of bed 22 | 23 | ## Breakfast 24 | 25 | - Eat eggs 26 | - Drink coffee 27 | 28 | # In the evening 29 | 30 | ## Dinner 31 | 32 | - Eat spaghetti 33 | - Drink wine 34 | 35 | --- 36 | 37 | A simple standard plot: 38 | 39 | ```{r, cars, fig.cap="A scatterplot.", echo=FALSE} 40 | plot(cars) 41 | ``` 42 | 43 | --- 44 | 45 | ## Going to sleep 46 | 47 | - Get in bed 48 | - Count sheep 49 | 50 | ## Calling C from R 51 | 52 | ```{c, test-c, results='hide'} 53 | void square(double *x) { 54 | *x = *x * *x; 55 | } 56 | ``` 57 | 58 | Test the `square()` function: 59 | 60 | ```{r} 61 | .C('square', 9)[[1]] 62 | .C('square', 123)[[1]] 63 | ``` 64 | -------------------------------------------------------------------------------- /RMarkdown/html-document.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "HTML test" 3 | # themes: 4 | # “cerulean”, “journal”, “flatly”, “readable”, “spacelab”, “united”, 5 | # “cosmo”, “lumen”, “paper”, “sandstone”, “simplex”, “yeti” 6 | # code highlighting: 7 | # “default”, “tango”, “pygments”, “kate”, “monochrome”, “espresso”, 8 | # “zenburn”, “haddock”, “textmate” 9 | output: 10 | html_document: 11 | toc: true 12 | toc_depth: 2 13 | self_contained: false 14 | code_folding: show 15 | theme: lumen 16 | highlight: textmate 17 | css: html-document.css 18 | --- 19 | 20 | ```{r setup, include=FALSE} 21 | library(ggplot2) 22 | theme_set(theme_bw(base_size=12)) 23 | theme_update(panel.background = element_rect(fill = "transparent", colour = NA), 24 | plot.background = element_rect(fill = "transparent", colour = NA)) 25 | knitr::opts_chunk$set(dev.args=list(bg="transparent")) 26 | ``` 27 | 28 | # Inline R 29 | 30 | Inline formula $\tfrac{7}{2^3 + 1} = `r 7 / (2^3 + 1)`$ code and a random `r rnorm(10)` vector. 31 | 32 | # Random points in R 33 | 34 | This plots 2000 random points … 35 | 36 | ```{r} 37 | xx <- rnorm(2000) 38 | yy <- rnorm(2000) 39 | plot(xx, yy, pch=20, color = rgb(0,0,0,alpha=0.3)) 40 | ``` 41 | 42 | 43 | ## Enhanced Scatterplot 44 | 45 | ```{r} 46 | library(car) 47 | attach(mtcars) 48 | scatterplotMatrix(~mpg+disp+drat+wt|cyl, 49 | data=mtcars, 50 | main="Three Cylinder Options" 51 | ) 52 | ``` 53 | 54 | # ggplot2 demo 55 | 56 | This is straight from a [ggplot2 introduction](http://r-statistics.co/Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html). 57 | 58 | ```{r} 59 | # Setup ---------------------------------------------- 60 | options(scipen=999) 61 | library(ggplot2) 62 | data("midwest", package = "ggplot2") 63 | theme_set(theme_bw()) 64 | # midwest <- read.csv("http://goo.gl/G1K41K") # bkup data source 65 | 66 | # Add plot components -------------------------------- 67 | gg <- ggplot(midwest, aes(x=area, y=poptotal)) + 68 | geom_point(aes(col=state, size=popdensity), alpha=0.5) + 69 | geom_smooth(method="loess", se=F) + xlim(c(0, 0.1)) + ylim(c(0, 500000)) + 70 | labs(title="Area Vs Population", 71 | y="Population", x="Area", caption="Source: midwest") 72 | 73 | # Call plot ------------------------------------------ 74 | plot(gg) 75 | ``` 76 | 77 | -------------------------------------------------------------------------------- /RMarkdown/prettydoc-architect.rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "R Markdown and prettydoc" 3 | subtitle: "The Architect Theme" 4 | author: "Harald Schilly" 5 | date: "`r Sys.Date()`" 6 | output: 7 | prettydoc::html_pretty: 8 | theme: architect 9 | --- 10 | 11 | 12 | ```{r setup, include=FALSE} 13 | # transparent plots 14 | library(ggplot2) 15 | theme_set(theme_bw(base_size=12)) 16 | theme_update(panel.background = element_rect(fill = "transparent", colour = NA), 17 | plot.background = element_rect(fill = "transparent", colour = NA)) 18 | knitr::opts_chunk$set(dev.args=list(bg="transparent")) 19 | ``` 20 | 21 | ## Info 22 | 23 | This is taken from [http://yixuan.cos.name/prettydoc/](http://yixuan.cos.name/prettydoc/) 24 | showcasing the "Architect" theme. 25 | Derived from work by Yixuan Qiu. 26 | 27 | ### Headers 28 | 29 | #### Level 4 30 | 31 | ##### Level 5 32 | 33 | ### A demo table 34 | 35 | | | Df | Sum Sq | Mean Sq | F value | Pr(>F) | | 36 | | --------- | --- | ------ | ------- | ------- | ------- | ---- | 37 | | Block | 5 | 343.3 | 68.66 | 4.447 | 0.01594 | \* | 38 | | N | 1 | 189.3 | 189.28 | 12.259 | 0.00437 | \*\* | 39 | | P | 1 | 8.4 | 8.40 | 0.544 | 0.47490 | | 40 | | K | 1 | 95.2 | 95.20 | 6.166 | 0.02880 | \* | 41 | | N:P | 1 | 21.3 | 21.28 | 1.378 | 0.26317 | | 42 | | N:K | 1 | 33.1 | 33.14 | 2.146 | 0.16865 | | 43 | | P:K | 1 | 0.5 | 0.48 | 0.031 | 0.86275 | | 44 | | Residuals | 12 | 185.3 | 15.44 | | | | 45 | 46 | ### Lists 47 | 48 | There are three kinds of lies: 49 | 50 | 1. Lies 51 | 2. Damned lies 52 | 3. Statistics 53 | - Frequentists 54 | - Bayesian 55 | - ... 56 | 57 | Supported highlighters in `prettydoc`: 58 | 59 | - `github`: Style similar to Github 60 | - `vignette`: Style used by `rmarkdown::html_vignette` 61 | 62 | ### Markups 63 | 64 | **Bold**, _italic_, don't say this. 65 | 66 | ### Code 67 | 68 | Familiar `knitr` R code and plots: 69 | 70 | ```{r fig.width=6, fig.height=6, fig.align='center'} 71 | n <- 1000 72 | x1 <- matrix(sort(rnorm(n, mean = 2, sd = 2.5)), ncol = 2) 73 | x2 <- matrix(rnorm(n, mean = 2.5, sd = 2.5), ncol = 2) 74 | x <- rbind(x1, x2) 75 | smoothScatter(x, xlab = "x1", ylab = "x2") 76 | head(x) 77 | ``` 78 | 79 | ### Data Frame visualized via `knitr::kable` 80 | 81 | ```{r results='asis'} 82 | knitr::kable(head(data.frame(x1=x1, x2=x2))) 83 | ``` 84 | -------------------------------------------------------------------------------- /RMarkdown/python3.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: python3 test 3 | --- 4 | 5 | ```{r setup, include=FALSE} 6 | # this setup code is important, otherwise it won't run! 7 | library(reticulate) 8 | use_python('/usr/bin/python3') 9 | 10 | # alternatively, you can use this to set an engine executable 11 | #knitr::opts_chunk$set(engine.path = list( 12 | # python = '/usr/bin/python3' 13 | #)) 14 | ``` 15 | 16 | # Hi, I'm Python 17 | 18 | ```{python} 19 | x = 12 + 23**5 20 | print(x) 21 | ``` 22 | 23 | Running 24 | 25 | ```{python} 26 | import sys 27 | print(sys.version) 28 | ``` 29 | 30 | ## Plotting 31 | 32 | ```{python} 33 | import numpy as np 34 | import matplotlib.pyplot as plt 35 | xx = np.linspace(0, 10, 100) 36 | yy = np.sin(xx) 37 | plt.plot(xx, yy) 38 | plt.show() 39 | ``` 40 | 41 | ## R still works, too 42 | 43 | ```{r} 44 | x <- c(1,2,3,2,1) 45 | plot(x) 46 | ``` 47 | 48 | ## Interactions between R and Python 49 | 50 | This uses the [reticulate](https://github.com/rstudio/reticulate) R library: 51 | 52 | Retrieve the value of `x` from the Python session again: 53 | 54 | ```{r} 55 | py$x 56 | ``` 57 | 58 | Assign to a variable in the Python session from R: 59 | 60 | ```{r} 61 | py$y = 1:5 62 | ``` 63 | 64 | See the value of `y` in the Python session: 65 | 66 | ```{python} 67 | print(y) 68 | ``` 69 | -------------------------------------------------------------------------------- /RMarkdown/readme.bib: -------------------------------------------------------------------------------- 1 | @Manual{R-base, 2 | title = {R: A Language and Environment for Statistical 3 | Computing}, 4 | author = {{R Core Team}}, 5 | organization = {R Foundation for Statistical Computing}, 6 | address = {Vienna, Austria}, 7 | year = {2017}, 8 | url = {https://www.R-project.org/}, 9 | } 10 | 11 | 12 | @manual{sagemath, 13 | Key = {SageMath}, 14 | Author = {{The Sage Developers}}, 15 | Title = {{S}ageMath, the {S}age {M}athematics {S}oftware {S}ystem ({V}ersion 8.3)}, 16 | note = {{\tt https://www.sagemath.org}}, 17 | Year = {2018}, 18 | } 19 | 20 | 21 | @manual{cocalc, 22 | Key = {CoCalc}, 23 | Author = {The CoCalc Authors}, 24 | Title = {{Collaborative Calculation in the Cloud}}, 25 | note = {{\tt https://www.cocalc.com}}, 26 | Year = {2018}, 27 | } -------------------------------------------------------------------------------- /RMarkdown/rticles/acm_article/Makefile: -------------------------------------------------------------------------------- 1 | # Produce sensys-abstract compliant PDFs from all Markdown files in a directory 2 | # Manuel Moraga | mmoraga@kth.se 3 | 4 | # List files to be made 5 | PDFS := $(patsubst %.md,%.pdf,$(wildcard *.md)) 6 | 7 | all : $(PDFS) 8 | 9 | # Accepts PDF target with markdown syntax, makes them using pandoc 10 | %.pdf : %.md 11 | pandoc $< -o $@ --template=shortpaper.latex --filter pandoc-citeproc --csl=acm-sig-proceedings.csl 12 | 13 | clean : 14 | rm $(PDFS) 15 | 16 | rebuild: clean all 17 | -------------------------------------------------------------------------------- /RMarkdown/rticles/acm_article/README.md: -------------------------------------------------------------------------------- 1 | # pandoc-shortpaper 2 | 3 | A template for building shortpapers in pandoc using the sensys-abstract.csl latex documentclass 4 | 5 | ## Usage 6 | 7 | To compile all markdown files to pdf 8 | 9 | make 10 | 11 | ## Example 12 | 13 | [View example PDF](http://spanners.github.io/pandoc-shortpaper/example.pdf) 14 | 15 | ## Sources 16 | 17 | * `acm-sig-proceedings.csl`: ACM SIG Proceedings Template. 18 | CC-SA Naeem Esfahani and Chris Horn. 19 | 20 | * `shortpaper.latex`: ... 21 | * `sensys-abstract.cls`: ... 22 | * ... 23 | 24 | -------------------------------------------------------------------------------- /RMarkdown/rticles/acm_article/acm_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Short Paper 3 | author: 4 | - name: Alice Anonymous 5 | email: alice@example.com 6 | affiliation: Some Institute of Technology 7 | - name: Bob Security 8 | email: bob@example.com 9 | affiliation: Another University 10 | abstract: | 11 | This is the abstract. 12 | 13 | It consists of two paragraphs. 14 | bibliography: sigproc.bib 15 | output: rticles::acm_article 16 | --- 17 | 18 | 19 | 20 | # Introduction 21 | Lorem ipsum dolor sit[@meier2012] amet, consectetur adipiscing[@fenner2012a] elit. Pellentesque rhoncus ut tellus eu tristique. Duis pharetra velit vitae viverra elementum. Nulla metus dui, pulvinar id enim at, pellentesque semper ipsum. Phasellus cursus dignissim ipsum, sed congue orci pretium quis. Maecenas rhoncus leo a cursus euismod. Fusce a erat eu ipsum tristique tempus at sed tortor. Aliquam erat volutpat. Donec at pretium lorem. Donec pretium nunc id nunc bibendum convallis. Phasellus quis enim id massa feugiat egestas hendrerit sollicitudin nibh. Sed blandit eros id tellus porta, eget ullamcorper urna posuere. Pellentesque laoreet lacus nibh, a mattis libero viverra sit amet. Sed vitae diam interdum, pharetra neque sit amet, dictum lectus. 22 | 23 | Donec massa justo, ultricies quis facilisis sed, tristique nec metus. Vestibulum id condimentum diam. Integer semper augue id porttitor ultrices. Cras vulputate felis eu diam porttitor, ac pulvinar nisi imperdiet. Donec eros felis, imperdiet vel malesuada at, varius et quam. Phasellus facilisis non risus eu placerat. Sed ac mollis lorem. 24 | 25 | # Evaluation 26 | Nullam semper imperdiet orci, at lacinia est aliquet et. Sed justo nibh, aliquet et velit at, pharetra consequat velit. Nullam nec ligula sagittis, adipiscing nisl sed, varius massa. Mauris quam ante, aliquet a nunc et, faucibus imperdiet libero. Suspendisse odio tortor, bibendum vel semper sit amet, euismod ac ante. Nunc nec dignissim turpis, ac blandit massa. Donec auctor massa ac vestibulum aliquam. Fusce auctor dictum lobortis. Vivamus tortor augue, convallis quis augue sit amet, laoreet tristique quam. Donec id volutpat orci. Suspendisse at mi vel elit accumsan porta ac ut diam. Nulla ut dapibus quam. 27 | 28 | Sed est odio, ornare in rutrum et, dapibus in urna. Suspendisse varius massa in ipsum placerat, quis tristique magna consequat. Suspendisse non convallis augue. Quisque fermentum justo et lorem volutpat euismod. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi sagittis interdum justo, eu consequat nisi convallis in. Sed tincidunt risus id lacinia ultrices. Phasellus ac ligula sed mi mattis lacinia ac non felis. Etiam at dui tellus. 29 | 30 | # Conclusion 31 | Duis nec purus sed neque porttitor tincidunt vitae quis augue. Donec porttitor aliquam ante, nec convallis nisl ornare eu. Morbi ut purus et justo commodo dignissim et nec nisl. Donec imperdiet tellus dolor, vel dignissim risus venenatis eu. Aliquam tempor imperdiet massa, nec fermentum tellus sollicitudin vulputate. Integer posuere porttitor pharetra. Praesent vehicula elementum diam a suscipit. Morbi viverra velit eget placerat pellentesque. Nunc congue augue non nisi ultrices tempor. 32 | 33 | # References 34 | 35 | --- 36 | references: 37 | - id: meier2012 38 | title: Professinal Android 4 Application Development 39 | author: 40 | - family: Meier 41 | given: Reto 42 | type: book 43 | publisher: John Wiley & Sons, Inc. 44 | issued: 45 | year: 2012 46 | month: 5 47 | - id: fenner2012a 48 | title: One-click science marketing 49 | author: 50 | - family: Fenner 51 | given: Martin 52 | container-title: Nature Materials 53 | volume: 11 54 | URL: 'http://dx.doi.org/10.1038/nmat3283' 55 | DOI: 10.1038/nmat3283 56 | issue: 4 57 | publisher: Nature Publishing Group 58 | page: 261-263 59 | type: article-journal 60 | issued: 61 | year: 2012 62 | month: 3 63 | ... 64 | 65 | -------------------------------------------------------------------------------- /RMarkdown/rticles/acm_article/sigproc.bib: -------------------------------------------------------------------------------- 1 | @ARTICLE{bowman:reasoning, 2 | AUTHOR = "Mic Bowman and Saumya K. Debray and Larry L. Peterson", 3 | TITLE = "Reasoning About Naming Systems", 4 | JOURNAL = "ACM Trans. Program. Lang. Syst.", 5 | VOLUME = {15}, 6 | NUMBER = {5}, 7 | PAGES = {795-825}, 8 | MONTH = "November", 9 | YEAR = {1993} } 10 | 11 | @ARTICLE{braams:babel, 12 | AUTHOR = "Johannes Braams", 13 | TITLE = "Babel, a Multilingual Style-Option System for Use with LaTeX's Standard Document Styles", 14 | JOURNAL = {TUGboat}, 15 | VOLUME = {12}, 16 | NUMBER = {2}, 17 | PAGES = {291-301}, 18 | MONTH = "June", 19 | YEAR = {1991} } 20 | 21 | @INPROCEEDINGS{clark:pct, 22 | AUTHOR = "Malcolm Clark", 23 | TITLE = "Post Congress Tristesse", 24 | BOOKTITLE = "TeX90 Conference Proceedings", 25 | PAGES = "84-89", 26 | ORGANIZATION = "TeX Users Group", 27 | MONTH = "March", 28 | YEAR = {1991} } 29 | 30 | @ARTICLE{herlihy:methodology, 31 | AUTHOR = "Maurice Herlihy", 32 | TITLE = "A Methodology for Implementing Highly Concurrent 33 | Data Objects", 34 | JOURNAL = {ACM Trans. Program. Lang. Syst.}, 35 | VOLUME = {15}, 36 | NUMBER = {5}, 37 | PAGES = {745-770}, 38 | MONTH = "November", 39 | YEAR = {1993} } 40 | 41 | @BOOK{Lamport:LaTeX, 42 | AUTHOR = "Leslie Lamport", 43 | TITLE = "LaTeX User's Guide and Document Reference Manual", 44 | PUBLISHER = "Addison-Wesley Publishing Company", 45 | ADDRESS = "Reading, Massachusetts", 46 | YEAR = "1986" } 47 | 48 | @BOOK{salas:calculus, 49 | AUTHOR = "S.L. Salas and Einar Hille", 50 | TITLE = "Calculus: One and Several Variable", 51 | PUBLISHER = "John Wiley and Sons", 52 | ADDRESS = "New York", 53 | YEAR = "1978" } 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /RMarkdown/rticles/acs_article/acstest.bib: -------------------------------------------------------------------------------- 1 | @article{Garnier2007, 2 | abstract = {The roots of swarm intelligence are deeply embedded in the biological study of self-organized behaviors in social insects. From the routing of traffic in telecommunication networks to the design of control algorithms for groups of autonomous robots, the collective behaviors of these animals have inspired many of the foundational works in this emerging research field. For the first issue of this journal dedicated to swarm intelligence, we review the main biological principles that underlie the organization of insects’ colonies. We begin with some reminders about the decentralized nature of such systems and we describe the un- derlying mechanisms of complex collective behaviors of social insects, from the concept of stigmergy to the theory of self-organization in biological systems.We emphasize in partic- ular the role of interactions and the importance of bifurcations that appear in the collective output of the colony when some of the system’s parameters change. We then propose to categorize the collective behaviors displayed by insect colonies according to four functions that emerge at the level of the colony and that organize its global behavior. Finally, we ad- dress the role of modulations of individual behaviors by disturbances (either environmental or internal to the colony) in the overall flexibility of insect colonies. We conclude that fu- ture studies about self-organized biological behaviors should investigate such modulations to better understand how insect colonies adapt to uncertain worlds.}, 3 | author = {Garnier, Simon and Gautrais, Jacques and Theraulaz, Guy}, 4 | doi = {10.1007/s11721-007-0004-y}, 5 | file = {:Users/simongarnier/Work/bibliography/Mendeley/Swarm Intelligence/2007/Garnier, Gautrais, Theraulaz - 2007.pdf:pdf}, 6 | issn = {1935-3812}, 7 | journal = {Swarm Intelligence}, 8 | keywords = {self organization collective,self-organization collective,social insects,stigmergy,swarm intelligence}, 9 | mendeley-tags = {swarm intelligence}, 10 | month = jul, 11 | number = {1}, 12 | pages = {3--31}, 13 | title = {{The biological principles of swarm intelligence}}, 14 | url = {http://www.springerlink.com/index/10.1007/s11721-007-0004-y}, 15 | volume = {1}, 16 | year = {2007} 17 | } 18 | -------------------------------------------------------------------------------- /RMarkdown/rticles/aea_article/BibFile.bib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/aea_article/BibFile.bib -------------------------------------------------------------------------------- /RMarkdown/rticles/aea_article/aea_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Untitled" 3 | short: "A shorter title" 4 | journal: "AER" # AER, AEJ, PP, JEL 5 | month: "`r format(Sys.Date(), '%m')`" 6 | year: "`r format(Sys.Date(), '%Y')`" 7 | vol: 1 8 | issue: 1 9 | jel: 10 | - A10 11 | - A11 12 | keywords: 13 | - first keyword 14 | - second keyword 15 | author: 16 | - name: Alice Anonymous 17 | firstname: Alice 18 | surname: Anonymous 19 | email: alice@example.com 20 | affiliation: Some Institute of Technology 21 | - name: Bob Security 22 | firstname: Bob 23 | surname: Security 24 | email: bob@example.com 25 | affiliation: Another University 26 | acknowledgements: | 27 | Acknowledgements 28 | abstract: | 29 | Abstract goes here 30 | output: rticles::aea_article 31 | --- 32 | 33 | American Economic Review Pointers: 34 | 35 | \begin{itemize} 36 | \item Do not use an "Introduction" heading. Begin your introductory material 37 | before the first section heading. 38 | 39 | \item Avoid style markup (except sparingly for emphasis). 40 | 41 | \item Avoid using explicit vertical or horizontal space. 42 | 43 | \item Captions are short and go below figures but above tables. 44 | 45 | \item The tablenotes or figurenotes environments may be used below tables 46 | or figures, respectively, as demonstrated below. 47 | 48 | \item If you have difficulties with the mathtime package, adjust the package 49 | options appropriately for your platform. If you can't get it to work, just 50 | remove the package or see our technical support document online (please 51 | refer to the author instructions). 52 | 53 | \item If you are using an appendix, it goes last, after the bibliography. 54 | Use regular section headings to make the appendix headings. 55 | 56 | \item If you are not using an appendix, you may delete the appendix command 57 | and sample appendix section heading. 58 | 59 | \item Either the natbib package or the harvard package may be used with bibtex. 60 | To include one of these packages, uncomment the appropriate usepackage command 61 | above. Note: you can't use both packages at once or compile-time errors will result. 62 | 63 | \end{itemize} 64 | 65 | \section{First Section in Body} 66 | 67 | Sample figure: 68 | 69 | \begin{figure} 70 | Figure here. 71 | 72 | \caption{Caption for figure below.} 73 | \begin{figurenotes} 74 | Figure notes without optional leadin. 75 | \end{figurenotes} 76 | \begin{figurenotes}[Source] 77 | Figure notes with optional leadin (Source, in this case). 78 | \end{figurenotes} 79 | \end{figure} 80 | 81 | Sample table: 82 | 83 | \begin{table} 84 | \caption{Caption for table above.} 85 | 86 | \begin{tabular}{lll} 87 | & Heading 1 & Heading 2 \\ 88 | Row 1 & 1 & 2 \\ 89 | Row 2 & 3 & 4% 90 | \end{tabular} 91 | \begin{tablenotes} 92 | Table notes environment without optional leadin. 93 | \end{tablenotes} 94 | \begin{tablenotes}[Source] 95 | Table notes environment with optional leadin (Source, in this case). 96 | \end{tablenotes} 97 | \end{table} 98 | 99 | References here (manual or bibTeX). If you are using bibTeX, add your bib file 100 | name in place of BibFile in the bibliography command. 101 | % Remove or comment out the next two lines if you are not using bibtex. 102 | \bibliographystyle{aea} 103 | \bibliography{references} 104 | 105 | % The appendix command is issued once, prior to all appendices, if any. 106 | \appendix 107 | 108 | \section{Mathematical Appendix} 109 | -------------------------------------------------------------------------------- /RMarkdown/rticles/aea_article/references.bib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/aea_article/references.bib -------------------------------------------------------------------------------- /RMarkdown/rticles/amq_article/authorcommands.tex: -------------------------------------------------------------------------------- 1 | %% Vous pouvez ajouter ici toutes les commandes que vous avez définies. 2 | %% Par exemple 3 | 4 | % \newcommand{\lr}[1]{\left(#1\right)} 5 | % \newcommand{\abs}[1]{\left\vert#1\right\vert} 6 | -------------------------------------------------------------------------------- /RMarkdown/rticles/amq_article/authorpackages.tex: -------------------------------------------------------------------------------- 1 | %% Vous pouvez ajouter ici tous les packages que vous avez besoin. 2 | %% Par exemple 3 | 4 | % \usepackage{pstricks} 5 | % \usepackage{enumitem} 6 | -------------------------------------------------------------------------------- /RMarkdown/rticles/amq_article/mybibliography.tex: -------------------------------------------------------------------------------- 1 | \bigskip 2 | 3 | \bibliographystyle{alpha} 4 | \begin{thebibliography}{10} 5 | 6 | \bibitem{cout} Couture, M. (2010, mise à jour 18 avril). {\em Revue internationale des technologies en édagogie universitaire. Normes bibliographiques - Adaptation française des normes de l'APA}. Récupéré le 3 janvier 2011 du site de l'auteur : \href {http://www.teluq.uqam.ca/~mcouture/apa}{http://www.teluq.uqam.ca/~mcouture/apa} 7 | 8 | \bibitem{daha} Dahan-Dalmedico, A. et Peiffer, J. (1982). {\em Histoire des mathématiques-Routes et dédales}. Paris, France: Études vivantes. 9 | 10 | \bibitem{desg} Desgraupes, B. (2003). {\em \LaTeX, Apprentissage, guide et référence}. France: Vuibert. 11 | 12 | \bibitem{ctan} Fairbairns, R. (2006, mise à jour le 21 janvier 2006). {\em Search CTAN For a File}, Récupéré le 3 janvier 2011 du site de CTAN :\href{http://www.tex.ac.uk/CTANfind.html}{http://www.tex.ac.uk/CTANfind.html}.\\ 13 | Demander texlive pour arriver à \\tex-archive/systems/texlive/Images/Images/texlive-inst.iso.bz2 14 | 15 | Cliquer pour récupérer l'image compressée du CD au format bzip2 (550 Mo!) 16 | 17 | \bibitem{flipo} Flipo, D. (2004). \LaTeX, logiciel libre et gratuit, comme alternative à MS-Word, {\em Quadrature}, no. 54, 12--15. 18 | 19 | \bibitem{faq} Kluth, M.-P. et Bayart, B. (1997, mise à jour 16 octobre 2001). {\em FAQ \LaTeX~de l'équipe Grappa}. Récupéré le 3 janvier 2011 du site du groupe Grappa de l'Université de Lille 3 : \href{http://www.grappa.univ-lille3.fr/FAQ-LaTeX/}{http://www.grappa.univ-lille3.fr/FAQ-LaTeX/}. 20 | 21 | \bibitem{lamp} Lamport, L. (1986). {\em \LaTeX: A Document Preparation System}. Reading, MA: Addison-Wesley Publishing Company. 22 | 23 | \bibitem{mass} Masson, B. (2009). \begin{itshape}{\LaTeX, créer ses commandes}\end{itshape}. Récupéré le 3 janvier 2011 du site de l'auteur :\href {http://bertrandmasson.free.fr/wp-content/uploads/commande.pdf}{http://bertrandmasson.free.fr/wp-content/uploads/commande.pdf}. 24 | 25 | \bibitem{oeti} Oetiker, T., Partl, H., Hyna, I. et Schlegl, E. (1999). {\em Une courte (?) introduction à \LaTeXe, ou \LaTeXe~en 88 minutes}, Version 3.3. Récupéré le 3 janvier 2011 du site du Loria : \href{http://tex.loria.fr/general/flshort-3.3.pdf}{http://tex.loria.fr/general/flshort-3.3.pdf}. 26 | 27 | \bibitem{roll}Rolland, C. (2000). {\em \LaTeX~par la pratique} ($2^e$ Éd.). Paris, France: Eyrolles. 28 | 29 | \end{thebibliography} 30 | -------------------------------------------------------------------------------- /RMarkdown/rticles/amq_article/pics/Figure1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/amq_article/pics/Figure1.jpg -------------------------------------------------------------------------------- /RMarkdown/rticles/amq_article/pics/Figure2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/amq_article/pics/Figure2.pdf -------------------------------------------------------------------------------- /RMarkdown/rticles/ams_article/figure01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/ams_article/figure01.pdf -------------------------------------------------------------------------------- /RMarkdown/rticles/ctex.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "在R Markdown文档中使用中文" 3 | author: 4 | - 谢益辉 5 | - 邱怡轩 6 | - 于淼 7 | documentclass: ctexart 8 | output: 9 | rticles::ctex: 10 | fig_caption: yes 11 | number_sections: yes 12 | toc: yes 13 | classoption: "hyperref," 14 | --- 15 | 16 | # 引言 17 | 18 | 中文LaTeX文档并非难题。当然这句话得站在巨人 [CTeX](http://ctex.org) 的肩膀上才能说,它让我们只需要一句 19 | 20 | ```latex 21 | \documentclass{ctexart} % 或者ctexrep/ctexbook 22 | ``` 23 | 24 | 或者 25 | 26 | ```latex 27 | \usepackage{ctex} 28 | ``` 29 | 30 | 就轻松搞定中文LaTeX排版问题。 31 | 32 | # 字体和选项 33 | 34 | LaTeX包[**ctex**](http://ctan.org/pkg/ctex)支持若干种字体选项,如果你是**ctex**老用户,请注意这里我们要求的最低版本是2.2,你可能需要升级你的LaTeX包。从版本2.0开始,**ctex**支持根据不同操作系统自动选择中文字体,简直是为人类进步作出了巨大贡献,我们再也不必费尽口舌向用户解释“啊,你用Windows啊,那么你该使用什么字体;啊,你用Mac啊,又该如何如何”。 35 | 36 | 下面的YAML元数据应该能满足多数用户的需求,主要设置两项参数:文档类为`ctexart`(当然也可以是别的类),输出格式为`rticles::ctex`,其默认LaTeX引擎为XeLaTeX(真的,别纠结你的旧爱PDFLaTeX了)。 37 | 38 | ```yaml 39 | --- 40 | documentclass: ctexart 41 | output: rticles::ctex 42 | --- 43 | ``` 44 | 45 | `rticles::ctex`的参数都是普通的`pdf_document`参数,参见文档**rmarkdown**包的文档,这里就不赘述了。 46 | 47 | Windows和Mac用户应该都已经有自带的中文字体了。Linux用户可以考虑 [Fandol字体](http://ctan.org/pkg/fandol),它号称是免费的,不过我们也没太搞清楚它的来头。如果你不想操心这些问题,我们强烈建议你卸载你当前的 LaTeX 套装(TeX Live 或 MiKTeX 或 MacTeX),换上 TinyTeX,一切将会自动化搞定。 48 | 49 | ```{r eval=FALSE} 50 | devtools::install_github(c('rstudio/rmarkdown', 'yihui/tinytex')) 51 | tinytex::install_tinytex() 52 | ``` 53 | 54 | # R代码段 55 | 56 | R代码用R Markdown的语法嵌入,即三个反引号开始一段代码```` ```{r} ````和三个反引号```` ``` ```` 结束一段代码: 57 | 58 | ```{r} 59 | options(digits = 4) 60 | fit = lm(dist ~ speed, data = cars) 61 | coef(summary(fit)) 62 | b = coef(fit) 63 | ``` 64 | 65 | 上面回归方程中的斜率是`r b[2]`,完整的回归方程为:$$ Y = `r b[1]` + `r b[2]`x$$ 66 | 67 | 画图当然也是木有问题的啦,想画就说嘛,不说我怎么知道你想画呢? 68 | 69 | ```{r scatter, fig.cap='cars数据散点图以及回归直线。'} 70 | par(mar = c(4, 4, .1, .1), las = 1) 71 | plot(cars, pch = 19) 72 | abline(fit, col = 'red') 73 | ``` 74 | 75 | 请不要问我为什么图浮动到下一页去了,这么初级的LaTeX问题问出来信不信我扁你。 76 | 77 | # 源代码控 78 | 79 | 这里提供的rticles模板可能由于种种原因不能满足客官的要求,LaTeX用户就是这样永无止境地调格式(唉,跟Word用户到底有啥区别呢)。若真是需要调整,你可以复制一份默认模板去改,如前面所说,本文档的模板是`rticles::ctex_template()`,它是一个文本文件。若熟悉LaTeX的话一看就明白,只不过里面有些Pandoc变量而已;若不熟悉LaTeX我们在这里说了也白说,花几天时间好好啃一啃LaTeX入门手册吧。 80 | 81 | 本文档所用的模板是从Pandoc默认LaTeX模板基础上做了少许改动而来的:https://github.com/yihui/pandoc-templates/blob/ctex/default.latex 具体改动从GIT提交消息日志中可以看到,主要就是去掉了mathspec包和hyperref包。 82 | 83 | # 小结 84 | 85 | 事实证明我们可以理直气壮地通过XeLaTeX将中文R Markdown转化为PDF文档,麻麻再也不用担心我的论文满屏幕都是反斜杠,朕养完小白鼠之后终于不必先折腾三个小时LaTeX再开始写实验报告了:打开RStudio,菜单File > New File > R Markdown,然后从模板中选择CTeX Documents,搞定。 86 | -------------------------------------------------------------------------------- /RMarkdown/rticles/elsevier_article/elsevier_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Short Paper 3 | author: 4 | - name: Alice Anonymous 5 | email: alice@example.com 6 | affiliation: Some Institute of Technology 7 | footnote: Corresponding Author 8 | - name: Bob Security 9 | email: bob@example.com 10 | affiliation: Another University 11 | address: 12 | - code: Some Institute of Technology 13 | address: Department, Street, City, State, Zip 14 | - code: Another University 15 | address: Department, Street, City, State, Zip 16 | abstract: | 17 | This is the abstract. 18 | 19 | It consists of two paragraphs. 20 | 21 | journal: "An awesome journal" 22 | date: "`r Sys.Date()`" 23 | bibliography: mybibfile.bib 24 | output: rticles::elsevier_article 25 | --- 26 | 27 | _Text based on elsarticle sample manuscript, see [http://www.elsevier.com/author-schemas/latex-instructions#elsarticle](http://www.elsevier.com/author-schemas/latex-instructions#elsarticle)_ 28 | 29 | 30 | The Elsevier article class 31 | ========================== 32 | 33 | #### Installation 34 | 35 | If the document class *elsarticle* is not available on your computer, 36 | you can download and install the system package *texlive-publishers* 37 | (Linux) or install the LaTeX package *elsarticle* using the package 38 | manager of your TeX installation, which is typically TeX Live or MikTeX. 39 | 40 | #### Usage 41 | 42 | Once the package is properly installed, you can use the document class 43 | *elsarticle* to create a manuscript. Please make sure that your 44 | manuscript follows the guidelines in the Guide for Authors of the 45 | relevant journal. It is not necessary to typeset your manuscript in 46 | exactly the same way as an article, unless you are submitting to a 47 | camera-ready copy (CRC) journal. 48 | 49 | #### Functionality 50 | 51 | The Elsevier article class is based on the standard article class and 52 | supports almost all of the functionality of that class. In addition, it 53 | features commands and options to format the 54 | 55 | - document style 56 | 57 | - baselineskip 58 | 59 | - front matter 60 | 61 | - keywords and MSC codes 62 | 63 | - theorems, definitions and proofs 64 | 65 | - lables of enumerations 66 | 67 | - citation style and labeling. 68 | 69 | Front matter 70 | ============ 71 | 72 | The author names and affiliations could be formatted in two ways: 73 | 74 | (1) Group the authors per affiliation. 75 | 76 | (2) Use footnotes to indicate the affiliations. 77 | 78 | See the front matter of this document for examples. You are recommended 79 | to conform your choice to the journal you are submitting to. 80 | 81 | Bibliography styles 82 | =================== 83 | 84 | There are various bibliography styles available. You can select the 85 | style of your choice in the preamble of this document. These styles are 86 | Elsevier styles based on standard styles like Harvard and Vancouver. 87 | Please use BibTeX to generate your bibliography and include DOIs 88 | whenever available. 89 | 90 | Here are two sample references: @Feynman1963118 [@Dirac1953888]. 91 | 92 | References {#references .unnumbered} 93 | ========== 94 | -------------------------------------------------------------------------------- /RMarkdown/rticles/elsevier_article/mybibfile.bib: -------------------------------------------------------------------------------- 1 | @article{Dirac1953888, 2 | title = "The lorentz transformation and absolute time", 3 | journal = "Physica ", 4 | volume = "19", 5 | number = "1-–12", 6 | pages = "888--896", 7 | year = "1953", 8 | doi = "10.1016/S0031-8914(53)80099-6", 9 | author = "P.A.M. Dirac" 10 | } 11 | 12 | @article{Feynman1963118, 13 | title = "The theory of a general quantum system interacting with a linear dissipative system", 14 | journal = "Annals of Physics ", 15 | volume = "24", 16 | pages = "118--173", 17 | year = "1963", 18 | doi = "10.1016/0003-4916(63)90068-X", 19 | author = "R.P Feynman and F.L {Vernon Jr.}" 20 | } 21 | -------------------------------------------------------------------------------- /RMarkdown/rticles/generate.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "# Generate all `rticles` drafts" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 1, 15 | "metadata": { 16 | "collapsed": false 17 | }, 18 | "outputs": [ 19 | { 20 | "name": "stderr", 21 | "output_type": "stream", 22 | "text": [ 23 | "Loading required package: rticles\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "require(rticles)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "metadata": { 35 | "collapsed": false 36 | }, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/html": [ 41 | ] 42 | }, 43 | "execution_count": 2, 44 | "metadata": { 45 | }, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "# cleanup\n", 51 | "system2(\"bash\", args = c(\"-c\", \"'rm ctex*'\"))\n", 52 | "system2(\"bash\", args = c(\"-c\", \"'find -mindepth 1 -type d -print0 | xargs -0 rm -rf'\"), \n", 53 | " stdout = TRUE)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 3, 59 | "metadata": { 60 | "collapsed": false 61 | }, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "[1] \"problem: Error in rmarkdown::draft(fn, template = name, package = \\\"rticles\\\"): The template 'ctex_template' was not found in the rticles package\\n\"\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "for (name in getNamespaceExports(\"rticles\")) {\n", 73 | " fn = paste(name, \".Rmd\", sep=\"\")\n", 74 | " tryCatch({\n", 75 | " rmarkdown::draft(fn, template = name, package = \"rticles\")\n", 76 | " }, error = function(err) {\n", 77 | " print(paste(\"problem:\", err))\n", 78 | " })\n", 79 | "}" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 0, 85 | "metadata": { 86 | "collapsed": false 87 | }, 88 | "outputs": [ 89 | ], 90 | "source": [ 91 | ] 92 | } 93 | ], 94 | "metadata": { 95 | "kernelspec": { 96 | "display_name": "R (R-Project)", 97 | "language": "r", 98 | "name": "ir" 99 | }, 100 | "language_info": { 101 | "codemirror_mode": "r", 102 | "file_extension": ".r", 103 | "mimetype": "text/x-r-source", 104 | "name": "R", 105 | "pygments_lexer": "r", 106 | "version": "3.4.4" 107 | } 108 | }, 109 | "nbformat": 4, 110 | "nbformat_minor": 0 111 | } -------------------------------------------------------------------------------- /RMarkdown/rticles/ieee_article/mybibfile.bib: -------------------------------------------------------------------------------- 1 | @article{Dirac1953888, 2 | title = "The lorentz transformation and absolute time", 3 | journal = "Physica", 4 | volume = "19", 5 | number = "1--12", 6 | pages = "888--896", 7 | year = "1953", 8 | doi = "10.1016/S0031-8914(53)80099-6", 9 | author = "P.A.M. Dirac" 10 | } 11 | 12 | @article{Feynman1963118, 13 | title = "The theory of a general quantum system interacting with a linear dissipative system", 14 | journal = "Annals of Physics ", 15 | volume = "24", 16 | pages = "118--173", 17 | year = "1963", 18 | doi = "10.1016/0003-4916(63)90068-X", 19 | author = "R.P Feynman and F.L {Vernon Jr.}" 20 | } 21 | -------------------------------------------------------------------------------- /RMarkdown/rticles/jss_article/jss_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | author: 3 | - name: FirstName LastName 4 | affiliation: University/Company 5 | address: > 6 | First line 7 | Second line 8 | email: \email{name@company.com} 9 | url: http://rstudio.com 10 | - name: Second Author 11 | affiliation: Affiliation 12 | title: 13 | formatted: "A Capitalized Title: Something about a Package \\pkg{foo}" 14 | # If you use tex in the formatted title, also supply version without 15 | plain: "A Capitalized Title: Something about a Package foo" 16 | # For running headers, if needed 17 | short: "\\pkg{foo}: A Capitalized Title" 18 | abstract: > 19 | The abstract of the article. 20 | keywords: 21 | # at least one keyword must be supplied 22 | formatted: [keywords, not capitalized, "\\proglang{Java}"] 23 | plain: [keywords, not capitalized, Java] 24 | preamble: > 25 | \usepackage{amsmath} 26 | output: rticles::jss_article 27 | --- 28 | 29 | # Introduction 30 | 31 | This template demonstrates some of the basic latex you'll need to know to create a JSS article. 32 | 33 | ## Code formatting 34 | 35 | Don't use markdown, instead use the more precise latex commands: 36 | 37 | * \proglang{Java} 38 | * \pkg{plyr} 39 | * \code{print("abc")} 40 | 41 | # R code 42 | 43 | Can be inserted in regular R markdown blocks. 44 | 45 | ```{r} 46 | x <- 1:10 47 | x 48 | ``` 49 | -------------------------------------------------------------------------------- /RMarkdown/rticles/jss_article/jsslogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/jss_article/jsslogo.jpg -------------------------------------------------------------------------------- /RMarkdown/rticles/mdpi_article/appendix.tex: -------------------------------------------------------------------------------- 1 | %% optional 2 | \appendixtitles{no} %Leave argument "no" if all appendix headings stay EMPTY (then no dot is printed after "Appendix A"). If the appendix sections contain a heading then change the argument to "yes". 3 | \appendixsections{multiple} %Leave argument "multiple" if there are multiple sections. Then a counter is printed ("Appendix A"). If there is only one appendix section then change the argument to "one" and no counter is printed ("Appendix"). 4 | \appendix 5 | \section{} 6 | \subsection{} 7 | The appendix is an optional section that can contain details and data supplemental to the main text. For example, explanations of experimental details that would disrupt the flow of the main text, but nonetheless remain crucial to understanding and reproducing the research shown; figures of replicates for experiments of which representative data is shown in the main text can be added here if brief, or as Supplementary data. Mathematical proofs of results not central to the paper can be added as an appendix. 8 | 9 | \section{} 10 | All appendix sections must be cited in the main text. In the appendixes, Figures, Tables, etc. should be labeled starting with `A', e.g., Figure A1, Figure A2, etc. 11 | -------------------------------------------------------------------------------- /RMarkdown/rticles/mdpi_article/mybibfile.bib: -------------------------------------------------------------------------------- 1 | 2 | @article{leutnant_stormwater_2016, 3 | title = {Stormwater {Pollutant} {Process} {Analysis} with {Long}-{Term} {Online} {Monitoring} {Data} at {Micro}-{Scale} {Sites}}, 4 | volume = {8}, 5 | issn = {2073-4441}, 6 | url = {http://www.mdpi.com/2073-4441/8/7/299}, 7 | doi = {10.3390/w8070299}, 8 | language = {en}, 9 | number = {7}, 10 | urldate = {2016-07-21}, 11 | journal = {Water}, 12 | author = {Leutnant, Dominik and Muschalla, Dirk and Uhl, Mathias}, 13 | month = jul, 14 | year = {2016}, 15 | note = {00000}, 16 | pages = {299} 17 | } 18 | 19 | @book{gujer_systems_2008, 20 | address = {Berlin, Heidelberg, Germany}, 21 | title = {Systems {Analysis} for {Water} {Technology}}, 22 | isbn = {978-3-540-77277-4}, 23 | shorttitle = {Systems {Analysis} for {Water} {Technology}}, 24 | publisher = {Springer-Verlag}, 25 | author = {Gujer, W.}, 26 | year = {2008} 27 | } 28 | 29 | @article{bertrand-krajewski_distribution_1998, 30 | title = {Distribution of pollutant mass vs volume in stormwater discharges and the first flush phenomenon}, 31 | volume = {32}, 32 | shorttitle = {Distribution of pollutant mass vs volume in stormwater discharges and the first flush phenomenon}, 33 | url = {http://www.scopus.com/inward/record.url?eid=2-s2.0-0032146023&partnerID=40&md5=d6517b6efa014bc12f3ae70abe71977d}, 34 | number = {8}, 35 | journal = {Water Research}, 36 | author = {Bertrand-Krajewski, J. L. and Chebbo, G. and Saget, A.}, 37 | year = {1998}, 38 | keywords = {Combined sewer system, First flush, Pollutant load distribution, Separate sewer system, Storage and treatment tanks, Stormwater discharges, Suspended Solids}, 39 | pages = {2341--2356} 40 | } 41 | -------------------------------------------------------------------------------- /RMarkdown/rticles/mnras_article/README.md: -------------------------------------------------------------------------------- 1 | # pandoc-mnras 2 | 3 | A template for building MNRAS Journal articles in pandoc. 4 | -------------------------------------------------------------------------------- /RMarkdown/rticles/mnras_article/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/mnras_article/example.png -------------------------------------------------------------------------------- /RMarkdown/rticles/mnras_article/references.bib: -------------------------------------------------------------------------------- 1 | @ARTICLE{Author2012, 2 | AUTHOR = "Author A.~N.", 3 | YEAR = {2012}, 4 | JOURNAL = "Journal of Improbable Astronomy", 5 | VOLUME = {1}, 6 | NUMBER = {1} } 7 | 8 | @ARTICLE{Others2013, 9 | AUTHOR = "Others S.", 10 | YEAR = {2013}, 11 | JOURNAL = "Journal of Interesting Stuff", 12 | VOLUME = {17}, 13 | NUMBER = {198} } 14 | -------------------------------------------------------------------------------- /RMarkdown/rticles/peerj_article/sample.bib: -------------------------------------------------------------------------------- 1 | @ARTICLE{Figueredo:2009dg, 2 | doi = {10.1007/s12110-009-9068-2}, 3 | url = {https://doi.org/10.1007%2Fs12110-009-9068-2}, 4 | year = 2009, 5 | month = {Aug}, 6 | publisher = {Springer Nature}, 7 | volume = {20}, 8 | number = {3}, 9 | pages = {317--330}, 10 | author = {Aurelio Jos{\'{e}} Figueredo and Pedro S. A. Wolf}, 11 | title = {Assortative Pairing and Life History Strategy}, 12 | journal = {Human Nature} 13 | } 14 | -------------------------------------------------------------------------------- /RMarkdown/rticles/peerj_article/view.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/peerj_article/view.jpg -------------------------------------------------------------------------------- /RMarkdown/rticles/plos_article/PLOS-submission.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/plos_article/PLOS-submission.eps -------------------------------------------------------------------------------- /RMarkdown/rticles/plos_article/mybibfile.bib: -------------------------------------------------------------------------------- 1 | @article{Dirac1953888, 2 | title = "The lorentz transformation and absolute time", 3 | journal = "Physica ", 4 | volume = "19", 5 | number = "1-–12", 6 | pages = "888--896", 7 | year = "1953", 8 | doi = "10.1016/S0031-8914(53)80099-6", 9 | author = "P.A.M. Dirac" 10 | } 11 | 12 | @article{Feynman1963118, 13 | title = "The theory of a general quantum system interacting with a linear dissipative system", 14 | journal = "Annals of Physics ", 15 | volume = "24", 16 | pages = "118--173", 17 | year = "1963", 18 | doi = "10.1016/0003-4916(63)90068-X", 19 | author = "R.P Feynman and F.L {Vernon Jr.}" 20 | } 21 | -------------------------------------------------------------------------------- /RMarkdown/rticles/plos_article/plos_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Title of submission to PLOS journal 3 | author: 4 | - name: Alice Anonymous 5 | email: alice@example.com 6 | affiliation: Some Institute of Technology 7 | corresponding: alice@example.com 8 | - name: Bob Security 9 | email: bob@example.com 10 | affiliation: Another University 11 | address: 12 | - code: Some Institute of Technology 13 | address: Department, Street, City, State, Zip 14 | - code: Another University 15 | address: Department, Street, City, State, Zip 16 | abstract: | 17 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget porta erat. Morbi consectetur est vel gravida pretium. Suspendisse ut dui eu ante cursus gravida non sed sem. Nullam sapien tellus, commodo id velit id, eleifend volutpat quam. Phasellus mauris velit, dapibus finibus elementum vel, pulvinar non tellus. Nunc pellentesque pretium diam, quis maximus dolor faucibus id. Nunc convallis sodales ante, ut ullamcorper est egestas vitae. Nam sit amet enim ultrices, ultrices elit pulvinar, volutpat risus. 18 | 19 | author_summary: | 20 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget porta erat. Morbi consectetur est vel gravida pretium. Suspendisse ut dui eu ante cursus gravida non sed sem. Nullam sapien tellus, commodo id velit id, eleifend volutpat quam. Phasellus mauris velit, dapibus finibus elementum vel, pulvinar non tellus. Nunc pellentesque pretium diam, quis maximus dolor faucibus id. Nunc convallis sodales ante, ut ullamcorper est egestas vitae. Nam sit amet enim ultrices, ultrices elit pulvinar, volutpat risus. 21 | 22 | bibliography: mybibfile.bib 23 | output: rticles::plos_article 24 | csl: plos.csl 25 | --- 26 | 27 | _Text based on plos sample manuscript, see [http://journals.plos.org/ploscompbiol/s/latex](http://journals.plos.org/ploscompbiol/s/latex)_ 28 | 29 | # Introduction 30 | 31 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget porta erat. Morbi consectetur est vel gravida pretium. Suspendisse ut dui eu ante cursus gravida non sed sem. Phasellus mauris velit, dapibus finibus elementum vel, pulvinar non tellus. Nunc pellentesque pretium diam, quis maximus dolor faucibus id. Nunc convallis sodales ante, ut ullamcorper est egestas vitae. Nam sit amet enim ultrices, ultrices elit pulvinar, volutpat risus. 32 | 33 | A list 34 | 35 | - Item 1 36 | - Item 2 37 | 38 | Here are two sample references: @Feynman1963118 [@Dirac1953888]. 39 | 40 | # References {#references .unnumbered} 41 | -------------------------------------------------------------------------------- /RMarkdown/rticles/pnas_article/frog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/pnas_article/frog.png -------------------------------------------------------------------------------- /RMarkdown/rticles/pnas_article/pnas-sample.bib: -------------------------------------------------------------------------------- 1 | @inproceedings{belkin2002using, 2 | title={Using manifold stucture for partially labeled classification}, 3 | author={Belkin, Mikhail and Niyogi, Partha}, 4 | booktitle={Advances in neural information processing systems}, 5 | pages={929--936}, 6 | year={2002} 7 | } 8 | 9 | @article{berard1994embedding, 10 | title={Embedding Riemannian manifolds by their heat kernel}, 11 | author={B{\'e}rard, Pierre and Besson, G{\'e}rard and Gallot, Sylvain}, 12 | journal={Geometric \& Functional Analysis GAFA}, 13 | volume={4}, 14 | number={4}, 15 | pages={373--398}, 16 | year={1994}, 17 | publisher={Springer} 18 | } 19 | 20 | @article{coifman2005geometric, 21 | title={Geometric diffusions as a tool for harmonic analysis and structure definition of data: Diffusion maps}, 22 | author={Coifman, Ronald R and Lafon, Stephane and Lee, Ann B and Maggioni, Mauro and Nadler, Boaz and Warner, Frederick and Zucker, Steven W}, 23 | journal={Proceedings of the National Academy of Sciences of the United States of America}, 24 | volume={102}, 25 | number={21}, 26 | pages={7426--7431}, 27 | year={2005}, 28 | publisher={National Acad Sciences} 29 | } -------------------------------------------------------------------------------- /RMarkdown/rticles/pnas_article/pnasmathematics.sty: -------------------------------------------------------------------------------- 1 | %%% PNAS one column mathematics article style file 2 | %%% For use with pnas-new.cls 3 | \NeedsTeXFormat{LaTeX2e} 4 | \ProvidesPackage{pnasmathematics}[2016/02/28 v1.2 PNAS one column mathematics article style] 5 | 6 | %% Set whether the abstract is set into the first column 7 | \setboolean{shortarticle}{false} 8 | % true = set into first column 9 | % false = spans page width 10 | 11 | %% Set to single column style 12 | \onecolumn 13 | \setboolean{singlecolumn}{true} 14 | 15 | %% Set colors 16 | \definecolor{color2}{RGB}{130,0,0} % color 17 | 18 | %% Set up the first page footnote/fact box here 19 | \RequirePackage{float} 20 | \floatstyle{plain} 21 | \newfloat{sigstatement}{b!}{sst} 22 | 23 | \additionalelement{% 24 | \begin{sigstatement} 25 | \sffamily 26 | \mdfdefinestyle{pnassigstyle}{linewidth=0.7pt,backgroundcolor=pnasblueback,linecolor=pnasbluetext,fontcolor=pnasbluetext,innertopmargin=6pt,innerrightmargin=6pt,innerbottommargin=6pt,innerleftmargin=6pt} 27 | \@ifundefined{@significancestatement}{}{% 28 | \begin{mdframed}[style=pnassigstyle]% 29 | \section*{Significance Statement}% 30 | \@significancestatement 31 | \end{mdframed}} 32 | % \medskip 33 | \scriptsize 34 | \@ifundefined{@authorcontributions}{}{\@authorcontributions} 35 | \vskip5pt% 36 | \@ifundefined{@authordeclaration}{}{\@authordeclaration} 37 | \vskip5pt% 38 | \@ifundefined{@equalauthors}{}{\@equalauthors} 39 | \vskip5pt% 40 | \@ifundefined{@correspondingauthor}{}{\@correspondingauthor} 41 | \end{sigstatement} 42 | } 43 | 44 | %% No additional elements nor pnasbreak required 45 | %\additionalelement{} 46 | \def\pnasbreak{} 47 | 48 | \endinput -------------------------------------------------------------------------------- /RMarkdown/rticles/pnas_article/pnasresearcharticle.sty: -------------------------------------------------------------------------------- 1 | %%% PNAS two column research article style file 2 | %%% For use with pnas-new.cls 3 | \NeedsTeXFormat{LaTeX2e} 4 | \ProvidesPackage{pnasresearcharticle}[2016/02/28 v1.2 PNAS two column research article style] 5 | 6 | %% Set whether the abstract is set into the first column 7 | \setboolean{shortarticle}{true} 8 | % true = set into first column 9 | % false = spans page width 10 | 11 | %% Set colors 12 | \definecolor{color2}{RGB}{130,0,0} % color 13 | 14 | %% Set up the first page footnote/fact box here 15 | \RequirePackage{float} 16 | \floatstyle{plain} 17 | \newfloat{sigstatement}{b!}{sst} 18 | 19 | \additionalelement{% 20 | \afterpage{\begin{sigstatement} 21 | \sffamily 22 | \mdfdefinestyle{pnassigstyle}{linewidth=0.7pt,backgroundcolor=pnasblueback,linecolor=pnasbluetext,fontcolor=pnasbluetext,innertopmargin=6pt,innerrightmargin=6pt,innerbottommargin=6pt,innerleftmargin=6pt} 23 | \@ifundefined{@significancestatement}{}{% 24 | \begin{mdframed}[style=pnassigstyle]% 25 | \section*{Significance Statement}% 26 | \@significancestatement 27 | \end{mdframed}} 28 | % \medskip 29 | \scriptsize 30 | \@ifundefined{@authorcontributions}{}{\@authorcontributions} 31 | \vskip5pt% 32 | \@ifundefined{@authordeclaration}{}{\@authordeclaration} 33 | \vskip5pt% 34 | \@ifundefined{@equalauthors}{}{\@equalauthors} 35 | \vskip5pt% 36 | \@ifundefined{@correspondingauthor}{}{\@correspondingauthor} 37 | \end{sigstatement}} 38 | } 39 | 40 | %% Break at end of article (before references) 41 | % The blank line before the strip command ensures there is nothing placed 42 | % directly before the break (which can cause formatting issues). 43 | \newcommand{\pnasbreak}{ 44 | 45 | \begin{strip} 46 | \vskip-11pt 47 | \end{strip} 48 | } 49 | 50 | \endinput -------------------------------------------------------------------------------- /RMarkdown/rticles/pnas_article/widetext.sty: -------------------------------------------------------------------------------- 1 | \NeedsTeXFormat{LaTeX2e} 2 | \ProvidesPackage{widetext} 3 | 4 | %% Mimics the widetext environment of revtex4 for any other class package 5 | %% Eg: article.cls 6 | %% 7 | %% Compiled by: Anjishnu Sarkar 8 | %% 9 | %% Advantages: 10 | %% *) Supports float (eg: figure) in two column format (Advantage over 11 | %% multicol package) 12 | %% *) One and twocolumn exist on the same page 13 | %% *) Flow of text shown via rule 14 | %% *) Equal height of text when in two column format 15 | %% 16 | %% Acknowledgment(s): 17 | %% 1. Instead of re-inventing the wheel, two packages (flushend, cuted) of 18 | %% the sttools bundle are used. The sttools bundle is available from CTAN. 19 | %% Lisence of these packages rests with their corresponding author. 20 | %% Any bug/problem with flushend and cuted should be forwarded to their 21 | %% corresponding package authors. 22 | %% 2. The idea of the rule came from the following latex community website 23 | %% http://www.latex-community.org/forum/viewtopic.php?f=5&t=2770 24 | %% 25 | %% This package just defines the widetext environment and the rules. 26 | %% 27 | %% Usage: 28 | %% \documentclass[a4paper,12pt,twocolumn]{article} 29 | %% \usepackage{widetext} 30 | %% 31 | %% \begin{document} 32 | %% 33 | %% Some text in twocolumn 34 | %% 35 | %% \begin{widetext} 36 | %% Text in onecolumn format. 37 | %% \end{widetext} 38 | %% 39 | %% Some more text in twocolumn 40 | %% 41 | %% \end{document} 42 | %%%%%%%%%%%%%%%%%%%% 43 | 44 | %% Package required for equal height while in 2 columns format 45 | \IfFileExists{flushend.sty} 46 | {\RequirePackage{flushend}} 47 | {\typeout{} 48 | \typeout{Package widetext error: Install the flushend package which is 49 | a part of sttools bundle. Available from CTAN.} 50 | \typeout{} 51 | \stop 52 | } 53 | 54 | %% Package required for onecolumn and twocolumn to exist on the same page. 55 | %% and also required for widetext environment. 56 | \IfFileExists{cuted.sty} 57 | {\RequirePackage{cuted}} 58 | {\typeout{} 59 | \typeout{Package widetext error: Install the cuted package which is 60 | a part of sttools bundle. Available from CTAN.} 61 | \typeout{} 62 | \stop 63 | } 64 | 65 | 66 | \newlength\@parindent 67 | \setlength\@parindent{\parindent} 68 | 69 | \if@twocolumn 70 | \newenvironment{widetext} 71 | {% 72 | \begin{strip} 73 | \rule{\dimexpr(0.5\textwidth-0.5\columnsep-0.4pt)}{0.4pt}% 74 | \rule{0.4pt}{6pt} 75 | \par %\vspace{6pt} 76 | \parindent \@parindent 77 | }% 78 | {% 79 | \par 80 | \hfill\rule[-6pt]{0.4pt}{6.4pt}% 81 | \rule{\dimexpr(0.5\textwidth-0.5\columnsep-1pt)}{0.4pt} 82 | \end{strip} 83 | } 84 | \else 85 | \newenvironment{widetext}{}{} 86 | \fi -------------------------------------------------------------------------------- /RMarkdown/rticles/rjournal_article/RJreferences.bib: -------------------------------------------------------------------------------- 1 | @Manual{R, 2 | title = {R: A Language and Environment for Statistical Computing}, 3 | author = {{R Core Team}}, 4 | organization = {R Foundation for Statistical Computing}, 5 | address = {Vienna, Austria}, 6 | year = {2012}, 7 | note = {{ISBN} 3-900051-07-0}, 8 | url = {http://www.R-project.org/}, 9 | } 10 | 11 | @article{ihaka:1996, 12 | Author = {Ihaka, Ross and Gentleman, Robert}, 13 | Journal = {Journal of Computational and Graphical Statistics}, 14 | Number = 3, 15 | Pages = {299--314}, 16 | Title = {R: A Language for Data Analysis and Graphics}, 17 | Volume = 5, 18 | Year = 1996} 19 | -------------------------------------------------------------------------------- /RMarkdown/rticles/rjournal_article/Rlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/rjournal_article/Rlogo.png -------------------------------------------------------------------------------- /RMarkdown/rticles/rjournal_article/preamble.tex: -------------------------------------------------------------------------------- 1 | % Any extra LaTeX you need in the preamble 2 | -------------------------------------------------------------------------------- /RMarkdown/rticles/rjournal_article/rjournal_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Capitalized Title Here 3 | author: 4 | - name: Author One 5 | affiliation: Affiliation 6 | address: 7 | - line 1 8 | - line 2 9 | email: author1@work 10 | - name: Author Two 11 | affiliation: Affiliation 12 | address: 13 | - line 1 14 | - line 2 15 | email: author2@work 16 | abstract: > 17 | An abstract of less than 150 words. 18 | output: 19 | rticles::rjournal_article: 20 | includes: 21 | in_header: preamble.tex 22 | --- 23 | 24 | ## Introduction 25 | 26 | Introductory section which may include references in parentheses 27 | \citep{R}, or cite a reference such as \citet{R} in the text. 28 | 29 | ## Section title in sentence case 30 | 31 | This section may contain a figure such as Figure \ref{figure:rlogo}. 32 | 33 | \begin{figure}[htbp] 34 | \centering 35 | \includegraphics{Rlogo} 36 | \caption{The logo of R.} 37 | \label{figure:rlogo} 38 | \end{figure} 39 | 40 | ## Another section 41 | 42 | There will likely be several sections, perhaps including code snippets, such as: 43 | 44 | ```{r} 45 | x <- 1:10 46 | x 47 | ``` 48 | 49 | ## Summary 50 | 51 | This file is only a basic article template. For full details of _The R Journal_ style and information on how to prepare your article for submission, see the [Instructions for Authors](https://journal.r-project.org/share/author-guide.pdf). 52 | \bibliography{RJreferences} 53 | -------------------------------------------------------------------------------- /RMarkdown/rticles/rsos_article/OPENSCIENCE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/rsos_article/OPENSCIENCE.pdf -------------------------------------------------------------------------------- /RMarkdown/rticles/rsos_article/OpenAccesslogo_bw.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/rsos_article/OpenAccesslogo_bw.pdf -------------------------------------------------------------------------------- /RMarkdown/rticles/rsos_article/RSOS_Pubs_Logo_Line_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/rsos_article/RSOS_Pubs_Logo_Line_CMYK.pdf -------------------------------------------------------------------------------- /RMarkdown/rticles/rsos_article/RS_crossmark_logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/RMarkdown/rticles/rsos_article/RS_crossmark_logo.pdf -------------------------------------------------------------------------------- /RMarkdown/rticles/rss_article/bibliography.bib: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /RMarkdown/rticles/rss_article/rss_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Untitled" 3 | short_title: "Untitled" 4 | author: "Author 1" 5 | short_author: "Author 1 et. al." 6 | affiliation: "Affiliation" 7 | address: "Address" 8 | city: "City" 9 | country: "Country" 10 | email: "email (at) address" 11 | author2: "Author 2" 12 | affiliation2: "Affiliation" 13 | address2: "Address" 14 | city2: "Los Angeles" 15 | country2: "Country" 16 | email2: "email (at) address" 17 | abstract: | 18 | Abstract goes here 19 | keywords: keywords 20 | bibliography: "bibliography" 21 | output: rticles::rss_article 22 | --- 23 | 24 | # Introduction 25 | 26 | This template demonstrates some of the basic latex you'll need to know to create a RSS article. 27 | 28 | # R code 29 | 30 | Can be inserted in regular R markdown blocks. 31 | 32 | ```{r} 33 | x <- 1:10 34 | x 35 | ``` 36 | -------------------------------------------------------------------------------- /RMarkdown/rticles/sim_article/bibfile.bib: -------------------------------------------------------------------------------- 1 | @article{Knupp1999, 2 | author = "Knupp, PM", 3 | title = "Winslow smoothing on two-dimensional unstructured meshes", 4 | year = "1999", 5 | journal = "Eng {C}omput", 6 | volume = "15", 7 | pages = "263--268" 8 | } 9 | 10 | @techreport{kamm2000, 11 | author = "Kamm, J", 12 | title = "Evaluation of the {S}edov-von {N}eumann-{T}aylor blast wave solution", 13 | institution = "Los {A}lamos {N}ational {L}aboratory", 14 | year = "2000", 15 | number = "Technical {R}eport LA-UR-00-6055" 16 | } 17 | 18 | @article{Taylor1937, 19 | author = "Taylor, GI and Green, AE", 20 | title = "Mechanism of the production of small eddies from large ones", 21 | year = "1937", 22 | journal = "P {R}oy {S}oc {L}ond {A} {M}at", 23 | volume = "158", 24 | number = "895", 25 | pages = "499--521" 26 | } 27 | 28 | -------------------------------------------------------------------------------- /RMarkdown/rticles/springer_article/bibliography.bib: -------------------------------------------------------------------------------- 1 | %% Copied from asa_article template 2 | 3 | 4 | @incollection{Galyardt14mmm, 5 | Author = {April Galyardt}, 6 | Booktitle = {Handbook of Mixed Membership Models}, 7 | Date-Added = {2014-08-21 21:18:27 +0000}, 8 | Date-Modified = {2014-08-21 21:18:27 +0000}, 9 | Editor = {Edoardo M. Airoldi and David Blei and Erosheva, Elena and Fienberg, Stephen E.}, 10 | Publisher = {Chapman and Hall}, 11 | Title = {Interpreting Mixed Membership Models: Implications of Erosheva's Representation Theorem}, 12 | Year = {2014} 13 | } 14 | 15 | 16 | @incollection{Mislevy06Cog, 17 | Author = {Robert Mislevy}, 18 | Booktitle = {Educational Assessment}, 19 | Chapter = {8}, 20 | Date-Added = {2014-08-21 20:58:59 +0000}, 21 | Date-Modified = {2014-08-21 20:58:59 +0000}, 22 | Editor = {Robert L. Brennan}, 23 | Publisher = {American Council on Education and Praeger Publishers}, 24 | Title = {Cognitive Psychology and Educational Assessment}, 25 | Year = {2006} 26 | } 27 | -------------------------------------------------------------------------------- /RMarkdown/rticles/springer_article/springer_article.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Title here 3 | subtitle: Do you have a subtitle? If so, write it here 4 | titlerunning: Short form of title (if too long for head) 5 | authorrunning: Short form of author list if too long for running head 6 | thanks: | 7 | Grants or other notes about the article that should go on the front 8 | page should be placed here. General acknowledgments should be placed at the 9 | end of the article. 10 | 11 | authors: 12 | - name: Äüthör 1 13 | address: Department of YYY, University of XXX 14 | email: abc@def 15 | 16 | - name: Âuthóř 2 17 | address: Department of ZZZ, University of WWW 18 | email: djf@wef 19 | 20 | keywords: 21 | - key 22 | - dictionary 23 | - word 24 | 25 | #PACS: 26 | #- PAC1 27 | #- superPAC 28 | 29 | MSC: 30 | - MSC code 1 31 | - MSC code 2 32 | 33 | abstract: | 34 | The text of your abstract. 150 -- 250 words. 35 | 36 | bibliography: bibliography.bib 37 | output: rticles::springer_article 38 | --- 39 | 40 | # Introduction {#intro} 41 | 42 | Your text comes here. Separate text sections with 43 | 44 | # Section title {#sec:1} 45 | 46 | Text with citations by @Galyardt14mmm, [@Mislevy06Cog]. 47 | 48 | ## Subsection title {#sec:2} 49 | 50 | as required. Don't forget to give each section 51 | and subsection a unique label (see Sect. \ref{sec:1}). 52 | 53 | #### Paragraph headings 54 | 55 | Use paragraph headings as needed. 56 | 57 | \begin{align} 58 | a^2+b^2=c^2 59 | \end{align} 60 | 61 | 62 | 63 | 64 | 65 | # References 66 | -------------------------------------------------------------------------------- /fortran/cylinder.f90: -------------------------------------------------------------------------------- 1 | program cylinder 2 | 3 | ! source: https://en.wikibooks.org/wiki/Fortran/Fortran_examples 4 | ! Calculate the surface area of a cylinder. 5 | ! 6 | ! Declare variables and constants. 7 | ! constants=pi 8 | ! variables=radius squared and height 9 | 10 | implicit none ! Require all variables to be explicitly declared 11 | 12 | integer :: ierr 13 | character(1) :: yn 14 | real :: radius, height, area 15 | real, parameter :: pi = 3.141592653589793 16 | 17 | interactive_loop: do 18 | 19 | ! Prompt the user for radius and height 20 | ! and read them. 21 | 22 | write (*,*) 'Enter radius and height.' 23 | read (*,*,iostat=ierr) radius,height 24 | 25 | ! If radius and height could not be read from input, 26 | ! then cycle through the loop. 27 | 28 | if (ierr /= 0) then 29 | write(*,*) 'Error, invalid input.' 30 | cycle interactive_loop 31 | end if 32 | 33 | ! Compute area. The ** means "raise to a power." 34 | 35 | area = 2 * pi * (radius**2 + radius*height) 36 | 37 | ! Write the input variables (radius, height) 38 | ! and output (area) to the screen. 39 | 40 | write (*,'(1x,a7,f6.2,5x,a7,f6.2,5x,a5,f6.2)') & 41 | 'radius=',radius,'height=',height,'area=',area 42 | 43 | yn = ' ' 44 | yn_loop: do 45 | write(*,*) 'Perform another calculation? y[n]' 46 | read(*,'(a1)') yn 47 | if (yn=='y' .or. yn=='Y') exit yn_loop 48 | if (yn=='n' .or. yn=='N' .or. yn==' ') exit interactive_loop 49 | end do yn_loop 50 | 51 | end do interactive_loop 52 | 53 | end program cylinder -------------------------------------------------------------------------------- /fortran/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | gfortran -o cylinder cylinder.f90 3 | ./cylinder 4 | 5 | -------------------------------------------------------------------------------- /fortran/run.term: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/fortran/run.term -------------------------------------------------------------------------------- /gap/gap.sagews: -------------------------------------------------------------------------------- 1 | ︠c917fdb6-a6b5-40e1-9ba6-cda5d54e952f︠ 2 | gap.version() 3 | ︡eb3add54-1d54-4aa5-bc63-f82908f2ab52︡{"stdout":"'4.5.7'\n"}︡ 4 | ︠a78c5876-45fc-49a1-be30-7b70c2486abe︠ 5 | 6 | A = AbelianGroup(3, [2,3,4], names="abc") 7 | A 8 | ︡f78885c0-819a-408d-88d0-10ef2a288442︡{"stdout":"Multiplicative Abelian group isomorphic to C2 x C3 x C4\n"}︡ 9 | ︠1e899c21-c300-42ac-991f-87c153052b80︠ 10 | a,b,c = A.gens() 11 | (c^3*b).list() 12 | ︡5bbb7720-dbe2-4793-bece-21b71ea3b07c︡{"stdout":"[0, 1, 3]\n"}︡ 13 | ︠5512ee66-76b0-4a87-9026-3844bd326a5c︠ 14 | A.permutation_group() 15 | ︡c002647c-53cb-49cc-90e6-a0d96292580b︡{"stdout":"Permutation Group with generators [(6,7,8,9), (3,4,5), (1,2)]\n"}︡ 16 | ︠d509e8db-4824-4d01-a1a7-0fa2eed8d2b4︠ 17 | S5 = SymmetricGroup(5) 18 | A5 = AlternatingGroup(5) 19 | A5.is_subgroup(S5) 20 | ︡74393ee6-b835-4e86-a8f7-1b5e52dd92b7︡{"stdout":"True\n"}︡ 21 | ︠9c1738a1-9db3-4f26-af7b-c3fd567f50d0︠ 22 | A5.gens() 23 | ︡bb949b09-ab6b-4503-a4c0-2e1d2649271e︡{"stdout":"[(3,4,5), (1,2,3,4,5)]\n"}︡ 24 | ︠2caf53e2-844b-48f1-b2d6-d4018a99441e︠ 25 | S5_gap = gap(S5) 26 | A5_gap = gap(A5) 27 | ︡c3ed38be-6489-4b1f-8d50-1a19c2d2a772︡ 28 | ︠77fdb0e3-a043-4b2e-a932-b3303d407770︠ 29 | S5_gap.DerivedSeries() 30 | ︡89e9b4f9-3632-4e2c-bb72-59f1cc662979︡{"stdout":"[ SymmetricGroup( [ 1 .. 5 ] ), AlternatingGroup( [ 1 .. 5 ] ) ]\n"}︡ 31 | ︠5ab82ebf-9b98-48b8-97ab-7db5373ac104︠ 32 | A5_gap.CompositionSeries() 33 | ︡33d4ded6-cf10-4a6f-89f0-d16f664f5b10︡{"stdout":"[ AlternatingGroup( [ 1 .. 5 ] ), Group( () ) ]\n"}︡ 34 | ︠d5b89239-48ff-4b0c-a1ce-058f9bdb40db︠ 35 | for cjcls in A5_gap.ConjugacyClasses(): 36 | print cjcls 37 | print cjcls.Orbits() 38 | print 39 | ︡176d7bd5-0ec1-4d36-b7c9-ab5337d80130︡{"stdout":"ConjugacyClass( AlternatingGroup( [ 1 .. 5 ] ), () )\n[ [ () ] ]\n\nConjugacyClass( AlternatingGroup( [ 1 .. 5 ] ), (1,2)(3,4) )\n[ [ (1,2)(3,4), (2,3)(4,5), (1,2)(4,5), (1,5)(3,4), (2,4)(3,5), (1,5)(2,3), \n (1,2)(3,5), (1,3)(4,5), (1,4)(3,5), (2,5)(3,4), (1,3)(2,4), (1,4)(2,3), \n (1,5)(2,4), (1,4)(2,5), (1,3)(2,5) ] ]\n\nConjugacyClass( AlternatingGroup( [ 1 .. 5 ] ), (1,2,3) )\n[ [ (1,2,3), (2,3,4), (1,2,4), (3,4,5), (2,4,5), (2,3,5), (1,2,5), (1,4,5), \n (1,3,5), (2,5,3), (1,3,4), (2,4,3), (1,5,3), (1,4,3), (3,5,4), (2,5,4), \n (1,4,2), (1,5,4), (1,5,2), (1,3,2) ] ]\n\nConjugacyClass( AlternatingGroup( [ 1 .. 5 ] ), (1,2,3,4,5) )\n[ [ (1,2,3,4,5), (1,2,4,5,3), (1,4,2,3,5), (1,2,5,3,4), (1,5,2,4,3), \n (1,4,5,2,3), (1,3,5,4,2), (1,3,2,5,4), (1,3,4,2,5), (1,5,3,2,4), \n (1,4,3,5,2), (1,5,4,3,2) ] ]\n\nConjugacyClass( AlternatingGroup( [ 1 .. 5 ] ), (1,2,3,5,4) )\n[ [ (1,2,3,5,4), (1,5,2,3,4), (1,2,4,3,5), (1,3,4,5,2), (1,3,2,4,5), \n (1,2,5,4,3), (1,4,5,3,2), (1,4,2,5,3), (1,5,4,2,3), (1,4,3,2,5), \n (1,5,3,4,2), (1,3,5,2,4) ] ]\n\n"}︡ 40 | ︠8d30cce7-0c60-4060-ae05-d5ecce4c953b︠ 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /gap/gap_directly.sagews: -------------------------------------------------------------------------------- 1 | ︠7849fc9c-9d01-40cf-8537-7b11917d42c5s︠ 2 | %gap 3 | (9 + 5)*(3+3); 4 | ︡66a5f5bd-7d53-4014-a535-ce9b916d3924︡︡{"stdout":"84","done":false}︡{"done":true} 5 | ︠5e126cd9-d054-4384-bd3d-9a58174c1ac8s︠ 6 | %gap 7 | F:= GF( 16 ); 8 | LeftActingDomain( F ); 9 | ︡e7483a14-87b3-46d4-8468-e952fe04a8d7︡︡{"stdout":"GF(2^4)\nGF(2)","done":false}︡{"done":true} 10 | ︠aacd269d-ab17-43e9-88cc-25281f6653b0s︠ 11 | %gap 12 | G:= AsVectorSpace( GF( 4 ), F ); 13 | F = G; 14 | LeftActingDomain( G ); 15 | ︡9db7b64c-8df4-4db1-ba32-29cb2cf058f8︡︡{"stdout":"AsField( GF(2^2), GF(2^4) )\ntrue\nGF(2^2)","done":false}︡{"done":true} 16 | ︠1e304322-500e-4830-bf6d-8ffb11efa88ds︠ 17 | ︡9c78bffd-d2ec-4b33-83cd-9a7a0f2d4cf4︡︡{"done":true} 18 | ︠66b05cd6-02e6-4663-a676-28ee6c64fd56s︠ 19 | %gap 20 | s8 := Group( (1,2), (1,2,3,4,5,6,7,8) ); 21 | a8 := DerivedSubgroup( s8 ); 22 | ︡84359815-a578-48ad-baaf-991a6c21697d︡︡{"stdout":"Group([ (1,2), (1,2,3,4,5,6,7,8) ])\nGroup([ (1,2,3), (2,3,4), (2,4)(3,5), (2,6,4), (3,7,5), (4,8,6) ])","done":false}︡{"done":true} 23 | ︠6134fd07-f486-4a14-bdf3-98a2172b72fds︠ 24 | %gap 25 | Size(a8); 26 | IsAbelian(a8); 27 | IsPerfect(a8); 28 | ︡75f03b91-ceda-4186-9098-84aef7c5d28b︡︡{"stdout":"20160\nfalse\ntrue","done":false}︡{"done":true} 29 | ︠2712fbc9-42d9-44cc-a367-cbbad2218186s︠ 30 | %gap 31 | syl2 := SylowSubgroup( a8, 2 ); 32 | Size( syl2 ); 33 | ︡6e3f2fe5-7320-4e5c-9d3a-4e8414cf5f45︡︡{"stdout":"Group([ (1,3)(7,8), (2,4)(7,8), (5,6)(7,8), (5,7)(6,8), (1,2)(3,4)(5,7)\n(6,8), (1,5)(2,7)(3,6)(4,8) ])\n64","done":false}︡{"done":true} 34 | ︠b1658225-2a77-4ab3-8c7e-34862d932c3es︠ 35 | %gap 36 | Normalizer( a8, syl2 ) = syl2; 37 | ︡da0a87a9-f223-489c-aec9-feb7c2c3b052︡︡{"stdout":"true","done":false}︡{"done":true} 38 | ︠fe66952c-a4ed-4f0b-8324-65190f75be23s︠ 39 | %gap 40 | cent := Centralizer( a8, Centre( syl2 ) ); 41 | Size( cent ); 42 | ︡750a21c0-40a9-41d3-a14a-79e3d7208bc9︡︡{"stdout":"Group([ (1,3)(2,4)(5,6)(7,8), (5,6)(7,8), (5,7)(6,8), (2,4)(7,8), (2,5)\n(4,6), (1,2)(3,4) ])\n192","done":false}︡{"done":true} 43 | ︠60c58572-8548-4ddc-9b29-c38b379b1d29s︠ 44 | ︡8c750f5b-a0fe-4c60-ba0d-0fdfac46b3bd︡︡{"done":true} 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /go/go.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/go/go.pdf -------------------------------------------------------------------------------- /index.yaml: -------------------------------------------------------------------------------- 1 | tags: 2 | calc: 3 | name: Calculus 4 | sage: 5 | name: SageMath 6 | r: 7 | name: R Project 8 | md: 9 | name: Markdown 10 | latex: 11 | name: LaTeX 12 | licenses: 13 | gpl3: GNU General Public License 3.0 14 | a20: Apache 2.0 15 | --- 16 | id: sagemath-cocalc 17 | title: SageMath in CoCalc 18 | thumbnail: thumbs/sage-in-cocalc.png 19 | description: > 20 | Learn how to use [SageMath](http://www.sagemath.org) in CoCalc. 21 | tags: 22 | - sage 23 | - math 24 | - intro 25 | src: sage/ 26 | license: a20 27 | category: intro 28 | --- 29 | id: r-cocalc 30 | title: R Statistical Software in CoCalc 31 | tags: 32 | - r 33 | - stats 34 | - intro 35 | src: r/ 36 | description: > 37 | Learn how to get started with [R Statistical Software](http://www.r-project.org/) in CoCalc 38 | license: a20 39 | category: intro 40 | thumbnail: thumbs/r-in-cocalc.png 41 | --- 42 | id: julia-cocalc 43 | title: Julia in CoCalc 44 | tags: 45 | - intro 46 | - julia 47 | src: julia/ 48 | description: > 49 | Learn how to get started with [Julia](https://www.julialang.org/) in CoCalc. 50 | license: a20 51 | category: intro 52 | thumbnail: julia/julia-logo-325-by-225.png 53 | --- 54 | id: rmarkdown 55 | title: RMarkdown in CoCalc 56 | tags: 57 | - intro 58 | - r 59 | src: RMarkdown/ 60 | description: > 61 | Various examples of [RMarkdown](https://rmarkdown.rstudio.com/) documents in CoCalc. 62 | thumbnail: thumbs/rmd.png 63 | category: intro 64 | license: a20 65 | --- 66 | id: md-cocalc 67 | title: Markdown in CoCalc 68 | description: > 69 | Quick introduction and reference guide for working with Markdown text formatting in CoCalc. 70 | tags: 71 | - md 72 | - intro 73 | license: a20 74 | src: markdown/ 75 | thumbnail: thumbs/markdown-in-cocalc.png 76 | category: intro 77 | --- 78 | id: sagetex-cocalc 79 | title: SageTeX in CoCalc 80 | description: > 81 | SageTex enables LaTeX to evaluate Sage-code right inside the document – e.g. `$\sage{1+1}$` produces the formula `$2$` 82 | and `\sageplot{...}` calculates and draws a graphic. 83 | CoCalc fully manages the compilation process behind the scenes for you. 84 | website: https://ctan.org/pkg/sagetex?lang=en 85 | src: latex/sagetex/ 86 | license: a20 87 | thumbnail: thumbs/sagetex-in-cocalc.png 88 | tags: 89 | - intro 90 | - math 91 | - sage 92 | - latex 93 | category: latex 94 | --- 95 | id: pythontex 96 | title: PythonTeX in CoCalc 97 | src: latex/pythontex/ 98 | license: a20 99 | description: > 100 | [PythonTeX]() enhances LaTeX documents to insert and run Python code from within the document itself. 101 | E.g. `\py{2*3}` inserts `5`, more advanced mathematics via `sympy` blocks, 102 | and you can insert dynamically create plots. 103 | CoCalc fully manages the compilation process behind the scenes for you. 104 | thumbnail: thumbs/pythontex.png 105 | tags: 106 | - intro 107 | - latex 108 | - math 109 | category: latex 110 | --- 111 | id: latex-beamer-cocalc 112 | title: Minimal LaTeX beamer presentation 113 | description: > 114 | This is a quick minimal beamer presentation template. 115 | website: https://en.wikipedia.org/wiki/Beamer_(LaTeX) 116 | license: a20 117 | thumbnail: thumbs/latex-beamer-in-cocalc.png 118 | src: latex/presentation/ 119 | category: latex 120 | tags: 121 | - latex 122 | --- 123 | id: latex-multiple-files-cocalc 124 | title: Multiple source files in CoCalc 125 | description: > 126 | This template explains and demonstrates how to work with multiple source files in LaTeX on CoCalc. 127 | It allows you to edit each individual part with preview, and then combines all parts into one master document. 128 | license: a20 129 | src: latex/multiple-files/ 130 | thumbnail: thumbs/latex-multiple-documents.png 131 | category: latex 132 | tags: 133 | - latex 134 | -------------------------------------------------------------------------------- /julia/batman-demo-300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/julia/batman-demo-300.png -------------------------------------------------------------------------------- /julia/julia-logo-325-by-225.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/julia/julia-logo-325-by-225.png -------------------------------------------------------------------------------- /latex/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore common LaTeX extensions 2 | *.pdf 3 | *.aux 4 | *-blx.bib 5 | *.toc 6 | *.fls 7 | *.run.xml 8 | *.blg 9 | *.backup 10 | *.bbl 11 | *.fdb_latexmk 12 | *.nav 13 | *.snm 14 | *.idx 15 | *.ilg 16 | *.ind 17 | *.out 18 | *.log 19 | *.synctex.gz 20 | *.sagetex.sage 21 | *.sagetex.sage.py 22 | *.pytxcode 23 | -------------------------------------------------------------------------------- /latex/README.md: -------------------------------------------------------------------------------- 1 | CoCalc LaTeX Support 2 | ==================== 3 | 4 | [CoCalc](https://cocalc.com) allows you to run LaTeX online in a full Linux environment. 5 | It supports the standard compilers, `latexmk`, and a large number of libraries are pre-installed. 6 | On top of that, support for `SageTeX` and `PythonTeX` adds the capability of running SageMath or Python code 7 | right inside of TeX files to seamlessly embed code, results, formulas and plots. 8 | 9 | 10 | * [`multiple-files`](./multiple-files) demonstrates how to setup a larger LaTeX document with multiple source files 11 | * [`sagetex`](./sagetex) shows how to run SageMath inside a document 12 | * [`pythontex`](./pythontex) features an example file for running PythonTeX 13 | * [`presentation`](./presentation) contains a basic beamer presentation template 14 | -------------------------------------------------------------------------------- /latex/multiple-files/10-make.tex: -------------------------------------------------------------------------------- 1 | \documentclass[master.tex]{subfiles} 2 | 3 | \setcounter{chapter}{0} 4 | 5 | \begin{document} 6 | 7 | \chapter{Makefile} 8 | 9 | \section{\texttt{latexmk}} 10 | 11 | \texttt{latexmk} is a versatile utility for building \LaTeX documents. 12 | It automatically handles table of content, indices, 13 | references and bibliography. 14 | 15 | To make it also work well with SageTeX (see page \ref{sec:sagetex}), 16 | you have to add the file \texttt{latexmkrc} 17 | into the current directory. 18 | It defines additional dependencies and instructions for 19 | building the whole document using SageTeX. 20 | 21 | For more information, type a terminal \texttt{man latexmk}. 22 | 23 | \section{Use \texttt{make} to build the PDF} 24 | 25 | Finally, one has to tell the CoCalc environment to use 26 | instead of the default build command 27 | the much more sophisticated Makefile. 28 | In order to do so, 29 | first add the Makefile to your project, 30 | modify it to match your filenames, 31 | and then click on the `build`-button (top right) 32 | and change the command to \texttt{make 'filename.pdf'}. 33 | In our case here, this is \texttt{make '10-make.pdf'} 34 | or \texttt{make 'master.pdf'} for the master document. 35 | 36 | Then, SageMathCloud will call the Makefile's definition to build the PDF document. 37 | 38 | When enabled correctly, at the bottom of each file (like this one here), 39 | this configuration string will appear: 40 | 41 | \begin{verbatim} 42 | %sagemathcloud={"latex_command":"make '10-make.pdf'"} 43 | \end{verbatim} 44 | 45 | Do not delete it! 46 | 47 | \end{document} 48 | %sagemathcloud={"latex_command":"make '10-make.pdf'"} -------------------------------------------------------------------------------- /latex/multiple-files/20-subfiles.tex: -------------------------------------------------------------------------------- 1 | \documentclass[master.tex]{subfiles} 2 | 3 | \setcounter{chapter}{1} 4 | 5 | \begin{document} 6 | 7 | \chapter{Subfiles Package} 8 | 9 | The subfiles \LaTeX package~\cite{subfiles} 10 | is able to combine multiple source files 11 | in one single document. 12 | In contrast to other commands like \verb|\input| or \verb|\include|, 13 | it is also possible to render the partial document with 14 | the header definitions of the master document. 15 | 16 | Also, in the header of each subfile, 17 | additional instructions can be embedded. 18 | In this example here, 19 | \verb|\setcounter{chapter}{1}| sets the counter for the chapter 20 | in order to get a consistent numbering. 21 | (Otherwise -- because \LaTeX only sees this partical document -- 22 | it would start its numbering at 1 and not 2.) 23 | 24 | 25 | \end{document} 26 | %sagemathcloud={"latex_command":"make '20-subfiles.pdf'"} -------------------------------------------------------------------------------- /latex/multiple-files/30-komascript.tex: -------------------------------------------------------------------------------- 1 | \documentclass[master.tex]{subfiles} 2 | 3 | \setcounter{chapter}{2} 4 | 5 | \begin{document} 6 | 7 | \chapter{KOMA-Script} 8 | 9 | KOMA-Script~\cite{komascript} is a bundle of document classes 10 | replacing article, book, letter, etc. 11 | It is not required for this multiple source-file demo, 12 | but still included for completeness. 13 | 14 | \end{document} 15 | %sagemathcloud={"latex_command":"make '30-komascript.pdf'"} -------------------------------------------------------------------------------- /latex/multiple-files/40-sagetex.tex: -------------------------------------------------------------------------------- 1 | \documentclass[master.tex]{subfiles} 2 | 3 | \setcounter{chapter}{3} 4 | 5 | \begin{document} 6 | 7 | \chapter{SageTeX} 8 | \label{sec:sagetex} 9 | 10 | 11 | \section{SageTeX and \texttt{latexmk}} 12 | 13 | \texttt{latexmk} is a versatile utility for building \LaTeX documents. 14 | It automatically learns about the inter-dependencies of all 15 | documents and generated intermediate files. 16 | It uses this information to run and repeatedly re-run various tools 17 | to produce a working final document. 18 | 19 | To make it work well with SageTeX, 20 | the file \texttt{latexmkrc} in the current directory defines 21 | additional dependencies and instructions. 22 | 23 | For more information, type a terminal \texttt{man latexmk}. 24 | 25 | To enable SageTeX in combination with \texttt{latexmk}, 26 | this page explains how to modify the \texttt{latexmkrc} file: 27 | 28 | \url{https://github.com/dandrake/sagetex/wiki} 29 | 30 | Little caveat: to make it work in this demo, 31 | a small wrapper script ``\texttt{run-sagetex.py}'' 32 | handles the filename and calling in order to work with SageTeX 33 | correctly. 34 | 35 | \section{SageTeX Demo} 36 | 37 | 1 + 1 = \sage{1+1} 38 | 39 | % this is only processed in SageMath and not displayed 40 | \begin{sagesilent} 41 | x = var('x') 42 | ex = (1 + x)^5 43 | exe = ex.expand() 44 | \end{sagesilent} 45 | 46 | $\sage{ex} \rightarrow \sage{exe}$ 47 | 48 | Raw Strings: 49 | 50 | \sagestr{str(CartesianProduct(['a', 'b'], [1, 2, 3]).list())} 51 | 52 | Defining a function g: 53 | 54 | \begin{sageblock} 55 | a = 2 56 | b = 3 57 | x = var('x') 58 | g = a * sin(b * x) + sqrt(x) 59 | \end{sageblock} 60 | 61 | And a plot of $g = \sage{g}$ from $[0, 10]$: 62 | 63 | \sageplot[width=.5\textwidth]{plot(g, 0, 10)} 64 | 65 | \end{document} 66 | %sagemathcloud={"latex_command":"make '40-sagetex.pdf'"} 67 | -------------------------------------------------------------------------------- /latex/multiple-files/bibliography.bib: -------------------------------------------------------------------------------- 1 | @misc{sagetex, 2 | author={Drake, Dan and et. al.}, 3 | title={SageTeX Github Repository}, 4 | year={2015}, 5 | url={https://github.com/dandrake/sagetex} 6 | } 7 | 8 | @book{komascript, 9 | title={KOMA-Script: Eine Sammlung von Klassen und Paketen für \LaTeX 2e}, 10 | author={Kohm, Markus}, 11 | year={2014}, 12 | publisher={Lehmanns Media}, 13 | url={https://www.ctan.org/pkg/koma-script} 14 | } 15 | 16 | @misc{subfiles, 17 | title={Subfiles \LaTeX{} package}, 18 | author={Garcia, Federico}, 19 | year={2012}, 20 | url={https://www.ctan.org/pkg/subfiles} 21 | } -------------------------------------------------------------------------------- /latex/multiple-files/latexmkrc: -------------------------------------------------------------------------------- 1 | 2 | add_cus_dep('sage', 'sout', 0, 'makesout'); 3 | $hash_calc_ignore_pattern{'sage'} = '^( _st_.goboom| ?_st_.current_tex_line|print .SageT)'; 4 | sub makesout { 5 | system("python run-sagetex.py '$_[0].sage'"); 6 | } 7 | -------------------------------------------------------------------------------- /latex/multiple-files/makefile: -------------------------------------------------------------------------------- 1 | OUTDIR=build 2 | MAIN=master.tex 3 | MAINPDF=$(MAIN:.tex=.pdf) 4 | 5 | default: $(MAINPDF) 6 | 7 | distclean: clean 8 | -$(RM) *.pdf *.dvi *-blx.bib *.bbl *.run.xml *.synctex.gz *.log 9 | -$(RM) *.py.out *.py.err latex.py 10 | -$(RM) -R $(OUTDIR) 11 | -git clean -fx 12 | 13 | clean: 14 | latexmk -C 15 | -$(RM) $(OUTDIR)/*.pdf $(OUTDIR)/*.synctex.gz 16 | -$(RM) *.pdf *.synctex.gz 17 | 18 | %.pdf: %.tex 19 | latexmk -pdf -bibtex -synctex=1 -interaction=nonstopmode -outdir=$(OUTDIR) $< 20 | -cp -vlf $(OUTDIR)/$@ . 21 | -cp -vlf $(OUTDIR)/$(patsubst %.tex,%.synctex.gz,$<) . 22 | -------------------------------------------------------------------------------- /latex/multiple-files/run-sagetex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # This is a small wrapper script, because running sage on a 3 | # *.sagetex.sage file in a subdirectory is broken. Once this 4 | # works fine, and produces the sout file in the subdirectory, 5 | # this script is no longer necessary -> modify latexmkrc ! 6 | import sys, os 7 | print("run-sagetex.py -- START".center(80, "-")) 8 | dir, file = sys.argv[1].split(os.path.sep) 9 | os.system("cd %s && sage %s" % (dir, file)) 10 | print("run-sagetex.py -- END".center(80, "-")) 11 | -------------------------------------------------------------------------------- /latex/sagetex/README.md: -------------------------------------------------------------------------------- 1 | Sage + LaTeX = SageTeX 2 | ====================== 3 | 4 | This demos how Sage and LaTeX can be combined. 5 | 6 | Automatic Mode 7 | -------------- 8 | 9 | Just click on the `*.tex` files and the two-pane editor should show up. 10 | SageTex and BibTex is run automatically, too! 11 | 12 | Manual Mode 13 | ----------- 14 | 15 | Edit the `.tex` file, compile it via `latexmk filename.tex` in the Terminal. 16 | 17 | If you change some Sage commands, you have to re-run `sage filename.sagetex.sage` 18 | in order to incorporate the changes in the output. 19 | 20 | 21 | Links 22 | ----- 23 | 24 | * [SageTex](http://www.ctan.org/tex-archive/macros/latex/contrib/sagetex/) 25 | -------------------------------------------------------------------------------- /latex/sagetex/minimal.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage[utf8]{inputenc} 4 | \usepackage{fullpage} 5 | \usepackage{mathtools} 6 | \usepackage{sagetex} 7 | \usepackage{url} 8 | 9 | \title{This is a demo of SageTeX} 10 | 11 | \begin{document} 12 | 13 | \maketitle 14 | 15 | To learn more about \LaTeX: \url{https://en.wikibooks.org/wiki/LaTeX} 16 | 17 | For SageTeX, please check out the project: 18 | \url{https://github.com/dandrake/sagetex} 19 | 20 | \section{Test} 21 | 22 | Testing $\frac{1}{178} = \sage{n(1/178)}$. 23 | 24 | \section{Plotting} 25 | 26 | is always fun ... 27 | 28 | \sageplot[width=.5\textwidth]{plot(x * (1+ sin(x)), (x,-10,10))} 29 | 30 | \section{This is a test} 31 | 32 | Testing $(1-x^2)^3 = \sage{((1-x^2)^2).expand()}$. 33 | 34 | Using Sage\TeX, one can use Sage to compute things and put them into 35 | your \LaTeX{} document. For example, there are 36 | $\sage{number_of_partitions(1269)}$ integer partitions of $1269$. 37 | You don't need to compute the number yourself, or even cut and paste 38 | it from somewhere. 39 | 40 | Here's some Sage code: 41 | 42 | \begin{sageblock} 43 | f(x) = cos(2*x)^2 / (2+x) 44 | \end{sageblock} 45 | 46 | The first derivative of $f$ is $\sage{diff(f,x)}$. 47 | 48 | The second derivative of $f$ is 49 | 50 | \[ 51 | \frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} = 52 | \sage{diff(f, x, 2)(x)}. 53 | \] 54 | 55 | Here's a plot of $f$ from $-1$ to $10$: 56 | 57 | \sageplot[width=.5\textwidth]{plot(f, -1, 10)} 58 | 59 | \section{AMS Math} 60 | 61 | $$P\left(A=2\middle|\frac{A^2}{B}>4\right)$$ 62 | 63 | Matrix: 64 | 65 | \begin{equation*} 66 | A_{m,n} = 67 | \begin{pmatrix} 68 | a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ 69 | a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ 70 | \vdots & \vdots & \ddots & \vdots \\ 71 | a_{m,1} & a_{m,2} & \cdots & a_{m,n} 72 | \end{pmatrix} 73 | \end{equation*} 74 | 75 | More here: \url{https://en.wikibooks.org/wiki/LaTeX/Mathematics}. 76 | 77 | \section{Pure Text} 78 | 79 | Usually, \verb|\sage{}| assumes that the value presented is 80 | a mathematical formula and wraps it into \$. 81 | Alternatively, one can display a Python-string via \verb|\sagestr{}|. 82 | 83 | \begin{sagesilent} 84 | u = 1 + 1 85 | \end{sagesilent} 86 | 87 | 1+1 = \sagestr{str(u)}. 88 | 89 | \end{document} 90 | -------------------------------------------------------------------------------- /markdown/markdown-in-jupyter.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "# Markdown in Jupyter Notebooks" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": { 15 | "collapsed": false 16 | }, 17 | "source": [ 18 | "In order to be able to enter formatted Markdown text, select \"Markdown\" in the dropdown for the mode of the cell (it usually says \"code\")." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "collapsed": false 25 | }, 26 | "source": [ 27 | "## Quick reference\n", 28 | "\n", 29 | "### Visual look\n", 30 | "\n", 31 | "* `**bold**`: **bold** text\n", 32 | "* `_italic_`: _italic_\n", 33 | "* `~~strike~~`: ~~strike~~\n", 34 | "* Headers: `# Main`, `## Subheader`, `### Subsub header`, ...\n", 35 | "\n", 36 | "Explore more by selecting words and clicking on the formatting buttons of this editor.\n", 37 | "\n", 38 | "### Structure\n", 39 | "\n", 40 | "Lists:\n", 41 | "```\n", 42 | "* item1\n", 43 | "* item2\n", 44 | "```\n", 45 | "\n", 46 | "Enumeration:\n", 47 | "```\n", 48 | "1. item1\n", 49 | "1. item2\n", 50 | "```\n", 51 | "\n", 52 | "### Special elements\n", 53 | "\n", 54 | "* Links: `[name of link](http://url.it.links/to)`\n", 55 | "\n", 56 | "## Formuas\n", 57 | "\n", 58 | "It is also possible to embed formulas. They are formatted using [MathJax](https://www.mathjax.org/).\n", 59 | "\n", 60 | "Inline $x^2$ formula.\n", 61 | "\n", 62 | "\\begin{equation}\n", 63 | " E = mc^2\n", 64 | "\\end{equation}\n", 65 | "\n", 66 | "## References\n", 67 | "\n", 68 | "* [Original description](https://daringfireball.net/projects/markdown/)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 0, 74 | "metadata": { 75 | "collapsed": false 76 | }, 77 | "outputs": [ 78 | ], 79 | "source": [ 80 | ] 81 | } 82 | ], 83 | "metadata": { 84 | "kernelspec": { 85 | "display_name": "Python 3 (Ubuntu Linux)", 86 | "language": "python", 87 | "name": "python3" 88 | }, 89 | "language_info": { 90 | "codemirror_mode": { 91 | "name": "ipython", 92 | "version": 3 93 | }, 94 | "file_extension": ".py", 95 | "mimetype": "text/x-python", 96 | "name": "python", 97 | "nbconvert_exporter": "python", 98 | "pygments_lexer": "ipython3", 99 | "version": "3.5.2" 100 | } 101 | }, 102 | "nbformat": 4, 103 | "nbformat_minor": 0 104 | } -------------------------------------------------------------------------------- /markdown/markdown-in-sage-worksheet.sagews: -------------------------------------------------------------------------------- 1 | ︠43903d18-ce6c-4346-897b-a9b8a8c0dd65i︠ 2 | %md 3 | # Markdown in Sage Worksheets 4 | ︡31b9552b-8239-4870-9f43-308d3d76f6b2︡{"done":true,"md":"# Markdown in Sage Worksheets"} 5 | ︠69279351-e9ce-489d-b3fd-001a903f4a59s︠ 6 | # this is a normal code block, with a comment line 7 | 1+1 8 | ︡1aec2848-fd19-4661-95fb-dd56ff35102f︡{"stdout":"2\n"}︡{"done":true}︡ 9 | ︠9ab4c14f-a73e-45d1-b3bd-6a368749fad3︠ 10 | %md 11 | In order to be able to enter markdown text between calculations, start a new block of code with `%md`! 12 | 13 | Unfold the next block below this output, to see how the "Quick reference" is typeset. 14 | ︡f8714668-abab-424b-942f-95aa24949f7f︡{"done":true,"md":"In order to be able to enter markdown text between calculations, start a new block of code with `%md`!"} 15 | ︠4dda9745-47ec-4ed8-a18d-a251331271e7i︠ 16 | %md 17 | ## Quick reference 18 | 19 | ### Visual look 20 | 21 | * `**bold**`: **bold** text 22 | * `_italic_`: _italic_ 23 | * `~~strike~~`: ~~strike~~ 24 | * Headers: `# Main`, `## Subheader`, `### Subsub header`, ... 25 | 26 | Explore more by selecting words and clicking on the formatting buttons of this editor. 27 | 28 | ### Structure 29 | 30 | Lists: 31 | ``` 32 | * item1 33 | * item2 34 | ``` 35 | 36 | Enumeration: 37 | ``` 38 | 1. item1 39 | 1. item2 40 | ``` 41 | 42 | ### Special elements 43 | 44 | * Links: `[name of link](http://url.it.links/to)` 45 | 46 | ## Formuas 47 | 48 | It is also possible to embed formulas. They are formatted using [MathJax](https://www.mathjax.org/). 49 | 50 | Inline $x^2$ formula. 51 | 52 | \begin{equation} 53 | E = mc^2 54 | \end{equation} 55 | 56 | ## References 57 | 58 | * [Original description](https://daringfireball.net/projects/markdown/) 59 | ︡a7c05705-3deb-49b0-aff3-6697c6b6483e︡{"done":true,"md":"## Quick reference\n\n### Visual look\n\n* `**bold**`: **bold** text\n* `_italic_`: _italic_\n* `~~strike~~`: ~~strike~~\n* Headers: `# Main`, `## Subheader`, `### Subsub header`, ...\n\nExplore more by selecting words and clicking on the formatting buttons of this editor.\n\n### Structure\n\nLists:\n```\n* item1\n* item2\n```\n\nEnumeration:\n```\n1. item1\n1. item2\n```\n\n### Special elements\n\n* Links: `[name of link](http://url.it.links/to)`\n\n## Formuas\n\nIt is also possible to embed formulas. They are formatted using [MathJax](https://www.mathjax.org/).\n\nInline $x^2$ formula.\n\n\\begin{equation}\n E = mc^2\n\\end{equation}\n\n## References\n\n* [Original description](https://daringfireball.net/projects/markdown/)"} 60 | ︠1c219d76-489b-432d-8795-20c825273566︠ 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /markdown/markdown-intro.md: -------------------------------------------------------------------------------- 1 | # Markdown Formatting 2 | 3 | Formatting text with markdown is very simple. 4 | The idea is that some characters, positioned at specific locations or wrapped around words, are transformed into instructions how the output should look like. 5 | Additionally, normal HTML tags can be added, too. 6 | 7 | On the right hand side you can see a real-time preview of the rendered document. 8 | 9 | ## Quick reference 10 | 11 | ### Visual look 12 | 13 | * `**bold**`: **bold** text 14 | * `_italic_`: _italic_ 15 | * `~~strike~~`: ~~strike~~ 16 | * Headers: `# Main`, `## Subheader`, `### Subsub header`, ... 17 | 18 | Explore more by selecting words and clicking on the formatting buttons of this editor. 19 | 20 | ### Structure 21 | 22 | Lists: 23 | ``` 24 | * item1 25 | * item2 26 | ``` 27 | 28 | Enumeration: 29 | ``` 30 | 1. item1 31 | 1. item2 32 | ``` 33 | 34 | ### Special elements 35 | 36 | * Links: `[name of link](http://url.it.links/to)` 37 | 38 | ## Formulas 39 | 40 | It is also possible to embed formulas. They are formatted using [MathJax](https://www.mathjax.org/). 41 | 42 | Inline $x^2$ formula. 43 | 44 | \begin{equation} 45 | E = mc^2 46 | \end{equation} 47 | 48 | ## References 49 | 50 | * [Original description](https://daringfireball.net/projects/markdown/) 51 | -------------------------------------------------------------------------------- /ocaml/Readme.md: -------------------------------------------------------------------------------- 1 | OCaml 2 | ----- 3 | 4 | This is a really small demo that [OCaml](http://ocaml.org/) works. 5 | 6 | In the terminal, just issue `ocaml example1.ml` and you should see the 10th Fibonaccy number. 7 | -------------------------------------------------------------------------------- /ocaml/compile.term: -------------------------------------------------------------------------------- 1 | 3453371b-2d7e-4f1c-a9f4-751d33a504fb -------------------------------------------------------------------------------- /ocaml/example1.ml: -------------------------------------------------------------------------------- 1 | (* Fibonacci function *) 2 | 3 | let rec fib n = 4 | if n < 2 then 1 else fib (n - 1) + fib (n - 2) 5 | ;; 6 | 7 | print_int (fib ( 10 )); 8 | print_newline(); 9 | -------------------------------------------------------------------------------- /octave/myfirst.m: -------------------------------------------------------------------------------- 1 | clear 2 | a=2; 3 | b=3; 4 | c=a+b; -------------------------------------------------------------------------------- /r/.gitignore: -------------------------------------------------------------------------------- 1 | r-plot.* 2 | figure.* 3 | autos.dat -------------------------------------------------------------------------------- /r/rpy2talk/rpy2talk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/r/rpy2talk/rpy2talk.pdf -------------------------------------------------------------------------------- /sage/3dplot.sagews: -------------------------------------------------------------------------------- 1 | ︠0ad4469a-c1be-4817-b741-586c1cf97d5ci︠ 2 | %md 3 | A 3D plot, displayed via the three.js library. Adding the threejs parameter `show(…, threejs=True)` is no longer necessary. 4 | ︡4d2767aa-115e-406d-bd3e-726541237783︡{"html":"

A 3D plot, displayed via the three.js library. Adding the threejs parameter show(…, threejs=True) is no longer necessary.

\n"}︡ 5 | ︠dcf933cd-c77f-4eed-87e4-a8cbb551e64a︠ 6 | var('x,y,z') 7 | T = RDF(golden_ratio) 8 | p = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x)) 9 | r = 4.77 10 | show(implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r), plot_points=33)) 11 | ︠f233119a-c619-4afc-8e2a-5e0934ce9799︠ 12 | g = icosahedron(color='green', mesh=2, opacity=.4) 13 | g += sphere(size=.3,center=(0,0,1),color='red') 14 | g += text3d("in the clouds...", (1/2,0,-1), fontsize=20, fontface="Courier") 15 | show(g) 16 | ︠ed23db90-26c7-4149-a3ca-a58e20460532︠ 17 | g = text3d("3D Pillow ...", (2,-1/2,1/2), fontsize=40, fontface="Droid", color='blue') 18 | for i in srange(-2*pi,2*pi,pi/3, include_endpoint=True): 19 | g += parametric_plot3d((2 * cos(x), sin(x * i), sin(x)*cos(i * x)), (x,0,2*pi),plot_points=200, color='purple') 20 | show(g) 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sage/basics.sagews: -------------------------------------------------------------------------------- 1 | ︠5eb63087-9306-44bd-8d96-ce0a74839ee3i︠ 2 | %md 3 | ## Sage Basics 4 | 5 | Evaluate all cells via pressing the `Shift`+`Return` keys or the small "play" button in the menu. 6 | 7 | ︡12fbd4c0-f8e2-4b08-8b03-79b5b1abf4fb︡{"html":"

Sage Basics

\n\n

Evaluate all cells via pressing the Shift+Return keys or the small “play” button in the menu.

\n"}︡ 8 | ︠e3f5916d-1904-41e1-b02c-2b60185db6a5︠ 9 | x = var('x') 10 | solve(2*x^2 + 3 * x - 10 == 0, x) 11 | ︡c93eed45-6be0-4c97-b1f3-9363b2518288︡{"stdout":"[x == -1/4*sqrt(89) - 3/4, x == 1/4*sqrt(89) - 3/4]\n"}︡ 12 | ︠edeeb0ed-8818-43e7-a96c-4b702a64ae6c︠ 13 | # expressions 14 | var('x y z') 15 | ex1 = 2 * x / (1 + x + y ^2) * sin(x*z) 16 | ex2 = ex1 / x / sin(x*z) 17 | show(ex1) 18 | show(ex2) 19 | ︠3f2d7a03-8b3d-47f8-980a-79bda1f390e8︠ 20 | phi = var('phi') 21 | find_root(cos(phi) * sin(tan(phi - pi/2)) == sqrt(phi), 0, 2 * pi) 22 | ︡c32787cd-d140-4090-9158-ce2871753c10︡{"stdout":"0.2637894422530672"}︡{"stdout":"\n"}︡ 23 | ︠77f17302-71e3-4aa0-8287-df2e9f72c6bd︠ 24 | diff(sin(x^2), x, 4) 25 | ︡93dabe7e-4481-4114-b560-03c86187cb83︡{"stdout":"16*x^4*sin(x^2) - 48*x^2*cos(x^2) - 12*sin(x^2)\n"}︡ 26 | ︠eb66dad4-8d19-4cc0-a0f9-bab4a50a20fa︠ 27 | A = Matrix(ZZ, [[1,2,-3],[3,2,1],[1,1,1]]) 28 | A.inverse() 29 | ︡9bdd2416-ed9e-4744-bfd3-e15a5bfe718b︡{"stdout":"[-1/6 5/6 -4/3]\n[ 1/3 -2/3 5/3]\n[-1/6 -1/6 2/3]\n"}︡ 30 | ︠19ebea0e-039d-4f29-a70f-c9cb776a53d5︠ 31 | A2 = A.change_ring(RDF) 32 | A2.inverse() 33 | ︡606ca2bd-1739-44e6-bf89-54399c658d46︡{"stdout":"[-0.166666666667 0.833333333333 -1.33333333333]\n[ 0.333333333333 -0.666666666667 1.66666666667]\n[-0.166666666667 -0.166666666667 0.666666666667]"}︡{"stdout":"\n"}︡ 34 | ︠2b15a82c-41d6-47d3-8a61-f2582697b1ce︠ 35 | v = vector(ZZ, [-4, 0, 1]) 36 | s = A \ v 37 | s 38 | ︡14221feb-08c3-4c59-95e7-4448a9d8e60c︡{"stdout":"(-2/3, 1/3, 4/3)\n"}︡ 39 | ︠cab27b12-58d5-4b9d-bc8c-903c589bf6e0︠ 40 | v == A * s 41 | ︡db351962-8419-4d77-a10f-2a0a401b3d87︡{"stdout":"True\n"}︡ 42 | ︠ce05bff7-c361-4db4-be6d-5dc2060a6b81︠ 43 | A.echelon_form() 44 | ︡059372c2-2be4-413f-ba08-52be40eb26ae︡{"stdout":"[1 0 5]\n[0 1 2]\n[0 0 6]\n"}︡ 45 | ︠64be15ef-7706-41b1-aff6-6347a36d0ab4︠ 46 | E = EllipticCurve('131a') 47 | E.plot() 48 | ︡5a3e12d5-ff1f-40be-a4ca-500953588ca9︡{"file":{"show":true,"uuid":"6fd688ad-ddb4-4c31-bf42-66b4f53513db","filename":"/mnt/home/2Qrdjpk5/.sage/temp/compute3a/31270/tmp_LFLywp.png"}}︡ 49 | ︠a8804e64-497d-4124-aa91-f11e0daa9418i︠ 50 | E2 = E.change_ring(GF(101)) 51 | E2.plot() 52 | ︡e0164ed6-a08d-4361-bd9f-e732f6ff593e︡{"file":{"show":true,"uuid":"bfaaf341-656b-49f1-a8ea-c979284e94e2","filename":"/mnt/home/2Qrdjpk5/.sage/temp/compute3a/31270/tmp_dE7T9_.png"}}︡ 53 | ︠282581a4-95e3-47d6-921a-b671e21fc702︠ 54 | bessel_J(2.1,1, 'pari', 250) 55 | ︡232fa6b7-7a2b-43a0-97d2-3548cda441b3︡{"stdout":"0.097838255257252160061715725960235803678515571060227678839771094653725501184\n"}︡ 56 | ︠54bf1c1f-c0df-42a7-97fa-682003e2f6c7︠ 57 | 58 | show(sum(plot(lambda x : bessel_J(x, k), (x, -pi, 3 * pi), color=Color((k/5.,1-k/5., 1))) for k in range(1,5))) 59 | ︡f5d92474-fdf5-4b28-86fa-7c49ee63b185︡{"file":{"show":true,"uuid":"43ae546d-83bb-4d89-9561-66cabc29c358","filename":"/mnt/home/2Qrdjpk5/.sage/temp/compute3a/31270/tmp__iRuio.png"}}︡ 60 | ︠f7418ece-7989-444e-8c43-19961ca91b41︠ 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /sage/interact/Algebra/ideal.sagews: -------------------------------------------------------------------------------- 1 | ︠c461758b-4cd8-44e4-931a-6b5993110ac4︠ 2 | @interact 3 | def gfan_browse(p1 = input_box('x^3+y^2',type = str, label='polynomial 1: '), p2 = input_box('y^3+z^2',type = str, label='polynomial 2: '), p3 = input_box('z^3+x^2',type = str, label='polynomial 3: ')): 4 | R. = PolynomialRing(QQ,3) 5 | i1 = ideal(R(p1),R(p2),R(p3)) 6 | gf1 = i1.groebner_fan() 7 | testr = gf1.render() 8 | html('Groebner fan of the ideal generated by: ' + str(p1) + ', ' + str(p2) + ', ' + str(p3)) 9 | show(testr, axes = False, figsize=[8,8*(3^(.5))/2]) 10 | ︡e5818029-0d61-44e1-b591-0e57bfa7d2a0︡{"interact":{"style":"None","flicker":false,"layout":[[["p1",12,null]],[["p2",12,null]],[["p3",12,null]],[["",12,null]]],"id":"cea9dc9a-49cb-4d3d-822a-7ffd7840b20c","controls":[{"control_type":"input-box","default":"x^3+y^2","label":"polynomial 1: ","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"p1","type":""},{"control_type":"input-box","default":"y^3+z^2","label":"polynomial 2: ","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"p2","type":""},{"control_type":"input-box","default":"z^3+x^2","label":"polynomial 3: ","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"p3","type":""}]}}︡ 11 | ︠48102307-52c3-4b3f-82c5-2effaa6da164︠ 12 | -------------------------------------------------------------------------------- /sage/interact/Bioinformatics/coalescent.sagews: -------------------------------------------------------------------------------- 1 | ︠02a6d748-c6f5-4994-9457-bd6dfc762bee︠ 2 | def next_gen(x, selection=1.0): 3 | '''Creates the next generation from the previous; also returns parent-child indexing list''' 4 | next_x = [] 5 | for ind in range(len(x)): 6 | if random() < (1 + selection)/len(x): 7 | rind = 0 8 | else: 9 | rind = int(round(random()*(len(x)-1)+1/2)) 10 | next_x.append((x[rind],rind)) 11 | next_x.sort() 12 | return [[x[0] for x in next_x],[x[1] for x in next_x]] 13 | def coal_plot(some_data): 14 | '''Creates a graphics object from coalescent data''' 15 | gens = some_data[0] 16 | inds = some_data[1] 17 | gen_lines = line([[0,0]]) 18 | pts = Graphics() 19 | ngens = len(gens) 20 | gen_size = len(gens[0]) 21 | for x in range(gen_size): 22 | pts += point((x,ngens-1), hue = gens[0][x]/float(gen_size*1.1)) 23 | p_frame = line([[-.5,-.5],[-.5,ngens-.5], [gen_size-.5,ngens-.5], [gen_size-.5,-.5], [-.5,-.5]]) 24 | for g in range(1,ngens): 25 | for x in range(gen_size): 26 | old_x = inds[g-1][x] 27 | gen_lines += line([[x,ngens-g-1],[old_x,ngens-g]], hue = gens[g-1][old_x]/float(gen_size*1.1)) 28 | pts += point((x,ngens-g-1), hue = gens[g][x]/float(gen_size*1.1)) 29 | return pts+gen_lines+p_frame 30 | d_field = RealField(10) 31 | @interact 32 | def coalescents(pop_size = slider(2,100,1,15,'Population size'), selection = slider(-1,1,.1,0, 'Selection for first taxon'), s = selector(['Again!'], label='Refresh', buttons=True)): 33 | print 'Population size: ' + str(pop_size) 34 | print 'Selection coefficient for first taxon: ' + str(d_field(selection)) 35 | start = [i for i in range(pop_size)] 36 | gens = [start] 37 | inds = [] 38 | while gens[-1][0] != gens[-1][-1]: 39 | g_index = len(gens) - 1 40 | n_gen = next_gen(gens[g_index], selection = selection) 41 | gens.append(n_gen[0]) 42 | inds.append(n_gen[1]) 43 | coal_data1 = [gens,inds] 44 | print 'Generations until coalescence: ' + str(len(gens)) 45 | show(coal_plot(coal_data1), axes = False, figsize = [8,4.0*len(gens)/pop_size], ymax = len(gens)-1) 46 | ︡39b0e4a1-c94d-43a3-85c5-3379afca9cc8︡{"interact":{"style":"None","flicker":false,"layout":[[["pop_size",12,null]],[["selection",12,null]],[["s",12,null]],[["",12,null]]],"id":"de185ed6-7687-468a-94a1-e89fd8f49eff","controls":[{"control_type":"slider","default":13,"var":"pop_size","width":null,"vals":["2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100"],"animate":true,"label":"Population size","display_value":true},{"control_type":"slider","default":10,"var":"selection","width":null,"vals":["-1.00000000000000","-0.900000000000000","-0.800000000000000","-0.700000000000000","-0.600000000000000","-0.500000000000000","-0.400000000000000","-0.300000000000000","-0.200000000000000","-0.100000000000000","-1.38777878078145e-16","0.0999999999999999","0.200000000000000","0.300000000000000","0.400000000000000","0.500000000000000","0.600000000000000","0.700000000000000","0.800000000000000","0.900000000000000","1.00000000000000"],"animate":true,"label":"Selection for first taxon","display_value":true},{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Again!"],"label":"Refresh","nrows":null,"width":null,"var":"s"}]}}︡ 47 | ︠a61e8a12-d777-4198-8370-e01f483d17b1︠ 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /sage/interact/Calculus/newtonMethod.sagews: -------------------------------------------------------------------------------- 1 | ︠6c6e5e08-b19a-4a03-90fd-ec4347a26564i︠ 2 | def newton_method(f, c, eps, maxiter=100): 3 | x = f.variables()[0] 4 | fprime = f.derivative(x) 5 | try: 6 | g = f._fast_float_(x) 7 | gprime = fprime._fast_float_(x) 8 | except AttributeError: 9 | g = f; gprime = fprime 10 | iterates = [c] 11 | for i in xrange(maxiter): 12 | fc = g(c) 13 | if abs(fc) < eps: return c, iterates 14 | c = c - fc/gprime(c) 15 | iterates.append(c) 16 | return c, iterates 17 | 18 | var('x') 19 | html("

Double Precision Root Finding Using Newton's Method

") 20 | @interact 21 | def _(f = x^2 - 2, c = float(0.5), eps=(-3,(-16..-1)), interval=float(0.5)): 22 | eps = 10^(eps) 23 | print "eps = %s"%float(eps) 24 | z, iterates = newton_method(f, c, eps) 25 | print "root =", z 26 | print "f(c) = %r"%f(x=z) 27 | n = len(iterates) 28 | print "iterations =", n 29 | html(iterates) 30 | P = plot(f, (x,z-interval, z+interval), rgbcolor='blue') 31 | h = P.ymax(); j = P.ymin() 32 | L = sum(point((w,(n-1-float(i))/n*h), rgbcolor=(float(i)/n,0.2,0.3), pointsize=10) + \ 33 | line([(w,h),(w,j)],rgbcolor='black',thickness=0.2) for i,w in enumerate(iterates)) 34 | show(P + L, xmin=z-interval, xmax=z+interval) 35 | 36 | ︡b2221899-9700-4bbe-bc6f-618d3f1681d0︡{"stdout":"x\n"}︡{"html":"

Double Precision Root Finding Using Newton's Method

"}︡{"interact":{"style":"None","flicker":false,"layout":[[["f",12,null]],[["c",12,null]],[["eps",12,null]],[["interval",12,null]],[["",12,null]]],"id":"c82daa0f-c941-4da6-bc8f-655c585455f9","controls":[{"control_type":"input-box","default":"x^2 - 2","label":"f","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"f","type":null},{"control_type":"input-box","default":0.5,"label":"c","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"c","type":null},{"control_type":"slider","default":13,"var":"eps","width":null,"vals":["-16","-15","-14","-13","-12","-11","-10","-9","-8","-7","-6","-5","-4","-3","-2","-1"],"animate":true,"label":"eps","display_value":true},{"control_type":"input-box","default":0.5,"label":"interval","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"interval","type":null}]}}︡ 37 | ︠08c479e5-df6b-427c-a556-ef2589bd8b04︠ 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /sage/interact/Calculus/parametricSurfaceArea.sagews: -------------------------------------------------------------------------------- 1 | ︠cc771cca-48be-4502-afee-73b22267c975︠ 2 | var('u,v') 3 | npi = RDF(pi) 4 | @interact 5 | def viewer(mesh = checkbox(default = False, label = 'Show u,v meshlines'), uc = slider(-2,2,1/10,0, label = 'Constant u value'), vc = slider(-2,2,1/10,0, label = 'Constant v value'), functions = input_box([u,v^2,u^2+v])): 6 | f1(u,v) = functions[0] 7 | f2(u,v) = functions[1] 8 | f3(u,v) = functions[2] 9 | surface_plot = parametric_plot3d([f1,f2,f3], (u,-2,2), (v,-2,2), mesh = mesh, opacity = .8) 10 | constant_u = line3d([[f1(uc,q), f2(uc,q), f3(uc,q)] for q in srange(-2,2,.01)], rgbcolor = (1,0,0), thickness = 3) 11 | constant_v = line3d([[f1(q,vc), f2(q,vc), f3(q,vc)] for q in srange(-2,2,.01)], rgbcolor = (0,1,0), thickness = 3) 12 | show(surface_plot + constant_u + constant_v, frame = False) 13 | ︡b4a915d7-dcbd-4570-b1ee-40cf9ac096b7︡{"stdout":"(u, v)\n"}︡{"interact":{"style":"None","flicker":false,"layout":[[["mesh",12,null]],[["uc",12,null]],[["vc",12,null]],[["functions",12,null]],[["",12,null]]],"id":"f0849464-1c1e-4d51-8724-3e337bf203fa","controls":[{"default":false,"var":"mesh","readonly":false,"control_type":"checkbox","label":"Show u,v meshlines"},{"control_type":"slider","default":20,"var":"uc","width":null,"vals":["-2","-19/10","-9/5","-17/10","-8/5","-3/2","-7/5","-13/10","-6/5","-11/10","-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2"],"animate":true,"label":"Constant u value","display_value":true},{"control_type":"slider","default":20,"var":"vc","width":null,"vals":["-2","-19/10","-9/5","-17/10","-8/5","-3/2","-7/5","-13/10","-6/5","-11/10","-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2"],"animate":true,"label":"Constant v value","display_value":true},{"control_type":"input-box","default":"[u, v^2, u^2 + v]","label":"functions","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"functions","type":null}]}}︡ 14 | ︠c5fc08a9-fa39-4a62-90ca-cba340b6d02e︠ 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sage/interact/Calculus/polarCurve.sagews: -------------------------------------------------------------------------------- 1 | ︠ba839b95-c021-44b8-b4a7-9320bcce261f︠ 2 | @interact 3 | def para(n1 = slider(1,5,1,default = 2), n2 = slider(1,5,1,default = 3), a1 = slider(1,10,1/10,6/5), a2 = slider(1,10,1/10,6), b = slider(0,2,1/50,0)): 4 | var('t') 5 | html('$r=' + latex(b+sin(a1*t)^n1 + cos(a2*t)^n2)+'$') 6 | p = parametric_plot((cos(t)*(b+sin(a1*t)^n1 + cos(a2*t)^n2), sin(t)*(b+sin(a1*t)^n1 + cos(a2*t)^n2)), (t,0, 20*pi), plot_points = 1024, rgbcolor = (0,0,0)) 7 | show(p, figsize = [5,5], xmin = -2-b, xmax = 2+b, ymin = -2-b, ymax = 2+b, axes = False) 8 | ︡2e3164d7-6d24-4dcc-acc2-d4435bf4cdec︡{"interact":{"style":"None","flicker":false,"layout":[[["n1",12,null]],[["n2",12,null]],[["a1",12,null]],[["a2",12,null]],[["b",12,null]],[["",12,null]]],"id":"1d108ebd-67e4-412f-9ad4-f6d4f055db76","controls":[{"control_type":"slider","default":1,"var":"n1","width":null,"vals":["1","2","3","4","5"],"animate":true,"label":"n1","display_value":true},{"control_type":"slider","default":2,"var":"n2","width":null,"vals":["1","2","3","4","5"],"animate":true,"label":"n2","display_value":true},{"control_type":"slider","default":2,"var":"a1","width":null,"vals":["1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4","41/10","21/5","43/10","22/5","9/2","23/5","47/10","24/5","49/10","5","51/10","26/5","53/10","27/5","11/2","28/5","57/10","29/5","59/10","6","61/10","31/5","63/10","32/5","13/2","33/5","67/10","34/5","69/10","7","71/10","36/5","73/10","37/5","15/2","38/5","77/10","39/5","79/10","8","81/10","41/5","83/10","42/5","17/2","43/5","87/10","44/5","89/10","9","91/10","46/5","93/10","47/5","19/2","48/5","97/10","49/5","99/10","10"],"animate":true,"label":"a1","display_value":true},{"control_type":"slider","default":50,"var":"a2","width":null,"vals":["1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4","41/10","21/5","43/10","22/5","9/2","23/5","47/10","24/5","49/10","5","51/10","26/5","53/10","27/5","11/2","28/5","57/10","29/5","59/10","6","61/10","31/5","63/10","32/5","13/2","33/5","67/10","34/5","69/10","7","71/10","36/5","73/10","37/5","15/2","38/5","77/10","39/5","79/10","8","81/10","41/5","83/10","42/5","17/2","43/5","87/10","44/5","89/10","9","91/10","46/5","93/10","47/5","19/2","48/5","97/10","49/5","99/10","10"],"animate":true,"label":"a2","display_value":true},{"control_type":"slider","default":0,"var":"b","width":null,"vals":["0","1/50","1/25","3/50","2/25","1/10","3/25","7/50","4/25","9/50","1/5","11/50","6/25","13/50","7/25","3/10","8/25","17/50","9/25","19/50","2/5","21/50","11/25","23/50","12/25","1/2","13/25","27/50","14/25","29/50","3/5","31/50","16/25","33/50","17/25","7/10","18/25","37/50","19/25","39/50","4/5","41/50","21/25","43/50","22/25","9/10","23/25","47/50","24/25","49/50","1","51/50","26/25","53/50","27/25","11/10","28/25","57/50","29/25","59/50","6/5","61/50","31/25","63/50","32/25","13/10","33/25","67/50","34/25","69/50","7/5","71/50","36/25","73/50","37/25","3/2","38/25","77/50","39/25","79/50","8/5","81/50","41/25","83/50","42/25","17/10","43/25","87/50","44/25","89/50","9/5","91/50","46/25","93/50","47/25","19/10","48/25","97/50","49/25","99/50","2"],"animate":true,"label":"b","display_value":true}]}}︡ 9 | ︠17e00a0b-9028-48d8-b790-38e25a709c5e︠ 10 | -------------------------------------------------------------------------------- /sage/interact/Calculus/quadricSurface.sagews: -------------------------------------------------------------------------------- 1 | ︠f806ebcc-3f0b-4991-9edb-af1adaba0564︠ 2 | var('x,y,z') 3 | quadrics = {'Ellipsoid':x^2+y^2+z^2-1,'Elliptic paraboloid':x^2+y^2-z,'Hyperbolic paraboloid':x^2-y^2-z, '1-Sheeted Hyperboloid':x^2+y^2-z^2-1,'2-Sheeted Hyperboloid':x^2-y^2-z^2-1, 'Cone':x^2+y^2-z^2} 4 | @interact 5 | def quads(q = selector(quadrics.keys()), a = slider(0,5,1/2,default = 1)): 6 | f = quadrics[q].subs({x:x*a^(1/2)}) 7 | if a==0 or q=='Cone': html('
$'+latex(f)+' \ $'+ '(degenerate)
') 8 | else: html('
$'+latex(f)+'$
') 9 | p = implicit_plot3d(f,(x,-2,2),(y,-2,2),(z,-2,2), plot_points = 75) 10 | show(p) 11 | ︡f933b6fd-660a-49ba-8d1a-5f28d52dbcd9︡{"stdout":"(x, y, z)\n"}︡{"interact":{"style":"None","flicker":false,"layout":[[["q",12,null]],[["a",12,null]],[["",12,null]]],"id":"640d1f44-36e2-4e95-9b08-0a4b5615c822","controls":[{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Ellipsoid","2-Sheeted Hyperboloid","Hyperbolic paraboloid","Cone","1-Sheeted Hyperboloid","Elliptic paraboloid"],"label":"q","nrows":null,"width":null,"var":"q"},{"control_type":"slider","default":2,"var":"a","width":null,"vals":["0","1/2","1","3/2","2","5/2","3","7/2","4","9/2","5"],"animate":true,"label":"a","display_value":true}]}}︡ 12 | ︠40f89a79-e4db-4079-8f59-cf5b360be6a6︠ 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sage/interact/DiffEq/heatFourier.sagews: -------------------------------------------------------------------------------- 1 | ︠ab1b64a5-65f8-4846-b182-c128ac33c96c︠ 2 | var('x') 3 | x0 = 0 4 | k=1 5 | f = x*exp(-x^2) 6 | p = plot(f,0,2*pi, thickness=2) 7 | c = 1/pi 8 | orden=10 9 | alpha=[(n,c*numerical_integral(f*sin(x*n/2),0,2*pi)[0] ) for n in range(1,orden)] 10 | 11 | @interact 12 | def _(tiempo = (0.1*j for j in (0..10)) ): 13 | ft = sum( a*sin(x*n/2)*exp(-k*(n/2)^2*tiempo) for n,a in alpha) 14 | pt = plot(ft, 0, 2*pi, color='green', thickness=2) 15 | show( p + pt, ymin = -.2) 16 | ︡e89c3e02-494d-42ca-9b5b-f6e9a8e8f7cf︡{"stdout":"x\n"}︡{"interact":{"style":"None","flicker":false,"layout":[[["tiempo",12,null]],[["",12,null]]],"id":"60f12d1e-6fe5-45d6-afa9-9c9ffb7f56bf","controls":[{"control_type":"slider","default":0,"var":"tiempo","width":null,"vals":["0.000000000000000","0.100000000000000","0.200000000000000","0.300000000000000","0.400000000000000","0.500000000000000","0.600000000000000","0.700000000000000","0.800000000000000","0.900000000000000","1.00000000000000"],"animate":true,"label":"tiempo","display_value":true}]}}︡ 17 | ︠7853e2cc-f96b-424b-9d43-34fcd4d40b8c︠ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sage/interact/DiffEq/picardIter.sagews: -------------------------------------------------------------------------------- 1 | ︠67cc9381-2791-4da7-bedb-608391128632︠ 2 | def picard_iteration(f, a, c, iterations): 3 | ''' 4 | Computes the N-th Picard iterate for the IVP 5 | 6 | x' = f(t,x), x(a) = c. 7 | 8 | EXAMPLES: 9 | sage: var('x t s') 10 | (x, t, s) 11 | sage: a = 0; c = 2 12 | sage: f = lambda t,x: 1-x 13 | sage: picard_iteration(f, a, c, 0) 14 | 2 15 | sage: picard_iteration(f, a, c, 1) 16 | 2 - t 17 | sage: picard_iteration(f, a, c, 2) 18 | t^2/2 - t + 2 19 | sage: picard_iteration(f, a, c, 3) 20 | -t^3/6 + t^2/2 - t + 2 21 | 22 | ''' 23 | if iterations == 0: 24 | return c 25 | if iterations == 1: 26 | x0 = lambda t: c + integral(f(t=s,x=c), s, a, t) 27 | return expand(x0(t)) 28 | for i in range(iterations): 29 | x_old = lambda s: picard_iteration(f, a, c, iterations-1).subs(t=s) 30 | x0 = lambda t: c + integral(f(t=s,x=x_old(s)), s, a, t) 31 | return expand(x0(t)) 32 | 33 | @interact 34 | def picarder(n_iterations = slider(0,20,1,default = 2)): 35 | var('x,t,s') 36 | f = lambda t,x:x 37 | html("Exact solution to $x' = x$, $x(0) = 1$ is $x = \exp(t)$
") 38 | pic = picard_iteration(f,0,1,n_iterations) 39 | html('The Picard iteration approximation after ' + str(n_iterations) + ' iterations is:
') 40 | html('$'+latex(pic)+'$') 41 | exact = plot(exp(t),(t,0,2)) 42 | pic_plot = plot(pic,(t,0,2), rgbcolor = (1,0,0)) 43 | show(exact + pic_plot) 44 | ︡1e2ecb4c-5b93-49b5-aa6a-0d6916a03982︡{"interact":{"style":"None","flicker":false,"layout":[[["n_iterations",12,null]],[["",12,null]]],"id":"acefc23b-36a7-49cb-bc43-4cb16eab0460","controls":[{"control_type":"slider","default":2,"var":"n_iterations","width":null,"vals":["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"],"animate":true,"label":"n_iterations","display_value":true}]}}︡ 45 | ︠f6212a93-4d42-41b7-a2f1-f135534b5956︠ 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /sage/interact/Fractals/digitSetDilationMatrix.sagews: -------------------------------------------------------------------------------- 1 | ︠8d83f61f-89f2-4b73-b4de-27d430c03c7a︠ 2 | A = matrix([[1,1],[-1,1]]) 3 | D = [vector([0,0]), vector([1,0])] 4 | 5 | @interact 6 | def f(A = matrix([[1,1],[-1,1]]), D = '[[0,0],[1,0]]', k=(3..17)): 7 | print "Det = ", A.det() 8 | D = matrix(eval(D)).rows() 9 | def Dn(k): 10 | ans = [] 11 | for d in Tuples(D, k): 12 | s = sum(A^n*d[n] for n in range(k)) 13 | ans.append(s) 14 | return ans 15 | 16 | G = points([v.list() for v in Dn(k)],size=50) 17 | 18 | show(G, frame=True, axes=False) 19 | ︡0370de21-6ecd-4c30-bb71-9a25fc76eaa0︡{"interact":{"style":"None","flicker":false,"layout":[[["A",12,null]],[["D",12,null]],[["k",12,null]],[["",12,null]]],"id":"083b4f22-6282-4c03-b721-0332d339fa4c","controls":[{"control_type":"input-grid","ncols":2,"default":[["1","1"],["-1","1"]],"label":"A","nrows":2,"width":5,"var":"A"},{"control_type":"input-box","default":"[[0,0],[1,0]]","label":"D","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"D","type":""},{"control_type":"slider","default":0,"var":"k","width":null,"vals":["3","4","5","6","7","8","9","10","11","12","13","14","15","16","17"],"animate":true,"label":"k","display_value":true}]}}︡ 20 | ︠b8300312-f4c8-4b4b-8205-8974d8d5588f︠ 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sage/interact/Fractals/sierpinskiTri.sagews: -------------------------------------------------------------------------------- 1 | ︠d0254607-e783-4125-b566-28b505277f7a︠ 2 | def sierpinski(N): 3 | '''Generates the Sierpinski triangle by taking the modulo-2 of each element in Pascal's triangle''' 4 | return [([0] * (N // 2 - a // 2)) + [binomial(a, b) % 2 for b in range(a + 1)] + ([0] * (N // 2 - a // 2)) for a in range(0, N, 2)] 5 | 6 | @interact 7 | def _(N=slider([2 ** a for a in range(12)], label='Number of iterations', default=64), size=slider(1, 20, label='Size', step_size=1, default=9)): 8 | M = sierpinski(2 * N) 9 | matrix_plot(M, cmap='binary').show(figsize=[size, size]) 10 | ︡35fca000-924c-4ef6-99bd-a69f230711c4︡{"interact":{"style":"None","flicker":false,"layout":[[["N",12,null]],[["size",12,null]],[["",12,null]]],"id":"bf13980b-3c14-4915-8b10-49093e0c8c80","controls":[{"control_type":"slider","default":6,"var":"N","width":null,"vals":["1","2","4","8","16","32","64","128","256","512","1024","2048"],"animate":true,"label":"Number of iterations","display_value":true},{"control_type":"slider","default":8,"var":"size","width":null,"vals":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"],"animate":true,"label":"Size","display_value":true}]}}︡ 11 | ︠76b537f2-054c-49c4-8687-854cbf83ca04︠ 12 | -------------------------------------------------------------------------------- /sage/interact/Fractals/twinDragon.sagews: -------------------------------------------------------------------------------- 1 | ︠188a9912-9adc-4dd0-97c0-4411620bc1e7︠ 2 | A = matrix([[1,1],[-1,1]]) 3 | D = [vector([0,0]), vector([1,0])] 4 | 5 | @interact 6 | def f(A = matrix([[1,1],[-1,1]]), D = '[[0,0],[1,0]]', k=(3..17)): 7 | print "Det = ", A.det() 8 | D = matrix(eval(D)).rows() 9 | def Dn(k): 10 | ans = [] 11 | for d in Tuples(D, k): 12 | s = sum(A^(-n)*d[n] for n in range(k)) 13 | ans.append(s) 14 | return ans 15 | 16 | G = points([v.list() for v in Dn(k)]) 17 | 18 | show(G, frame=True, axes=False) 19 | ︡0c52f821-72c0-4808-aa95-5e5e8f5660d7︡{"interact":{"style":"None","flicker":false,"layout":[[["A",12,null]],[["D",12,null]],[["k",12,null]],[["",12,null]]],"id":"826ce711-2f07-4040-bc9d-a070850d9008","controls":[{"control_type":"input-grid","ncols":2,"default":[["1","1"],["-1","1"]],"label":"A","nrows":2,"width":5,"var":"A"},{"control_type":"input-box","default":"[[0,0],[1,0]]","label":"D","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"D","type":""},{"control_type":"slider","default":0,"var":"k","width":null,"vals":["3","4","5","6","7","8","9","10","11","12","13","14","15","16","17"],"animate":true,"label":"k","display_value":true}]}}︡ 20 | ︠bc1b89b2-281a-4d82-a6da-d150e4d3d582︠ 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sage/interact/Fractals/twinDragon3D.sagews: -------------------------------------------------------------------------------- 1 | ︠dbb53311-ee3f-464f-a79f-e1125a92b5d5︠ 2 | A = matrix([[0,0,2],[1,0,1],[0,1,-1]]) 3 | D = '[[0,0,0],[1,0,0]]' 4 | 5 | def Dn(D,A,k): 6 | ans = [] 7 | for d in Tuples(D, k): 8 | s = sum(A^n*d[n] for n in range(k)) 9 | ans.append(s) 10 | return ans 11 | 12 | @interact 13 | def f(A = matrix([[0,0,2],[1,0,1],[0,1,-1]]), D = '[[0,0,0],[1,0,0]]', k=(3..15), labels=True): 14 | print "Det = ", A.det() 15 | D = matrix(eval(D)).rows() 16 | print "D:" 17 | print D 18 | G = point3d([v.list() for v in Dn(D,A,k)], size=8)#, opacity=.85) 19 | if labels: 20 | G += sum([text3d(str(v),v) for v in Dn(D,A,k)]) 21 | show(G, axes=False, frame=False) 22 | ︡abfad67f-4b12-48a6-83ba-dc7ece90d6f4︡{"interact":{"style":"None","flicker":false,"layout":[[["A",12,null]],[["D",12,null]],[["k",12,null]],[["labels",12,null]],[["",12,null]]],"id":"77faa5bc-2ca3-49b0-a583-5c9910c20e50","controls":[{"control_type":"input-grid","ncols":3,"default":[["0","0","2"],["1","0","1"],["0","1","-1"]],"label":"A","nrows":3,"width":5,"var":"A"},{"control_type":"input-box","default":"[[0,0,0],[1,0,0]]","label":"D","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"D","type":""},{"control_type":"slider","default":0,"var":"k","width":null,"vals":["3","4","5","6","7","8","9","10","11","12","13","14","15"],"animate":true,"label":"k","display_value":true},{"default":true,"var":"labels","readonly":false,"control_type":"checkbox","label":"labels"}]}}︡ 23 | ︠2459e05d-17de-46ee-a8e2-28926d519647︠ 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /sage/interact/Games/nim.sagews: -------------------------------------------------------------------------------- 1 | ︠d50d0b95-0174-4d19-be01-c1eb693c0bd7︠ 2 | #El juego del nim 3 | def game_repr(heap_sizes): 4 | return '\n'.join('%d:'%i+'*'*n for i,n in enumerate(heap_sizes)) 5 | def bitlist2number(bitlist): 6 | return int('0'+''.join([str(bit) for bit in reversed(bitlist)]),2) 7 | def move_nim(heap_sizes): 8 | '''Given a nim game, returns the next move (heap and amount) 9 | ''' 10 | all_digits=[n.bits() for n in heap_sizes] 11 | N=max(len(l) for l in all_digits) 12 | digi=[0]*N 13 | for l in all_digits: 14 | for i in range(len(l)): 15 | digi[i]+=l[i] 16 | digi2=[digi[i]%2 for i in range(len(digi))] 17 | if max(digi2)==0:raise Exception("I cannot win!") 18 | maxInd=max(i for i in range(N) if digi2[i]) 19 | 20 | heap=min(i for i in range(len(heap_sizes)) if len(all_digits[i])>maxInd and all_digits[i][maxInd]>0) 21 | localbits=heap_sizes[heap].bits()[0:maxInd] 22 | globalbits=digi2[0:maxInd] 23 | correction=bitlist2number( [b2 if b2 and not b1 else 0 for b1,b2 in zip(localbits,globalbits)] ) - bitlist2number( [b2 if b2 and b1 else 0 for b1,b2 in zip(localbits,globalbits)] ) 24 | amount=2^maxInd -correction 25 | return (heap,amount) 26 | 27 | nim=[1,3,5,6] 28 | @interact 29 | def _(heap=selector(range(len(nim)), buttons=True), 30 | amount=selector(range(max(nim)+1), buttons=True), 31 | auto_update=False): 32 | global nim 33 | if max(nim)==0: 34 | print 'You have lost' 35 | return 36 | else: 37 | print 'Try to take the last item' 38 | if heap>=0 and 00) 55 | myamount=1 56 | nim[myheap]-=myamount 57 | print game_repr(nim) 58 | if max(nim)==0: 59 | print 'I win' 60 | else: 61 | print 'Please move again' 62 | else: 63 | print 'Choose a heap and the amount to substract from that heap' 64 | print game_repr(nim) 65 | ︡e8f9f6d5-a5b3-4a3f-a7bb-f87db6cd5705︡{"interact":{"style":"None","flicker":false,"layout":[[["heap",12,null]],[["amount",12,null]],[["auto_update",12,null]],[["",12,null]]],"id":"322cae66-9f3a-4d12-88c5-4b998414e6ae","controls":[{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["0","1","2","3"],"label":"heap","nrows":null,"width":null,"var":"heap"},{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["0","1","2","3","4","5","6"],"label":"amount","nrows":null,"width":null,"var":"amount"},{"default":false,"var":"auto_update","readonly":false,"control_type":"checkbox","label":"auto_update"}]}}︡ 66 | ︠534566af-aa05-42b7-bca1-7e15cfde66f5︠ 67 | ︡e86b9491-d5cb-482c-8cd5-e085bb0711a8︡ 68 | ︠c2243781-fefc-453e-9f43-bbaa27d3d47b︠ 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /sage/interact/Games/queens.sagews: -------------------------------------------------------------------------------- 1 | ︠5d1bc51f-82ed-4788-be30-397d0f758787︠ 2 | queens=[] 3 | opciones=['Clean board', 'Add queen', 'Remove queen' ] 4 | 5 | @interact 6 | def _(queen=input_box(default=(0,0)), opcion=selector(opciones, buttons=True), auto_update=False ): 7 | global queens 8 | if opcion=='Clean board': 9 | queens=[] 10 | elif opcion=='Add queen': 11 | if queen not in queens: 12 | queens.append(queen) 13 | else: 14 | if queen in queens: 15 | queens.remove(queen) 16 | 17 | board=matrix(ZZ,8,8) 18 | for x in range(8): 19 | for y in range(8): 20 | board[x,y]=(x+y)%2*7 21 | for x,y in queens: 22 | for i in range(8): 23 | if i!=y: board[x,i]=1+(x+i)%2*5 24 | if i!=x: board[i,y]=1+(i+y)%2*5 25 | for i in range(-min(x,y),min(8-x,8-y)): 26 | if i!=0: board[x+i,y+i]=1+(x+y)%2*5 27 | for i in range(max(-x,y-7),min(8-x,y+1)): 28 | if i!=0: board[x+i,y-i]=1+(x+y)%2*5 29 | for x,y in queens: 30 | if ( board[x,y]==1 or board[x,y]==6 ): 31 | print 'Queen at (%d,%d) is threatened by another queen'%(x,y) 32 | board[x,y]=4 33 | else: 34 | board[x,y]=3 35 | show(matrix_plot(board, cmap='Oranges' )) 36 | ︡cdc166ff-8611-454d-9b6f-a0f79c5ff056︡{"interact":{"style":"None","flicker":false,"layout":[[["queen",12,null]],[["opcion",12,null]],[["auto_update",12,null]],[["",12,null]]],"id":"7fb23ed2-fc3d-4bf1-b110-40385cf550ba","controls":[{"control_type":"input-box","default":"(0, 0)","label":"queen","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"queen","type":null},{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Clean board","Add queen","Remove queen"],"label":"opcion","nrows":null,"width":null,"var":"opcion"},{"default":false,"var":"auto_update","readonly":false,"control_type":"checkbox","label":"auto_update"}]}}︡ 37 | ︠e991d67c-7304-4e17-85ad-10a9ec1981ae︠ 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sage/interact/Games/zeros.sagews: -------------------------------------------------------------------------------- 1 | ︠b350e176-4159-4907-8a4d-db86a179a5cfi︠ 2 | import random 3 | 4 | def init(): 5 | global B,Br,n,round,tm,t,v 6 | B = 40 7 | Br = 15 8 | n = 1 9 | round = 0 10 | tm = 0 11 | t = walltime() 12 | 13 | 14 | init() 15 | 16 | html("

Zeros

") 17 | html("

How many zeros?

") 18 | 19 | @interact 20 | def zeros(a=selector(buttons=True, nrows=1, values=['Reset'] + [1..B], default=1)): 21 | if a == 'Reset': 22 | init() 23 | html("
") 24 | global B,Br,n,round,tm,t,v 25 | if a == n: 26 | if round > 0: 27 | html("RIGHT") 28 | r = walltime() - t 29 | tm += r 30 | round += 1 31 | t = walltime() 32 | while True: 33 | n2 = random.randrange(1,Br) 34 | if n2 != n: 35 | n = n2 36 | break 37 | if Br < B: 38 | Br += 2 39 | elif round > 0: 40 | html("Wrong. Try again...") 41 | html("
") 42 | html(""%random.randrange(-2,5)) 43 | print ' '*random.randrange(20) + '0'*n 44 | html("") 45 | if round > 0: 46 | html("

Score: %s rounds, Average time: %.1f seconds
"%( 47 | round, float(tm)/round)) 48 | ︡cb488e1d-c1c6-46ca-8682-06d8ca50dc47︡{"html":"

Zeros

"}︡{"html":"

How many zeros?

"}︡{"interact":{"style":"None","flicker":false,"layout":[[["a",12,null]],[["",12,null]]],"id":"45649c9a-e135-4924-85b1-4aa88f565385","controls":[{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":1,"lbls":["Reset","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40"],"label":"a","nrows":1,"width":null,"var":"a"}]}}︡ 49 | ︠9a989cb7-91cf-4454-bb8a-c741e2129a94︠ 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /sage/interact/Geometry/evolutes.sagews: -------------------------------------------------------------------------------- 1 | ︠729af806-0262-4301-9a54-9a277f7c68cd︠ 2 | var('t'); 3 | def norma(v): 4 | return sqrt(sum(x^2 for x in v)) 5 | paso_angulo=5 6 | 7 | @interact 8 | def _( gamma1=input_box(default=sin(t)), gamma2=input_box(default=1.3*cos(t)), 9 | draw_normal_lines=True, 10 | rango_angulos=range_slider(0,360,paso_angulo,(0,90),label='Draw lines for these angles'), 11 | draw_osculating_circle=True, 12 | t0=input_box(default=pi/3,label='parameter value for the osculating circle'), 13 | auto_update=False ): 14 | 15 | gamma=(gamma1,gamma2) 16 | gammap=(gamma[0].derivative(),gamma[1].derivative()) 17 | np=norma(gammap) 18 | gammapp=(gammap[0].derivative(),gammap[1].derivative()) 19 | npp=norma(gammapp) 20 | 21 | normal=(gammap[1]/np, -gammap[0]/np) 22 | curvatura=(gammap[1]*gammapp[0]-gammap[0]*gammapp[1])/norma(gammap)^3 23 | radio=1/curvatura 24 | 25 | centros=(gamma[0]+radio*normal[0],gamma[1]+radio*normal[1]) 26 | 27 | curva=parametric_plot(gamma,(t,0,2*pi)) 28 | evoluta=parametric_plot(centros,(t,0,2*pi), color='red') 29 | grafica=curva+evoluta 30 | 31 | if draw_normal_lines: 32 | f=2*pi/360 33 | lineas=sum(line2d( [ (gamma[0](t=i*f), gamma[1](t=i*f)), 34 | (centros[0](t=i*f), centros[1](t=i*f)) ], 35 | thickness=1,rgbcolor=(1,0.8,0.8)) 36 | for i in range(rango_angulos[0], rango_angulos[1]+paso_angulo, paso_angulo)) 37 | grafica+=lineas 38 | 39 | if draw_osculating_circle and 0 8: 11 | print "n reduced to 8" 12 | n = 8 13 | print "n = %s (dimension)"%n 14 | G = graphs.CubeGraph(n) 15 | elif graph == 'RandomGNP': 16 | print "n = %s (number of vertices)"%n 17 | print "p = %s%% (edge probability)"%p 18 | G = graphs.RandomGNP(n, p/100.0) 19 | print G.automorphism_group() 20 | show(plot(G)) 21 | ︡039401fb-9feb-48a2-8f3e-ce8756d6eb35︡{"interact":{"style":"None","flicker":false,"layout":[[["graph",12,null]],[["n",12,null]],[["p",12,null]],[["",12,null]]],"id":"f5e960c7-2de5-45e0-bcc7-a0032812515a","controls":[{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["CycleGraph","CubeGraph","RandomGNP"],"label":"graph","nrows":null,"width":null,"var":"graph"},{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["1","2","3","4","5","6","7","8","9","10"],"label":"n","nrows":1,"width":null,"var":"n"},{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["10","20","30","40","50","60","70","80","90","100"],"label":"p","nrows":1,"width":null,"var":"p"}]}}︡ 22 | ︠a8e33cfd-49db-4006-9dbf-e9ec8522df55︠ 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sage/interact/Graphics/interactive2DPlot.sagews: -------------------------------------------------------------------------------- 1 | ︠afcdea30-a98f-4dc3-8136-497c075905ab︠ 2 | def error_msg(msg): 3 | print '

Error: %s

' % msg 4 | 5 | @interact 6 | def interactive_2d_plotter(expression=input_box('sin(x)', 'Expression', str), x_range=range_slider(-10,10,1,(0,10), label='X Range'), square=checkbox(True, 'Square'), axes=checkbox(True, 'Show Axes')): 7 | if expression: 8 | try: 9 | expression = SR(expression) # turn string into a Sage expression 10 | except TypeError: 11 | print error_msg('This is not an expression.') 12 | return 13 | try: 14 | xmin, xmax = x_range 15 | if square or not axes: 16 | print "var('%s')\nplot(%s).show(%s%s%s)" % (expression.variables()[0], repr(expression), 'aspect_ratio=1' if square else '', ', ' if square and not axes else '', 'axes=False' if not axes else '') 17 | if square: 18 | plot(expression, xmin, xmax).show(aspect_ratio=1, axes=axes) 19 | else: 20 | plot(expression, xmin, xmax).show(axes=axes) 21 | else: 22 | print "var('%s')\nplot(%s)" % (expression.variables()[0], repr(expression)) 23 | plot(expression, xmin, xmax).show(axes=axes) 24 | except ValueError: 25 | print error_msg('This expression has more than one variable.') 26 | return 27 | except TypeError: 28 | print error_msg("This expression contains an unknown function.") 29 | return 30 | ︡89516b34-686a-48a6-9454-e1c81b214719︡{"interact":{"style":"None","flicker":false,"layout":[[["expression",12,null]],[["x_range",12,null]],[["square",12,null]],[["axes",12,null]],[["",12,null]]],"id":"85092596-6dd6-4f5c-8f79-b2323d437fc7","controls":[{"control_type":"input-box","default":"sin(x)","label":"Expression","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"expression","type":""},{"control_type":"range-slider","default":[10,20],"var":"x_range","width":null,"vals":["-10","-9","-8","-7","-6","-5","-4","-3","-2","-1","0","1","2","3","4","5","6","7","8","9","10"],"animate":true,"label":"X Range","display_value":true},{"default":true,"var":"square","readonly":false,"control_type":"checkbox","label":"Square"},{"default":true,"var":"axes","readonly":false,"control_type":"checkbox","label":"Show Axes"}]}}︡ 31 | ︠add6f5b2-484a-4a31-8723-a6d189a6a9b4︠ 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sage/interact/Graphics/paintEgg.sagews: -------------------------------------------------------------------------------- 1 | ︠8b4453a8-e2a6-443e-95d6-a0906e01e189︠ 2 | var('s,t') 3 | g(s) = ((0.57496*sqrt(121 - 16.0*s^2))/sqrt(10.+ s)) 4 | def P(color, rng): 5 | return parametric_plot3d((cos(t)*g(s), sin(t)*g(s), s), (s,rng[0],rng[1]), (t,0,2*pi), plot_points = [150,150], rgbcolor=color, frame = False, opacity = 1) 6 | colorlist = ['red','blue','red','blue'] 7 | 8 | @interact 9 | def _(band_number = selector(range(1,5)), current_color = Color('red'), auto_update=False): 10 | html('

Egg Painter

') 11 | colorlist[band_number-1] = current_color 12 | egg = sum([P(colorlist[i],[-2.75+5.5*(i/4),-2.75+5.5*(i+1)/4]) for i in range(4)]) 13 | show(egg) 14 | ︡e0be7776-dca7-4d2a-aafa-b8c6848acc74︡{"stdout":"(s, t)\n"}︡{"interact":{"style":"None","flicker":false,"layout":[[["band_number",12,null]],[["current_color",12,null]],[["auto_update",12,null]],[["",12,null]]],"id":"3118d83e-4a19-4f66-8463-a9ecd111fff0","controls":[{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["1","2","3","4"],"label":"band_number","nrows":null,"width":null,"var":"band_number"},{"widget":null,"control_type":"color-selector","hide_box":false,"Color":"","label":"current_color","default":"#ff0000","readonly":false,"var":"current_color"},{"default":false,"var":"auto_update","readonly":false,"control_type":"checkbox","label":"auto_update"}]}}︡ 15 | ︠642ea26f-d386-4ea8-9d72-8bd73d4afabe︠ 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sage/interact/Graphics/plotColor.sagews: -------------------------------------------------------------------------------- 1 | ︠c21a4a38-efbf-4a93-9259-4ed7b43bbb04︠ 2 | @interact 3 | def color_experimenter(expression=input_box('x^2', 'Expression', str), color=Color('red')): 4 | if expression: 5 | try: 6 | plot(SR(expression), rgbcolor=color).show() 7 | except TypeError: 8 | print "There's a problem with your expression." 9 | ︡6c5392c1-3f6a-4b80-b95f-80889edd0da9︡{"interact":{"style":"None","flicker":false,"layout":[[["expression",12,null]],[["color",12,null]],[["",12,null]]],"id":"2dc156e6-4c8b-44f0-91c5-bb1d3beb0687","controls":[{"control_type":"input-box","default":"x^2","label":"Expression","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"expression","type":""},{"widget":null,"control_type":"color-selector","hide_box":false,"Color":"","label":"color","default":"#ff0000","readonly":false,"var":"color"}]}}︡ 10 | ︠55f52e17-fef2-482d-b4a7-ac16c1e7bc2b︠ 11 | -------------------------------------------------------------------------------- /sage/interact/Graphics/plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/sage/interact/Graphics/plt.png -------------------------------------------------------------------------------- /sage/interact/LinearAlgebra/determTranspose.sagews: -------------------------------------------------------------------------------- 1 | ︠6f6bdd75-dacf-46dc-829b-9445d5c5ac0b︠ 2 | srg = srange(-4,4,1/10,include_endpoint=True) 3 | @interact 4 | def dualv(a1=slider(srg,default=1),a2=slider(srg,default=2), a3=slider(srg,default=-1),a4=slider(srg,default=3)): 5 | A1 = arrow2d([0,0],[a1,a2],rgbcolor='black') 6 | A2 = arrow2d([0,0],[a3,a4],rgbcolor='black') 7 | A3 = arrow2d([0,0],[a1,a3],rgbcolor='black') 8 | A4 = arrow2d([0,0],[a2,a4],rgbcolor='black') 9 | p1 = polygon([[0,0],[a1,a2],[a1+a3,a2+a4],[a3,a4],[0,0]], alpha=.5) 10 | p2 = polygon([[0,0],[a1,a3],[a1+a2,a3+a4],[a2,a4],[0,0]],rgbcolor='red', alpha=.5) 11 | A = matrix([[a1,a2],[a3,a4]]) 12 | html('

The determinant of a matrix is equal to the determinant of the transpose

') 13 | html("$det(%s) = det(%s)$"%(latex(A),latex(A.transpose()))) 14 | show(A1+A2+A3+A4+p1+p2) 15 | ︡b0e8abcd-94f1-4e60-b73a-9517ad7d0501︡{"interact":{"style":"None","flicker":false,"layout":[[["a1",12,null]],[["a2",12,null]],[["a3",12,null]],[["a4",12,null]],[["",12,null]]],"id":"44069cd3-2605-4183-acc5-847026e86e2e","controls":[{"control_type":"slider","default":50,"var":"a1","width":null,"vals":["-4","-39/10","-19/5","-37/10","-18/5","-7/2","-17/5","-33/10","-16/5","-31/10","-3","-29/10","-14/5","-27/10","-13/5","-5/2","-12/5","-23/10","-11/5","-21/10","-2","-19/10","-9/5","-17/10","-8/5","-3/2","-7/5","-13/10","-6/5","-11/10","-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4"],"animate":true,"label":"a1","display_value":true},{"control_type":"slider","default":60,"var":"a2","width":null,"vals":["-4","-39/10","-19/5","-37/10","-18/5","-7/2","-17/5","-33/10","-16/5","-31/10","-3","-29/10","-14/5","-27/10","-13/5","-5/2","-12/5","-23/10","-11/5","-21/10","-2","-19/10","-9/5","-17/10","-8/5","-3/2","-7/5","-13/10","-6/5","-11/10","-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4"],"animate":true,"label":"a2","display_value":true},{"control_type":"slider","default":30,"var":"a3","width":null,"vals":["-4","-39/10","-19/5","-37/10","-18/5","-7/2","-17/5","-33/10","-16/5","-31/10","-3","-29/10","-14/5","-27/10","-13/5","-5/2","-12/5","-23/10","-11/5","-21/10","-2","-19/10","-9/5","-17/10","-8/5","-3/2","-7/5","-13/10","-6/5","-11/10","-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4"],"animate":true,"label":"a3","display_value":true},{"control_type":"slider","default":70,"var":"a4","width":null,"vals":["-4","-39/10","-19/5","-37/10","-18/5","-7/2","-17/5","-33/10","-16/5","-31/10","-3","-29/10","-14/5","-27/10","-13/5","-5/2","-12/5","-23/10","-11/5","-21/10","-2","-19/10","-9/5","-17/10","-8/5","-3/2","-7/5","-13/10","-6/5","-11/10","-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4"],"animate":true,"label":"a4","display_value":true}]}}︡ 16 | ︠1d654e8a-7cef-4b13-a579-6f842ae01bc6︠ 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sage/interact/LinearAlgebra/gerschgorinCircle.sagews: -------------------------------------------------------------------------------- 1 | ︠f15ae216-ce83-410c-b6f7-e0a656cc82edi︠ 2 | from scipy import linalg 3 | html('

The Gerschgorin circle theorem

') 4 | @interact 5 | def Gerschgorin(Ain = input_box(default='[[10,1,1/10,0],[-1,9,0,1],[1,0,2,3/10],[-.5,0,-.3,1]]', type = str, label = 'A = '), an_size = slider(1,100,1,1.0)): 6 | A = sage_eval(Ain) 7 | size = len(A) 8 | html('$A = ' + latex(matrix(RealField(10),A))+'$') 9 | A = matrix(RealField(10),A) 10 | B = [[0 for i in range(size)] for j in range(size)] 11 | for i in range(size): 12 | B[i][i] = A[i][i] 13 | B = matrix(B) 14 | frames = [] 15 | 16 | centers = [(real(q),imag(q)) for q in [A[i][i] for i in range(size)]] 17 | radii_row = [sum([abs(A[i][j]) for j in range(i)+range(i+1,size)]) for i in range(size)] 18 | radii_col = [sum([abs(A[j][i]) for j in range(i)+range(i+1,size)]) for i in range(size)] 19 | x_min = min([centers[i][0]-radii_row[i] for i in range(size)]+[centers[i][0]-radii_col[i] for i in range(size)]) 20 | x_max = max([centers[i][0]+radii_row[i] for i in range(size)]+[centers[i][0]+radii_col[i] for i in range(size)]) 21 | y_min = min([centers[i][1]-radii_row[i] for i in range(size)]+[centers[i][1]-radii_col[i] for i in range(size)]) 22 | y_max = max([centers[i][1]+radii_row[i] for i in range(size)]+[centers[i][1]+radii_col[i] for i in range(size)]) 23 | 24 | if an_size > 1: 25 | t_range= srange(0,1+1/an_size,1/an_size) 26 | else: 27 | t_range = [1] 28 | for t in t_range: 29 | C = t*A + (1-t)*B 30 | eigs = [CDF(x) for x in linalg.eigvals(C.numpy())] 31 | eigpoints = points([(real(q),imag(q)) for q in eigs],pointsize = 10, rgbcolor = (0,0,0)) 32 | centers = [(real(q),imag(q)) for q in [A[i][i] for i in range(size)]] 33 | radii_row = [sum([abs(C[i][j]) for j in range(i)+range(i+1,size)]) for i in range(size)] 34 | radii_col = [sum([abs(C[j][i]) for j in range(i)+range(i+1,size)]) for i in range(size)] 35 | scale = max([(x_max-x_min),(y_max-y_min)]) 36 | scale = 7/scale 37 | row_circles = sum([circle(centers[i],radii_row[i],fill=True, alpha = .3) for i in range(size)]) 38 | col_circles = sum([circle(centers[i],radii_col[i],fill=True, rgbcolor = (1,0,0), alpha = .3) for i in range(size)]) 39 | ft = eigpoints+row_circles+col_circles 40 | frames.append(ft) 41 | show(animate(frames,figsize = [(x_max-x_min)*scale,(y_max-y_min)*scale], xmin = x_min, xmax=x_max, ymin = y_min, ymax = y_max)) 42 | ︡31423c29-cb0a-46fb-9388-3a588f182adc︡{"html":"

The Gerschgorin circle theorem

"}︡{"interact":{"style":"None","flicker":false,"layout":[[["Ain",12,null]],[["an_size",12,null]],[["",12,null]]],"id":"a9b0f9ee-b87f-4dc1-a755-9cfe057b9ad0","controls":[{"control_type":"input-box","default":"[[10,1,1/10,0],[-1,9,0,1],[1,0,2,3/10],[-.5,0,-.3,1]]","label":"A = ","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"Ain","type":""},{"control_type":"slider","default":0,"var":"an_size","width":null,"vals":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100"],"animate":true,"label":"an_size","display_value":true}]}}︡ 43 | ︠2501ff14-7706-414c-bd0a-388469930574︠ 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /sage/interact/LinearAlgebra/linearTransform.sagews: -------------------------------------------------------------------------------- 1 | ︠71e5a9ee-d10f-422b-bdef-2a3a7a3e84c5︠ 2 | @interact 3 | def linear_transformation(A=matrix([[1,-1],[-1,1/2]]),theta=slider(0, 2*pi, .1), r=slider(0.1, 2, .1, default=1)): 4 | v=vector([r*cos(theta), r*sin(theta)]) 5 | w = A*v 6 | circles = sum([circle((0,0), radius=i, color='black') for i in [1..2]]) 7 | html("$%s %s=%s$"%tuple(map(latex, [A, v.column().n(4), w.column().n(4)]))) 8 | show(v.plot(color='red')+w.plot(color='blue')+circles,aspect_ratio=1) 9 | ︡b8a3dfe0-2874-4b1a-a711-ccc7c15fb2b4︡{"interact":{"style":"None","flicker":false,"layout":[[["A",12,null]],[["theta",12,null]],[["r",12,null]],[["",12,null]]],"id":"01776d6f-f6ef-43dd-acd3-d990abef4c9c","controls":[{"control_type":"input-grid","ncols":2,"default":[["1","-1"],["-1","1/2"]],"label":"A","nrows":2,"width":5,"var":"A"},{"control_type":"slider","default":0,"var":"theta","width":null,"vals":["0","0.100000000000000","0.200000000000000","0.300000000000000","0.400000000000000","0.500000000000000","0.600000000000000","0.700000000000000","0.800000000000000","0.900000000000000","1.00000000000000","1.10000000000000","1.20000000000000","1.30000000000000","1.40000000000000","1.50000000000000","1.60000000000000","1.70000000000000","1.80000000000000","1.90000000000000","2.00000000000000","2.10000000000000","2.20000000000000","2.30000000000000","2.40000000000000","2.50000000000000","2.60000000000000","2.70000000000000","2.80000000000000","2.90000000000000","3.00000000000000","3.10000000000000","3.20000000000000","3.30000000000000","3.40000000000000","3.50000000000000","3.60000000000000","3.70000000000000","3.80000000000000","3.90000000000000","4.00000000000000","4.10000000000000","4.20000000000000","4.30000000000000","4.40000000000000","4.50000000000000","4.60000000000000","4.70000000000000","4.80000000000000","4.90000000000000","5.00000000000000","5.10000000000000","5.20000000000000","5.30000000000000","5.40000000000000","5.50000000000000","5.60000000000000","5.70000000000000","5.80000000000000","5.90000000000000","5.99999999999999","6.09999999999999","6.19999999999999"],"animate":true,"label":"theta","display_value":true},{"control_type":"slider","default":9,"var":"r","width":null,"vals":["0.100000000000000","0.200000000000000","0.300000000000000","0.400000000000000","0.500000000000000","0.600000000000000","0.700000000000000","0.800000000000000","0.900000000000000","1.00000000000000","1.10000000000000","1.20000000000000","1.30000000000000","1.40000000000000","1.50000000000000","1.60000000000000","1.70000000000000","1.80000000000000","1.90000000000000","2.00000000000000"],"animate":true,"label":"r","display_value":true}]}}︡ 10 | ︠5d630688-d87b-4a6c-85f4-fe2fb747005c︠ 11 | -------------------------------------------------------------------------------- /sage/interact/Miscellaneous/beatFreq.sagews: -------------------------------------------------------------------------------- 1 | ︠0f861d4f-50be-4b0e-afa8-cbebafdb79c8︠ 2 | import wave 3 | 4 | class SoundFile: 5 | def __init__(self, signal,lab=''): 6 | self.file = wave.open('./test' + lab + '.wav', 'wb') 7 | self.signal = signal 8 | self.sr = 44100 9 | 10 | def write(self): 11 | self.file.setparams((1, 2, self.sr, 44100*4, 'NONE', 'noncompressed')) 12 | self.file.writeframes(self.signal) 13 | self.file.close() 14 | 15 | mypi = float(pi) 16 | from math import sin 17 | 18 | @interact 19 | def sinsound(freq_ratio = slider(1/144,1,1/144,1/12)): 20 | hz1 = 440.0 21 | hz2 = float(440.0*2^freq_ratio) 22 | html('$\cos(\omega t) - \cos(\omega_0 t) = 2 \sin(\\frac{\omega + \omega_0}{2}t) \sin(\\frac{\omega - \omega_0}{2}t)$') 23 | s2 = [sin(hz1*x*mypi*2)+sin(hz2*x*mypi*2) for x in srange(0,4,1/44100.0)] 24 | s2m = max(s2) 25 | s2f = [16384*x/s2m for x in s2] 26 | s2str = ''.join(wave.struct.pack('h',x) for x in s2f) 27 | lab="%1.2f"%float(freq_ratio) 28 | f = SoundFile(s2str,lab=lab) 29 | f.write() 30 | pnum = 1500+int(500/freq_ratio) 31 | show(list_plot(s2[0:pnum],plotjoined=True)) 32 | html('') 33 | html('Frequencies: '+ '$\omega_0 = ' + str(hz1) + ' $, $\omega = '+latex(hz2) + '$') 34 | ︡dede0cb1-960e-4f84-8e8c-b7a346bb1bbe︡{"interact":{"style":"None","flicker":false,"layout":[[["freq_ratio",12,null]],[["",12,null]]],"id":"24b2c063-b566-4cf6-a50a-d1aece4193c2","controls":[{"control_type":"slider","default":11,"var":"freq_ratio","width":null,"vals":["1/144","1/72","1/48","1/36","5/144","1/24","7/144","1/18","1/16","5/72","11/144","1/12","13/144","7/72","5/48","1/9","17/144","1/8","19/144","5/36","7/48","11/72","23/144","1/6","25/144","13/72","3/16","7/36","29/144","5/24","31/144","2/9","11/48","17/72","35/144","1/4","37/144","19/72","13/48","5/18","41/144","7/24","43/144","11/36","5/16","23/72","47/144","1/3","49/144","25/72","17/48","13/36","53/144","3/8","55/144","7/18","19/48","29/72","59/144","5/12","61/144","31/72","7/16","4/9","65/144","11/24","67/144","17/36","23/48","35/72","71/144","1/2","73/144","37/72","25/48","19/36","77/144","13/24","79/144","5/9","9/16","41/72","83/144","7/12","85/144","43/72","29/48","11/18","89/144","5/8","91/144","23/36","31/48","47/72","95/144","2/3","97/144","49/72","11/16","25/36","101/144","17/24","103/144","13/18","35/48","53/72","107/144","3/4","109/144","55/72","37/48","7/9","113/144","19/24","115/144","29/36","13/16","59/72","119/144","5/6","121/144","61/72","41/48","31/36","125/144","7/8","127/144","8/9","43/48","65/72","131/144","11/12","133/144","67/72","15/16","17/18","137/144","23/24","139/144","35/36","47/48","71/72","143/144","1"],"animate":true,"label":"freq_ratio","display_value":true}]}}︡ 35 | ︠7228bbaf-adb8-436b-9e4f-f454f4c72498︠ 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /sage/interact/Miscellaneous/cellularAutomata.sagews: -------------------------------------------------------------------------------- 1 | ︠a4027af1-d620-490e-9606-d830011de71f︠ 2 | from numpy import zeros 3 | from random import randint 4 | 5 | def cellular(rule, N, initial='Single-cell'): 6 | '''Yields a matrix showing the evolution of a Wolfram's cellular automaton 7 | 8 | rule: determines how a cell's value is updated, depending on its neighbors 9 | N: number of iterations 10 | initial: starting condition; can be either single-cell or a random binary row 11 | ''' 12 | M=zeros( (N,2*N+2), dtype=int) 13 | if initial=='Single-cell': 14 | M[0,N]=1 15 | else: 16 | M[0]=[randint(0,1) for a in range(0,2*N+2)] 17 | 18 | for j in range(1,N): 19 | for k in range(0,2*N): 20 | l = 4*M[j-1,k-1] + 2*M[j-1,k] + M[j-1,k+1] 21 | M[j,k]=rule[ l ] 22 | return M[:,:-1] 23 | 24 | def num2rule(number): 25 | if not 0 <= number <= 255: 26 | raise Exception('Invalid rule number') 27 | binary_digits = number.digits(base=2) 28 | return binary_digits + [0]*(8-len(binary_digits)) 29 | 30 | @interact 31 | def _( initial=selector(['Single-cell', 'Random'], label='Starting condition'), N=input_box(label='Number of iterations',default=100), 32 | rule_number=input_box(label='Rule number',default=110), 33 | size = slider(1, 11, label= 'Size', step_size=1, default=6 ), auto_update=False): 34 | rule = num2rule(rule_number) 35 | M = cellular(rule, N, initial) 36 | plot_M = matrix_plot(M, cmap='binary') 37 | plot_M.show( figsize=[size,size]) 38 | ︡36ac1a8e-f0e1-494a-a5cd-e6b784eb1c39︡{"interact":{"style":"None","flicker":false,"layout":[[["initial",12,null]],[["N",12,null]],[["rule_number",12,null]],[["size",12,null]],[["auto_update",12,null]],[["",12,null]]],"id":"c343f4a6-bded-45a2-bba5-c0b869ea0026","controls":[{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Single-cell","Random"],"label":"Starting condition","nrows":null,"width":null,"var":"initial"},{"control_type":"input-box","default":100,"label":"Number of iterations","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"N","type":null},{"control_type":"input-box","default":110,"label":"Rule number","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"rule_number","type":null},{"control_type":"slider","default":5,"var":"size","width":null,"vals":["1","2","3","4","5","6","7","8","9","10","11"],"animate":true,"label":"Size","display_value":true},{"default":false,"var":"auto_update","readonly":false,"control_type":"checkbox","label":"auto_update"}]}}︡ 39 | ︠63b776f1-2994-4bbb-95f6-823b4b4f873a︠ 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /sage/interact/Miscellaneous/interactiveVenn.sagews: -------------------------------------------------------------------------------- 1 | ︠f8eff22e-9524-4603-a39e-fd89026fe542︠ 2 | def f(s, braces=True): 3 | t = ', '.join(sorted(list(s))) 4 | if braces: return '{' + t + '}' 5 | return t 6 | def g(s): return set(str(s).replace(',',' ').split()) 7 | 8 | @interact 9 | def _(X='1,2,3,a', Y='2,a,3,4,apple', Z='a,b,10,apple'): 10 | S = [g(X), g(Y), g(Z)] 11 | X,Y,Z = S 12 | XY = X & Y 13 | XZ = X & Z 14 | YZ = Y & Z 15 | XYZ = XY & Z 16 | html('
') 17 | html("$X \cap Y$ = %s"%f(XY)) 18 | html("$X \cap Z$ = %s"%f(XZ)) 19 | html("$Y \cap Z$ = %s"%f(YZ)) 20 | html("$X \cap Y \cap Z$ = %s"%f(XYZ)) 21 | html('
') 22 | centers = [(cos(n*2*pi/3), sin(n*2*pi/3)) for n in [0,1,2]] 23 | scale = 1.7 24 | clr = ['yellow', 'blue', 'green'] 25 | G = Graphics() 26 | for i in range(len(S)): 27 | G += circle(centers[i], scale, rgbcolor=clr[i], 28 | fill=True, alpha=0.3) 29 | for i in range(len(S)): 30 | G += circle(centers[i], scale, rgbcolor='black') 31 | 32 | # Plot what is in one but neither other 33 | for i in range(len(S)): 34 | Z = set(S[i]) 35 | for j in range(1,len(S)): 36 | Z = Z.difference(S[(i+j)%3]) 37 | G += text(f(Z,braces=False), (1.5*centers[i][0],1.7*centers[i][1]), rgbcolor='black') 38 | 39 | 40 | # Plot pairs of intersections 41 | for i in range(len(S)): 42 | Z = (set(S[i]) & S[(i+1)%3]) - set(XYZ) 43 | C = (1.3*cos(i*2*pi/3 + pi/3), 1.3*sin(i*2*pi/3 + pi/3)) 44 | G += text(f(Z,braces=False), C, rgbcolor='black') 45 | 46 | # Plot intersection of all three 47 | G += text(f(XYZ,braces=False), (0,0), rgbcolor='black') 48 | 49 | # Show it 50 | G.show(aspect_ratio=1, axes=False) 51 | ︡894d8b39-2312-4e1b-99bb-04b53738e06a︡{"interact":{"style":"None","flicker":false,"layout":[[["X",12,null]],[["Y",12,null]],[["Z",12,null]],[["",12,null]]],"id":"5741b9c1-2a2e-4fac-a305-90ff8f3ad00d","controls":[{"control_type":"input-box","default":"1,2,3,a","label":"X","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"X","type":""},{"control_type":"input-box","default":"2,a,3,4,apple","label":"Y","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"Y","type":""},{"control_type":"input-box","default":"a,b,10,apple","label":"Z","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"Z","type":""}]}}︡ 52 | ︠410f44a7-e482-4bae-882b-501646e14b81︠ 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /sage/interact/Miscellaneous/minkowskiSum.sagews: -------------------------------------------------------------------------------- 1 | ︠46930314-d11b-4b9b-9fb1-c0bdd941f9b7︠ 2 | def minkdemo(list1,list2): 3 | ''' 4 | Returns the Minkowski sum of two lists. 5 | ''' 6 | output = [] 7 | for stuff1 in list1: 8 | for stuff2 in list2: 9 | temp = [stuff1[i] + stuff2[i] for i in range(len(stuff1))] 10 | output.append(temp) 11 | return output 12 | @interact 13 | def minksumvis(x1tri = slider(-1,1,1/10,0, label = 'Triangle point x coord.'), yb = slider(1,4,1/10,2, label = 'Blue point y coord.')): 14 | t_list = [[1,0],[x1tri,1],[0,0]] 15 | kite_list = [[3, 0], [1, 0], [0, 1], [1, yb]] 16 | triangle = polygon([[q[0]-6,q[1]] for q in t_list], alpha = .5, rgbcolor = (1,0,0)) 17 | t_vert = point([x1tri-6,1], rgbcolor = (1,0,0)) 18 | b_vert = point([kite_list[3][0]-4,yb], rgbcolor = (0,0,1)) 19 | kite = polygon([[q[0]-4,q[1]] for q in kite_list], alpha = .5,rgbcolor = (0,0,1)) 20 | p12 = minkdemo(t_list, kite_list) 21 | p12 = [[q[0],q[1]] for q in p12] 22 | p12poly = Polyhedron(p12) 23 | edge_lines = Graphics() 24 | verts = p12poly.vertices() 25 | for an_edge in p12poly.vertex_adjacencies(): 26 | edge_lines += line([verts[an_edge[0]], verts[an_edge[1][0]]]) 27 | edge_lines += line([verts[an_edge[0]], verts[an_edge[1][1]]]) 28 | triangle_sum = Graphics() 29 | for vert in kite_list: 30 | temp_list = [] 31 | for q in t_list: 32 | temp_list.append([q[i] + vert[i] for i in range(len(t_list[0]))]) 33 | triangle_sum += polygon(temp_list, alpha = .5, rgbcolor = (1,0,0)) 34 | kite_sum = Graphics() 35 | for vert in t_list: 36 | temp_list = [] 37 | for q in kite_list: 38 | temp_list.append([q[i] + vert[i] for i in range(len(t_list[0]))]) 39 | kite_sum += polygon(temp_list, alpha = .3,rgbcolor = (0,0,1)) 40 | labels = text('+', (-4.3,.5), rgbcolor = (0,0,0)) 41 | labels += text('=', (-.2,.5), rgbcolor = (0,0,0)) 42 | show(labels + t_vert + b_vert+ triangle + kite + triangle_sum + kite_sum + edge_lines, axes=False, figsize = [11.0*.7, 4*.7], xmin = -6, ymin = 0, ymax = 4) 43 | ︡53991a7f-e74c-4157-b4f2-dbd22be97b1b︡{"interact":{"style":"None","flicker":false,"layout":[[["x1tri",12,null]],[["yb",12,null]],[["",12,null]]],"id":"3475095e-8786-44f2-9a00-2a878ada5e3b","controls":[{"control_type":"slider","default":10,"var":"x1tri","width":null,"vals":["-1","-9/10","-4/5","-7/10","-3/5","-1/2","-2/5","-3/10","-1/5","-1/10","0","1/10","1/5","3/10","2/5","1/2","3/5","7/10","4/5","9/10","1"],"animate":true,"label":"Triangle point x coord.","display_value":true},{"control_type":"slider","default":10,"var":"yb","width":null,"vals":["1","11/10","6/5","13/10","7/5","3/2","8/5","17/10","9/5","19/10","2","21/10","11/5","23/10","12/5","5/2","13/5","27/10","14/5","29/10","3","31/10","16/5","33/10","17/5","7/2","18/5","37/10","19/5","39/10","4"],"animate":true,"label":"Blue point y coord.","display_value":true}]}}︡ 44 | ︠0aeb4d64-2f09-4392-a0d9-01b78f691df8︠ 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /sage/interact/Miscellaneous/snippetProfile.sagews: -------------------------------------------------------------------------------- 1 | ︠8620d518-7e80-47e1-877f-20fedab0b795i︠ 2 | html('

Profile the given input

') 3 | import cProfile; import profile 4 | @interact 5 | def _(cmd = ("Statement", '2 + 2'), 6 | do_preparse=("Preparse?", True), cprof =("cProfile?", False)): 7 | if do_preparse: cmd = preparse(cmd) 8 | if cprof: 9 | cProfile.runctx(cmd,globals(), locals()) 10 | else: 11 | profile.runctx(cmd,globals(), locals()) 12 | ︡f616bec1-e8b4-416d-af48-375b8fade9c5︡{"html":"

Profile the given input

"}︡{"interact":{"style":"None","flicker":false,"layout":[[["cmd",12,null]],[["do_preparse",12,null]],[["cprof",12,null]],[["",12,null]]],"id":"0a033359-cbb0-419b-b114-13fb4b144278","controls":[{"control_type":"input-box","default":"2 + 2","label":"Statement","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"cmd","type":""},{"default":true,"var":"do_preparse","readonly":false,"control_type":"checkbox","label":"Preparse?"},{"default":false,"var":"cprof","readonly":false,"control_type":"checkbox","label":"cProfile?"}]}}︡ 13 | ︠d4802a82-220d-41d7-b614-19f0a7455818︠ 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sage/interact/Miscellaneous/unreadable.sagews: -------------------------------------------------------------------------------- 1 | ︠94eb447d-4f60-418c-b215-fe5ecc458ccb︠ 2 | @interact 3 | def _(h=(20,(1,36,1))): 4 | print (lambda f:f(0,f))( 5 | lambda n,f:'%s\n%s'%( 6 | ('*'*(2*n+1)).join([' '*(h-n-1)]*2), 7 | ((n 100: 9 | g = k(2) 10 | else: 11 | g = k.multiplicative_generator() 12 | a = ZZ.random_element(10, maxp) 13 | b = ZZ.random_element(10, maxp) 14 | 15 | html(""" 16 | 32 |

%s-Bit Diffie-Hellman Key Exchange

33 |
    34 |
  1. Alice and Bob agree to use the prime number p = %s and base g = %s.
  2. 35 |
  3. Alice chooses the secret integer a = %s, then sends Bob (ga mod p):
    %s%s mod %s = %s.
  4. 36 |
  5. Bob chooses the secret integer b=%s, then sends Alice (gb mod p):
    %s%s mod %s = %s.
  6. 37 |
  7. Alice computes (gb mod p)a mod p:
    %s%s mod %s = %s.
  8. 38 |
  9. Bob computes (ga mod p)b mod p:
    %s%s mod %s = %s.
  10. 39 |
40 | """ % (bits, p, g, a, g, a, p, (g^a), b, g, b, p, (g^b), (g^b), a, p, 41 | (g^ b)^a, g^a, b, p, (g^a)^b)) 42 | ︡72a5019d-3492-4d1d-b91c-963c72c26ad8︡{"interact":{"style":"None","flicker":false,"layout":[[["bits",12,null]],[["button",12,null]],[["",12,null]]],"id":"49b2c506-9020-4c2c-8abb-c76b5d7a06a9","controls":[{"control_type":"slider","default":0,"var":"bits","width":null,"vals":["8","12","16","20","24","28","32","36","40","44","48","52","56","60","64","68","72","76","80","84","88","92","96","100","104","108","112","116","120","124","128","132","136","140","144","148","152","156","160","164","168","172","176","180","184","188","192","196","200","204","208","212","216","220","224","228","232","236","240","244","248","252","256","260","264","268","272","276","280","284","288","292","296","300","304","308","312","316","320","324","328","332","336","340","344","348","352","356","360","364","368","372","376","380","384","388","392","396","400","404","408","412","416","420","424","428","432","436","440","444","448","452","456","460","464","468","472","476","480","484","488","492","496","500","504","508","512"],"animate":true,"label":"Number of bits","display_value":false},{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Show new example"],"label":"","nrows":null,"width":null,"var":"button"}]}}︡ 43 | ︠12f911b6-895d-493b-b0a0-d8e5dfd8a751︠ 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/IntegerFactorization/divisibilityPoset.sagews: -------------------------------------------------------------------------------- 1 | ︠df08c18f-bea5-45f7-a918-f17af6e38ac0︠ 2 | @interact 3 | def _(n=(5..100)): 4 | Poset(([1..n], lambda x, y: y%x == 0) ).show() 5 | ︡ab6c83b0-08ac-4c82-b0a6-bb71ab1760c2︡{"interact":{"style":"None","flicker":false,"layout":[[["n",12,null]],[["",12,null]]],"id":"14904679-6f13-4775-ad1a-48bae28ba2f9","controls":[{"control_type":"slider","default":0,"var":"n","width":null,"vals":["5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100"],"animate":true,"label":"n","display_value":true}]}}︡ 6 | ︠a3c3ba45-45ac-4138-9f24-886ef1202b71︠ 7 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/IntegerFactorization/factorTrees.sagews: -------------------------------------------------------------------------------- 1 | ︠f440ad67-5c50-428c-85ec-44a459f33d48︠ 2 | import random 3 | def ftree(rows, v, i, F): 4 | if len(v) > 0: # add a row to g at the ith level. 5 | rows.append(v) 6 | w = [] 7 | for i in range(len(v)): 8 | k, _, _ = v[i] 9 | if k is None or is_prime(k): 10 | w.append((None,None,None)) 11 | else: 12 | d = random.choice(divisors(k)[1:-1]) 13 | w.append((d,k,i)) 14 | e = k//d 15 | if e == 1: 16 | w.append((None,None)) 17 | else: 18 | w.append((e,k,i)) 19 | if len(w) > len(v): 20 | ftree(rows, w, i+1, F) 21 | def draw_ftree(rows,font): 22 | g = Graphics() 23 | for i in range(len(rows)): 24 | cur = rows[i] 25 | for j in range(len(cur)): 26 | e, f, k = cur[j] 27 | if not e is None: 28 | if is_prime(e): 29 | c = (1,0,0) 30 | else: 31 | c = (0,0,.4) 32 | g += text(str(e), (j*2-len(cur),-i), fontsize=font, rgbcolor=c) 33 | if not k is None and not f is None: 34 | g += line([(j*2-len(cur),-i), ((k*2)-len(rows[i-1]),-i+1)], 35 | alpha=0.5) 36 | return g 37 | 38 | @interact 39 | def factor_tree(n=100, font=(10, (8..20)), redraw=['Redraw']): 40 | n = Integer(n) 41 | rows = [] 42 | v = [(n,None,0)] 43 | ftree(rows, v, 0, factor(n)) 44 | show(draw_ftree(rows, font), axes=False) 45 | ︡50ead4a3-87f6-4110-9d3d-fc47dc2db929︡{"interact":{"style":"None","flicker":false,"layout":[[["n",12,null]],[["font",12,null]],[["redraw",12,null]],[["",12,null]]],"id":"6aa1f909-3d36-49fa-a71d-34352bb2ae48","controls":[{"control_type":"input-box","default":100,"label":"n","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"n","type":null},{"control_type":"slider","default":2,"var":"font","width":null,"vals":["8","9","10","11","12","13","14","15","16","17","18","19","20"],"animate":true,"label":"font","display_value":true},{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Redraw"],"label":"redraw","nrows":null,"width":null,"var":"redraw"}]}}︡ 46 | ︠94d58344-79e5-4470-a4d9-df4c0a7e1dc7︠ 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/ModularForms/charpodyHecke.sagews: -------------------------------------------------------------------------------- 1 | ︠ec7ac4aa-63fa-4f56-8925-d0d16073dea9︠ 2 | # Note -- in Sage-2.10.3; multiedges are missing in plots; loops are missing in 3d plots 3 | @interact 4 | def f(N = prime_range(11,400), 5 | p = selector(prime_range(2,12),nrows=1), 6 | three_d = ("Three Dimensional", False)): 7 | S = SupersingularModule(N) 8 | T = S.hecke_matrix(p) 9 | G = DiGraph(T, multiedges=not three_d) 10 | if three_d: 11 | G.remove_loops() 12 | html("

Charpoly and Hecke Graph: Level %s, T_%s

"%(N,p)) 13 | show(T.charpoly().factor()) 14 | if three_d: 15 | show(G.plot3d(), aspect_ratio=[1,1,1]) 16 | else: 17 | show(G.plot(),figsize=7) 18 | ︡c8907817-4198-4bea-bdf3-662606ee6af8︡{"interact":{"style":"None","flicker":false,"layout":[[["N",12,null]],[["p",12,null]],[["three_d",12,null]],[["",12,null]]],"id":"3632091c-4e0d-4fed-8f16-95eac8870730","controls":[{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["11","13","17","19","23","29","31","37","41","43","47","53","59","61","67","71","73","79","83","89","97","101","103","107","109","113","127","131","137","139","149","151","157","163","167","173","179","181","191","193","197","199","211","223","227","229","233","239","241","251","257","263","269","271","277","281","283","293","307","311","313","317","331","337","347","349","353","359","367","373","379","383","389","397"],"label":"N","nrows":null,"width":null,"var":"N"},{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["2","3","5","7","11"],"label":"p","nrows":1,"width":null,"var":"p"},{"default":false,"var":"three_d","readonly":false,"control_type":"checkbox","label":"Three Dimensional"}]}}︡ 19 | ︠b8f19e4a-4e0c-4e9b-8c2e-5564169df82f︠ 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/ModularForms/computeCuspidalSubgroup.sagews: -------------------------------------------------------------------------------- 1 | ︠2eaa79c2-899e-42e7-8d69-91d13227f7fa︠ 2 | html('

Cuspidal Subgroups of Modular Jacobians J0(N)

') 3 | @interact 4 | def _(N=selector([1..8*13], ncols=8, width=10, default=10)): 5 | A = J0(N) 6 | print A.cuspidal_subgroup() 7 | ︡e80f1dca-339c-4d56-bd80-52965cff0cca︡{"html":"

Cuspidal Subgroups of Modular Jacobians J0(N)

"}︡{"interact":{"style":"None","flicker":false,"layout":[[["N",12,null]],[["",12,null]]],"id":"a77b85cb-0bf4-4a92-bb1c-becad472fe50","controls":[{"buttons":false,"control_type":"selector","ncols":8,"button_classes":null,"default":9,"lbls":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","101","102","103","104"],"label":"N","nrows":null,"width":10,"var":"N"}]}}︡ 8 | ︠e810ab42-37b8-442d-89d3-b3aab1a08db2︠ 9 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/ModularForms/computeModForm.sagews: -------------------------------------------------------------------------------- 1 | ︠5d43b5f2-4453-4dd0-a1ae-624232547c5a︠ 2 | @interact 3 | def _(N=[1..100], k=selector([2,4,..,12],nrows=1), prec=(3..40), 4 | group=[(Gamma0, 'Gamma0'), (Gamma1, 'Gamma1')]): 5 | M = CuspForms(group(N),k) 6 | print M; print '\n'*3 7 | print "Computing basis...\n\n" 8 | if M.dimension() == 0: 9 | print "Space has dimension 0" 10 | else: 11 | prec = max(prec, M.dimension()+1) 12 | for f in M.basis(): 13 | view(f.q_expansion(prec)) 14 | print "\n\n\nDone computing basis." 15 | ︡3d047c57-920f-4760-b5ed-0652ac8f42f6︡{"interact":{"style":"None","flicker":false,"layout":[[["N",12,null]],[["k",12,null]],[["prec",12,null]],[["group",12,null]],[["",12,null]]],"id":"5f64ac8e-3d95-4149-8156-aa7c0df50d09","controls":[{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100"],"label":"N","nrows":null,"width":null,"var":"N"},{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["2","4","6","8","10","12"],"label":"k","nrows":1,"width":null,"var":"k"},{"control_type":"slider","default":0,"var":"prec","width":null,"vals":["3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40"],"animate":true,"label":"prec","display_value":true},{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["Gamma0","Gamma1"],"label":"group","nrows":null,"width":null,"var":"group"}]}}︡ 16 | ︠04589819-3590-4f8f-9e4b-6acaa17c0fc6︠ 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/ModularForms/ellipticCurveFinite.sagews: -------------------------------------------------------------------------------- 1 | ︠21ee2fcc-35c3-4716-b4a9-c538df98e7fa︠ 2 | E = EllipticCurve('37a') 3 | @interact 4 | def _(p=slider(prime_range(1000), default=389)): 5 | show(E) 6 | print "p = %s"%p 7 | show(E.change_ring(GF(p)).plot(),xmin=0,ymin=0) 8 | ︡3196acc7-7d1e-408b-bc2c-756a9b29498d︡{"interact":{"style":"None","flicker":false,"layout":[[["p",12,null]],[["",12,null]]],"id":"325b834a-6cf2-40a4-858c-8481b3c1486f","controls":[{"control_type":"slider","default":76,"var":"p","width":null,"vals":["2","3","5","7","11","13","17","19","23","29","31","37","41","43","47","53","59","61","67","71","73","79","83","89","97","101","103","107","109","113","127","131","137","139","149","151","157","163","167","173","179","181","191","193","197","199","211","223","227","229","233","239","241","251","257","263","269","271","277","281","283","293","307","311","313","317","331","337","347","349","353","359","367","373","379","383","389","397","401","409","419","421","431","433","439","443","449","457","461","463","467","479","487","491","499","503","509","521","523","541","547","557","563","569","571","577","587","593","599","601","607","613","617","619","631","641","643","647","653","659","661","673","677","683","691","701","709","719","727","733","739","743","751","757","761","769","773","787","797","809","811","821","823","827","829","839","853","857","859","863","877","881","883","887","907","911","919","929","937","941","947","953","967","971","977","983","991","997"],"animate":true,"label":"p","display_value":true}]}}︡ 9 | ︠abc9f590-b9c0-468b-91ec-9a6fc96e2f47︠ 10 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/Other/computeBernoulli.sagews: -------------------------------------------------------------------------------- 1 | ︠81dcbd3d-b8c3-457c-893b-d647a1216c69︠ 2 | @interact 3 | def _(m=selector([1..15],nrows=2), n=(7,(3..10))): 4 | G = DirichletGroup(m) 5 | s = "

First n=%s Bernoulli numbers attached to characters with modulus m=%s

"%(n,m) 6 | s += '' 7 | s += '' + \ 8 | ''.join(''%k for k in [1..n]) + '' 9 | for eps in G.list(): 10 | v = ''.join([''%latex(eps.bernoulli(k)) for k in [1..n]]) 11 | s += '%s\n'%( 12 | eps, eps.conductor(), v) 13 | s += '
$\\chi$Conductor$B_{%s,\chi}$
$%s$
%s%s
' 14 | html(s) 15 | ︡6dc6bb50-7d55-4b81-bc14-06705b4816b7︡{"interact":{"style":"None","flicker":false,"layout":[[["m",12,null]],[["n",12,null]],[["",12,null]]],"id":"581b8e90-face-420f-bc2a-9296057aab19","controls":[{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"],"label":"m","nrows":2,"width":null,"var":"m"},{"control_type":"slider","default":4,"var":"n","width":null,"vals":["3","4","5","6","7","8","9","10"],"animate":true,"label":"n","display_value":true}]}}︡ 16 | ︠f23f67a4-73ca-4d35-87d4-a75a97713ee7︠ 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/Other/fundDomainSL2.sagews: -------------------------------------------------------------------------------- 1 | ︠16765d23-9a12-417b-be50-0467cfed4a8a︠ 2 | L = [[-0.5, 2.0^(x/100.0) - 1 + sqrt(3.0)/2] for x in xrange(1000, -1, -1)] 3 | R = [[0.5, 2.0^(x/100.0) - 1 + sqrt(3.0)/2] for x in xrange(1000)] 4 | xes = [x/1000.0 for x in xrange(-500,501,1)] 5 | M = [[x,abs(sqrt(x^2-1))] for x in xes] 6 | fundamental_domain = L+M+R 7 | fundamental_domain = [[x-1,y] for x,y in fundamental_domain] 8 | @interact 9 | def _(gen = selector(['t+1', 't-1', '-1/t'], buttons=True,nrows=1)): 10 | global fundamental_domain 11 | if gen == 't+1': 12 | fundamental_domain = [[x+1,y] for x,y in fundamental_domain] 13 | elif gen == 't-1': 14 | fundamental_domain = [[x-1,y] for x,y in fundamental_domain] 15 | elif gen == '-1/t': 16 | new_dom = [] 17 | for x,y in fundamental_domain: 18 | sq_mod = x^2 + y^2 19 | new_dom.append([(-1)*x/sq_mod, y/sq_mod]) 20 | fundamental_domain = new_dom 21 | P = polygon(fundamental_domain) 22 | P.ymax(1.2); P.ymin(-0.1) 23 | P.show() 24 | ︡64fe0b5c-3512-4794-9c62-fd4254c10889︡{"interact":{"style":"None","flicker":false,"layout":[[["gen",12,null]],[["",12,null]]],"id":"f0415528-4c3a-4ef8-924e-9537b4f8c807","controls":[{"buttons":true,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["t+1","t-1","-1/t"],"label":"gen","nrows":1,"width":null,"var":"gen"}]}}︡ 25 | ︠a946eb46-43ad-47b7-97cf-104508d8432b︠ 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /sage/interact/NumberTheory/Other/plotContinueFrac.sagews: -------------------------------------------------------------------------------- 1 | ︠3087dcc6-c101-4cf8-9fdd-13fa12096411︠ 2 | @interact 3 | def _(number=e, ymax=selector([5,20,..,400],nrows=2), clr=Color('purple'), prec=[500,1000,..,5000]): 4 | c = list(continued_fraction(RealField(prec)(number))); print c 5 | show(line([(i,z) for i, z in enumerate(c)],rgbcolor=clr),ymax=ymax,figsize=[10,2]) 6 | ︡6cbd17de-777e-4d49-8462-664f7eafc334︡{"interact":{"style":"None","flicker":false,"layout":[[["number",12,null]],[["ymax",12,null]],[["clr",12,null]],[["prec",12,null]],[["",12,null]]],"id":"6a7882dd-c0e2-45fd-a6c5-4ec780dc1062","controls":[{"control_type":"input-box","default":"e","label":"number","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"number","type":null},{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["5","20","35","50","65","80","95","110","125","140","155","170","185","200","215","230","245","260","275","290","305","320","335","350","365","380","395"],"label":"ymax","nrows":2,"width":null,"var":"ymax"},{"widget":null,"control_type":"color-selector","hide_box":false,"Color":"","label":"clr","default":"#800080","readonly":false,"var":"clr"},{"buttons":false,"control_type":"selector","ncols":null,"button_classes":null,"default":0,"lbls":["500","1000","1500","2000","2500","3000","3500","4000","4500","5000"],"label":"prec","nrows":null,"width":null,"var":"prec"}]}}︡ 7 | ︠f229692b-283e-4c3e-a345-d302e2e72dc1︠ 8 | -------------------------------------------------------------------------------- /sage/interact/Statistics/dishonestCasino.sagews: -------------------------------------------------------------------------------- 1 | ︠0cefdbd8-ee2b-4380-83ca-bc75de8afb2b︠ 2 | m = hmm.DiscreteHiddenMarkovModel([[0.8,0.2],[0.1,0.9]], [[1/10,1/10,1/10,1/10,1/10,1/2],[1/6,1/6,1/6,1/6,1/6,1/6]], [.2,.8],emission_symbols=[1,2,3,4,5,6]) 3 | @interact 4 | def dishonest_casino(auto_update=False): 5 | test = list(m.generate_sequence(80)) 6 | vit_test = list(m.viterbi(test[0])[0]) 7 | html('

The Occasionally Dishonest Casino

') 8 | html('Emissions:'+str(test[0]).replace(',','').replace(' ','')[1:-1]) 9 | vit_str = str(vit_test).replace(',','').replace(' ','') 10 | vit_str = vit_str.replace('1','F').replace('0','L')[1:-1] 11 | html('Viterbi: '+vit_str) 12 | actual_str = str(list(test[1])).replace(',','').replace(' ','') 13 | actual_str = actual_str.replace('1','F').replace('0','L')[1:-1] 14 | html('Actual: '+ actual_str) 15 | ︡f505104f-9518-4b23-bae5-5142ae00fde9︡{"interact":{"style":"None","flicker":false,"layout":[[["auto_update",12,null]],[["",12,null]]],"id":"b02c368e-3df3-4567-9c00-041cfce3bf89","controls":[{"default":false,"var":"auto_update","readonly":false,"control_type":"checkbox","label":"auto_update"}]}}︡ 16 | ︠e7d203ba-55e4-482a-bc1d-3a4c9e2984d3︠ 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sage/interact/Topology/winding.sagews: -------------------------------------------------------------------------------- 1 | ︠cebf4704-1ec3-4eb9-b235-f61d6cf80684︠ 2 | var('t') 3 | 4 | def winding_number_integral(x, y, a, b): 5 | r2 = x^2 + y^2 6 | xp = x.derivative(t) 7 | yp = y.derivative(t) 8 | integrando = (x*yp -y*xp)/r2 9 | i,e = numerical_integral(integrando, a, b) 10 | return round(i/(2*pi)) 11 | 12 | N = 20 13 | epsilon = 1e-7 14 | def all_the_zeros(f, a, b): 15 | '''all_the_zeros de f(t), asuming f is periodic''' 16 | delta= (b-a)/N 17 | zeros = [] 18 | for t in srange(a, b ,delta): 19 | try: 20 | zeros.append(find_root(f, t-epsilon, t+delta+epsilon)) 21 | except: 22 | pass 23 | zeros.sort() 24 | if not zeros: return zeros 25 | if abs(zeros[0] + 2*pi - zeros[-1])epsilon: 30 | zeros_cleaned.append(c) 31 | if abs(zeros[0] + 2*pi - zeros[-1]) epsilon: 40 | raise ValueError, "Curve is not closed!" 41 | 42 | xp = x.derivative(t) 43 | yp = y.derivative(t) 44 | xp1 = xp/(xp^2 + yp^2) 45 | yp1 = yp/(xp^2 + yp^2) 46 | 47 | html(r'$\int \frac{1}{x^2 + y^2}(xdy-ydx)=%d$'%winding_number_integral(x,y,a,b)) 48 | 49 | zeros = all_the_zeros(x,a, b) 50 | wn = 0 51 | left2right = [] 52 | right2left = [] 53 | for t0 in zeros: 54 | if y(t0)>0: 55 | if xp(t0) > 0: 56 | left2right.append((x(t0), y(t0))) 57 | wn -= 1 58 | else: 59 | right2left.append((x(t0), y(t0))) 60 | wn += 1 61 | 62 | print 'Winding number = (# of red points) - (# of green points): ', wn 63 | 64 | p = (parametric_plot((x,y),(t,0,1)) + 65 | arrow((x(0),y(0)), (x(0) + xp1(0), y(0) + yp1(0))) + 66 | point2d([(0,0)], color = 'black', pointsize = 70)) 67 | if left2right: 68 | p += point2d(left2right , color = 'green', pointsize = 50) 69 | if right2left: 70 | p += point2d(right2left , color = 'red', pointsize = 50) 71 | p.show(aspect_ratio=1) 72 | ︡6c4c476d-20ee-4aae-a71f-212f000a2520︡{"stdout":"t\n"}︡{"interact":{"style":"None","flicker":false,"layout":[[["x",12,null]],[["y",12,null]],[["a",12,null]],[["b",12,null]],[["",12,null]]],"id":"40ac074b-c53e-40df-9651-9ae50d3fda10","controls":[{"control_type":"input-box","default":"cos(4*pi*t)","label":"x","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"x","type":null},{"control_type":"input-box","default":"sin(4*pi*t) + sin(2*pi*t) + 1","label":"y","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"y","type":null},{"control_type":"input-box","default":0,"label":"a","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"a","type":null},{"control_type":"input-box","default":1,"label":"b","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"b","type":null}]}}︡ 73 | ︠68d9303e-2268-415f-ab57-ef1ccfda346c︠ 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /sage/interact/WebApp/pieChart.sagews: -------------------------------------------------------------------------------- 1 | ︠bc620323-5702-4803-ba2f-92b59e8d88f3︠ 2 | # Google Chart API: http://code.google.com/apis/chart 3 | import urllib2 as inet 4 | from pylab import imshow 5 | @interact 6 | def gChart(title="Google Chart API plots Pie Charts!", color1=Color('purple'), color2=Color('black'), color3=Color('yellow'), val1=slider(0,1,.05,.5), val2=slider(0,1,.05,.3), val3=slider(0,1,.05,0.1), label=("Maths Physics Chemistry")): 7 | url = "http://chart.apis.google.com/chart?cht=p3&chs=600x300" 8 | url += '&chtt=%s&chts=000000,25'%title.replace(" ","+") 9 | url += '&chco=%s'%(','.join([color1.html_color()[1:],color2.html_color()[1:],color3.html_color()[1:]])) 10 | url += '&chl=%s'%label.replace(" ","|") 11 | url += '&chd=t:%s'%(','.join(map(str,[val1,val2,val3]))) 12 | print url 13 | html('
'%url) 14 | ︡51a55c78-21bb-4101-aa4b-10384e391ec2︡{"interact":{"style":"None","flicker":false,"layout":[[["title",12,null]],[["color1",12,null]],[["color2",12,null]],[["color3",12,null]],[["val1",12,null]],[["val2",12,null]],[["val3",12,null]],[["label",12,null]],[["",12,null]]],"id":"231d3a91-6389-4dda-8252-9c56d21e9d98","controls":[{"control_type":"input-box","default":"Google Chart API plots Pie Charts!","label":"title","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"title","type":""},{"widget":null,"control_type":"color-selector","hide_box":false,"Color":"","label":"color1","default":"#800080","readonly":false,"var":"color1"},{"widget":null,"control_type":"color-selector","hide_box":false,"Color":"","label":"color2","default":"#000000","readonly":false,"var":"color2"},{"widget":null,"control_type":"color-selector","hide_box":false,"Color":"","label":"color3","default":"#ffff00","readonly":false,"var":"color3"},{"control_type":"slider","default":10,"var":"val1","width":null,"vals":["0.000000000000000","0.0500000000000000","0.100000000000000","0.150000000000000","0.200000000000000","0.250000000000000","0.300000000000000","0.350000000000000","0.400000000000000","0.450000000000000","0.500000000000000","0.550000000000000","0.600000000000000","0.650000000000000","0.700000000000000","0.750000000000000","0.800000000000000","0.850000000000000","0.900000000000000","0.950000000000000","1.00000000000000"],"animate":true,"label":"val1","display_value":true},{"control_type":"slider","default":6,"var":"val2","width":null,"vals":["0.000000000000000","0.0500000000000000","0.100000000000000","0.150000000000000","0.200000000000000","0.250000000000000","0.300000000000000","0.350000000000000","0.400000000000000","0.450000000000000","0.500000000000000","0.550000000000000","0.600000000000000","0.650000000000000","0.700000000000000","0.750000000000000","0.800000000000000","0.850000000000000","0.900000000000000","0.950000000000000","1.00000000000000"],"animate":true,"label":"val2","display_value":true},{"control_type":"slider","default":2,"var":"val3","width":null,"vals":["0.000000000000000","0.0500000000000000","0.100000000000000","0.150000000000000","0.200000000000000","0.250000000000000","0.300000000000000","0.350000000000000","0.400000000000000","0.450000000000000","0.500000000000000","0.550000000000000","0.600000000000000","0.650000000000000","0.700000000000000","0.750000000000000","0.800000000000000","0.850000000000000","0.900000000000000","0.950000000000000","1.00000000000000"],"animate":true,"label":"val3","display_value":true},{"control_type":"input-box","default":"Maths Physics Chemistry","label":"label","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"label","type":""}]}}︡ 15 | ︠66964a3a-2742-4f29-bc87-c94a96ee23aa︠ 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sage/interactive.sagews: -------------------------------------------------------------------------------- 1 | ︠40498f9a-5871-45ee-a35e-f6eb5d480f38i︠ 2 | %md 3 | Interactive Elements 4 | ︡7dac6e10-5a26-47eb-89e1-6e3b4e52053b︡{"html":"

Interactive Elements

\n"}︡ 5 | ︠23f68532-7cac-4716-b716-773db178c3f3︠ 6 | u, x = var('u x') 7 | @interact 8 | def diff_interact(n = slider(range(1,10), default = 3)): 9 | ex = sin(2*x^2) * x 10 | show(latex(ex)) 11 | show(latex(ex.diff(n))) 12 | 13 | ︡92019d97-e523-41af-b43d-8d18f762ec92︡{"interact":{"style":"None","flicker":false,"layout":[[["n",12,null]],[["",12,null]]],"id":"6925e8eb-5cda-4818-a127-04765bc4ca89","controls":[{"control_type":"slider","default":2,"var":"n","width":null,"vals":["1","2","3","4","5","6","7","8","9"],"animate":true,"label":"n","display_value":true}]}}︡ 14 | ︠fa68aa2d-b93f-4131-aa57-a6241d2b1756︠ 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sage/pi.sagews: -------------------------------------------------------------------------------- 1 | ︠b5eb3b78-dd91-4d03-9235-b33cf1924ec3i︠ 2 | %md 3 | # Different Approximations of $\pi$ 4 | ︡ae47d4fa-f622-49d3-b9e7-ca96dde9c507︡{"html":"

Different Approximations of $\\pi$

\n"}︡ 5 | ︠35c9d02b-f26e-4754-b67f-fd822ada39e8︠ 6 | # Sage's value 7 | n(pi, digits = 100) 8 | ︡4ceae033-5559-40a8-aba3-fda5aab4f380︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡ 9 | ︠7b5595c9-bbe6-4423-9604-a8b622a8a83f︠ 10 | # using mpmath - http://code.google.com/p/mpmath/ 11 | import mpmath as mm 12 | mm.mp.dps = 100 13 | print mm.pi 14 | print 2*mm.asinh(1j).imag 15 | print mm.gamma(0.5)**2 16 | print mm.sqrt(6*mm.zeta(2)) 17 | print mm.quad(lambda x: 4*mm.sqrt(1-x**2), [0, 1]) 18 | print mm.quad(lambda x: mm.exp(-x**2), [-mm.inf, mm.inf]) ** 2 19 | print mm.nsum(lambda n: 4*(-1)**n/(2*n+1), [0, mm.inf]) 20 | print mm.limit(lambda n: 2**(4*n+1)*mm.factorial(n)**4/(2*n+1)/mm.factorial(2*n)**2, mm.inf) 21 | print mm.findroot(mm.sin, 3.14) 22 | ︡fa85768a-4c20-4cf1-b1a5-1cfc650e07c5︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068"}︡{"stdout":"\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡{"stdout":"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\n"}︡ 23 | ︠f113fb20-74bd-4bb2-aec9-cf822176829e︠ 24 | # dropping points 25 | import numpy as np 26 | N = 10000 27 | x, y = 2 * np.random.rand(2, N) - 1 28 | inside = np.sum(np.sqrt(x^2 + y^2) <= 1) 29 | list_plot(zip(x, y), color='gray', size = 1) + circle((0,0), 1, color= 'green') 30 | print("pi ~ %f" % (float(inside) / N * 4)) 31 | ︡a921f5f9-7e8e-44f4-a277-02ba73723448︡{"once":false,"file":{"show":true,"uuid":"a4da6194-7318-4322-9b89-523a91bf6be3","filename":"/mnt/home/2Qrdjpk5/.sage/temp/compute3a/10749/tmp_CSF_fq.png"}}︡{"stdout":"pi ~ 3.135200\n"}︡ 32 | ︠a4a7ccad-d22b-4ddf-9f44-496f3cc6e4b6︠ 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /sage/xkcd.sagews: -------------------------------------------------------------------------------- 1 | ︠8ec79a7a-f821-4cbd-adec-d6c01f8f5008a︠ 2 | %auto 3 | 4 | # AUTHOR: Maarten Derickx 5 | import urllib2 6 | import json 7 | @interact 8 | def xkcd(n=""): 9 | file = None 10 | data = None 11 | url = "http://dynamic.xkcd.com/api-0/jsonp/comic/%s"%n 12 | try: 13 | file = urllib2.urlopen(url) 14 | data=file.read() 15 | except urllib2.HTTPError: 16 | pass 17 | finally: 18 | if file: 19 | file.close() 20 | if data: 21 | data=json.loads(data) 22 | img=data['img'] 23 | alt=data['alt'] 24 | title=data['safe_title'] 25 | link="http://xkcd.com/%s"%n 26 | html('

%s

Source: %s
'%(title,img,alt,link,link)) 27 | return 28 | raise RuntimeError,"Could not obtain comic data from %s . Maybe you should enable time travel!"%url 29 | ︡9f7171bb-1a96-48f4-a042-d694d494674f︡{"auto":true}︡{"interact":{"style":"None","flicker":false,"layout":[[["n",12,null]],[["",12,null]]],"id":"d865106f-f5b8-4776-951b-de465305a950","controls":[{"control_type":"input-box","default":"","label":"n","nrows":1,"width":null,"readonly":false,"submit_button":null,"var":"n","type":""}]}}︡ 30 | ︠d034ea97-4f45-4bc1-8bd8-bee75d11730b︠ 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /sage/yoda.sagews: -------------------------------------------------------------------------------- 1 | ︠208397ea-d7fa-48ba-bc04-aca5b39fd194i︠ 2 | %md 3 | # Render Yoda in interactive 3d using THREE.js 4 | 5 | **Warning:** If your browser uses canvas instead of webgl, this will be painfully slow. With webgl, it is very fast 6 | after the model loads. 7 | ︡bd1e2a80-c63a-4521-beea-adc2fb6dc73a︡{"html":"

Render Yoda in interactive 3d using THREE.js

\n\n

Warning: If your browser uses canvas instead of webgl, this will be painfully slow. With webgl, it is very fast\nafter the model loads.

\n"}︡ 8 | ︠73e5841f-fa48-4ae3-aa41-310668ffb884a︠ 9 | %auto 10 | # Yoda! -- over 53,756 triangles. 11 | from scipy import io 12 | x = io.loadmat('yodapose.mat') 13 | from sage.plot.plot3d.index_face_set import IndexFaceSet 14 | V = x['V']; F3=x['F3']-1; F4=x['F4']-1 15 | Y = IndexFaceSet(F3,V,color='green') + IndexFaceSet(F4,V,color='green') 16 | Y = Y.rotateZ(-1); Y = Y.rotateX(-1) 17 | show(Y, frame=False) 18 | ︡fd3e1f76-4517-4d87-94cf-0fb6c95ddfa7︡{"auto":true}︡{"html":"
"}︡{"obj":"{\"foreground\": null, \"camera_distance\": 28.513779200054678, \"height\": null, \"width\": null, \"renderer\": null, \"background\": null}","javascript":{"coffeescript":false,"code":"$('#848dc08b-bb7b-4b77-a904-96c457ecdf67').salvus_threejs(obj)"},"once":false}︡ 19 | ︠5aaaee4f-595a-4775-99a3-d4dce36d5ae8︠ 20 | # 53756 vertices! 21 | len(x['V']) 22 | ︡8a1b1984-df55-4347-b733-598c69faf463︡{"stdout":"53756\n"}︡ 23 | ︠d6248cd2-8768-450d-a311-041d22fa372e︠ 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /sage/yodapose.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/sage/yodapose.mat -------------------------------------------------------------------------------- /sagews-jupyter/r-completion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/sagews-jupyter/r-completion.png -------------------------------------------------------------------------------- /sagews-jupyter/sage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/sagews-jupyter/sage.png -------------------------------------------------------------------------------- /sagews-jupyter/simpleLoop.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/sagews-jupyter/simpleLoop.wav -------------------------------------------------------------------------------- /sympy/sympy-code.sagews: -------------------------------------------------------------------------------- 1 | ︠191922d8-6385-4a48-a8a0-df9f7dcd9386i︠ 2 | %md 3 | Sympy Code Generating Test 4 | -------------------------- 5 | 6 | * [Codegen](http://docs.sympy.org/dev/modules/utilities/codegen.html) 7 | * [Autowrap](http://docs.sympy.org/dev/modules/utilities/autowrap.html) 8 | ︡12577e2c-c3d2-40a4-8c4c-e3d43188e02b︡{"html":"

Sympy Code Generating Test

\n\n\n"}︡ 9 | ︠a4d795ec-6f92-453a-89b5-1b1fa8c959eda︠ 10 | %auto 11 | from sympy.utilities.codegen import codegen 12 | from sympy.utilities.autowrap import autowrap, binary_function 13 | from sympy import symbols, oo, pprint, IndexedBase, Idx, Eq 14 | ︡178fb8d4-bf9f-4799-baf8-079bca6a9b71︡{"auto":true}︡ 15 | ︠99a0e7c3-0401-4f2b-8cfb-bce796fb4993︠ 16 | x, y, z = symbols('x y z') 17 | expr = ((1-x+y-z**2)**7).expand() 18 | #binary_callable = autowrap(expr) 19 | #binary_callable(2,3,1) 20 | 21 | f = binary_function('f', expr) 22 | f(x,y).evalf(2, subs = {x:1.1, y : -2.2}) 23 | 24 | ︡0e7ecd1d-43de-4b2b-ae39-f33d1020840c︡{"stderr":"Error in lines 5-5\n"}︡{"stderr":"Traceback (most recent call last):\n File \"/mnt/home/2Qrdjpk5/.sagemathcloud/sage_server.py\", line 494, in execute\n exec compile(block+'\\n', '', 'single') in namespace, locals\n File \"\", line 1, in \n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 406, in binary_function\n binary = autowrap(expr, **kwargs)\n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 386, in autowrap\n return code_wrapper.wrap_code(routine, helpers=helps)\n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 129, in wrap_code\n self._process_files(routine)\n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 153, in _process_files\n \"Error while executing command: %s\" % \" \".join(command))\nCodeWrapError: Error while executing command: f2py -m wrapper_module_4 -c wrapped_code_4.f90\n"}︡ 25 | ︠6d2c19be-d11e-4e60-813d-43f6124ba060︠ 26 | A, x, y = map(IndexedBase, ['A', 'x', 'y']) 27 | m, n = symbols('m n', integer=True) 28 | i = Idx('i', m) 29 | j = Idx('j', n) 30 | expr = Eq(y[i], A[i, j]*x[j]) 31 | pprint(expr, use_unicode=True) 32 | ︡f252813e-882c-4130-ab17-d0950fbe85e9︡{"stdout":"y[i] = A[i, j]⋅x[j]\n"}︡ 33 | ︠f983eade-3615-4907-8e71-d63fdb2b5c4e︠ 34 | matvec = autowrap(expr) 35 | matvec 36 | ︡2d593c6a-b156-448d-8bd3-3c60862a1c53︡{"stderr":"Error in lines 1-1\n"}︡{"stderr":"Traceback (most recent call last):\n File \"/mnt/home/2Qrdjpk5/.sagemathcloud/sage_server.py\", line 494, in execute\n exec compile(block+'\\n', '', 'single') in namespace, locals\n File \"\", line 1, in \n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 386, in autowrap\n return code_wrapper.wrap_code(routine, helpers=helps)\n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 129, in wrap_code\n self._process_files(routine)\n File \"/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sympy/utilities/autowrap.py\", line 153, in _process_files\n \"Error while executing command: %s\" % \" \".join(command))\nCodeWrapError: Error while executing command: f2py -m wrapper_module_1 -c wrapped_code_1.f90\n"}︡ 37 | ︠8a22b49e-ec69-4106-ad08-7a8ca0073332︠ 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sympy/sympy-intro.sagews: -------------------------------------------------------------------------------- 1 | ︠d8ea3ebc-3789-4e21-8858-fe82d61caec5i︠ 2 | %md 3 | Sympy 4 | ----- 5 | 6 | Cells are evaluated in Sage, hence there are a few differences. 7 | 8 | * Raw Python integer numbers are entered by appending an `r`, like `42r`. 9 | * The `^` symbol automatically expands to `**`. 10 | ︡9e71c464-5bd9-4a9f-844b-51c6dc1334b6︡{"html":"

Sympy

\n\n

Cells are evaluated in Sage, hence there are a few differences.

\n\n
    \n
  • Raw Python integer numbers are entered by appending an r, like 42r.
  • \n
  • The ^ symbol automatically expands to **.
  • \n
\n"}︡ 11 | ︠12e9d2b0-4c5f-49d3-b625-0d320e397c8aa︠ 12 | %auto 13 | from __future__ import division 14 | import sympy as sy 15 | from sympy import symbols, log, pi, oo, pprint, Function, limit 16 | x, y, z, t = symbols('x y z t') 17 | k, m, n = symbols('k m n', integer=True) 18 | f, g, h = symbols('f g h', cls=Function) 19 | ︡f42726ae-e04c-4745-9ddd-0961ac9235ca︡{"auto":true}︡ 20 | ︠d461d4ef-c468-412c-a8bf-d268f0196b5b︠ 21 | ex = x * log(2*x) / log(x) 22 | simplify(ex) 23 | ︡4df71821-c1e0-4987-9c9f-2289fccf74d9︡{"stdout":"x + x*log(2)/log(x)\n"}︡ 24 | ︠66826ac7-fc7f-41b4-ac1d-f4449118976b︠ 25 | ex.subs({x : 2*pi}) 26 | ︡20b26977-6a28-40dd-a9f4-b57754660ed6︡{"stdout":"2*pi*log(4*pi)/log(2*pi)\n"}︡ 27 | ︠d79457ad-9526-4a47-866e-20722748580d︠ 28 | limit((x-3*x^2)/(1-x-2 * x^2), x, oo) 29 | ︡8b833874-ae75-46e1-92f2-2e265b4f6106︡{"stdout":"3/2"}︡{"stdout":"\n"}︡ 30 | ︠aabd2cc1-95bd-4f04-ac8b-d8ab507e058d︠ 31 | expr = (x^2 - 1)/(x - 1) 32 | print expr 33 | print expr.cancel() 34 | ︡32fa59d3-2789-4a50-b688-06b7e60bd143︡{"stdout":"(x**2 - 1)/(x - 1)\n"}︡{"stdout":"x + 1\n"}︡ 35 | ︠81817e50-2c7e-4799-a5b8-3d799512cea5︠ 36 | expr2 = log(expr).integrate(x) 37 | pprint(expr2, use_unicode=True) 38 | ︡2c44f3b9-a655-4d06-b169-9187cf09cbcd︡{"stdout":" ⎛ 2 ⎞ ⎛ 2 ⎞\n ⎜ x 1 ⎟ ⎜ x 1 ⎟\nx⋅log⎜───── - ─────⎟ - x + log⎜───── - ─────⎟\n ⎝x - 1 x - 1⎠ ⎝x - 1 x - 1⎠\n"}︡ 39 | ︠6135d32b-2f30-4ecf-9a3f-3da6412ce91c︠ 40 | @interact 41 | def diffit(i = slider(range(7), default = 3)): 42 | expr = sin(i * x) ^ (i * x) 43 | pprint(expr, use_unicode=True) 44 | print 45 | dexpr = expr.diff(x, i) 46 | pprint(dexpr, use_unicode=True) 47 | ︡b44ecf3e-25cd-4f43-b806-045e8c913ca3︡{"interact":{"style":"None","flicker":false,"layout":[[["i",12,null]],[["",12,null]]],"id":"8a863777-3a15-4b6b-a647-41761296b572","controls":[{"control_type":"slider","default":3,"var":"i","width":null,"vals":["0","1","2","3","4","5","6"],"animate":true,"label":"i","display_value":true}]}}︡ 48 | ︠9caffed7-1ba8-4523-94ec-560ac3e363b0︠ 49 | ︡e489dbef-5cfa-442e-9a86-03e809cb8b77︡ 50 | ︠63e98b73-4ab4-4df3-bb7d-1ac8e0960a57︠ 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /thumbs/latex-beamer-in-cocalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/latex-beamer-in-cocalc.png -------------------------------------------------------------------------------- /thumbs/latex-multiple-documents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/latex-multiple-documents.png -------------------------------------------------------------------------------- /thumbs/markdown-in-cocalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/markdown-in-cocalc.png -------------------------------------------------------------------------------- /thumbs/pythontex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/pythontex.png -------------------------------------------------------------------------------- /thumbs/r-in-cocalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/r-in-cocalc.png -------------------------------------------------------------------------------- /thumbs/rmd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/rmd.png -------------------------------------------------------------------------------- /thumbs/sage-in-cocalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/sage-in-cocalc.png -------------------------------------------------------------------------------- /thumbs/sagetex-in-cocalc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagemathinc/cocalc-example-files/ae6843467aeaadef9b1098816adf546a86b51c28/thumbs/sagetex-in-cocalc.png -------------------------------------------------------------------------------- /web-app-worksheet/app.css: -------------------------------------------------------------------------------- 1 | .app-output { 2 | color:#555; 3 | padding: 2em; 4 | border:1px solid orange; 5 | border-radius:25px; 6 | box-shadow: 10px 10px 5px #888888; 7 | } -------------------------------------------------------------------------------- /web-app-worksheet/app.html: -------------------------------------------------------------------------------- 1 | 2 | Generate Random Number 3 | 4 | 5 | 6 |
7 | Output is appended here:
8 |
9 | 10 | -------------------------------------------------------------------------------- /web-app-worksheet/app.js: -------------------------------------------------------------------------------- 1 | $(".app-button").click(function(e) { 2 | 3 | var n = parseFloat($(".app-input").val()); 4 | 5 | worksheet.execute_code({ 6 | code: "salvus.data['n'] * random()", 7 | data: {n:n}, 8 | preparse: false, 9 | cb : function(mesg) { 10 | console.log(mesg); 11 | if (mesg.stdout) { 12 | $(".app-output").append(mesg.stdout); 13 | } 14 | } 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /web-app-worksheet/app.sagews: -------------------------------------------------------------------------------- 1 | ︠73d9cd7e-11d8-4f5f-8072-2517fce80b1di︠ 2 | %md 3 | ## Example of a standard Javascript/HTML/CSS application in a worksheet. 4 | 5 | - Edit the files app.html, app.css and app.js, then evaluate the cell below. 6 | 7 | 8 | ︡09c1e655-83cf-4482-8554-2f5629c87ac9︡{"html":"

Example of a standard Javascript/HTML/CSS application in a worksheet.

\n\n
    \n
  • Edit the files app.html, app.css and app.js, then evaluate the cell below.
  • \n
\n"}︡ 9 | ︠208a9eb0-e3d1-471a-a9de-357e0f005e45︠ 10 | %load app.html app.css 11 | sleep(0.1); salvus.javascript(open('app.js').read()) # I'll later make it so you can do '%load app.js'... 12 | 13 | ︡f85a3db0-1b42-4836-a598-b145bf889f8d︡{"once":false,"file":{"show":false,"uuid":"ea60a5a9-248a-49dc-a6f5-e1ca54581d9b","filename":"app.html"}}︡{"obj":"{}","javascript":{"coffeescript":false,"code":"opts.element.append($(\"
\").load(\"/blobs/app.html?uuid=ea60a5a9-248a-49dc-a6f5-e1ca54581d9b\"))"},"once":false}︡{"once":false,"file":{"show":false,"uuid":"6eb51297-400c-45d5-9ef3-a5c356f7e731","filename":"app.css"}}︡{"obj":"{}","javascript":{"coffeescript":false,"code":"$.get(\"/blobs/app.css?uuid=6eb51297-400c-45d5-9ef3-a5c356f7e731\", function(css) { $('').html(css).appendTo(\"body\")});"},"once":false}︡{"obj":"{}","javascript":{"coffeescript":false,"code":"$(\".app-button\").click(function(e) {\n\n n = parseFloat($(\".app-input\").val());\n\n worksheet.execute_code({\n code: \"salvus.data['n'] * random()\",\n data: {n:n},\n preparse: false,\n cb : function(mesg) {\n console.log(mesg);\n if (mesg.stdout) {\n $(\".app-output\").append(mesg.stdout);\n }\n }\n })\n})"},"once":false}︡ 14 | ︠cd8cb026-c432-4ce1-ae37-86be83a57851︠ 15 | 16 | 17 | ︡b930b5c4-4684-46d7-9e70-2a6dbe671523︡{"obj":"{}","javascript":{"coffeescript":false,"code":"$(\".app-button\").click(function(e) {\n\n worksheet.execute_code({\n code: \"salvus.data['n'] * random()\",\n data: {n:5},\n preparse: false,\n cb : function(mesg) {\n console.log(mesg);\n if (mesg.stdout) {\n $(\".app-output\").append(mesg.stdout);\n }\n }\n })\n})"},"once":false}︡ 18 | ︠9290a7fc-3e57-4523-b594-a71b2b22745f︠ 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /webservice/Readme.md: -------------------------------------------------------------------------------- 1 | Webservice 2 | ---------- 3 | 4 | This is a small demo how a web-service can be started inside SMC. 5 | See `main.py` for more details. 6 | 7 | Start it in the terminal via: 8 | 9 | `$ sage -python main.py` 10 | 11 | -------------------------------------------------------------------------------- /webservice/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # This runs a demo-webservice inside SMC. 4 | # Run by typing 5 | # sage -python main.py 6 | 7 | import json 8 | import os 9 | 10 | from flask import Flask, request 11 | app = Flask(__name__) 12 | #app.debug = True # Uncomment this if you wish to debug 13 | 14 | port = 8765 15 | info_path = os.path.join(os.environ['HOME'], ".smc", "info.json") 16 | info = json.load(open(info_path, 'r')) 17 | base_url = "/%s/port/%s" % (info['project_id'], port) 18 | 19 | html_template = """ 20 | 23 | 24 | 25 | 26 | %(title)s 27 | 28 | 29 | 30 | 31 |

%(content)s

32 | 33 | 34 | 35 | """ 36 | 37 | 38 | @app.route(base_url + '/', strict_slashes=False) 39 | def info(): 40 | content = """

SMC Webservice running

41 |

Routes:

42 | 43 | """ % { 48 | 'route': base_url 49 | } 50 | return html_template % {'title': 'Info', 'content': content} 51 | 52 | 53 | @app.route(base_url + '/get', methods=['GET']) 54 | def get_something(): 55 | content = """

Try something like %(base_url)s/get?something=foo

""" % { 56 | 'base_url': base_url 57 | } 58 | if request.method == 'GET': 59 | something = request.args.get("something", "") 60 | if len(something) > 0: 61 | content = "Got " + something 62 | return html_template % {'title': 'Info', 'content': content} 63 | 64 | 65 | @app.route(base_url + '/header', methods=['GET']) 66 | def get_header(): 67 | 68 | header = '' 69 | 70 | for k, v in request.headers.iteritems(): 71 | header += '{} = {}\n'.format(k, v) 72 | 73 | content = ''' 74 |
The header information I got about you ...
75 |
76 |     {header}
77 |     
78 | '''.format(header=header) 79 | 80 | return content 81 | 82 | 83 | if __name__ == "__main__": 84 | try: 85 | info = json.load( 86 | open(os.path.join(os.environ['HOME'], ".smc", "info.json"), 'r')) 87 | print("Try to open https://cocalc.com" + base_url + '/') 88 | app.run(host='0.0.0.0', port=port) 89 | import sys 90 | sys.exit(0) 91 | except Exception as e: 92 | print "... failed, try another port (change the port= line in the script) \n%s" % e 93 | -------------------------------------------------------------------------------- /webservice/run.term: -------------------------------------------------------------------------------- 1 | 41e9336f-ca0e-457a-a0cc-9b4e8841c6be --------------------------------------------------------------------------------