├── .github
├── Dockerfile
├── icons
│ ├── blue.ico
│ └── orange.ico
└── workflows
│ ├── create-wsl-image.yml
│ ├── update-dockerfile-dev.yml
│ └── update-dockerfile-master.yml
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.rst
└── notebooks
└── Start here.ipynb
/.github/Dockerfile:
--------------------------------------------------------------------------------
1 | # Multi-stage Dockerfile for slim Sage
2 | # https://docs.docker.com/build/building/multi-stage
3 |
4 | FROM ghcr.io/sagemath/sage/sage-ubuntu-jammy-minimal-with-targets:10.6 AS target
5 |
6 | # Resolve symbolic links to recreate them later
7 | RUN readlink /sage/prefix >> /sage/prefix_link
8 | RUN readlink /sage/venv >> /sage/venv_link
9 |
10 | WORKDIR /sage
11 |
12 | # Strip executables in /sage
13 | RUN LC_ALL=C find local src pkgs -type f -exec strip '{}' ';' 2>&1 | grep -v "file format not recognized" || true
14 |
15 | # Clean up before copying in the next stage
16 | RUN rm -rf local/share/doc local/share/*/doc local/share/*/examples local/share/singular/html
17 |
18 | # Remove all __pycache__ directories
19 | RUN find /sage -type d -name "__pycache__" -exec rm -rf {} +
20 | # Remove all .c .cpp files corresponding to .pyx files
21 | RUN find /sage -name "*.pyx" | sed 's/\(.*\)[.]pyx$/\1.c \1.cpp/' | xargs rm -f +
22 |
23 | FROM ghcr.io/sagemath/sage/sage-ubuntu-jammy-minimal-with-system-packages:10.6
24 |
25 | USER root
26 |
27 | # Remove warnings
28 | ENV DEBIAN_FRONTEND noninteractive
29 | ENV DEBCONF_NOWARNINGS="yes"
30 |
31 | # Install JupyterLab to the system
32 | RUN apt-get update
33 | RUN apt-get install -y --no-install-recommends python3-pip
34 | RUN python3 -m pip install --no-warn-script-location --no-cache-dir notebook jupyterlab ipywidgets
35 |
36 | # Disable annoying popup for Jupyter news
37 | RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
38 |
39 | # Install /sage from target
40 | COPY --from=target /sage/local /sage/local
41 | COPY --from=target /sage/src/bin /sage/src/bin
42 | COPY --from=target /sage/src/sage /sage/src/sage
43 | COPY --from=target /sage/sage /sage/sage
44 | COPY --from=target /sage/pkgs/sage-conf /sage/pkgs/sage-conf
45 |
46 | # Recreate symbolic links
47 | COPY --from=target /sage/prefix_link /sage/prefix_link
48 | COPY --from=target /sage/venv_link /sage/venv_link
49 | RUN ln -s $(cat /sage/prefix_link) /sage/prefix && rm /sage/prefix_link
50 | RUN ln -s $(cat /sage/venv_link) /sage/venv && rm /sage/venv_link
51 |
52 | # Configure Sage library
53 | RUN /sage/sage -pip install --root-user-action=ignore /sage/pkgs/sage-conf
54 |
55 | # Remove problematic lines!
56 | RUN sed -i '/^__requires__/d' /sage/venv/bin/sage-venv-config
57 | RUN sed -i '/^__import__/d' /sage/venv/bin/sage-venv-config
58 |
--------------------------------------------------------------------------------
/.github/icons/blue.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagemath/sage-binder-env/0c6ba26c96262f643fedc626c38074fac3fbf60a/.github/icons/blue.ico
--------------------------------------------------------------------------------
/.github/icons/orange.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagemath/sage-binder-env/0c6ba26c96262f643fedc626c38074fac3fbf60a/.github/icons/orange.ico
--------------------------------------------------------------------------------
/.github/workflows/create-wsl-image.yml:
--------------------------------------------------------------------------------
1 | name: Build docker image and export for WSL
2 |
3 | on:
4 | schedule:
5 | - cron: '0 2 * * *' # Run every day
6 | workflow_dispatch:
7 |
8 | jobs:
9 | build-and-export:
10 | runs-on: ubuntu-latest
11 | outputs:
12 | upload_url: ${{ steps.create_release.outputs.upload_url }}
13 | version: ${{ steps.extract_version.outputs.version }}
14 | steps:
15 |
16 | # Create WSL export (a tar file) of the minimal Sage install
17 |
18 | - name: Prepare Dockerfile
19 | run: |
20 | curl -o Dockerfile https://raw.githubusercontent.com/sagemath/sage-binder-env/master/Dockerfile
21 | sed -i '/COPY notebooks/d' Dockerfile # remove the line from Dockerfile
22 |
23 | - name: Extract version from Dockerfile
24 | id: extract_version
25 | run: |
26 | VERSION=$(grep '^FROM ghcr.io/sagemath/sage-binder-env:' Dockerfile | sed 's/^FROM ghcr.io\/sagemath\/sage-binder-env://')
27 | echo "VERSION=$VERSION" >> $GITHUB_ENV
28 | echo "version=$VERSION" >> $GITHUB_OUTPUT
29 |
30 | - name: Build and export Docker image
31 | run: |
32 | docker build -t sagemath-container .
33 | export CONTAINER_ID=$(docker create sagemath-container)
34 | docker export $CONTAINER_ID -o sagemath-$VERSION-wsl.tar
35 |
36 | - name: Upload tar file as artifact
37 | id: upload-artifact
38 | uses: actions/upload-artifact@v4
39 | with:
40 | name: sagemath-${{ env.VERSION }}-wsl
41 | path: sagemath-${{ env.VERSION }}-wsl.tar
42 |
43 | # Make a release
44 |
45 | - name: Get latest release version
46 | id: get_latest_release
47 | run: |
48 | LATEST_VERSION=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name // "0.0.0"' | sed 's/v//')
49 | echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
50 |
51 | - name: Zip the tar file
52 | if: ${{ env.VERSION != env.LATEST_VERSION }}
53 | run: |
54 | zip sagemath-${{ env.VERSION }}-wsl.zip sagemath-${{ env.VERSION }}-wsl.tar
55 |
56 | - name: Create GitHub Release
57 | if: ${{ env.VERSION != env.LATEST_VERSION }}
58 | id: create_release
59 | uses: actions/create-release@v1
60 | env:
61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 | with:
63 | tag_name: v${{ env.VERSION }}
64 | release_name: Run SageMath ${{ env.VERSION }} on WSL
65 | body: |
66 | We recommend you check if WSL is enabled before running the installer.
67 |
68 | The .ps1 installer downloads the .zip file and imports a minimized SageMath ${{ env.VERSION }} into WSL.
69 |
70 | After downloading the installer, right-click it to open the context menu and run it with PowerShell.
71 | You may also open the installer as a text file, and copy and paste all lines into a PowerShell window.
72 |
73 | The installer should create two shortcuts on your desktop: one for launching SageMath
74 | and another to start the Jupyter server for SageMath.
75 |
76 | The minimized SageMath is the same as the one used in the Binder environment, meaning no bells and whistles.
77 | Notably the Sage build system is not included.
78 | draft: false
79 | prerelease: false
80 |
81 | - name: Upload release asset
82 | if: ${{ env.VERSION != env.LATEST_VERSION }}
83 | uses: actions/upload-release-asset@v1
84 | env:
85 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86 | with:
87 | upload_url: ${{ steps.create_release.outputs.upload_url }}
88 | asset_path: ./sagemath-${{ env.VERSION }}-wsl.zip
89 | asset_name: sagemath-${{ env.VERSION }}-wsl.zip
90 | asset_content_type: application/zip
91 |
92 | # Generate a Windows PowerShell script
93 |
94 | - name: Checkout repo
95 | uses: actions/checkout@v3
96 |
97 | - name: Generate PowerShell Script
98 | run: |
99 | cat << EOF > download_and_import_sagemath_to_wsl.ps1
100 | # ----------------------------------------------------
101 | # Copy and paste all lines into the Windows PowerShell
102 | # ----------------------------------------------------
103 |
104 | [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
105 | try {
106 | Write-Host "Checking WSL installation."
107 | wsl --install --no-distribution
108 | if (\$LASTEXITCODE -ne 0) {
109 | Write-Host "WSL installation failed."
110 | Read-Host -Prompt "Press any key to exit"; exit
111 | }
112 | } catch {
113 | Write-Host "Could not check WSL installation, proceeding with fingers crossed."
114 | }
115 | # Check if SageMath already exists in WSL
116 | \$sagemathWSL = "SageMath-$VERSION"
117 | if ((wsl -l -q) -contains \$sagemathWSL) {
118 | # Ask user if they want to reinstall SageMath
119 | \$response = Read-Host "\$sagemathWSL is already installed. Do you want to reinstall it? (y/n)"
120 | if (\$response -eq "y") {
121 | Write-Host "Uninstalling \$sagemathWSL."
122 | # Unregister the existing SageMath WSL distribution
123 | wsl --unregister \$sagemathWSL
124 | } else {
125 | Read-Host "OK. Press any key to exit"; exit
126 | }
127 | }
128 | \$artifactUrl = "https://github.com/sagemath/sage-binder-env/releases/download/v$VERSION/sagemath-$VERSION-wsl.zip"
129 | \$zipFilePath = "\$PWD\\artifact.zip"
130 | \$dataPath = "\$HOME\\AppData\\Local\\SageMath"
131 | \$tarFilePath = "\$dataPath\\sagemath-$VERSION-wsl.tar"
132 | # Ensure the path exists
133 | if (-Not (Test-Path \$dataPath)) { New-Item -Path \$dataPath -ItemType Directory > \$null }
134 | # Skip downloading and extracting if the tar file already exists
135 | if (-Not (Test-Path \$tarFilePath)) {
136 | Write-Host "Downloading \$sagemathWSL..."
137 | Start-BitsTransfer -Source \$artifactUrl -Destination \$zipFilePath
138 | Write-Host "Extracting..."
139 | Expand-Archive -Path \$zipFilePath -DestinationPath \$dataPath -Force
140 | if (Test-Path \$tarFilePath) { Remove-Item \$zipFilePath }
141 | } else {
142 | Write-Host "\$sagemathWSL was already downloaded."
143 | }
144 | # Import the WSL image
145 | Write-Host "Start importing..."
146 | wsl --import SageMath-$VERSION \$dataPath \$tarFilePath
147 | # Check if importing succeeded
148 | if (-Not ((wsl -l -q) -contains \$sagemathWSL)) {
149 | Write-Host "Importing \$sagemathWSL into WSL failed."
150 | Write-Host "If WSL was freshly installed by this installer, try again after rebooting the computer."
151 | Read-Host "Press any key to exit"; exit
152 | }
153 | Write-Host "Creating shortcults at:"
154 | # Download icons for shortcuts
155 | \$iconUrlOrange = "https://raw.githubusercontent.com/sagemath/sage-binder-env/refs/heads/master/.github/icons/orange.ico"
156 | \$iconUrlBlue = "https://raw.githubusercontent.com/sagemath/sage-binder-env/refs/heads/master/.github/icons/blue.ico"
157 | \$iconPathOrange = "\$dataPath\\orange.ico"
158 | \$iconPathBlue = "\$dataPath\\blue.ico"
159 | # Download the icon if it doesn't exist
160 | if (-Not (Test-Path \$iconPathBlue)) {
161 | Start-BitsTransfer -Source \$iconUrlBlue -Destination \$iconPathBlue
162 | }
163 | if (-Not (Test-Path \$iconPathOrange)) {
164 | Start-BitsTransfer -Source \$iconUrlOrange -Destination \$iconPathOrange
165 | }
166 | # Create shortcuts
167 | \$ShortcutFile = "\$([Environment]::GetFolderPath('Desktop'))\\Run Sage.lnk"
168 | \$TargetPath = "C:\\Windows\\System32\\wsl.exe"
169 | \$Arguments = "-d \$sagemathWSL --user user --cd ~ /sage/sage"
170 | \$WScriptShell = New-Object -ComObject WScript.Shell
171 | \$Shortcut = \$WScriptShell.CreateShortcut(\$ShortcutFile)
172 | \$Shortcut.TargetPath = \$TargetPath
173 | \$Shortcut.Arguments = \$Arguments
174 | \$Shortcut.IconLocation = \$iconPathBlue
175 | \$Shortcut.Save()
176 | Write-Host "\$ShortcutFile"
177 | # Create a shortcut that starts Jupyter on Desktop
178 | \$ShortcutFile = "\$([Environment]::GetFolderPath('Desktop'))\\Run Jupyter.lnk"
179 | \$TargetPath = "C:\\Windows\\System32\\wsl.exe"
180 | \$Arguments = "-d \$sagemathWSL --user user --cd ~ jupyter lab --no-browser"
181 | \$WScriptShell = New-Object -ComObject WScript.Shell
182 | \$Shortcut = \$WScriptShell.CreateShortcut(\$ShortcutFile)
183 | \$Shortcut.TargetPath = \$TargetPath
184 | \$Shortcut.Arguments = \$Arguments
185 | \$Shortcut.IconLocation = \$iconPathOrange
186 | \$Shortcut.Save()
187 | Write-Host "\$ShortcutFile"
188 | Read-Host "\`n\$sagemathWSL installation succeeded!\`nPress any key to exit"
189 | EOF
190 | cat << EOF > remove_sagemath_from_wsl.ps1
191 | # ----------------------------------------------------
192 | # Copy and paste all lines into the Windows PowerShell
193 | # ----------------------------------------------------
194 |
195 | [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
196 | try {
197 | Write-Host "Checking WSL installation."
198 | wsl --install --no-distribution
199 | if (\$LASTEXITCODE -ne 0) {
200 | Write-Host "WSL installation failed."
201 | Read-Host -Prompt "Press any key to exit"; exit
202 | }
203 | } catch {
204 | Write-Host "Could not check WSL installation, proceeding with fingers crossed."
205 | }
206 | # Check if SageMath already exists in WSL
207 | \$sagemathWSL = "SageMath-$VERSION"
208 | \$dataPath = "\$HOME\\AppData\\Local\\SageMath"
209 | \$iconPathOrange = "\$dataPath\\orange.ico"
210 | \$iconPathBlue = "\$dataPath\\blue.ico"
211 | if ((wsl -l -q) -contains \$sagemathWSL) {
212 | # Ask user if they want to reinstall SageMath
213 | \$response = Read-Host "Do you want to uninstall \$(\$sagemathWSL) from WSL? (y/n)"
214 | if (\$response -eq "y") {
215 | Write-Host "Uninstalling \$sagemathWSL..."
216 | try {
217 | wsl --unregister \$sagemathWSL
218 | } catch {
219 | Write-Host "Failed: wsl --unregister \$sagemathWSL"
220 | }
221 | try {
222 | rm -recurse \$dataPath
223 | } catch {
224 | Write-Host "Failed: rm -recurse \$dataPath"
225 | }
226 | try {
227 | \$ShortcutFile = "\$([Environment]::GetFolderPath('Desktop'))\\Run Sage.lnk"
228 | rm \$ShortcutFile
229 | } catch {
230 | Write-Host "Failed: rm \$ShortcutFile"
231 | }
232 | try {
233 | \$ShortcutFile = "\$([Environment]::GetFolderPath('Desktop'))\\Run Jupyter.lnk"
234 | rm \$ShortcutFile
235 | } catch {
236 | Write-Host "Failed: rm \$ShortcutFile"
237 | }
238 | } else {
239 | Read-Host "OK. Press any key to exit"; exit
240 | }
241 | } else {
242 | Write-Host "\$sagemathWSL is not found."
243 | Read-Host -Prompt "Press any key to exit"; exit
244 | }
245 | Read-Host "\`n\$sagemathWSL uninstallation succeeded!\`nPress any key to exit"
246 | EOF
247 | shell: bash
248 |
249 | - name: Upload installation script as artifact
250 | uses: actions/upload-artifact@v4
251 | with:
252 | name: download_and_import_sagemath_to_wsl
253 | path: download_and_import_sagemath_to_wsl.ps1
254 |
255 | - name: Upload uninstallation script as artifact
256 | uses: actions/upload-artifact@v4
257 | with:
258 | name: remove_sagemath_from_wsl
259 | path: remove_sagemath_from_wsl.ps1
260 |
261 | - name: Upload installation script as release asset
262 | if: ${{ env.VERSION != env.LATEST_VERSION }}
263 | uses: actions/upload-release-asset@v1
264 | env:
265 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
266 | with:
267 | upload_url: ${{ steps.create_release.outputs.upload_url }}
268 | asset_path: ./download_and_import_sagemath_to_wsl.ps1
269 | asset_name: sagemath-${{ env.VERSION }}-wsl-installer.ps1
270 | asset_content_type: application/octet-stream
271 |
272 | - name: Upload uninstallation script as release asset
273 | if: ${{ env.VERSION != env.LATEST_VERSION }}
274 | uses: actions/upload-release-asset@v1
275 | env:
276 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
277 | with:
278 | upload_url: ${{ steps.create_release.outputs.upload_url }}
279 | asset_path: ./remove_sagemath_from_wsl.ps1
280 | asset_name: sagemath-${{ env.VERSION }}-wsl-uninstaller.ps1
281 | asset_content_type: application/octet-stream
282 |
283 | # build-exe:
284 | # runs-on: windows-latest
285 | # needs: build-and-export
286 | # if: ${{ contains(needs.build-and-export.outputs.upload_url || '', 'http') }}
287 | # steps:
288 | # - name: Checkout repository
289 | # uses: actions/checkout@v3
290 | #
291 | # - name: Download PowerShell Script artifact
292 | # uses: actions/download-artifact@v4
293 | # with:
294 | # name: download_and_import_sagemath_to_wsl
295 | #
296 | # - name: Install PS2EXE
297 | # run: |
298 | # Install-Module -Name ps2exe -Force
299 | # Import-Module ps2exe
300 | # Invoke-ps2exe -inputFile .\download_and_import_sagemath_to_wsl.ps1 -outputFile .\sagemath_installer.exe
301 | # shell: powershell
302 | #
303 | # - name: Upload EXE to GitHub Release
304 | # uses: actions/upload-release-asset@v1
305 | # env:
306 | # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
307 | # with:
308 | # upload_url: ${{ needs.build-and-export.outputs.upload_url }}
309 | # asset_path: ./sagemath_installer.exe
310 | # asset_name: sagemath-${{ needs.build-and-export.outputs.version }}-wsl-installer.exe
311 | # asset_content_type: application/octet-stream
312 |
--------------------------------------------------------------------------------
/.github/workflows/update-dockerfile-dev.yml:
--------------------------------------------------------------------------------
1 | name: Update dev image
2 |
3 | on:
4 | schedule:
5 | - cron: '0 1 * * *' # Run every day
6 | workflow_dispatch:
7 |
8 | env:
9 | SAGE_TARGET: ghcr.io/sagemath/sage/sage-ubuntu-jammy-minimal-with-targets
10 | SAGE_SYSTEM: ghcr.io/sagemath/sage/sage-ubuntu-jammy-minimal-with-system-packages
11 | TAG: dev
12 | BRANCH: dev
13 |
14 | jobs:
15 | build:
16 | runs-on: ubuntu-latest
17 | permissions:
18 | contents: write
19 | packages: write
20 | steps:
21 |
22 | # Prepare .github/Dockerfile for slim Sage image
23 |
24 | - name: Checkout code
25 | uses: actions/checkout@v4
26 | with:
27 | ref: ${{ env.BRANCH }}
28 | - name: Prepare .github/Dockerfile
29 | run: |
30 | SAGE_VERSION=$(docker run --rm ${SAGE_TARGET}:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
31 | SAGE_TARGET_ESCAPED=$(echo "${SAGE_TARGET}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
32 | SAGE_TARGET_VERSION_ESCAPED=$(echo "${SAGE_TARGET}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
33 | sed -i "s/FROM ${SAGE_TARGET_ESCAPED}:\S*/FROM ${SAGE_TARGET_VERSION_ESCAPED}/g" .github/Dockerfile
34 | SAGE_SYSTEM_ESCAPED=$(echo "${SAGE_SYSTEM}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
35 | SAGE_SYSTEM_VERSION_ESCAPED=$(echo "${SAGE_SYSTEM}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
36 | sed -i "s/FROM ${SAGE_SYSTEM_ESCAPED}:\S*/FROM ${SAGE_SYSTEM_VERSION_ESCAPED}/g" .github/Dockerfile
37 | PACKAGE_NAME=ghcr.io/${{ github.repository }}:${SAGE_VERSION}
38 | echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
39 | git config --global user.email alice@wonderland
40 | git config --global user.name alice
41 | git commit -a --amend -m "Dockerfile for Sage ${SAGE_VERSION}"
42 | git push -f origin $BRANCH
43 |
44 | # Build and publish the slim Sage image to github package registry (ghpr)
45 |
46 | - name: Log in to the Container registry
47 | uses: docker/login-action@v3
48 | with:
49 | registry: ghcr.io
50 | username: ${{ github.actor }}
51 | password: ${{ secrets.GITHUB_TOKEN }}
52 | - name: Build and push Docker image
53 | uses: docker/build-push-action@v5
54 | with:
55 | context: .github
56 | push: true
57 | tags: ${{ env.PACKAGE_NAME }}
58 |
59 | # Update files for Binder
60 |
61 | - name: Checkout code
62 | uses: actions/checkout@v4
63 | with:
64 | ref: ${{ env.BRANCH }}
65 | - name: Update files for Binder
66 | run: |
67 | PACKAGE_NAME=${{ env.PACKAGE_NAME }}
68 | PACKAGE_NAME_ESCAPED=$(echo "${PACKAGE_NAME}" | sed 's/\//\\\//g')
69 | sed -i "s/FROM \S*/FROM ${PACKAGE_NAME_ESCAPED}/g" Dockerfile
70 | sed -i "s/FROM \S*/FROM ${PACKAGE_NAME_ESCAPED}/g" README.rst
71 | git config --global user.email alice@wonderland
72 | git config --global user.name alice
73 | git commit -a --amend -m "Update files for Binder"
74 | git push -f origin $BRANCH
75 |
76 | # Build docker image for Binder from Dockerfile at root
77 |
78 | - name: Binder build
79 | timeout-minutes: 30
80 | continue-on-error: true
81 | run: |
82 | curl --keepalive-time 600 -L https://mybinder.org/build/gh/sagemath/sage-binder-env/$BRANCH
83 |
--------------------------------------------------------------------------------
/.github/workflows/update-dockerfile-master.yml:
--------------------------------------------------------------------------------
1 | name: Update master image
2 |
3 | on:
4 | schedule:
5 | - cron: '0 0 * * *' # Run every day
6 | workflow_dispatch:
7 |
8 | env:
9 | SAGE_TARGET: ghcr.io/sagemath/sage/sage-ubuntu-jammy-minimal-with-targets
10 | SAGE_SYSTEM: ghcr.io/sagemath/sage/sage-ubuntu-jammy-minimal-with-system-packages
11 | TAG: latest
12 | BRANCH: master
13 |
14 | jobs:
15 | build:
16 | runs-on: ubuntu-latest
17 | permissions:
18 | contents: write
19 | packages: write
20 | steps:
21 |
22 | # Prepare .github/Dockerfile for slim Sage image
23 |
24 | - name: Checkout code
25 | uses: actions/checkout@v4
26 | with:
27 | ref: ${{ env.BRANCH }}
28 | - name: Prepare .github/Dockerfile
29 | run: |
30 | SAGE_VERSION=$(docker run --rm ${SAGE_TARGET}:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
31 | SAGE_TARGET_ESCAPED=$(echo "${SAGE_TARGET}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
32 | SAGE_TARGET_VERSION_ESCAPED=$(echo "${SAGE_TARGET}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
33 | sed -i "s/FROM ${SAGE_TARGET_ESCAPED}:\S*/FROM ${SAGE_TARGET_VERSION_ESCAPED}/g" .github/Dockerfile
34 | SAGE_SYSTEM_ESCAPED=$(echo "${SAGE_SYSTEM}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
35 | SAGE_SYSTEM_VERSION_ESCAPED=$(echo "${SAGE_SYSTEM}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
36 | sed -i "s/FROM ${SAGE_SYSTEM_ESCAPED}:\S*/FROM ${SAGE_SYSTEM_VERSION_ESCAPED}/g" .github/Dockerfile
37 | PACKAGE_NAME=ghcr.io/${{ github.repository }}:${SAGE_VERSION}
38 | echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
39 | git config --global user.email alice@wonderland
40 | git config --global user.name alice
41 | git commit -a --amend -m "Dockerfile for Sage ${SAGE_VERSION}"
42 | git push -f origin $BRANCH
43 |
44 | # Build and publish the slim Sage image to github package registry (ghpr)
45 |
46 | - name: Log in to the Container registry
47 | uses: docker/login-action@v3
48 | with:
49 | registry: ghcr.io
50 | username: ${{ github.actor }}
51 | password: ${{ secrets.GITHUB_TOKEN }}
52 |
53 | - name: Build and push Docker image
54 | uses: docker/build-push-action@v5
55 | with:
56 | context: .github
57 | push: true
58 | tags: ${{ env.PACKAGE_NAME }}
59 |
60 | # Update files for Binder
61 |
62 | - name: Checkout code
63 | uses: actions/checkout@v4
64 | with:
65 | ref: ${{ env.BRANCH }}
66 | - name: Update files for Binder
67 | run: |
68 | PACKAGE_NAME=${{ env.PACKAGE_NAME }}
69 | PACKAGE_NAME_ESCAPED=$(echo "${PACKAGE_NAME}" | sed 's/\//\\\//g')
70 | sed -i "s/FROM \S*/FROM ${PACKAGE_NAME_ESCAPED}/g" Dockerfile
71 | sed -i "s/FROM \S*/FROM ${PACKAGE_NAME_ESCAPED}/g" README.rst
72 | git config --global user.email alice@wonderland
73 | git config --global user.name alice
74 | git commit -a --amend -m "Update files for Binder"
75 | git push -f origin $BRANCH
76 |
77 | # Build docker image for Binder from Dockerfile at root
78 |
79 | - name: Binder build
80 | timeout-minutes: 30
81 | continue-on-error: true
82 | run: |
83 | curl --keepalive-time 600 -L https://mybinder.org/build/gh/sagemath/sage-binder-env/$BRANCH
84 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sagemath/sage-binder-env/0c6ba26c96262f643fedc626c38074fac3fbf60a/.gitignore
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Dockerfile for binder
2 | # Reference: https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html
3 |
4 | FROM ghcr.io/sagemath/sage-binder-env:10.6
5 |
6 | USER root
7 |
8 | # Create user with uid 1000
9 | ARG NB_USER=user
10 | ARG NB_UID=1000
11 | ENV NB_USER user
12 | ENV NB_UID 1000
13 | ENV HOME /home/${NB_USER}
14 | RUN adduser --disabled-password --gecos "Default user" --uid ${NB_UID} ${NB_USER}
15 |
16 | # Make sure the contents of the notebooks directory are in ${HOME}
17 | COPY notebooks/* ${HOME}/
18 | RUN chown -R ${NB_USER}:${NB_USER} ${HOME}
19 |
20 | # Switch to the user
21 | USER ${NB_USER}
22 |
23 | # Install Sage kernel to Jupyter
24 | RUN mkdir -p $(jupyter --data-dir)/kernels
25 | RUN ln -s /sage/venv/share/jupyter/kernels/sagemath $(jupyter --data-dir)/kernels
26 |
27 | # Make Sage accessible from anywhere
28 | ENV PATH="/sage:$PATH"
29 |
30 | # Start in the home directory of the user
31 | WORKDIR /home/${NB_USER}
32 |
33 | # Create the jupyter_lab_config.py file with a custom logging filter to
34 | # suppress the perpetual nodejs warning
35 | RUN mkdir -p /home/${NB_USER}/.jupyter
36 | RUN echo "\
37 | import logging\n\
38 | \n\
39 | class NoNodeJSWarningFilter(logging.Filter):\n\
40 | def filter(self, record):\n\
41 | return 'Could not determine jupyterlab build status without nodejs' not in record.getMessage()\n\
42 | \n\
43 | logging.getLogger('LabApp').addFilter(NoNodeJSWarningFilter())\n\
44 | " > /home/${NB_USER}/.jupyter/jupyter_lab_config.py
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | A Binder repo for SageMath computing environment
2 | ================================================
3 |
4 | This repository is a Binder repo based on `SageMath `_. To
5 | access a computing environment created by `Binder `_ using
6 | SageMath kernel, click on this badge
7 |
8 | .. image:: https://mybinder.org/badge_logo.svg
9 | :target: https://mybinder.org/v2/gh/sagemath/sage-binder-env/master
10 |
11 |
12 | An example Binder repo for SageMath
13 | -----------------------------------
14 |
15 | Have a repository full of Jupyter notebooks using SageMath? It's easy to set up
16 | Binder to let anyone run them. Just fork this repo, put your notebooks in the
17 | `notebooks` directory, and modify this `README.rst` to your needs. In
18 | particular, you probably want to modify this line::
19 |
20 | :target: https://mybinder.org/v2/gh/...
21 |
22 | with `...` filled with the name of your forked repo. This makes the Binder badge use your
23 | repo to create the computing environment.
24 |
25 |
26 | Extending the Dockerfile
27 | ------------------------
28 |
29 | The `Dockerfile` is based on the Docker image::
30 |
31 | FROM ghcr.io/sagemath/sage-binder-env:10.6
32 |
33 | which contains the latest stable version of Sage.
34 |
35 | It includes Sage itself, and all the software packages typically
36 | included in a standard Sage installation, though not *everything*. In
37 | particular not optional Sage SPKGs, or other system software packages.
38 |
39 |
40 | Authors
41 | -------
42 |
43 | Nicolas M. Thiéry, E. Madison Bray, and Kwankyu Lee
44 |
--------------------------------------------------------------------------------
/notebooks/Start here.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# About SageMath\n",
8 | "\n",
9 | "[SageMath](https://www.sagemath.org) (Sage for short) is a general purpose computational mathematics system developed by a worldwide community of hundreds of researchers, teachers and engineers. It’s based on the Python programming language and includes GAP, PARI/GP, Singular, and dozens of other specialized libraries.\n",
10 | "\n",
11 | "This live document will guide you through the first steps of using Sage, and provide pointers to explore and learn further. In the following, we will be assuming that you are reading this document as a Jupyter notebook (Jupyter is the primary user interface\n",
12 | "for Sage).\n",
13 | "$\\def\\NN{\\mathbb{N}}\\def\\ZZ{\\mathbb{Z}}\\def\\QQ{\\mathbb{Q}}\\def\\RR{\\mathbb{R}}\\def\\CC{\\mathbb{C}}$\n",
14 | ""
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {},
20 | "source": [
21 | "## A first calculation\n",
22 | "\n",
23 | "Sage can be used as a pocket calculator: you type in some expression to be calculated, Sage evaluates it, and prints the result; and repeat. This is called the *Read-Eval-Print-Loop*. In the Jupyter notebook, you type the expression in an **input cell**, or **code cell**. This is the rectangle below this paragraph containing $1+1$. Click on the cell to select it, and press shift-enter to evaluate it. You may instead click the Run button (right triangle) in the toolbar."
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "metadata": {},
30 | "outputs": [],
31 | "source": [
32 | "1 + 1"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {},
38 | "source": [
39 | "Sage prints out its response in an **output cell** just below the input cell (that’s 2, so Sage confirms that 1 plus 1 is 2). Click again in the cell, replace $1+1$ by $2+2$, and evaluate it. Notice how much quicker it is now. That’s because a Sage process had to be started the first time, and then stayed ready.\n",
40 | "\n",
41 | "Congratulations, you have done your first calculations with Sage."
42 | ]
43 | },
44 | {
45 | "cell_type": "markdown",
46 | "metadata": {},
47 | "source": [
48 | "## Using the Jupyter notebook\n",
49 | "\n",
50 | "Now take some time to explore the Help menu. You find abundant information on Jupyter, Sage, and friends. \n",
51 | "For now we just review the basics of Jupyter notebook. Use the plus button in the toolbar to create a new input cell below this paragraph (you may need to first click this paragraph to focus), then calculate any simple expression of your liking.\n",
52 | "\n",
53 | "You can move around and edit any cell by clicking in it. Go back and change your $2+2$ above to $3+3$ and evaluate it once again.\n",
54 | "\n",
55 | "You can also edit any **text cell** by double clicking on it. Try it now! The text you see is using the [Markdown](https://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Working%20With%20Markdown%20Cells.html) markup language. Do some changes to the text, and evaluate it again to rerender it. Markdown supports a fair amount of basic formatting, such as bold, underline, basic lists, and so forth. Thanks to the LaTeX rendering engine [MathJax](https://www.mathjax.org/), you may embed mathematical formulae such as $\\sin x - y^3$ just like with LaTeX. It can be fun to type in fairly complicated math, like this:\n",
56 | "\n",
57 | "$$\n",
58 | " \\zeta(s)=\\sum_{n=1}^{\\infty}\\frac{1}{n^s}=\\prod_p \\left(\\frac{1}{1-p^{-s}}\\right)\n",
59 | "$$\n",
60 | "\n",
61 | "If you *mess everything up*, you can use the menu Kernel > Restart Kernel to restart Sage. You can also use the menu File > Save Notebook to save notebook, and File > Revert Notebook to Checkpoint to reset to any previously saved version."
62 | ]
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "metadata": {},
67 | "source": [
68 | "## More interactions\n",
69 | "\n",
70 | "We are now done with basic interaction with Sage. Much richer interactions are possible thanks to Jupyter’s *interactive widgets*. Evaluate the next code cell, and try clicking on the sliders to illustrate multiplication below. "
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": null,
76 | "metadata": {},
77 | "outputs": [],
78 | "source": [
79 | "@interact\n",
80 | "def f(n=(1..15), m=(1..15)):\n",
81 | " print(\"n * m = {} = {}\".format(n * m, factor(n * m)))\n",
82 | " P = polygon([(0, 0), (0, n), (m, n), (m, 0)])\n",
83 | " P.show(aspect_ratio=1, gridlines='minor', figsize=[3, 3], xmax=14, ymax=14)"
84 | ]
85 | },
86 | {
87 | "cell_type": "markdown",
88 | "metadata": {},
89 | "source": [
90 | "Also, you can try changing the slider ranges to something different by editing the input cell (make sure to also change `xmax`, `ymax`)."
91 | ]
92 | },
93 | {
94 | "cell_type": "markdown",
95 | "metadata": {},
96 | "source": [
97 | "## A brief tour\n",
98 | "\n",
99 | "We start showcasing the different areas of mathematics covered by Sage.\n",
100 | ""
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "This should output a rational number. If you know Python, notice the difference; Sage knows fractions!"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": null,
113 | "metadata": {},
114 | "outputs": [],
115 | "source": [
116 | "4/6"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "### Math display\n",
124 | "\n",
125 | "`%display latex` turns on math typesetting using MathJax. Type `%display plain` to turn it off."
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": null,
131 | "metadata": {},
132 | "outputs": [],
133 | "source": [
134 | "%display latex"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": null,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "factor(x^10 - 1)"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {},
150 | "outputs": [],
151 | "source": [
152 | "%display plain\n",
153 | "factor(x^10 - 1)"
154 | ]
155 | },
156 | {
157 | "cell_type": "markdown",
158 | "metadata": {},
159 | "source": [
160 | "### Plots"
161 | ]
162 | },
163 | {
164 | "cell_type": "code",
165 | "execution_count": null,
166 | "metadata": {},
167 | "outputs": [],
168 | "source": [
169 | "plot(sin(10*x))"
170 | ]
171 | },
172 | {
173 | "cell_type": "markdown",
174 | "metadata": {},
175 | "source": [
176 | "### Interactive widgets"
177 | ]
178 | },
179 | {
180 | "cell_type": "code",
181 | "execution_count": null,
182 | "metadata": {},
183 | "outputs": [],
184 | "source": [
185 | "@interact\n",
186 | "def plt(n=5, f=[sin, cos, tan]):\n",
187 | " return plot(f(n*x))"
188 | ]
189 | },
190 | {
191 | "cell_type": "markdown",
192 | "metadata": {},
193 | "source": [
194 | "### 3D plots"
195 | ]
196 | },
197 | {
198 | "cell_type": "code",
199 | "execution_count": null,
200 | "metadata": {},
201 | "outputs": [],
202 | "source": [
203 | "plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2))"
204 | ]
205 | },
206 | {
207 | "cell_type": "markdown",
208 | "metadata": {},
209 | "source": [
210 | "### Calculus"
211 | ]
212 | },
213 | {
214 | "cell_type": "code",
215 | "execution_count": null,
216 | "metadata": {},
217 | "outputs": [],
218 | "source": [
219 | "%display latex\n",
220 | "var('x,y')\n",
221 | "f = (cos(pi/4 - x) - tan(x)) / (1 - sin(pi/4 + x))\n",
222 | "limit(f, x = pi/4, dir='minus')"
223 | ]
224 | },
225 | {
226 | "cell_type": "code",
227 | "execution_count": null,
228 | "metadata": {},
229 | "outputs": [],
230 | "source": [
231 | "solve([x^2+y^2 == 1, y^2 == x^3 + x + 1], x, y)"
232 | ]
233 | },
234 | {
235 | "cell_type": "code",
236 | "execution_count": null,
237 | "metadata": {},
238 | "outputs": [],
239 | "source": [
240 | "plot3d(sin(pi*sqrt(x^2 + y^2)) / sqrt(x^2 + y^2), (x, -5, 5), (y, -5, 5))"
241 | ]
242 | },
243 | {
244 | "cell_type": "code",
245 | "execution_count": null,
246 | "metadata": {},
247 | "outputs": [],
248 | "source": [
249 | "contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),\n",
250 | " contours=[-8,-4,0,4,8], colorbar=True)"
251 | ]
252 | },
253 | {
254 | "cell_type": "markdown",
255 | "metadata": {},
256 | "source": [
257 | "### Algebra"
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": null,
263 | "metadata": {},
264 | "outputs": [],
265 | "source": [
266 | "factor(x^100 - 1)"
267 | ]
268 | },
269 | {
270 | "cell_type": "code",
271 | "execution_count": null,
272 | "metadata": {},
273 | "outputs": [],
274 | "source": [
275 | "p = 54 * x^4 + 36*x^3 - 102*x^2 - 72*x - 12\n",
276 | "p.factor()"
277 | ]
278 | },
279 | {
280 | "cell_type": "code",
281 | "execution_count": null,
282 | "metadata": {},
283 | "outputs": [],
284 | "source": [
285 | "for K in [ZZ, QQ, ComplexField(16), QQ[sqrt(2)], GF(5)]:\n",
286 | " print(K, \":\"); print(K['x'](p).factor())"
287 | ]
288 | },
289 | {
290 | "cell_type": "code",
291 | "execution_count": null,
292 | "metadata": {},
293 | "outputs": [],
294 | "source": [
295 | "ZZ.category()"
296 | ]
297 | },
298 | {
299 | "cell_type": "code",
300 | "execution_count": null,
301 | "metadata": {},
302 | "outputs": [],
303 | "source": [
304 | "sorted( ZZ.category().axioms() )"
305 | ]
306 | },
307 | {
308 | "cell_type": "markdown",
309 | "metadata": {},
310 | "source": [
311 | "### Linear algebra"
312 | ]
313 | },
314 | {
315 | "cell_type": "code",
316 | "execution_count": null,
317 | "metadata": {},
318 | "outputs": [],
319 | "source": [
320 | "A = matrix(GF(7), 4, [5,5,4,3,0,3,3,4,0,1,5,4,6,0,6,3]); A"
321 | ]
322 | },
323 | {
324 | "cell_type": "code",
325 | "execution_count": null,
326 | "metadata": {},
327 | "outputs": [],
328 | "source": [
329 | "P = A.characteristic_polynomial(); P"
330 | ]
331 | },
332 | {
333 | "cell_type": "code",
334 | "execution_count": null,
335 | "metadata": {},
336 | "outputs": [],
337 | "source": [
338 | "P(A) # Cayley-Hamilton"
339 | ]
340 | },
341 | {
342 | "cell_type": "code",
343 | "execution_count": null,
344 | "metadata": {},
345 | "outputs": [],
346 | "source": [
347 | "A.eigenspaces_left()"
348 | ]
349 | },
350 | {
351 | "cell_type": "markdown",
352 | "metadata": {},
353 | "source": [
354 | "Computing the rank of a large sparse matrix:"
355 | ]
356 | },
357 | {
358 | "cell_type": "code",
359 | "execution_count": null,
360 | "metadata": {},
361 | "outputs": [],
362 | "source": [
363 | "M = random_matrix(GF(7), 10000, sparse=True, density=3/10000)\n",
364 | "M.rank()"
365 | ]
366 | },
367 | {
368 | "cell_type": "markdown",
369 | "metadata": {},
370 | "source": [
371 | "### Geometry"
372 | ]
373 | },
374 | {
375 | "cell_type": "code",
376 | "execution_count": null,
377 | "metadata": {},
378 | "outputs": [],
379 | "source": [
380 | "polytopes.truncated_icosidodecahedron().plot()"
381 | ]
382 | },
383 | {
384 | "cell_type": "markdown",
385 | "metadata": {},
386 | "source": [
387 | "### Programming and plotting"
388 | ]
389 | },
390 | {
391 | "cell_type": "code",
392 | "execution_count": null,
393 | "metadata": {},
394 | "outputs": [],
395 | "source": [
396 | "n, l, x, y = 10000, 1, 0, 0\n",
397 | "p = [[0, 0]]\n",
398 | "for k in range(n):\n",
399 | " theta = (2 * pi * random()).n(digits=5)\n",
400 | " x, y = x + l * cos(theta), y + l * sin(theta)\n",
401 | " p.append([x, y])\n",
402 | "g = line(p, thickness=.4) + line([p[n], [0, 0]], color='red', thickness=2)\n",
403 | "g.show(aspect_ratio=1)"
404 | ]
405 | },
406 | {
407 | "cell_type": "markdown",
408 | "metadata": {},
409 | "source": [
410 | "### Interactive plots"
411 | ]
412 | },
413 | {
414 | "cell_type": "code",
415 | "execution_count": null,
416 | "metadata": {},
417 | "outputs": [],
418 | "source": [
419 | "var('x')\n",
420 | "@interact\n",
421 | "def g(f='x*sin(1/x)',\n",
422 | " c=slider(-1, 1, .01, default=-.5),\n",
423 | " n=(1..30),\n",
424 | " xinterval=range_slider(-1, 1, .1, default=(-8,8), label=\"x-interval\"),\n",
425 | " yinterval=range_slider(-1, 1, .1, default=(-3,3), label=\"y-interval\")):\n",
426 | " f = eval(f)\n",
427 | " x0 = c\n",
428 | " degree = n\n",
429 | " xmin,xmax = xinterval\n",
430 | " ymin,ymax = yinterval\n",
431 | " p = plot(f, xmin, xmax, thickness=4)\n",
432 | " dot = point((x0,f(x=x0)),pointsize=80,rgbcolor=(1,0,0))\n",
433 | " ft = f.taylor(x,x0,degree)\n",
434 | " pt = plot(ft, xmin, xmax, color='red', thickness=2, fill=f)\n",
435 | " show(dot + p + pt, ymin=ymin, ymax=ymax, xmin=xmin, xmax=xmax)\n",
436 | " html(r'$f(x)\\;=\\;%s$' % latex(f))\n",
437 | " html(r'$P_{%s}(x)\\;=\\;%s+R_{%s}(x)$' % (degree,latex(ft),degree))"
438 | ]
439 | },
440 | {
441 | "cell_type": "markdown",
442 | "metadata": {},
443 | "source": [
444 | "### Graph Theory\n",
445 | "\n",
446 | "Coloring graphs:"
447 | ]
448 | },
449 | {
450 | "cell_type": "code",
451 | "execution_count": null,
452 | "metadata": {},
453 | "outputs": [],
454 | "source": [
455 | "g = graphs.PetersenGraph(); g\n",
456 | "g.plot(partition=g.coloring())"
457 | ]
458 | },
459 | {
460 | "cell_type": "markdown",
461 | "metadata": {},
462 | "source": [
463 | "### Combinatorics\n",
464 | "\n",
465 | "Fast counting:"
466 | ]
467 | },
468 | {
469 | "cell_type": "code",
470 | "execution_count": null,
471 | "metadata": {},
472 | "outputs": [],
473 | "source": [
474 | "Partitions(100000).cardinality()"
475 | ]
476 | },
477 | {
478 | "cell_type": "markdown",
479 | "metadata": {},
480 | "source": [
481 | "Playing poker:"
482 | ]
483 | },
484 | {
485 | "cell_type": "code",
486 | "execution_count": null,
487 | "metadata": {},
488 | "outputs": [],
489 | "source": [
490 | "Suits = Set([\"Hearts\", \"Diamonds\", \"Spades\", \"Clubs\"])\n",
491 | "Values = Set([2, 3, 4, 5, 6, 7, 8, 9, 10, \"Jack\", \"Queen\", \"King\", \"Ace\"])\n",
492 | "Cards = cartesian_product([Values, Suits])\n",
493 | "Hands = Subsets(Cards, 5)\n",
494 | "Hands.random_element()"
495 | ]
496 | },
497 | {
498 | "cell_type": "code",
499 | "execution_count": null,
500 | "metadata": {},
501 | "outputs": [],
502 | "source": [
503 | "Hands.cardinality()"
504 | ]
505 | },
506 | {
507 | "cell_type": "markdown",
508 | "metadata": {},
509 | "source": [
510 | "### Algebraic Combinatorics\n",
511 | "\n",
512 | "Drawing an affine root systems:"
513 | ]
514 | },
515 | {
516 | "cell_type": "code",
517 | "execution_count": null,
518 | "metadata": {},
519 | "outputs": [],
520 | "source": [
521 | "L = RootSystem([\"G\", 2, 1]).ambient_space()\n",
522 | "p = L.plot(affine=False, level=1)\n",
523 | "p.show(aspect_ratio=[1, 1, 2], frame=False)"
524 | ]
525 | },
526 | {
527 | "cell_type": "markdown",
528 | "metadata": {},
529 | "source": [
530 | "### Number Theory"
531 | ]
532 | },
533 | {
534 | "cell_type": "code",
535 | "execution_count": null,
536 | "metadata": {},
537 | "outputs": [],
538 | "source": [
539 | "E = EllipticCurve('389a')\n",
540 | "plot(E, thickness=3)"
541 | ]
542 | },
543 | {
544 | "cell_type": "markdown",
545 | "metadata": {},
546 | "source": [
547 | "### Games\n",
548 | "\n",
549 | "Sudoku solver:"
550 | ]
551 | },
552 | {
553 | "cell_type": "code",
554 | "execution_count": null,
555 | "metadata": {},
556 | "outputs": [],
557 | "source": [
558 | "S = Sudoku('5...8..49...5...3..673....115..........2.8..........187....415..3...2...49..5...3'); S"
559 | ]
560 | },
561 | {
562 | "cell_type": "code",
563 | "execution_count": null,
564 | "metadata": {},
565 | "outputs": [],
566 | "source": [
567 | "list(S.solve())"
568 | ]
569 | },
570 | {
571 | "cell_type": "markdown",
572 | "metadata": {},
573 | "source": [
574 | "## Help system\n",
575 | "\n",
576 | "We review the three main ways to get help in Sage:\n",
577 | "\n",
578 | "- Navigating through the documentation \n",
579 | "- Tab-completion \n",
580 | "- Contextual help "
581 | ]
582 | },
583 | {
584 | "cell_type": "markdown",
585 | "metadata": {},
586 | "source": [
587 | "### Navigating through the documentation\n",
588 | "\n",
589 | "The Help menu gives access to the HTML documentation for Sage (and other pieces of software). This includes the Sage tutorial, the Sage thematic tutorials, and the Sage reference manual. \n",
590 | "\n",
591 | "This documentation is also available online from Sage’s web site\n",
592 | "[https://doc.sagemath.org](https://doc.sagemath.org/html/en/index.html) ."
593 | ]
594 | },
595 | {
596 | "cell_type": "markdown",
597 | "metadata": {},
598 | "source": [
599 | "### Completion and contextual documentation\n",
600 | "\n",
601 | "Start typing something and press the Tab key. The interface tries to complete it with a command name. If there is more than one completion, then they are all presented to you. Remember that Sage is case sensitive, i.e., it differentiates upper case from lower case. Hence the Tab completion of\n",
602 | "`klein` won’t show you the `KleinFourGroup` command that builds the group $ \\ZZ/2 \\times \\ZZ/2 $ as a permutation group. Try pressing the Tab key in the following cells (with cursor at the end):"
603 | ]
604 | },
605 | {
606 | "cell_type": "code",
607 | "execution_count": null,
608 | "metadata": {
609 | "tags": []
610 | },
611 | "outputs": [],
612 | "source": [
613 | "klein"
614 | ]
615 | },
616 | {
617 | "cell_type": "code",
618 | "execution_count": null,
619 | "metadata": {},
620 | "outputs": [],
621 | "source": [
622 | "Klein"
623 | ]
624 | },
625 | {
626 | "cell_type": "markdown",
627 | "metadata": {},
628 | "source": [
629 | "To see documentation and examples for a command, type a question mark `?` at the end of the command name and evaluate the cell.\n"
630 | ]
631 | },
632 | {
633 | "cell_type": "code",
634 | "execution_count": null,
635 | "metadata": {},
636 | "outputs": [],
637 | "source": [
638 | "KleinFourGroup?"
639 | ]
640 | },
641 | {
642 | "cell_type": "markdown",
643 | "metadata": {},
644 | "source": [
645 | "#### Exercise A\n",
646 | "\n",
647 | "What is the largest prime factor of $600851475143$?"
648 | ]
649 | },
650 | {
651 | "cell_type": "code",
652 | "execution_count": null,
653 | "metadata": {},
654 | "outputs": [],
655 | "source": [
656 | "factor?"
657 | ]
658 | },
659 | {
660 | "cell_type": "code",
661 | "execution_count": null,
662 | "metadata": {},
663 | "outputs": [],
664 | "source": []
665 | },
666 | {
667 | "cell_type": "markdown",
668 | "metadata": {},
669 | "source": [
670 | "### Digression: assignments and methods\n",
671 | "\n",
672 | "In the above manipulations we did not store any data for later use. This can be done in Sage with the assignment symbol as in:"
673 | ]
674 | },
675 | {
676 | "cell_type": "code",
677 | "execution_count": null,
678 | "metadata": {},
679 | "outputs": [],
680 | "source": [
681 | "a = 3\n",
682 | "b = 2\n",
683 | "a + b"
684 | ]
685 | },
686 | {
687 | "cell_type": "markdown",
688 | "metadata": {},
689 | "source": [
690 | "This can be understood as Sage evaluating the expression to the right of the = sign and creating the appropriate object, and then associating that object with a label, given by the left-hand side. Multiple assignments can be done at once:"
691 | ]
692 | },
693 | {
694 | "cell_type": "code",
695 | "execution_count": null,
696 | "metadata": {},
697 | "outputs": [],
698 | "source": [
699 | "a, b = 2, 3\n",
700 | "a"
701 | ]
702 | },
703 | {
704 | "cell_type": "code",
705 | "execution_count": null,
706 | "metadata": {},
707 | "outputs": [],
708 | "source": [
709 | "b"
710 | ]
711 | },
712 | {
713 | "cell_type": "markdown",
714 | "metadata": {},
715 | "source": [
716 | "This allows us to swap the values of two variables directly:"
717 | ]
718 | },
719 | {
720 | "cell_type": "code",
721 | "execution_count": null,
722 | "metadata": {},
723 | "outputs": [],
724 | "source": [
725 | "a, b = 2, 3\n",
726 | "a, b = b, a\n",
727 | "a, b"
728 | ]
729 | },
730 | {
731 | "cell_type": "markdown",
732 | "metadata": {},
733 | "source": [
734 | "We can also assign a common value to several variables simultaneously:"
735 | ]
736 | },
737 | {
738 | "cell_type": "code",
739 | "execution_count": null,
740 | "metadata": {},
741 | "outputs": [],
742 | "source": [
743 | "c = d = 1\n",
744 | "c, d"
745 | ]
746 | },
747 | {
748 | "cell_type": "code",
749 | "execution_count": null,
750 | "metadata": {},
751 | "outputs": [],
752 | "source": [
753 | "d = 2\n",
754 | "c, d"
755 | ]
756 | },
757 | {
758 | "cell_type": "markdown",
759 | "metadata": {},
760 | "source": [
761 | "Note that when we use the word *variable* in the computer-science sense we\n",
762 | "mean “a label attached to some data stored by Sage”. Once an object is\n",
763 | "created, some *methods* apply to it. This means *functions* but instead of\n",
764 | "writing `f(my_object)` you write `my_object.f()`:"
765 | ]
766 | },
767 | {
768 | "cell_type": "code",
769 | "execution_count": null,
770 | "metadata": {},
771 | "outputs": [],
772 | "source": [
773 | "p = 17\n",
774 | "p.is_prime()"
775 | ]
776 | },
777 | {
778 | "cell_type": "markdown",
779 | "metadata": {},
780 | "source": [
781 | "See [Tutorial: Objects and Classes in Python and Sage](http://doc.sagemath.org/html/en/thematic_tutorials/tutorial-objects-and-classes.html#tutorial-objects-and-classes) for details."
782 | ]
783 | },
784 | {
785 | "cell_type": "markdown",
786 | "metadata": {},
787 | "source": [
788 | "### Method discovery with tab-completion\n",
789 | "\n",
790 | ""
791 | ]
792 | },
793 | {
794 | "cell_type": "markdown",
795 | "metadata": {},
796 | "source": [
797 | "To know all methods of an object you can once more use Tab-completion. Write the name of the object followed by a dot and then press Tab:"
798 | ]
799 | },
800 | {
801 | "cell_type": "code",
802 | "execution_count": null,
803 | "metadata": {},
804 | "outputs": [],
805 | "source": [
806 | "a."
807 | ]
808 | },
809 | {
810 | "cell_type": "markdown",
811 | "metadata": {},
812 | "source": [
813 | "#### Exercise B\n",
814 | "\n",
815 | "Create the permutation 51324 and assign it to the variable p."
816 | ]
817 | },
818 | {
819 | "cell_type": "code",
820 | "execution_count": null,
821 | "metadata": {
822 | "tags": []
823 | },
824 | "outputs": [],
825 | "source": [
826 | "Permutation?"
827 | ]
828 | },
829 | {
830 | "cell_type": "code",
831 | "execution_count": null,
832 | "metadata": {},
833 | "outputs": [],
834 | "source": []
835 | },
836 | {
837 | "cell_type": "markdown",
838 | "metadata": {
839 | "tags": []
840 | },
841 | "source": [
842 | "What is the inverse of p?"
843 | ]
844 | },
845 | {
846 | "cell_type": "code",
847 | "execution_count": null,
848 | "metadata": {},
849 | "outputs": [],
850 | "source": [
851 | "p.inv"
852 | ]
853 | },
854 | {
855 | "cell_type": "markdown",
856 | "metadata": {},
857 | "source": [
858 | "Does $p$ have the pattern 123? What about 1234? And 312? (even if you don’t\n",
859 | "know what a pattern is, you should be able to find a command that does this)."
860 | ]
861 | },
862 | {
863 | "cell_type": "code",
864 | "execution_count": null,
865 | "metadata": {},
866 | "outputs": [],
867 | "source": [
868 | "p.pat"
869 | ]
870 | },
871 | {
872 | "cell_type": "markdown",
873 | "metadata": {},
874 | "source": [
875 | "### Linear algebra"
876 | ]
877 | },
878 | {
879 | "cell_type": "markdown",
880 | "metadata": {},
881 | "source": [
882 | "#### Exercise C\n",
883 | "\n",
884 | "Use the matrix() command to create the following matrix.\n",
885 | "\n",
886 | "$$\n",
887 | "M = \\left(\\begin{array}{rrrr}\n",
888 | "10 & 4 & 1 & 1 \\\\\n",
889 | "4 & 6 & 5 & 1 \\\\\n",
890 | "1 & 5 & 6 & 4 \\\\\n",
891 | "1 & 1 & 4 & 10\n",
892 | "\\end{array}\\right)\n",
893 | "$$"
894 | ]
895 | },
896 | {
897 | "cell_type": "code",
898 | "execution_count": null,
899 | "metadata": {},
900 | "outputs": [],
901 | "source": [
902 | "matrix?"
903 | ]
904 | },
905 | {
906 | "cell_type": "code",
907 | "execution_count": null,
908 | "metadata": {},
909 | "outputs": [],
910 | "source": []
911 | },
912 | {
913 | "cell_type": "markdown",
914 | "metadata": {},
915 | "source": [
916 | "Then, using methods of the matrix,\n",
917 | "\n",
918 | "1. Compute the determinant of the matrix. \n",
919 | "1. Compute the echelon form of the matrix. \n",
920 | "1. Compute the eigenvalues of the matrix. \n",
921 | "1. Compute the kernel of the matrix. \n",
922 | "1. Compute the LLL decomposition of the matrix (and lookup the\n",
923 | " documentation for what LLL is if needed!) "
924 | ]
925 | },
926 | {
927 | "cell_type": "code",
928 | "execution_count": null,
929 | "metadata": {},
930 | "outputs": [],
931 | "source": []
932 | },
933 | {
934 | "cell_type": "markdown",
935 | "metadata": {},
936 | "source": [
937 | "Now that you know how to access the different methods of matrices,\n",
938 | "\n",
939 | "1. Create the vector $ v = (1, -1, -1, 1) $. \n",
940 | "1. Compute the two products: $ M \\cdot v $ and $ v \\cdot M $. What mathematical operation is Sage doing implicitly? "
941 | ]
942 | },
943 | {
944 | "cell_type": "code",
945 | "execution_count": null,
946 | "metadata": {},
947 | "outputs": [],
948 | "source": [
949 | "vector?"
950 | ]
951 | },
952 | {
953 | "cell_type": "code",
954 | "execution_count": null,
955 | "metadata": {},
956 | "outputs": [],
957 | "source": []
958 | },
959 | {
960 | "cell_type": "markdown",
961 | "metadata": {},
962 | "source": [
963 | "Vectors in Sage can be used as row vectors or column vectors. A method such as eigenspaces might not\n",
964 | "return what you expect, so it is best to specify `eigenspaces_left` or `eigenspaces_right` instead. Same thing for kernel (`left_kernel` or `right_kernel`), and so on."
965 | ]
966 | },
967 | {
968 | "cell_type": "markdown",
969 | "metadata": {},
970 | "source": [
971 | "### Plotting\n",
972 | "\n",
973 | "The `plot()` command allows you to draw plots of functions. Recall\n",
974 | "that you can access the documentation by pressing the Tab key\n",
975 | "after writing `plot?` in a cell:"
976 | ]
977 | },
978 | {
979 | "cell_type": "code",
980 | "execution_count": null,
981 | "metadata": {},
982 | "outputs": [],
983 | "source": [
984 | "plot?"
985 | ]
986 | },
987 | {
988 | "cell_type": "markdown",
989 | "metadata": {},
990 | "source": [
991 | "Here is a simple example:"
992 | ]
993 | },
994 | {
995 | "cell_type": "code",
996 | "execution_count": null,
997 | "metadata": {},
998 | "outputs": [],
999 | "source": [
1000 | "var('x') # make sure x is a symbolic variable"
1001 | ]
1002 | },
1003 | {
1004 | "cell_type": "code",
1005 | "execution_count": null,
1006 | "metadata": {},
1007 | "outputs": [],
1008 | "source": [
1009 | "plot(sin(x^2), (x, 0, 10))"
1010 | ]
1011 | },
1012 | {
1013 | "cell_type": "markdown",
1014 | "metadata": {},
1015 | "source": [
1016 | "Here is a more complicated plot. Try to change every single input to the plot\n",
1017 | "command in some way, evaluating to see what happens:"
1018 | ]
1019 | },
1020 | {
1021 | "cell_type": "code",
1022 | "execution_count": null,
1023 | "metadata": {},
1024 | "outputs": [],
1025 | "source": [
1026 | "P = plot(sin(x^2), (x, -2, 2), rgbcolor=(0.8, 0, 0.2), thickness=3, linestyle='--', fill='axis')\n",
1027 | "show(P, gridlines=True)"
1028 | ]
1029 | },
1030 | {
1031 | "cell_type": "markdown",
1032 | "metadata": {},
1033 | "source": [
1034 | "Above we used the `show(P)` command to show a plot after it was created. You can\n",
1035 | "also use `P.show()` instead:"
1036 | ]
1037 | },
1038 | {
1039 | "cell_type": "code",
1040 | "execution_count": null,
1041 | "metadata": {},
1042 | "outputs": [],
1043 | "source": [
1044 | "P.show(gridlines=True)"
1045 | ]
1046 | },
1047 | {
1048 | "cell_type": "markdown",
1049 | "metadata": {},
1050 | "source": [
1051 | "Try putting the cursor right after `P.show(` and pressing Tab key to get a list of\n",
1052 | "the options for how you can change the values of the given inputs."
1053 | ]
1054 | },
1055 | {
1056 | "cell_type": "code",
1057 | "execution_count": null,
1058 | "metadata": {},
1059 | "outputs": [],
1060 | "source": [
1061 | "P.show("
1062 | ]
1063 | },
1064 | {
1065 | "cell_type": "markdown",
1066 | "metadata": {},
1067 | "source": [
1068 | "Plotting multiple functions at once is as easy as adding the plots together:"
1069 | ]
1070 | },
1071 | {
1072 | "cell_type": "code",
1073 | "execution_count": null,
1074 | "metadata": {},
1075 | "outputs": [],
1076 | "source": [
1077 | "P1 = plot(sin(x), (x, 0, 2*pi))\n",
1078 | "P2 = plot(cos(x), (x, 0, 2*pi), rgbcolor='red')\n",
1079 | "P1 + P2"
1080 | ]
1081 | },
1082 | {
1083 | "cell_type": "markdown",
1084 | "metadata": {},
1085 | "source": [
1086 | "### Symbolic Expressions\n",
1087 | "\n",
1088 | "Here is an example of a symbolic function:"
1089 | ]
1090 | },
1091 | {
1092 | "cell_type": "code",
1093 | "execution_count": null,
1094 | "metadata": {},
1095 | "outputs": [],
1096 | "source": [
1097 | "f(x) = x^4 - 8*x^2 - 3*x + 2\n",
1098 | "f(x)"
1099 | ]
1100 | },
1101 | {
1102 | "cell_type": "code",
1103 | "execution_count": null,
1104 | "metadata": {},
1105 | "outputs": [],
1106 | "source": [
1107 | "f(-3)"
1108 | ]
1109 | },
1110 | {
1111 | "cell_type": "markdown",
1112 | "metadata": {},
1113 | "source": [
1114 | "This is an example of a function in the *mathematical* variable $ x $. When Sage\n",
1115 | "starts, it defines the symbol $ x $ to be a mathematical variable. If you want\n",
1116 | "to use other symbols for variables, you must define them first:"
1117 | ]
1118 | },
1119 | {
1120 | "cell_type": "code",
1121 | "execution_count": null,
1122 | "metadata": {},
1123 | "outputs": [],
1124 | "source": [
1125 | "x^2"
1126 | ]
1127 | },
1128 | {
1129 | "cell_type": "code",
1130 | "execution_count": null,
1131 | "metadata": {},
1132 | "outputs": [],
1133 | "source": [
1134 | "u + v"
1135 | ]
1136 | },
1137 | {
1138 | "cell_type": "code",
1139 | "execution_count": null,
1140 | "metadata": {},
1141 | "outputs": [],
1142 | "source": [
1143 | "var('u v')"
1144 | ]
1145 | },
1146 | {
1147 | "cell_type": "code",
1148 | "execution_count": null,
1149 | "metadata": {},
1150 | "outputs": [],
1151 | "source": [
1152 | "u + v"
1153 | ]
1154 | },
1155 | {
1156 | "cell_type": "markdown",
1157 | "metadata": {},
1158 | "source": [
1159 | "Still, it is possible to define symbolic functions without first\n",
1160 | "defining their variables:"
1161 | ]
1162 | },
1163 | {
1164 | "cell_type": "code",
1165 | "execution_count": null,
1166 | "metadata": {},
1167 | "outputs": [],
1168 | "source": [
1169 | "f(w) = w^2\n",
1170 | "f(3)"
1171 | ]
1172 | },
1173 | {
1174 | "cell_type": "markdown",
1175 | "metadata": {},
1176 | "source": [
1177 | "In this case those variables are defined implicitly:"
1178 | ]
1179 | },
1180 | {
1181 | "cell_type": "code",
1182 | "execution_count": null,
1183 | "metadata": {},
1184 | "outputs": [],
1185 | "source": [
1186 | "w"
1187 | ]
1188 | },
1189 | {
1190 | "cell_type": "markdown",
1191 | "metadata": {},
1192 | "source": [
1193 | "#### Exercise D\n",
1194 | "\n",
1195 | "Define the symbolic function $ f(x) = x \\sin x^2 $. Plot $ f $ on the\n",
1196 | "domain $ [-3, 3] $ and color it red. Use the `find_root()` method to\n",
1197 | "numerically approximate the root of $ f $ on the interval $ [1, 2] $:"
1198 | ]
1199 | },
1200 | {
1201 | "cell_type": "code",
1202 | "execution_count": null,
1203 | "metadata": {},
1204 | "outputs": [],
1205 | "source": []
1206 | },
1207 | {
1208 | "cell_type": "markdown",
1209 | "metadata": {},
1210 | "source": [
1211 | "Compute the tangent line to $ f $ at $ x = 1 $:"
1212 | ]
1213 | },
1214 | {
1215 | "cell_type": "code",
1216 | "execution_count": null,
1217 | "metadata": {},
1218 | "outputs": [],
1219 | "source": []
1220 | },
1221 | {
1222 | "cell_type": "markdown",
1223 | "metadata": {},
1224 | "source": [
1225 | "Plot $ f $ and the tangent line to $ f $ at $ x = 1 $ in one image:"
1226 | ]
1227 | },
1228 | {
1229 | "cell_type": "code",
1230 | "execution_count": null,
1231 | "metadata": {},
1232 | "outputs": [],
1233 | "source": []
1234 | },
1235 | {
1236 | "cell_type": "markdown",
1237 | "metadata": {},
1238 | "source": [
1239 | "#### Exercise E (Advanced)\n",
1240 | "\n",
1241 | "Solve the following equation for $y$\n",
1242 | "\n",
1243 | "$$\n",
1244 | "y = 1 + x y^2\n",
1245 | "$$\n",
1246 | "\n",
1247 | "There are two solutions, take the one for which $ \\lim_{x\\to0} y(x) = 1 $.\n",
1248 | "(Don’t forget to create the variables $ x $ and $ y $!)."
1249 | ]
1250 | },
1251 | {
1252 | "cell_type": "code",
1253 | "execution_count": null,
1254 | "metadata": {},
1255 | "outputs": [],
1256 | "source": []
1257 | },
1258 | {
1259 | "cell_type": "markdown",
1260 | "metadata": {},
1261 | "source": [
1262 | "Expand $ y $ as a truncated Taylor series around $ 0 $ containing\n",
1263 | "$ n = 10 $ terms."
1264 | ]
1265 | },
1266 | {
1267 | "cell_type": "code",
1268 | "execution_count": null,
1269 | "metadata": {},
1270 | "outputs": [],
1271 | "source": []
1272 | },
1273 | {
1274 | "cell_type": "markdown",
1275 | "metadata": {},
1276 | "source": [
1277 | "Do you recognize the coefficients of the Taylor series expansion? You might want to use the [On-Line Encyclopedia of Integer Sequences](https://oeis.org/), or better yet, Sage’s class OEIS which queries the encyclopedia:"
1278 | ]
1279 | },
1280 | {
1281 | "cell_type": "code",
1282 | "execution_count": null,
1283 | "metadata": {},
1284 | "outputs": [],
1285 | "source": [
1286 | "oeis?"
1287 | ]
1288 | },
1289 | {
1290 | "cell_type": "code",
1291 | "execution_count": null,
1292 | "metadata": {},
1293 | "outputs": [],
1294 | "source": []
1295 | },
1296 | {
1297 | "cell_type": "markdown",
1298 | "metadata": {},
1299 | "source": [
1300 | "Congratulations for completing your first Sage tutorial!"
1301 | ]
1302 | },
1303 | {
1304 | "cell_type": "markdown",
1305 | "metadata": {},
1306 | "source": [
1307 | "## Exploring further"
1308 | ]
1309 | },
1310 | {
1311 | "cell_type": "markdown",
1312 | "metadata": {},
1313 | "source": [
1314 | "### Accessing Sage\n",
1315 | "\n",
1316 | "- The [Sage cell service](https://sagecell.sagemath.org) lets you evaluate individual Sage commands. \n",
1317 | "- In general, Sage computations can be embedded in any web page using [Thebe](https://thebe.readthedocs.io/en/stable).\n",
1318 | "- [Binder](https://mybinder.org) is a service that lets you run Jupyter online on top of an arbitrary software stack. \n",
1319 | " Sessions are free, anonymous, and temporary. You can use one of the existing repositories, or create your own. \n",
1320 | "\n",
1321 | ""
1322 | ]
1323 | },
1324 | {
1325 | "cell_type": "markdown",
1326 | "metadata": {},
1327 | "source": [
1328 | "### Ways to use Sage\n",
1329 | "\n",
1330 | "There are other ways beyond the Jupyter Notebook to use Sage: interactive command line, program scripts, etc.\n",
1331 | "See [Sage tutorial](https://doc.sagemath.org/html/en/tutorial/introduction.html#ways-to-use-sage)."
1332 | ]
1333 | },
1334 | {
1335 | "cell_type": "markdown",
1336 | "metadata": {},
1337 | "source": [
1338 | "### Resources\n",
1339 | "\n",
1340 | "- [Sage tutorial](https://doc.sagemath.org/html/en/tutorial/index.html) \n",
1341 | "- [Sage thematic tutorials](https://doc.sagemath.org/html/en/thematic_tutorials/index.html) \n",
1342 | "- [The open book *Computational Mathematics with Sage*](https://www.sagemath.org/sagebook/english.html)\n",
1343 | "- [Sage quick reference cards](https://wiki.sagemath.org/quickref) \n",
1344 | "- [Sage webpage https://www.sagemath.org](https://www.sagemath.org) \n",
1345 | "- [Ask Sage https://ask.sagemath.org](https://ask.sagemath.org) \n",
1346 | "- [Sage GitHub repo](https://github.com/sagemath/sage/issues)"
1347 | ]
1348 | }
1349 | ],
1350 | "metadata": {
1351 | "kernelspec": {
1352 | "display_name": "SageMath 10.1.rc0",
1353 | "language": "sage",
1354 | "name": "sagemath"
1355 | },
1356 | "language_info": {
1357 | "codemirror_mode": {
1358 | "name": "ipython",
1359 | "version": 3
1360 | },
1361 | "file_extension": ".py",
1362 | "mimetype": "text/x-python",
1363 | "name": "python",
1364 | "nbconvert_exporter": "python",
1365 | "pygments_lexer": "ipython3",
1366 | "version": "3.11.5"
1367 | }
1368 | },
1369 | "nbformat": 4,
1370 | "nbformat_minor": 4
1371 | }
1372 |
--------------------------------------------------------------------------------