\documentclass[10pt,letterpaper]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{outlines}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{cancel}
\usepackage{subcaption}
\DeclareCaptionOptionNoValue{centering}{\centering} % Make sure everything is centered in subs
\captionsetup[sub]{centering}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\usepackage{multirow}
\usepackage{cancel}
\usepackage{float}

\usepackage{parskip}

\usepackage{slantsc,lmodern}

\usepackage{pgfplotstable,booktabs}
\usepackage{framed}
\definecolor{shadecolor}{rgb}{0.9,0.9,0.9}

\usepackage{gensymb}

\usepackage{paralist}

\usepackage[paper=a4paper,margin=1in]{geometry}

\usepackage{etoolbox}

\newcommand{\volume}{{\ooalign{\hfil$V$\hfil\cr\kern0.08em--\hfil\cr}}}

\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

\author{Thaddeus Hughes \\ hughes.thad@gmail.com \\ thaddeus-maximus.github.io}
\date{\today}
\title{Transient Modeling of Flywheel-Based Pitchers}

\begin{document}
	\maketitle

	\begin{abstract}
		Flywheel based pitchers are very common ways to propel projectiles. They are well-suited to many such cases in that they are reasonably light, do not require keeping track of states, provide inherent strength-of-shot adjustment, and can be used in continous applications.

		Unfortunately, they are somewhat of a mystery, with design essentially relegated to trial-and-error rather than intuitive understanding or numerical simulation. This paper aims to change that.
	\end{abstract}

	\section{Hooded Pitcher}

	Consider the following \textit{hooded} pitcher. A wheel (red) is spun up to an initial RPM, and then a ball (blue) is introduced between it and an arced hood (black), which is concentric with the wheel.

	\begin{figure}[H]
	\includegraphics[height=2.5in]{hood_pitcher.jpeg}
	\begin{tikzpicture}[x=1in, y=1in]
	\fill[BrickRed, ultra thick, opacity=0.5] (0,0) circle(0.7);
	\draw[BrickRed,  ultra thick] (0,0) circle (0.7);
	\draw[BrickRed, ultra thick, ->] (0,0.4) arc(90:-200:0.4);
	\draw[black, ultra thick, rotate=20, line width=4] (-1.5,0) arc (180:90:1.5);
	\fill[Blue, ultra thick, rotate=35, opacity=0.5] (-1.1,0) circle(0.4);
	\draw[Blue, ultra thick, rotate=35] (-1.1,0) circle(0.4);
	\draw[gray, ultra thick, rotate=15, ->] (-1.1,0) arc (180:90:1.1) -- (0.8,1.1);
	\end{tikzpicture}
	\caption{Hooded pitcher: example and schematic.}
	\end{figure}

	% [d_b, m_b, moi_rat_b, k_b, w, d_w, I_w, mu_w, mu_h, omega_w_0, theta_0, theta_end] = params_pack;

	There are already many parameters of interest in this system.
	\begin{asparaenum}[]
		\item \textbf{$d_w$}, the wheel diameter
		\item $I_w$, the wheel's moment of inertia
		\item $\omega_{w,0}$, the wheel's initial velocity
		\item $d_b$, the ball's initial diameter
		\item $I_b$, the ball's moment of inertia
		\item $w$, the gap between the hood and the surface of the wheel
		\item $\theta$, the angle between inlet and outlet
	\end{asparaenum}

	The ball is accelerated as the wheel makes contact with the ball. The hood provides constraint, keeping the ball from simply spinning. Free-body diagrams may make this more clear.

	\begin{figure}[H]
	\begin{tikzpicture}[x=1.3in, y=1.3in]
	\fill[Blue, ultra thick, opacity=0.5] (0,0) circle(0.4);
	\draw[Blue, ultra thick] (0,0) circle(0.4);
	\draw[Black, ultra thick, ->, rotate=-20] (.8,0) -- (0.5,0) node[pos=0.3, above]{$N_w$};
	\draw[Black, ultra thick, ->, rotate=-20] (-.8,0) -- (-0.5,0) node[pos=0.3, above]{$N_h$};
	\draw[Black, ultra thick, ->, rotate=-20] (0.45,-0.3) -- (0.45,0) node[pos=0, below]{$F_w$};
	\draw[Black, ultra thick, ->, rotate=-20] (-0.45,-0.3) -- (-0.45,0) node[pos=0, below]{$F_h$};

	\node[black] at (0.9,0) {=} ;

	\fill[Blue, ultra thick, opacity=0.5] (1.8,0) circle(0.4);
	\draw[Blue, ultra thick] (1.8,0) circle(0.4);

	\draw[Black, ultra thick, ->, shift={(1.8,0)}, rotate=-20] (0,0.05) -- (0,0.7) node[pos=0.85, left]{$m_b a_b$};
	\draw[Black, ultra thick, ->, shift={(1.8,0)}, rotate=-20] (0.05,0) -- (0.7,0) node[pos=0.85, above]{$m_b a_{b,r}$};
	\draw[Black, ultra thick, ->, shift={(1.8,0)}] (-0.47,0) arc (180:250:0.47) node[pos=0.5, left]{$I_b \alpha_b$};
	\end{tikzpicture}
	\caption{Free-Body and Kinetic Diagrams for Ball}
	\end{figure}

	For the sake of simplicity, gravity is neglected during this split-second interaction. This leads to force balances

	\begin{align}
		F_h + F_w = m_b a_b \\
		N_h - N_w = m_b a_{b,r} = m_b \frac{v_b^2}{R}\\
		(F_w - F_h) \frac{w}{2} = I_b \alpha_b ,
	\end{align}

	where $R$ is the radius of the path travelled by the ball ($R = \frac{d_w + w}{2}$).

	\begin{figure}[H]
	\begin{tikzpicture}[x=1.3in, y=1.3in]
	\fill[BrickRed, ultra thick, opacity=0.5] (0,0) circle(0.4);
	\draw[BrickRed, ultra thick] (0,0) circle(0.4);
	\draw[Black, ultra thick, ->, rotate=-20] (-.8,0) -- (-0.5,0) node[pos=0.3, above]{$N_w$};
	\draw[Black, ultra thick, ->, rotate=-20] (-0.45,0.3) -- (-0.45,0) node[pos=0, above]{$F_w$};

	\node[black] at (0.6,0) {=} ;

	\fill[BrickRed, ultra thick, opacity=0.5] (1.3,0) circle(0.4);
	\draw[BrickRed, ultra thick] (1.3,0) circle(0.4);
	\draw[Black, ultra thick, <-, shift={(1.3,0)}] (-0.47,0) arc (180:250:0.47) node[pos=0.5, left]{$I_w \alpha_w$};
	\end{tikzpicture}
	\caption{Free-Body and Kinetic Diagrams for Wheel}
	\end{figure}

	This leads to the torque balance

	\begin{align}
		- N_w \frac{d_w}{2} = I_w \alpha_w
	\end{align}

	At this point we have four governing equations, four unknown forces, and four unknown kinematic properties. Let's recap and solve what we have so far to get expressions for the accelerations.

	\begin{align}
		\alpha_{b}	&= (F_w - F_h) \frac{w}{2 I_b} \\
		a_b 		&= \frac{F_h + F_w}{m_b} \\
		\alpha_{w}	&= - F_w \frac{d_w}{2 I_w}
	\end{align}

	The normal force comes from the compression of the ball and wheel. But the ball is also accelerating along the axis of the compression, making this not quite straightforward. To help simplify, we'll also assume an infinitely rigid wheel (which is often a valid assumption).

	\begin{figure}[H]
	\begin{tikzpicture}[x=1.5in, y=1.5in]
		\draw[decoration={aspect=0.3, segment length=5mm, amplitude=5mm,coil},decorate] (-1,0) -- (+1,0);
		\draw[->, ultra thick] (-1.6,0) -- (-1.1,0) node[pos=0.5, above]{$N_h$};
		\draw[->, ultra thick] (+1.6,0) -- (+1.1,0) node[pos=0.5, above]{$N_w$};
		\draw[->, ultra thick] (0,0.3) -- (-0.5,0.3) node[pos=0, right]{$m_b a_{b,r} = m_b v_b^2 / R$};
	\end{tikzpicture}
	\caption{Massed spring model of the ball.}
	\end{figure}

	The inertial forces can be resolved in such a spring of stiffness $k_b$ squeezed by $\delta$ as so:
	\begin{align}
		N_h = k_b \delta + \frac{m_b a_{b,r}}{2} = k_b \delta + \frac{m_b v_b^2}{2 R} \\
		N_w = k_b \delta - \frac{m_b a_{b,r}}{2} = k_b \delta - \frac{m_b v_b^2}{2 R}
	\end{align}

	\textit{Observation: As the ball accelerates through the hood, it lifts off the wheel until $N_w = 0$. This effect is magnified with a smaller arc radius.}

	\section{Developing a Friction Model}

	We can relate the normal forces to the frictional or tangential forces with a basic coloumb friction model. More sophisticated models are probably more accurate, but the intent of this model is to provide intuitively understandable results and general guidelines which should be followed up by real-world testing, so this is an appropriate model.

	\begin{align}
		F_h \leq \mu_h N_h \ & \text{sign}(0 - v_{b,top}) \\
		F_w \leq \mu_w N_w \ & \text{sign}(v_{w,surf} - v_{b,bottom})
	\end{align}

	Implementing this verbatim poses serious simulation problems. The simulation will oscillate back and forth between a positive and negative sign function, potentially crashing. There are many strategies to solve this problem, usually by solving accuracy of the math or investing in a complex solver. However, our case can be simplified algebraically up front, which will help make a much more stable solver.

	First, recognize that the sign associated with the wheel should either be positive or zero. The ball isn't going to start over-spinning with the wheel.
	Second, recognize that the spin of the ball should never exceed the speed of the ball such that the top of the ball travels backwards, so its sign should be negative or zero.
	Third, the sign becomes zero, the condition to calculate is no longer one of two surfaces at arbitrary velocities exchanging forces, but of two surfaces that have \textit{coupled}. This brings the driving physics away from force balance and towards pure kinematics. That is to say,

	\begin{align}
		v_{w,surf} = v_{b,bottom} \nonumber \\
		a_{w,surf} = a_{b,bottom} \nonumber \\
		\alpha_{w} \frac{d_w}{2} = a_{b} + \alpha_{b} \frac{w}{2}
	\end{align}

	and

	\begin{align}
		0 = v_{b,top} \nonumber \\
		0 = a_{b,top} \nonumber \\
		0 = a_{b} - \alpha_{b} \frac{w}{2} .
	\end{align}

	Substituting what we found earlier about the accelerations gives us

	\begin{align}
		- F_w \frac{d_w}{2 I_w} \frac{d_w}{2} = \frac{F_h + F_w}{m_b} + (F_w - F_h) \frac{w}{2 I_b} \frac{w}{2} \nonumber \\
		F_w \frac{d_w}{2 I_w} + \frac{F_w}{m_b} + F_w \frac{w}{2 I_b} \frac{w}{2} = - \frac{F_h}{m_b} + F_h \frac{w}{2 I_b} \frac{w}{2} \nonumber \\
		F_w = F_h \frac{\frac{w^2}{4 I_b} - \frac{1}{m_b}}{\frac{d_w}{2 I_w} + \frac{1}{m_b} + \frac{w^2}{4 I_b}}
	\end{align}

	in the case of no wheel slip, and

	\begin{align}
		0 = \frac{F_h + F_w}{m_b} - (F_w - F_h) \frac{w}{2 I_b} \frac{w}{2} \nonumber \\
		\frac{F_h}{m_b} + F_h \frac{w}{2 I_b} \frac{w}{2} = - \frac{F_w}{m_b} + F_h \frac{w}{2 I_b} \frac{w}{2} \nonumber \\
		F_h = F_w \frac{\frac{w^2}{4 I_b} - \frac{1}{m_b}}{\frac{w^2}{4 I_b} + \frac{1}{m_b}}
	\end{align}

	in the case of no hood slip. In these cases, the force of one is directly proportional to the other;
	\begin{align}
		F_h = K_1 F_w \\
		F_w = K_2 F_h
	\end{align}

	This means that when both hood and wheel stop slipping,

	\begin{align}
		F_h = F_w = 0 \text{ if } K_1 \neq K_2 \neq 0
	\end{align}

	But how is state determined? We simply go back to the sign equations.
	\begin{align}
		\textit{top attached when }& 0 \leq v_{b} - \omega_{b} \frac{w}{2} \\
		\textit{bottom attached when }& \omega_{w} \frac{d_w}{2} \leq v_{b} + \omega_{b} \frac{w}{2}
	\end{align}

	This developed friction model can be summarized with this pseudocode, which would be ran every iteration of the simulation loop.

\begin{algorithm}
	\begin{algorithmic}
	\State $\textit{Fw} \gets \textit{mw Nw}$
	\State $\textit{Fh} \gets \textit{mh Nh}$
	\If{$\textit{hood attached} \ \text{and} \ \textit{wheel attached}$}
	\State $\textit{Fw} \gets 0$
	\State $\textit{Fh} \gets 0$
	\ElsIf{$\textit{wheel attached}$}
	\State $\textit{Fw} \gets \textit{Fw in attached state}$
	\ElsIf{$\textit{hood attached}$}
	\State $\textit{Fh} \gets \textit{Fh in attached state}$
	\EndIf
	\BState
	\BState $\textit{... insert interesting simulation code ...}$
	\BState
	\If{$\textit{ball top speed goes positive}$}
	\State $\textit{hood attached} \gets \text{true}$
	\EndIf
	\If{$\textit{ball bottom speed exceeds wheel speed}$}
	\State $\textit{wheel attached} \gets \text{true}$
	\EndIf
	\end{algorithmic}
\end{algorithm}

	All that's left is to set up the state equations and initial conditions.

	\begin{align}
		\frac{d}{dt} \omega_b &= \alpha_b \\
		\frac{d}{dt} v_b &= a_b \\
		\frac{d}{dt} u_b &= v_b \\
		\frac{d}{dt} \omega_w &= \alpha_w \\
		v_b(0) &= 0 \\
		u_b(0) &= 0 \\
		\omega_w(0) &= \omega_{w,0} \\
		\textit{when} \ u_b &\geq \theta R \ \textit{terminate}
	\end{align}

\section{Dual-Wheel Pitchers}

Dual wheel pitchers are a little more complex as the effective gap is not constant during the ball's motion, and the wheel's normal forces contribute to ball acceleration. However, the basic strategy remains the same.

\begin{figure}[H]
	\includegraphics[height=2.5in]{dual_pitcher.png}
	\begin{tikzpicture}[x=0.7in, y=0.7in]
	\fill[BrickRed, ultra thick, opacity=0.5] (0,0) circle(0.6);
	\draw[BrickRed,  ultra thick] (0,0) circle (0.6);
	\fill[BrickRed, ultra thick, opacity=0.5, rotate=20] (0,2) circle(0.6);
	\draw[BrickRed,  ultra thick, rotate=20] (0,2) circle (0.6);
	\draw[BrickRed, ultra thick, ->, rotate=20] (0,0.4) arc(90:-200:0.4);
	\draw[BrickRed, ultra thick, <-, rotate=20] (0,2.4) arc(90:-200:0.4);
	\fill[Blue, ultra thick, rotate=20, opacity=0.5] (-0.45,1) circle(0.5);
	\draw[Blue, ultra thick, rotate=20] (-0.45,1) circle(0.5);
	\draw[gray, ultra thick, rotate=20, ->] (0,1) -- (1.2,1);
	\end{tikzpicture}
	\caption{Dual wheel pitcher: example and schematic.}
\end{figure}

Some critical dimensions are:

\begin{figure}[H]
	\begin{tikzpicture}[x=1in, y=1in]
	\fill[gray, ultra thick, opacity=0.5] (0,0) circle(0.7);
	\draw[gray,  ultra thick] (0,0) circle (0.7);
	\fill[gray, ultra thick, opacity=0.5, rotate=20] (0,2) circle(0.4);
	\draw[gray,  ultra thick, rotate=20] (0,2) circle (0.4);
	\fill[gray, ultra thick, rotate=20, opacity=0.5] (-0.45,1.17) circle(0.5);
	\draw[gray, ultra thick, rotate=20] (-0.45,1.17) circle(0.5);
	\draw[black, dashed, thick, rotate=20] (0,0) -- (0,2);
	\draw[black, dashed, thick, rotate=20] (0,0) -- (-0.45,1.17);
	\draw[black, dashed, thick, rotate=20] (0,2) -- (-0.45,1.17);
	\draw[black, ultra thick, <-] (0.75,0) -- (1.0,0) node[pos=1,right]{Ø$d_L$};
	\draw[black, ultra thick, <-, rotate=20] (0.45,2) -- (0.7,2) node[pos=1,right]{Ø$d_T$};
	\draw[black, ultra thick, <-, rotate=20] (-1.0,1.17) -- (-1.25,1.17) node[pos=1,left]{Ø$d_b$};
	\draw[red, ultra thick, ->, rotate=20] (0.05,0) -- (0.5,0) node[black,pos=0.5,above]{$x$};
	\draw[Green, ultra thick, ->, rotate=20] (0,0.05) -- (0,0.5) node[black,pos=0.5,right]{$y$};
	\draw[black, ultra thick, <-, rotate=20] (0,0.8) arc(90:75:0.8);
	\draw[black, ultra thick, <-, rotate=43] (0,0.8) arc(90:120:0.8) node[pos=1,left]{$- \theta$};
	\draw[black, ultra thick, <-, rotate=20] (0,1.4) arc(270:285:0.6);
	\draw[black, ultra thick, <-, rotate=20] (-0.27,1.47) arc(240:205:0.6) node[pos=1,left]{$- \psi$};
	\end{tikzpicture}
	\caption{Dual wheel pitcher key dimensions and coordinates. Note sign on angles.}
\end{figure}

Geometry allows us to relate these as so:
\begin{align}
	tan \theta &= \frac{x}{y} \\
	tan \psi   &= \frac{x}{\frac{d_L+d_T}{2} + w - y}
\end{align}

%Note at the beginning (and end),
%\begin{align}
%	x &= \frac{d_b + d_L}{2} sin \theta \\
%	x &= \frac{d_b + d_T}{2} sin \psi \\
%	y &= \frac{d_b + d_L}{2} cos \theta \\
%	y &= \frac{d_L+d_T}{2} + w - \frac{d_b + d_T}{2} cos \psi
%\end{align}

The instantaneous radii of the ball (distance from center of ball to top and bottom wheels) can be readily computed.
\begin{align}
	R_B = \sqrt{x^2 + y^2} - \frac{d_B}{2} \\
	R_T = \sqrt{x^2 + (\frac{d_T+d_B}{2} + w - y)^2} - \frac{d_T}{2}
\end{align}

To analyze the ball, begin by drawing free-body and kinetic diagrams.

\begin{figure}[H]
	\begin{tikzpicture}[x=1.3in, y=1.3in]
	\draw[red, ultra thick, ->, shift={(-1.4,0)}] (0.05,0) -- (0.4,0) node[black,pos=0.5,above]{$x$};
	\draw[Green, ultra thick, ->, shift={(-1.4,0)}] (0,0.05) -- (0,0.4) node[black,pos=0.5,right]{$y$};
	\fill[Blue, ultra thick, opacity=0.5] (0,0) circle(0.4);
	\draw[Blue, ultra thick] (0,0) circle(0.4);
	\draw[Black, ultra thick, ->, rotate=-110] (.8,0) -- (0.5,0) node[pos=0, right]{$N_L$};
	\draw[Black, ultra thick, ->, rotate=-80] (-.8,0) -- (-0.5,0) node[pos=0, right]{$N_T$};
	\draw[Black, ultra thick, ->, rotate=-110] (0.45,-0.3) -- (0.45,0) node[pos=0, below]{$F_L$};
	\draw[Black, ultra thick, ->, rotate=-80] (-0.45,-0.3) -- (-0.45,0) node[pos=0, left]{$F_T$};

	\node[black] at (0.9,0) {=} ;

	\fill[Blue, ultra thick, opacity=0.5] (1.8,0) circle(0.4);
	\draw[Blue, ultra thick] (1.8,0) circle(0.4);

	\draw[Black, ultra thick, ->, shift={(1.8,0)}] (0,0.05) -- (0,0.7) node[pos=0.85, left]{$m_b a_y$};
	\draw[Black, ultra thick, ->, shift={(1.8,0)}] (0.05,0) -- (0.7,0) node[pos=0.85, above]{$m_b a_x$};
	\draw[Black, ultra thick, ->, shift={(1.8,0)}] (-0.47,0) arc (180:250:0.47) node[pos=0.5, left]{$I_b \alpha_b$};
	\end{tikzpicture}
	\caption{Free-Body and Kinetic Diagrams for Ball}
\end{figure}

\begin{align}
	F_T cos \psi + F_L cos \theta + N_T sin \psi + N_L sin \theta &= m_b a_x \\
	F_T sin \psi - F_L sin \theta - N_T cos \psi + N_L cos \theta &= m_b a_y \\
	F_L R_L - F_T R_T &= I_b \alpha_b
\end{align}

We will assume negligible vertical acceleration, so $a_y = 0$. We can then solve and find

\begin{align}
	a_x = \frac{F_T cos \psi + F_L cos \theta + N_T sin \psi + N_L sin \theta}{m_b} \\
	\alpha_b = \frac{F_L R_L - F_T R_T}{I_b}
\end{align}

As for the flywheel, there are two cases: the flywheels are separately powered and not linked, and the flywheels are centrally powered and linked. The indepdendent case is the same as that of the hooded pitcher, that is to say,
\begin{align}
	\alpha_{T,free}	&= - F_T \frac{d_T}{2 I_T} \\
	\alpha_{L,free}	&= - F_L \frac{d_L}{2 I_L}
\end{align}

In the linked case, a gear ratio $G$ constrains the two wheels, which imparts torque $T_w$.

\begin{figure}[H]
	\begin{tikzpicture}[x=1.3in, y=1.3in]
	\fill[BrickRed, ultra thick, opacity=0.5] (0,0) circle(0.4);
	\draw[BrickRed, ultra thick] (0,0) circle(0.4);
	\draw[Black, ultra thick, ->, rotate=-20] (-.8,0) -- (-0.5,0) node[pos=0.3, above]{$N_w$};
	\draw[Black, ultra thick, ->, rotate=-20] (-0.45,0.3) -- (-0.45,0) node[pos=0, above]{$F_w$};
	\draw[Black, ultra thick, ->] (0,0.25) arc (90:300:0.25) node[pos=0.45, right]{$T_w$};

	\node[black] at (0.6,0) {=} ;

	\fill[BrickRed, ultra thick, opacity=0.5] (1.3,0) circle(0.4);
	\draw[BrickRed, ultra thick] (1.3,0) circle(0.4);
	\draw[Black, ultra thick, <-, shift={(1.3,0)}] (-0.47,0) arc (180:250:0.47) node[pos=0.5, left]{$I_w \alpha_w$};
\end{tikzpicture}
\caption{Free-Body and Kinetic Diagrams for Wheel}
\end{figure}

This leads to the torque balance

\begin{align}
	- N_w \frac{d_w}{2} - T_w = I_w \alpha_w \nonumber \\
	- F_T \frac{d_T}{2} - T_T = I_T \alpha_T \\
	- F_B \frac{d_B}{2} - T_B = I_B \alpha_B
\end{align}

The two wheels are coupled by a gear reduction $G$.

\begin{align}
	\alpha_L = \alpha_T G \\
	- T_L G = T_T
\end{align}

Solving these four equations yields

\begin{align}
	\alpha_{L,coupled} = \frac{- F_T \frac{d_T}{2 G} - F_L \frac{d_L}{2}}{I_L + I_T / G^2} \\
	\alpha_{T,coupled} = \alpha_L / G = \frac{- F_T \frac{d_T}{2 G} - F_L \frac{d_L}{2}}{G I_L + I_T / G}
\end{align}

The ball can, again, be modeled as a spring.

\begin{figure}[H]
	\begin{tikzpicture}[x=0.8in, y=0.8in]
	\draw[decoration={aspect=0.3, segment length=3mm, amplitude=3mm,coil},decorate, rotate=-20] (0,0) -- (0,-1);
	\draw[decoration={aspect=0.3, segment length=3mm, amplitude=3mm,coil},decorate, rotate=+20] (0,0) -- (0,+1);
	\draw[->, ultra thick, rotate=-20] (0,-1.5) -- (0,-1.1) node[pos=0.5, right]{$N_L$};
	\draw[->, ultra thick, rotate=+20] (0,+1.5) -- (0,+1.1) node[pos=0.5, right]{$N_T$};
	%\draw[->, ultra thick] (0,0) -- (-0.9,0) node[pos=.8, above]{$m_b a_{b,x}$};
	%\draw[->, ultra thick] (0,0) -- (0,-0.5) node[pos=.6, right]{$m_b a_{b,y}$};
	\end{tikzpicture}
	\caption{2-D spring model for ball}
\end{figure}

% Uh oh. This has rammifications

The friction model that follows is the same idea as that of the hooded pitcher, though it contains many more terms.

When the lower wheel grips:
\begin{align}
	v_{L,surf} = v_{b,bottom} \nonumber \\
	a_{L,surf} = a_{b,bottom} \nonumber \\
	\alpha_{L} \frac{d_L}{2} = a_{b} cos \theta + \alpha_{b} R_L \\
\end{align}

When the top wheel grips:
\begin{align}
	v_{T,surf} = v_{b,top} \nonumber \\
	a_{T,surf} = a_{b,top} \nonumber \\
	\alpha_{T} \frac{d_T}{2} = a_{b} cos \psi - \alpha_{b} R_T \\
\end{align}

First let's handle the simpler case of free, uncoupled wheels. For the lower side, we need to find $F_L$.
\begin{align}
	- F_L \frac{d_L}{2 I_L} \frac{d_L}{2} = (\frac{F_T cos \psi + F_L cos \theta + N_T sin \psi + N_L sin \theta}{m_b}) cos \theta + \frac{F_L R_L - F_T R_T}{I_b} R_L \\
	(\frac{N_T sin \psi + N_L sin \theta}{m_b}) cos \theta + F_T \frac{R_T}{I_b} R_L - \frac{F_T}{m_b} cos \psi cos \theta - F_L \frac{d_L}{2 I_L} \frac{d_L}{2} - \frac{F_L}{m_b} cos^2 \theta - F_L \frac{R_L^2}{I_b} = 0\\
	\textit{recognizing that this can be written in the form of } A + B F_T + C F_L = 0 \\
	A = (N_T sin \psi + N_L sin \theta) \frac{cos \theta}{m_b} \\
	B = \frac{R_T R_L}{I_b} - \frac{cos \psi cos \theta}{m_b} \\
	C = - \frac{d_L^2}{4 I_L} - \frac{cos^2 \theta}{m_b} - \frac{R_L^2}{I_b} \\
	F_{L,\ bottom\ gripped,\ free\ wheels} = \frac{A + B F_T}{- C}
\end{align}

For the top side, we need $F_T$.
\begin{align}
	- F_T \frac{d_T}{2 I_T} \frac{d_T}{2} = (\frac{F_T cos \psi + F_L cos \theta + N_T sin \psi + N_L sin \theta}{m_b}) cos \psi - \frac{F_L R_L - F_T R_T}{I_b} R_T \\
	(\frac{N_T sin \psi + N_L sin \theta}{m_b}) cos \psi - F_T \frac{R_T}{I_b} R_T - \frac{F_T}{m_b} cos^2 \psi - F_T \frac{d_T}{2 I_T} \frac{d_T}{2} + \frac{F_L}{m_b} cos \theta cos \psi - F_L \frac{R_L R_T}{I_b} = 0\\
	\textit{recognizing that this can be written in the form of } D + E F_L + F F_T = 0 \\
	D = (N_T sin \psi + N_L sin \theta) \frac{cos \psi}{m_b} \\
	E = \frac{R_L R_T}{I_b} - \frac{cos \theta cos \psi}{m_b} \\
	F = - \frac{d_T^2}{4 I_T} - \frac{cos^2 \psi}{m_b} - \frac{R_T^2}{I_b} \\
	F_{T,\ top\ gripped,\ free\ wheels} = \frac{D + E F_L}{- F}
\end{align}

The same analysis is repeated for the coupled flywheel case. When the lower wheel grips, we need to find $F_L$.
\begin{align}
	\frac{- F_T \frac{d_T}{2 G} - F_L \frac{d_L}{2}}{I_L + I_T / G^2} \frac{d_L}{2} = \nonumber \\
	(\frac{F_T cos \psi + F_L cos \theta + N_T sin \psi + N_L sin \theta}{m_b}) cos \theta + \frac{F_L R_L - F_T R_T}{I_b} R_L \\
	(\frac{N_T sin \psi + N_L sin \theta}{m_b}) cos \theta + F_T \frac{R_T}{I_b} R_L - \frac{F_T}{m_b} cos \psi cos \theta - F_T \frac{\frac{d_T}{2 G}}{I_L + I_T / G^2} \frac{d_L}{2} \nonumber \\
	- F_L \frac{\frac{d_L}{2}}{I_L + I_T / G^2} \frac{d_L}{2} - \frac{F_L}{m_b} cos^2 \theta - F_L \frac{R_L^2}{I_b} = 0\\
	\textit{recognizing that this can be written in the form of } A + B F_T + C F_L = 0 \\
	A = (N_T sin \psi + N_L sin \theta) \frac{cos \theta}{m_b} \\
	B = \frac{R_T R_L}{I_b} - \frac{cos \psi cos \theta}{m_b} - \frac{\frac{d_T d_L}{4 G}}{I_L + I_T / G^2} \\
	C = - \frac{\frac{d_L^2}{4}}{I_L + I_T / G^2} - \frac{cos^2 \theta}{m_b} - \frac{R_L^2}{I_b} \\
	F_{L,\ bottom\ gripped,\ free\ wheels} = \frac{A + B F_T}{- C}
\end{align}

For the top side, we need $F_T$.
\begin{align}
	\frac{- F_T \frac{d_T}{2 G} - F_L \frac{d_L}{2}}{G I_L + I_T / G} \frac{d_T}{2} = \nonumber \\
	(\frac{F_T cos \psi + F_L cos \theta + N_T sin \psi + N_L sin \theta}{m_b}) cos \psi - \frac{F_L R_L - F_T R_T}{I_b} R_T \\
	(\frac{N_T sin \psi + N_L sin \theta}{m_b}) cos \psi - F_T \frac{R_T}{I_b} R_T - \frac{F_T}{m_b} cos^2 \psi - F_T \frac{\frac{d_T}{2 G}}{G I_L + I_T / G} \frac{d_T}{2} \nonumber \\
	- F_L \frac{\frac{d_L}{2}}{G I_L + I_T / G} \frac{d_T}{2} - \frac{F_L}{m_b} cos \theta cos \psi + F_L \frac{R_L R_T}{I_b} = 0 \\
	\textit{recognizing that this can be written in the form of } D + E F_L + F F_T = 0 \\
	D = (N_T sin \psi + N_L sin \theta) \frac{cos \psi}{m_b} \\
	E = \frac{R_L R_T}{I_b} - \frac{\frac{d_L d_T}{4}}{G I_L + I_T / G} - \frac{cos \theta cos \psi}{m_b} \\
	F = - \frac{\frac{d_T^2}{4 G}}{G I_L + I_T / G} - \frac{cos^2 \psi}{m_b} - \frac{R_T^2}{I_b} \\
	F_{T,\ top\ gripped,\ free\ wheels} = \frac{D + E F_L}{- F}
\end{align}

For the case of both being gripped, we simply solve simultaneously.
\begin{align}
	A + B F_T + C F_L = 0 \text{ and } D + E F_L + F F_T = 0 \nonumber \\
	F_{L,\ both\ gripped} = \frac{A F-B D}{B E-C F} \\
	F_{T,\ both\ gripped} = \frac{C D-A E}{B E-C F}
\end{align}

State is determined as

\begin{align}
	\textit{top attached when } \omega_{T} \frac{d_T}{2} \leq v_{b} - \omega_{b} R_T \\
	\textit{lower attached when } \omega_{L} \frac{d_L}{2} \leq v_{b} + \omega_{b} R_L .
\end{align}

	All that's left is to set up the state equations and initial conditions.

	\begin{align}
		\frac{d}{dt} \omega_b &= \alpha_b \\
		\frac{d}{dt} v_b &= a_b \\
		\frac{d}{dt} x &= v_b \\
		\frac{d}{dt} \omega_T &= \alpha_T \\
		\frac{d}{dt} \omega_L &= \alpha_L \\
		v_b(0) &= 0 \\
		x(0) &= 0 \\
		\omega_T(0) &= \omega_{T,0} \\
		\omega_L(0) &= \omega_{L,0} \\
		\textit{when} \ x > x_end \ \textit{terminate}
	\end{align}

\section{Hybrid Pitchers}
An interesting design proliferated during the FRC 2020 season, consisting of a hooded pitcher with an extra set of 'afterburner' wheels where the hood would terminate. This could be modeled fairly easily (I simply haven't gotten to it yet). I may transfer the calculator into a single one consisting of only the hybrid pitcher, as hooded and dual-wheel pitchers could be considered just special cases.

\section{Sanity Checks}
	These are new analysis techniques so there is no prior art to compare to. However, we can still perform some sanity checks.

	\begin{figure}[H]
		\includegraphics[width=\textwidth]{validation/hood_EC_A.png}
		\caption{Hooded Flywheel Calculator - Exemplary Case}
	\end{figure}

	We can quickly check the relationship between ball velocity, ball spin, and wheel speed at exit. If the ball has finally latched onto the wheel, we'd see that the surface speeds of the wheel and ball should match. That is to say,

	\begin{align}
		v_b + \omega_b \frac{w}{2} = \omega_w \frac{d_w}{2}.
	\end{align}

	Numerically in this case,
	\begin{align}
		31.766 \frac{\text{ft}}{\text{s}} + 1456 \ \text{RPM} \times \frac{2 \pi / 60 \text{rad/s}}{\text{RPM}} \times \frac{5}{2} \text{in} \times \frac{\text{ft}}{12 \text{in}} &= 2426.6 \ \text{RPM} \times \frac{2 \pi / 60 \text{rad/s}}{\text{RPM}} \times \frac{6}{2} \text{in} \times \frac{\text{ft}}{12 \text{in}} \\
		63.5310 \frac{\text{ft}}{\text{s}} &\approx 63.5282 \frac{\text{ft}}{\text{s}} .
	\end{align}

	Is the wheel drop realistic? Let's look at the lost energy. There's definitely some losses as the ball interaction has friction, but let's quantify it.

	\begin{align}
		E = m_b v_b^2 + I_b \omega_b^2 + I_w \omega_w^2 \\
		E_{init} = 4 \text{$lbm\ in^2$} \times (3000 \text{RPM})^2 &= 115.5 \text{J} \\
		E_{final} = 0.3 \text{lbm} \times (31.766 \text{ft/s})^2 \nonumber \\
		+ \frac{2}{5} 0.3 \text{lbm} (\frac{5 \text{in}}{2})^2 \times (1456 \text{RPM})^2 \nonumber \\
		+ 4 \text{$lbm\ in^2$} \times (2426 \text{RPM})^2 &= 93.45 \text{J} \\
		\eta = \frac{E_{final}}{E_{init}} = \frac{93.45 \text{J}}{115.5 \text{J}} &= 80.9 \%
	\end{align}

	That's an efficiency less than 100\% (good, physics didn't break), and it isn't dreadfully low (signalling that there isn't too much slippage).

	The rev-up simulation does have some prior art to compare to, luckily. We can run basically the exact same simulation in the simple mechanism calculator.

	\begin{figure}[H]
		\includegraphics[width=\textwidth]{validation/hood_ECrev_A.png}
		\caption{Revving up a 4 $lbm\ in^2$ flywheel with a single NEO motor.}
	\end{figure}

	This shows it takes 0.154 seconds to rev up, nearly the same as the 0.153 in the previous example. Note that the efficiency is specified as 100 percent, as the rev-up calculator instead uses a different bearing friction value that the general mechanism calculator doesn't have.
\end{document}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage[utf8]{luainputenc}
\usepackage{aeguill}
\usepackage{setspace}

\tikzstyle{edge} = [fill,opacity=.5,fill opacity=.5,line cap=round, line join=round, line width=50pt]
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{13 février, 2015}
\maketitle
\section*{1.4 directed graphs}
{\bfseries digraphs} are graphs with orientations (arrows) on the edges

every term from graphs has a directed version for digraphs.

one notable lexicographical difference: edges are called {\bfseries arcs}.

\subsection*{examples}
\tikz\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]
  graph [tree layout] { 1<-2, 1->3, 1<-4->5,2->3,{2,3}<-5}
  [shift=(0:1)];

a digraph is {\bfseries weakly connected} if the underlying graph is connected.

a digraph is {\bfseries strongly connected} if for every $u,v\in V(G)$, there exists a directed $u-v$ path and a directed $v-u$ path.

\subsection*{thrm}
a digraph is strongly connected iff it contains a closed spanning directed walk.

\subsection*{notes}
in proving things about digraphs, the degree of a vertex is nuanced. eg arcs in and arcs out might be different numbers. so we say: let $D$ be a digraph and $v\in V(D)$ and we say {\bfseries id$(v)$} is the number of incoming arcs to $v$ and {\bfseries od$(v)$} is the number of outgoing arcs

\section*{4.1 directed graphs}
if $D$ is a simple digraph of size $m$ then $\sum\limits{\text{od}(v)}=\sum\limits{\text{id}(v)}=m$

\section*{eulerian digraphs}
eulerian circuit that is directed
\subsection*{thm}
a digraph $D$ has an eulerian circuit iff od$(v)=$id$(v)$ for all $v\in V(D)$
\subsubsection*{proof}
basically identical to undirected case

need everything to be even so we can go in and out, now we need to be able to go in and out similarly

\subsection*{thm}
a digraph $D$ has an eulerian path iff id$(v)=$od$(v)$ for all vertices but two called $u,v$ and od$(u)=$id$(u)+1$ and id$(v)=$od$(v)+1$
\section*{Homework}
2,7
\end{document}


% !TEX root = main.tex
% !TEX spellcheck = en-US

\section{Non-malleability of Marlin}
We show that $\marlin$ is \COMMENT{forking }simulation-extractable. To that end, we show
that $\marlin$ has all the required properties: has unique response property, is
rewinding-based knowledge sound, and its simulator can provide indistinguishable proofs
without a trapdoor, just by programming the random oracle.

\subsection{$\marlin$ Protocol Rolled-out}
$\marlin$ uses R1CS as its arithmetization method. Given
instance $\inp$, witness $\wit$ and $|\HHH| \times |\HHH|$ matrices $\vec{A},
\vec{B}, \vec{C}$, the prover shows that $\vec{A} (\inp^\top, \wit^\top)^\top \circ \vec{B}
(\inp^\top, \wit^\top)^\top = \vec{C} (\inp^\top, \wit^\top)^\top$, where
$\circ$ denotes entry-wise product.

We assume that the matrices have at most $|\KKK|$ non-zero entries. Obviously,
$|\KKK| \leq |\HHH|^2$. Let $b = 3$, the upper-bound of polynomial evaluations
the prover has to provide for each of the sent polynomials.  Denote by $\dconst$
an upper-bound for $\smallset{|\HHH| + 2b -1, 2 |\HHH| + b - 1, 6 |\KKK| - 6}$.

The idea of showing that the constraint system is fulfilled is as
follows. Denote by $\vec{z} = (\inp, \wit)$. The prover computes polynomials
$\p{z_A} (X), \p{z_B} (X), \p{z_C} (X)$ which encode vectors
$\vec{A} \vec{z}, \vec{B} \vec{z}, \vec{C} \vec{z}$ and have degree $<
|\HHH|$. Importantly, when constraints are fulfilled,
$ \p{z_A} (X) \p{z_B} (X) - \p{z_C} (X) = \p{h_0} (X) \ZERO_\HHH (X)$, for some
$\p{h_0} (X)$ and vanishing polynomial $\ZERO_\HHH (X)$. The prover sends
commitments to these polynomials and shows that they have been computed
correctly. More precisely, it shows that
\begin{equation}
  \label{eq:marlin_eq_2}
\forall \vec{M} \in \smallset{\vec{A}, \vec{B}, \vec{C}},  \forall \kappa \in \HHH,
\p{z_M} (\kappa) = \sum_{\iota \in \HHH} \vec{M}[\kappa, \iota] \p{z}(\iota).
\end{equation}

The ideal verifier checks the following equalities
\begin{equation}
  \label{eq:marlin_ver_eq}
  \begin{aligned}
    \p{h}_3 (\beta_3) \ZERO_\KKK (\beta_3) & = \p{a} (\beta_3) - \p{b} (\beta_3)
    (\beta_3 \p{g_3} (\beta_3) + \sigma_3 / |\KKK|)\\
    \p{r}(\alpha, \beta_2) \sigma_3 & = \p{h_2} (\beta_2) \ZERO_\HHH (\beta_2) +
    \beta_2 \p{g2} (\beta_2) + \sigma_2/|\HHH|\\
    \p{s}(\beta_1) + \p{r}(\alpha, \beta_1) (\sum_M \eta_M \p{z_M} (\beta_1)) -
    \sigma_2 \p{z} (\beta_1) & = \p{h_1} (\beta_1) \ZERO_\HHH (\beta_1) +
    \beta_1
    \p{g_1} (\beta_1) + \sigma_1/|\HHH| \\
    \p{z_A} (\beta_1) \p{z_B} (\beta_1) - \p{z_C} (\beta_1) & = \p{h_0}
    (\beta_1) \ZERO_\HHH (\beta_1)
  \end{aligned}
\end{equation}
where $\p{g_i} (X), \p{h_i} (X)$, $i \in \range{1}{3}$,
$\p{a} (X), \p{b} (X), \sigma_1, \sigma_2, \sigma_3$ are polynomials and
variables required by the sumcheck protocol which allows the verifier to efficiently
verify that \cref{eq:marlin_eq_2} holds.

\subsection{Unique Response Property}
\begin{lemma}\label{lem:marlinprot_ur}
  Let $\PCOM$ be a commitment of knowledge that is evaluation binding with security loss
  $\epsbind(\secpar)$ and has unique opening property with security loss
  $\epsop(\secpar)$. Then
  $\marlinprotfs$ is $\ur{2}$ against algebraic adversaries with security loss $2 \cdot \epsbinding (\secpar) + \epsop (\secpar)$.
\end{lemma}

\begin{proof}
	The proof is similar to the proof of \cref{lem:plonkprot_ur} and \cref{lem:sonicprot_ur}.
	An adversary who can break the $2$-unique response property of $\marlinprotfs$ can be either used to break the commitment scheme's evaluation binding or unique opening property. The former happens with the probability upper-bounded by $2 \cdot \epsbinding (\secpar)$, the latter with probability at most $\epsop (\secpar)$.
	By the union bound, the adversary is able to break the unique response property with probability upper bounded by $2 \cdot \epsbinding (\secpar) + \epsop (\secpar)$.
	\qed
	\end{proof}
%  \changedm{$11 \cdot (\epsop (\secpar)) + 6 \cdot \epsbind (\secpar) +
%    \infrac{3}{\abs{\FF_p}}.$} \mxout{$6 \cdot (\epsbind + \epsop + \epsk) + \epss$}

\COMMENT{\changedm{
\begin{proof}
  Let $\adv$ be an algebraic adversary tasked to break the $\ur{2}$-ness of
  $\marlinprotfs$. We show that the first prover's message determines, along with
  the verifiers challenges, the rest of it.  This is done by game hops. In the games,
  the adversary outputs two proofs $\zkproof^0$ and $\zkproof^1$ for the same statement.
  To distinguish polynomials and commitments which an honest prover sends in the
  proof from the polynomials and commitments computed by the adversary we write the
  latter using indices $0$ and $1$ (two indices as we have two transcripts), e.g.~to
  describe a polynomial provided by the adversary we write $\p{f}^0$ and
  $\p{f}^1$ instead of $\p{f}$ as in the description of the protocol.

  \ngame{0} In this game, the adversary additionally wins if it provides two transcripts that
  match on all $5$ messages sent by the prover.
  Obviously, in this game the adversary cannot win.

  \ngame{1} This game is identical to Game $\game{0}$ except that now the
  adversary additionally wins if it provides two transcripts that matches on the first four
  messages of the proof.

  \ncase{Game 0 to Game 1} We show that the probability that $\adv$ wins in one game but
  does not in the other is negligible.  Observe that in its $4$-th message, the
  adversary is given a challenge $\beta_3$ and has to open the previously computed
  commitments for polynomials $\p{g_3} (X), \p{h_3} (X)$. Since the transcripts match up
  to $\adv$'s $4$-th message, the challenge is the same in both.  Also, the adversary
  evaluates and opens evaluations of polynomials $\p{g_2} (X), \p{h_2} (X)$ evaluated at
  $\beta_2$ and
  $\p{s} (X), \p{z} (X), \p{z_A} (X), \p{z_B} (X), \p{z_C} (X), \p{h_1} (X), \p{g_1} (X)$
  evaluated at $\beta_1$. Hence, to be able to give two different openings in its $5$-th
  message, $\adv$ has to break the unique opening property of the KZG commitment scheme
  which happens with probability $11 \cdot \epsop (\secpar)$ tops (as $11$ polynomials are
  evaluated).

  \ngame{2} This game is identical to Game $\game{1}$ except that now the
  adversary additionally wins if it provides two transcripts that matches on the
  first three messages of the proof.

  \ncase{Game 1 to Game 2} In its $4$-th message the adversary
  provides $\sigma_3$ and commits to polynomials $\p{g_3} (X), \p{h_3} (X)$ which are
  uniquely determined. Probability that the adversary commits to wrong polynomials that it
  can later evaluate to correct values (i.e.~to values of evaluated correct polynomials)
  is upper bounded by $2 \cdot \epsbind (\secpar) + 1 / \abs{\FF_p}$. This is since the
  adversary either has to break binding property in at least one of two commitments or
  guess the evaluation point.

  \ngame{3} This game is identical to Game $\game{2}$ except that now the
  adversary additionally wins if it provides two transcripts that matches on the
  first two messages of the proof.

  \ncase{Game 2 to Game 3} In its $3$-rd message the adversary
  provides $\sigma_2$ and commits to polynomials $\p{g_2} (X), \p{h_2} (X)$ which are
  uniquely determined. Probability that the adversary commits to wrong polynomials that it
  can later evaluate to correct values (i.e.~to values of evaluated correct polynomials)
  is upper bounded by $2 \cdot \epsbind (\secpar) + 1 / \abs{\FF_p}$ as explained in the
  previous point.

  \ngame{4}  This game is identical to Game $\game{3}$ except that now the
  adversary additionally wins if it provides two transcripts that matches on the
  first message of the proof.

  \ncase{Game 3 to Game 4} In its $2$-nd message the adversary
  provides $\sigma_1$ and commits to polynomials $\p{g_1} (X), \p{h_1} (X)$ which are
  uniquely determined. Probability that the adversary commits to wrong polynomials that it
  can later evaluate to correct values (i.e.~to values of evaluated correct polynomials)
  is upper bounded by $2 \cdot \epsbind (\secpar) + 1 / \abs{\FF_p}$ as explained before.

  \ncase{Conclusion} Taking all the games together, probability that $\adv$ wins
  in Game 4 is upper-bounded by
  \[
    11 \cdot (\epsop (\secpar)) + 6 \cdot \epsbind (\secpar) + \frac{3}{\abs{\FF_p}}.
  \]
  \qed
\end{proof}
}}

\COMMENT{
  \michals{2.11}{Old proof}
\begin{proof}
  As in previous proofs, we show the property by game hops. Let
  $N = \p{g_1}, \p{h_1}, \p{g_2}, \p{h_2}, \p{g_3}, \p{h_3}$. That is, $N$ is a
  set of all polynomials which commitments prover sends after it sends its first message.

  \ncase{Game 0} In this game the adversary wins if it breaks evaluation
  binding, unique opening property, or knowledge soundness of one of commitments
  for polynomials in $N$.

  Probability that a $\ppt$ adversary wins in Game 0, is upper bounded by $6
  \cdot (\epsbind + \epsop + \epsk)$.

  \ncase{Game 1} In this game the adversary additionally wins if it breaks the
  $\ur{1}$ property of the protocol

  \ncase{Game 0 to Game 1} Probability that the adversary wins in Game 1 but not in Game 0
  is $\epss$. This is since in the honest proof the polynomials in $N$ are uniquely
  determined. W.l.o.g.~we analyse probability that adversary is able to produce two
  (different) pairs of polynomials $(\p{h_2}, \p{g_2})$ and $(\p{h'_2}, \p{g'_2})$ such
  that
  \begin{align*}
    \p{h_2} (X) \ZERO_{\HHH} (X) + X \p{g_2} (X) & = \p{h_2} (X) \ZERO_{\HHH} (X) +
                                                   X \p{g_2} (X)\\
    (\p{h_2} (X) - \p{h'_2} (X)) \ZERO_{\HHH} (X) & = X (\p{g'_2} (X) - \p{g'_2}
    (X)).
  \end{align*}
  Since $\p{h_2}, \p{g_2} \in \FF^{< |\HHH| - 1} [X]$ and
  $\ZERO \in \FF^{|\HHH|} [X]$, LHS has different degree than RHS unless both
  sides have degree $0$. This happens when $\p{h_2} (X) = \p{h'_2} (X)$ and
  $\p{g_2} (X) - \p{g'_2} (X)$.
  Thus, for the adversary to be successful in this game it has to provide acceptable
  proofs where $(\p{h_2}, \p{g_2})$ and $(\p{h'_2}, \p{g'_2})$ differ. One of such pair
  has to be incorrect and will be accepted with probability at most $\epss$.
\end{proof}}

\subsection{Rewinding-Based Knowledge Soundness}
\begin{lemma}
	\label{lem:marlinprot_ss}
	$\marlinprotfs$ is $(2, 2 \noofc + 3)$-rewinding-based knowledge sound against algebraic adversaries who make up to $q$ random oracle queries with security loss
	\[
	\epscss(\secpar,\accProb, q) \leq \left(1 - \frac{\accProb - (q + 1) \left( \frac{2 \noofc + 2}{p}\right)}{1 - \frac{2 \noofc + 2}{p}}\right) + (2 \noofc + 3)\cdot\epsudlog (\secpar)\,,
	\]
	Here $\accProb$ is a probability that the adversary outputs an acceptable proof,  and $\epsudlog(\secpar)$ is the security of $(2 \noofc + 2, 1)$-$\udlog$ assumption.
\end{lemma}
\begin{proof}
The proof is similar to the proof of \cref{lem:plonkprot_ss} and \cref{lem:sonicprot_ss}.
We use Attema et al.~\cite[Proposition 2]{EPRINT:AttFehKlo21} to bound the probability that the tree-building algorithm $\tdv$ does not obtain a tree of acceptable transcript in an expected number of runs. This happens with probability at most
\[
1 - \frac{\accProb - (q + 1) \left(\frac{2 \noofc + 2}{p} \right)}{1 - \frac{2 \noofc + 2}{p}}
\]
Let $\tree$ be the tree output by $\tdv$. If one of the proofs in $\tree$ is not accepting by the ideal verifier, one can break an instance of an updatable dlog assumption which happens with probability at most $(2 \noofc + 3)  \cdot \epsudlog (\secpar)$. In the case that all the transcripts are accepting by the ideal verifier, but $\extss$ fails to extract a valid witness from $\tree$, one can break the soundness of the ideal verifier in one of the transcripts. Taking a union bound completes the proof.
\qed
\end{proof}

\COMMENT{\begin{lemma}\label{lem:marlinprot_ss}
	Assume that an idealised $\marlinprot$ verifier fails with probability at most
	$\epsid(\secpar)$ and probability that a $\ppt$ adversary breaks $\udlog$ is
	bounded by $\epsudlog(\secpar)$. Then $\marlinprotfs$ is
	$(2, d + 1)$-rewinding-based knowledge
	sound with security loss $\epsid (\secpar) + \epsudlog (\secpar)$.
\end{lemma}
\begin{proof}
	% \michals{8.9}{Need to check the degrees}
	The proof goes similarly to the respective proofs for $\plonk$ and
	$\sonic$. That is, let $\srs$ be $\marlinprot$'s finalized SRS and denote by $\srs_1$
	all SRS's $\GRP_1$-elements. Let $\tdv$ be an algebraic adversary that
	produces a statement $\inp$ and a $(1, \dconst + 1, 1, 1)$-tree of
	accepting transcripts $\tree$. Note that in all transcripts the instance
	$\inp$, proof elements
	$\sigma_1, \gone{\p{w}(\chi), \p{z_A}(\chi), \p{z_B}(\chi), \p{z_C}(\chi),
		\p{h_0}(\chi), \p{s}(\chi)}, \gone{\p{g_1}(\chi), \p{h_1}(\chi)}$
	and challenges $\alpha, \eta_1, \eta_2, \eta_3$ are common as the transcripts
	share the first $3$ messages. The tree branches after the third message of the
	protocol where the challenge $\beta_1$ is presented, thus tree $\tree$ is
	build using different values of $\beta_1$.

	We consider the following games.

	\ncase{Game 0} In this game the adversary wins if all the transcripts it
	produced are acceptable by the ideal verifier,
	i.e.~$\vereq_{\inp, \zkproof}(X) = 0$, cf.~\cref{eq:marlin_ver_eq}, yet the extractor
	fails to extract a valid witness out of them.

	Probability of $\tdv$ winning this game is $\epsid(\secpar)$ as the protocol
	$\marlinprot$, instantiated with the idealised verification equation, is
	perfectly sound except with negligible probability of the idealised verifier
	failure $\epsid(\secpar)$. Hence for a valid proof $\zkproof$ for a statement
	$\inp$ there exists a witness $\wit$, such that $\REL(\inp, \wit)$ holds. Note
	that since the $\tdv$ produces $(\dconst + 1)$ accepting transcripts for
	different challenges $\beta_1$, it obtains the same number of different
	evaluations of polynomials $\p{z_A}, \p{z_B}, \p{z_C}$.

	Since the transcripts are acceptable by an idealised verifier, the equality
	$\p{z_A} (X) \p{z_B} (X) - \p{z_C} (X) = \p{h_0} (X) \ZERO_\HHH (X)$ holds and
	each of $\p{z}_M$, $M \in \smallset{A, B, C}$, has been computed
	correctly. Hence, $\p{z_A}, \p{z_B}, \p{z_C}$ encodes the valid witness for
	the proven statement. Since $\p{z_A}, \p{z_B}, \p{z_C}$ are of degree at most
	$\dconst$ and there is more than $(\dconst + 1)$ their evaluations
	known, $\extt$ can recreate their coefficients by interpolation and reveal the
	witness with probability $1$. Hence, the probability that extraction fails in
	that case is upper-bounded by probability of an idealised verifier failing
	$\epsid(\secpar)$, which is negligible.

	\ncase{Game 1} In this game the adversary additionally wins if it produces a
	transcript in $\tree$ such that $\vereq_{\inp, \zkproof}(\chi) = 0$, but
	$\vereq_{\inp, \zkproof}(X) \neq 0$. That is, the ideal verifier does not
	accept the proof, but the real verifier does.

	\ncase{Game 0 to Game 1} Assume the adversary wins in Game 1, but
	does not win in Game 0. We show that such adversary may be used to break the
	$\udlog$ assumption. More precisely, let $\tdv$ be an adversary that for
	relation $\REL$ and randomly picked $\srs \sample \kgen(\REL)$ produces a tree
	of accepting transcripts such that the winning condition of the game
	holds. Let $\rdvdulog$ be a reduction that gets as input an
	$(\dconst, 1)$-$\udlog$ instance $\gone{1, \ldots, \chi^\dconst}, \gtwo{1, \chi}$ and
	is tasked to output $\chi$. The reduction proceeds as follows---it builds $\adv$'s SRS $\srs$ in the updatable setting using the input $\udlog$ instance. Namely it answers $\adv$'s queries for SRS updates and sets the honest update of the SRS to be $\srs$. Let $\srs'$ be the finalized SRS and $(1, \tree)$ be the output
	returned by $\adv$. Let $\inp$ be a relation proven in $\tree$.  Consider a
	transcript $\zkproof \in \tree$ such that $\vereq_{\inp, \zkproof}(X) \neq 0$,
	but $\vereq_{\inp, \zkproof}(\chi) = 0$. Since the adversary is algebraic, all
	group elements included in $\tree$ are extended by their representation as a
	combination of the input $\GRP_1$-elements. Hence all coefficients of the
	verification equation polynomial $\vereq_{\inp, \zkproof}(X)$ are known and
	$\rdvudlog$ can find its zero points. Since
	$\vereq_{\inp, \zkproof}(\chi) = 0$, the targeted discrete log value $\chi'$ is
	among them.  Let $\chi_1, \ldots, \chi_\ell$ be the partial trapdoors of $\adv$'s SRS updates,  extracted by the reduction from the update proofs given by $\adv$. Now $\rdvudlog$ returns $\chi = \chi' (\chi_1 \chi_2 \ldots \chi_\ell)^{-1}$ and breaks the $\udlog$ assumption. Hence, the probability that this event happens is upper-bounded
	by $\epsudlog(\secpar)$.

\end{proof}}

\subsection{Trapdoor-Less Zero-Knowledge of Marlin}
\begin{lemma}
  \label{lem:marlin_hvzk}
  $\marlinprotfs$ is 2-programmable trapdoor-less zero-knowledge.
\end{lemma}
\begin{proof}
The simulator follows the protocol except that it picks the challenges $\alpha,
\eta_A, \eta_B, \eta_C, \beta_1, \beta_2, \beta_3$ before it picks the polynomials
it sends.

First, it picks $\p{\tilde{z}}_A (X)$, $\p{\tilde{z}}_B (X)$ at random and
$\p{\tilde{z}}_C (X)$ such that
$\p{\tilde{z}}_A (\beta_1) \p{\tilde{z}}_B (\beta_1) = \p{\tilde{z}}_C
(\beta_1)$.  Given the challenges and polynomials $\p{\tilde{z}}_A (X)$,
$\p{\tilde{z}}_B (X)$, $\p{\tilde{z}}_C (X)$ the simulator computes
$\sigma_1 \gets \sum_{\kappa \in \HHH} \p{s}(\kappa) + \p{r}(\alpha, X) (\sum_{M
  \in \smallset{A, B, C}}\eta_M \p{\tilde{z}}_M(X)) - \sum_{M \in \smallset{A,
    B, C}} \eta_M \p{r}_M (\alpha, X) \p{\tilde{z}} (X)$.

Then the simulator starts the protocol and follows it, except it programs the
random oracle such that on partial transcripts, it returns the challenges already picked by
$\simulator$.
\end{proof}

%\subsection{From Rewinding-Based Knowledge Soundness and Unique Response Property to\COMMENT{ forking}
%  Simulation Extractability of $\marlinprotfs$}
%\begin{corollary}
%  Assume that $\marlinprotfs$ is $\ur{2}$ with security
%  $\epsur(\secpar) = 6 \cdot (\epsbind + \epsop + \epsk)$, and rewinding-based knowledge sound
%  with security $\epss(\secpar)$. Let $\ro\colon \bin^* \to \bin^\secpar$ be a
%  random oracle. Let $\advse$ be an adversary that can make up to $q$
%  random oracle queries, and outputs an
%  acceptable proof for $\marlinprotfs$ with probability at least
%  $\accProb$. Then $\marlinprotfs$ is \COMMENT{forking }simulation-extractable with
%  extraction error $\eta = \epsur(\secpar)$. The extraction probability
%  $\extProb$ is at least
%  \[
%    \extProb \geq q^{-\dconst} (\accProb - 6 \cdot (\epsbind + \epsop +
%    \epsk))^{\dconst + 1} -\eps(\secpar)\,.
%\]
%	for some negligible $\eps(\secpar)$, $\dconst$ being, the upper bound of
%  constraints of the system.
%\end{corollary}

\subsection{Simulation Extractability of $\marlinprotfs$}
Since \cref{lem:marlinprot_ur,lem:marlinprot_ss,lem:marlin_hvzk} hold, $\marlinprotfs$ is $\ur{2}$, rewinding-based knowledge sound and trapdoor-less zero-knowledge. By making use
of \cref{thm:se}, we conclude that $\marlinprotfs$ is simulation-extractable as defined in \cref{def:simext}.

\begin{corollary}[Simulation extractability of $\marlinprotfs$]
	\label{thm:marlinprotfs_se}
	$\marlinprotfs$ is \emph{updatable simulation-extractable} against any $\ppt$ adversary $\advse$ who makes up to $q$ random oracle queries and returns an acceptable proof with probability at least $\accProb$ with extraction failure probability
	\[
	\epsse(\secpar, \accProb, q) \leq \left(1 - \frac{\accProb - \epsur (\secpar) - (q + 1) \epserr (\secpar)} {1 - \epserr (\secpar)}\right) + (2 \noofc + 3) \cdot \epsudlog (\secpar),
	\]
	where $\epserr (\secpar) = \frac{2 \noofc + 2}{p}$, $p$ is the size of the field, and $\noofc$ is the number of constrains in the circuit.
\end{corollary}

%\section{Further work}
%We identify a number of problems which we left as further work. First of all,
%the generalised version of the forking lemma presented in this paper can be
%generalised even further to include protocols where forking soundness holds for
%protocols where $\extt$ extracts a witness from a $(n_1, \ldots, n_\mu)$-tree of
%acceptable transcripts, where more than one $n_j > 1$. I.e.~to include
%protocols that for witness extraction require transcripts that branch at more
%than one point.
%
%Although we picked $\plonk$ and $\sonic$ as examples for our framework, it is
%not limited to SRS-based NIZKs. Thus, it would be interesting to apply it to
%known so-called transparent zkSNARKs like Bulletproofs \cite{SP:BBBPWM18},
%Aurora \cite{EC:BCRSVW19} or AuroraLight \cite{EPRINT:Gabizon19a}.
%
%Since the rewinding technique and the forking lemma used to show simulation
%extractability of $\plonkprotfs$ and $\sonicprotfs$ come with security loss,
%it would be interesting to show SE of these protocols directly in the
%algebraic group model.
%
%Although we focused here only on zkSNARKs, it is worth to
%investigating other protocols that may benefit from our framework, like
%e.g.~identification schemes.
%
%Last, but not least, this paper would benefit greatly if a more tight version
%of the generalised forking lemma was provided. However, we have to note here
%that some of the inequalities used in the proof are already tight, i.e.~for
%specific adversaries, some of the inequalities are already equalities.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\documentclass[12pt,noamsfonts]{amsart}

\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amscd}
\usepackage{epsfig}

\renewcommand{\baselinestretch}{1}

%%----------------------------------------------------------
%%  SHORTCUTS
%%----------------------------------------------------------
\def\ZZ{{\mathbb Z}}
\def\NN{{\mathbb N}}
\def\FF{{\mathbb F}}
\def\CC{{\mathbb C}}
\def\AA{{\mathbb A}}
\def\RR{{\mathbb R}}
\def\QQ{{\mathbb Q}}
\def\PP{{\mathbb P}}

\def\aa{{\mathbf a}}
\def\ee{{\mathbf e}}
\def\bx{{\mathbf x}}
\def\bt{{\mathbf t}}

\def\sV{{\sf V}}

\def\fp{{\mathfrak p}}
\def\fq{{\mathfrak q}}
\def\fb{{\mathfrak b}}
\def\fV{{\mathfrak U}}

\def\cM{{\mathcal M}}
\def\cF{{\mathcal F}}
\def\cG{{\mathcal G}}
\def\cO{{\mathcal O}}
\def\cA{{\mathcal A}}
\def\cL{{\mathcal L}}

\newcommand{\Spec}{\operatorname{Spec}}
\newcommand{\Proj}{\operatorname{Proj}}
\newcommand{\Aut}{\operatorname{Aut}}
\newcommand{\res}{\operatorname{res}}
\newcommand{\New}{\operatorname{New}}
\newcommand{\conv}{\operatorname{conv}}
\newcommand{\IN}{\operatorname{in}}
\newcommand{\codim}{\operatorname{codim}}

%%----------------------------------------------------------
%%  OTHER ENVIRONMENTS
%%----------------------------------------------------------
\newtheorem{lemma}{Lemma}
\newtheorem*{theorem}{Theorem}
\newtheorem{corollary}[lemma]{Corollary}
\newtheorem*{proposition}{Proposition}
\newtheorem*{claim}{Claim}
\newtheorem{question}{Question}

\theoremstyle{definition}
\newtheorem{definition}[lemma]{Definition}
\newtheorem{notation}[lemma]{Notation}
\newtheorem{example}{Example}
\newtheorem*{algorithm}{Algorithm}
\newtheorem*{remark}{Remark}

\theoremstyle{remark}
\newtheorem*{remarks}{Remarks}
\newtheorem*{proof*}{Proof}
\newtheorem*{solution}{Solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                        %%
%%                        BODY                            %%
%%                                                        %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\title[M2 and Schemes]{Macaulay~2 and the Geometry of Schemes}
\author[Smith]{Gregory G.~Smith}
\address{Department of Mathematics, University of California,
Berkeley, California, 94720}
\email{{\tt ggsmith@math.berkeley.edu}, {\tt bernd@math.berkeley.edu}}
\author[Sturmfels]{Bernd Sturmfels}

\maketitle

This tutorial illustrates how to use Dan Grayson and
Mike Stillman's computer algebra system, {\sc Macaulay2} \cite{GS}, to
study schemes.  The examples are taken from the homework for
an algebraic geometry class given at the
University of California, Berkeley in the
fall of 1999.  This graduate course was taught by the second author
with assistance from the first author.  Our choice of problems
follows the material in David Eisenbud and Joe Harris' textbook {\em
The Geometry of Schemes} \cite{EH}.  In fact, four of our ten problems
are taken directly from their exercises.

\subsection*{Distinguished Open Sets}

We begin with a simple example involving the definition of an
affine scheme --- see I.1.4 {\em Schemes as Schemes} in Eisenbud and Harris
\cite{EH}.  This example also indicates some of the subtleties involved
in working with arithmetic schemes.

\begin{question}
Let $R = \ZZ[x,y,z]$ and $X = \Spec(R)$; in other words, $X$ is affine
$3$-space over the integers.  Let $f = x$ and consider the basic open
subset $X_{f} \subset X$.
\begin{enumerate}
\item[(a)] If $e_{1} = x+y+z$, $e_{2} = xy+xz+yz$ and $e_{3} = xyz$
are the elementary symmetric functions then the set $\left\{ X_{e_{i}}
: \text{ $1 \leq i \leq 3$} \right\}$ is an open cover of $X_{f}$.
\item[(b)] If $p_{1} = x+y+z$, $p_{2} = x^{2}+y^{2}+z^{2}$ and $p_{3}
= x^{3}+y^{3}+z^{3}$ are the power sum symmetric functions then
$\left\{ X_{p_{i}} : \text{ $1 \leq i \leq 3$} \right\}$ is NOT an
open cover of $X_{f}$.
\end{enumerate}
\end{question}

\begin{solution}
To prove that $\left\{ X_{e_{i}} : \text{ $1 \leq i \leq 3$} \right\}$
is an open cover of $X_{f}$, it suffices to show that $e_{1}$, $e_{2}$
and $e_{3}$ generate the unit ideal in $R_{f}$ (Lemma I-16 in
 \cite{EH}).  This is equivalent to showing that
$x^{m}$ belongs to the $R$-ideal
$\langle e_{1}, e_{2}, e_{3} \rangle$
for some $m \in \NN$.
In particular, the saturation
$\big( \langle e_{1}, e_{2}, e_{3} \rangle : x^{\infty} \big)$ is the
unit ideal if and only if $\left\{ X_{e_{i}} : \text{ $1 \leq i \leq
3$} \right\}$ is an open cover of $X_{f}$.  Using {\sc Macaulay2}, we
obtain:
{\scriptsize
\begin{verbatim}

    i1 : R = ZZ[x, y, z];

    i2 : elementaryBasis = ideal( x+y+z, x*y+x*z+y*z, x*y*z );
    o2 : Ideal of R

    i3 : saturate(elementaryBasis, x)

    o3 = ideal 1
    o3 : Ideal of R

\end{verbatim}}
Similarly, to show that $\left\{ X_{p_{i}} : \text{ $1 \leq i \leq 3$}
\right\}$ is not an open cover of $X_{f}$, we prove that $\big(
\langle p_{1}, p_{2}, p_{3} \rangle : x^{\infty} \big)$ is not the
unit ideal.  We compute this saturation in {\sc Macaulay2} as follows:
{\scriptsize
\begin{verbatim}

    i4 : powerSumBasis = ideal( x+y+z, x^2+y^2+z^2, x^3+y^3+z^3 );
    o4 : Ideal of R

    i5 : saturate(powerSumBasis, x)

                                2           2
    o5 = ideal (6, x + y + z, 2y  - y*z + 2z , 3y*z)
    o5 : Ideal of R

\end{verbatim}}
\end{solution}

\subsection*{Irreducibility}

The study of complex semisimple Lie algebras gives rise to an
important family of algebraic varieties called nilpotent orbits.
To illustrate one of the topics in Section I.2.1 of
Eisenbud and Harris \cite{EH}, we examine the irreducibility of a
particular nilpotent orbit.

\begin{question}
Let $X$ be the set of complex $3 \times 3$ matrices which are
nilpotent.  Show that $X$ is an irreducible algebraic variety.
\end{question}

\begin{solution}
A $3 \times 3$ matrix $M$ is nilpotent if and only if its minimal
polynomial divides ${\sf T}^{k}$, for some $k \in \NN$.  Since each
irreducible factor of the characteristic polynomial of $M$ is also a
factor of the minimal polynomial, we conclude that the characteristic
polynomial of $M$ is ${\sf T}^{3}$.  It follows that the coefficients of the
characteristic polynomial of a generic $3 \times 3$ matrix define the
algebraic variety $X$.

To show $X$ is irreducible over $\CC$, we construct a rational parameterization
which defines it.  To achieve this, observe that ${\rm GL}_{n}(\CC)$
acts on $X$ by conjugation.  Jordan's canonical form theorem
implies that there are exactly three orbits; one for each of
the following matrices:
\[
N_{0} = \begin{bmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix}
\, , \,
N_{1} = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix}
\text{ and }
N_{2} = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \end{bmatrix}
\, .
\]
Each orbit is defined by a rational parameterization, so it suffices
to show that the closure of the orbit containing $N_{2}$ is the
entire variety $X$.  In {\sc Macaulay2}, this calculation can be done
as follows:
{\scriptsize
\begin{verbatim}

    i1 : S = QQ[t, y_0 .. y_8, a .. i, MonomialOrder => Eliminate 10];

    i2 : N2 = (matrix {{0,1,0},{0,0,1},{0,0,0}}) ** S

    o2 = {0} | 0 1 0 |
         {0} | 0 0 1 |
         {0} | 0 0 0 |
                 3       3
    o2 : Matrix S  <--- S

    i3 : G = genericMatrix(S, y_0, 3, 3);
                 3       3
    o3 : Matrix S  <--- S

\end{verbatim}}
\noindent To determine the entries in $\, G N_{2} G^{-1}$, we use the
classical adjoint to construct the inverse of the generic matrix $G$.
{\scriptsize
\begin{verbatim}

    i4 : adj = (G,i,j) -> (
              n := degree target G;
              m := degree source G;
              (-1)^(i+j)*det(
                  submatrix(G, {0..(i-1),(i+1)..(n-1)}, {0..(j-1),(j+1)..(m-1)}))
              );

    i5 : classicalAdjoint = (G) -> (
              n := degree target G;
              matrix table(n, n, (i, j) -> adj(G, j, i))
              );

    i6 : numerators = G*N2*classicalAdjoint(G);
                 3       3
    o6 : Matrix S  <--- S

    i7 : D = det(G);

    i8 : M = genericMatrix(S, a, 3, 3);
                 3       3
    o8 : Matrix S  <--- S

\end{verbatim}}
\noindent The entries in $G N_{2} G^{-1}$ give a rational
parameterization of the orbit generated by $N_{2}$.  We give an
``implicit representation'' of this variety by using elimination
theory, as in  Cox, Little and O'Shea \cite[\S 3.3]{CLO}.
{\scriptsize
\begin{verbatim}

    i9 : elimIdeal = minors(1, (D*id_(S^3))*M-numerators) + ideal(1 - D*t);
    o9 : Ideal of S

    i10 : closureOfOrbit = ideal selectInSubring(1, gens gb elimIdeal);
    o10 : Ideal of S

\end{verbatim}}
\noindent Finally, we verify that this orbit closure equals $X$
scheme-theoretically.
{\scriptsize
\begin{verbatim}

    i11 : X = ideal submatrix(
               (coefficients({0}, det(M - t*id_(S^3))))_1, {1,2,3} )

    o11 = ideal (a + e + i, b*d - a*e + c*g + f*h - a*i - e*i,
               - c*e*g + b*f*g + c*d*h - a*f*h - b*d*i + a*e*i)

    o11 : Ideal of S

    i12 : closureOfOrbit == X

    o12 = true

\end{verbatim}}
\end{solution}

\subsection*{Singular Points}

Section~I.2.2 in Eisenbud and Harris \cite{EH} provides the definition
of a singular point of a scheme.  In our third question, we study the
singular locus of a family of elliptic curves.  Note that section~V.3
in Eisenbud and Harris \cite{EH} also contains related material.

\begin{question}
Consider a general form of degree $3$ in $\QQ[x,y,z]$;
$$
F =  ax^{3}+bx^{2}y+cx^{2}z+dxy^{2}+exyz+fxz^{2}+gy^{3}+hy^{2}z
 +iyz^{2}+jz^{3}.
$$
Give necessary and sufficient conditions in terms of $a, \ldots, j$
for the cubic curve $\Proj\big( \QQ[x,y,z] / \langle F \rangle \big)$ to
have a singular point.
\end{question}

\begin{solution}
A time consuming elimination gives the degree $12$ polynomial which
defines the singular locus of a general form of degree $3$.  This can
be done in {\sc Macaulay2} as follows.  We have not displayed the
output {\tt o6}, as this discriminant  has $2040$ terms in the $10$
variables $a, \ldots, j$.

{\scriptsize
\begin{verbatim}

    i1 : S = QQ[x, y, z, a .. j, MonomialOrder => Eliminate 2 ];

    i2 : F = a*x^3+b*x^2*y+c*x^2*z+d*x*y^2+e*x*y*z+f*x*z^2
             +g*y^3+h*y^2*z+i*y*z^2+j*z^3;

    i3 : partials = submatrix( jacobian matrix{{ F }}, {0 .. 2}, {0})

    o3 = {1} | 3x2a+2xyb+y2d+2xzc+yze+z2f |
         {1} | x2b+2xyd+3y2g+xze+2yzh+z2i |
         {1} | x2c+xye+y2h+2xzf+2yzi+3z2j |

                 3       1
    o3 : Matrix S  <--- S

    i4 : singularities = ideal( partials ) + ideal( F );
    o4 : Ideal of S

    i5 : elimDiscr = ideal selectInSubring(1, gens gb singularities);
    o5 : Ideal of S

    i6 : elimDiscr = substitute(  elimDiscr, {z => 1});
    o6 : Ideal of S

\end{verbatim}}
\noindent There is also a simple and more useful determinantal formula
for this discriminant. It is a specialization of the formula (2.8) in
 \cite[\S 3.2]{CLO2}:
{\scriptsize
\begin{verbatim}

    i7 : hessian = det submatrix(jacobian ideal partials, {0..2}, {0..2});

    i8 : A = (coefficients( {0,1,2},
                  submatrix( jacobian matrix{{ F }}, {0 .. 2}, {0})
                ))_1;
                 3       6
    o8 : Matrix S  <--- S

    i9 : B = (coefficients( {0,1,2},
                  submatrix( jacobian matrix{{ hessian }}, {0 .. 2}, {0})
                ))_1;
                 3       6
    o9 : Matrix S  <--- S

    i10 : detDiscr = ideal det (A || B);
    o10 : Ideal of S

    i11 : detDiscr == elimDiscr

    o11 = true

\end{verbatim}}
\end{solution}

\subsection*{Fields of Definition}

Schemes over non-algebraically closed fields arise in number theory.
Our solution to Exercise~II-6 in \cite{EH}
indicates one technique for working over a number field in {\sc
Macaulay2}.

\begin{question}
An inclusion of fields $K \hookrightarrow L$ induces a map
$\AA_{L}^{n} \to \AA_{K}^{n}$.  Find the images in $\AA_{\QQ}^{2}$ of
the following points of $\AA_{\overline{\QQ}}^{2}$ under this map.
\begin{enumerate}
\item[(a)]  $\langle x - \sqrt{2}, y - \sqrt{2} \rangle$;
\item[(b)]  $\langle x - \sqrt{2}, y - \sqrt{3} \rangle$;
\item[(c)]  $\langle x - \zeta, y - \zeta^{-1} \rangle$ where $\zeta$ is
a $5$-th root of unity ;
\item[(d)]  $\langle \sqrt{2}x- \sqrt{3}y \rangle$;
\item[(e)]  $\langle \sqrt{2}x- \sqrt{3}y-1 \rangle$.
\end{enumerate}
\end{question}

\begin{solution}
The images can be determined by (1) replacing coefficients
not belonging to $K$ with indeterminates, (2) adding the minimal
polynomials of these coefficients to the given ideal in $\AA_{L}^{2}$ and
(3) eliminating the new indeterminates. Here are the five examples:

{\scriptsize
\begin{verbatim}

    i1 : S = QQ[a,b,x,y, MonomialOrder => Eliminate 2];

    i2 : Ia = ideal( x-a, y-a, a^2-2 );
    o2 : Ideal of S

    i3 : ideal selectInSubring(1, gens gb Ia)

                        2
    o3 = ideal (x - y, y  - 2)
    o3 : Ideal of S

    i4 : Ib = ideal( x-a, y-b, a^2-2, b^2-3 );
    o4 : Ideal of S

    i5 : ideal selectInSubring(1, gens gb Ib)

                 2       2
    o5 = ideal (y  - 3, x  - 2)
    o5 : Ideal of S

    i6 : Ic = ideal( x-a, y-a^4, a^4+a^3+a^2+a+1 );
    o6 : Ideal of S

    i7 : ideal selectInSubring(1, gens gb Ic)

                          2    2               3    2
    o7 = ideal (x*y - 1, x  + y  + x + y + 1, y  + y  + x + y + 1)
    o7 : Ideal of S

    i8 : Id = ideal( a*x+b*y, a^2-2, b^2-3 );
    o8 : Ideal of S

    i9 : ideal selectInSubring(1, gens gb Id)

                2   3  2
    o9 = ideal(x  - -*y )
                    2
    o9 : Ideal of S

    i10 : Ie = ideal( a*x+b*y-1, a^2-2, b^2-3 );
    o10 : Ideal of S

    i11 : ideal selectInSubring(1, gens gb Ie)

                 4     2 2   9  4    2   3  2   1
    o11 = ideal(x  - 3x y  + -*y  - x  - -*y  + -)
                             4           2      4
    o11 : Ideal of S

\end{verbatim}}
\end{solution}

\subsection*{Multiplicity}

The multiplicity of a zero-dimensional scheme $X$ at a point $p \in X$
is defined to be the length of the local ring $\mathcal{O}_{X,p}$.
Unfortunately, we cannot work directly in the local ring in {\sc
Macaulay2}. What we can do, however, is to compute the
multiplicity by computing the
degree of the component of $X$ supported at $p$; see \cite[page 66]{EH}.

\begin{question}
What is the multiplicity of the origin $(0,0,0)$ as a zero of the
polynomial equations
\[
x^{5}+y^{3}+z^{3} \,\, = \,\, x^{3}+y^{5}+z^{3} \,\, =
\,\, x^{3}+y^{3}+z^{5} \,\, = \, \, 0 \, ?
\]
\end{question}

\begin{solution}
If $I$ is the ideal generated by $x^{5}+y^{3}+z^{3}$,
$x^{3}+y^{5}+z^{3}$ and $x^{3}+y^{3}+z^{5}$ in $\QQ[x,y,z]$, then the
multiplicity of the origin is
\[
\dim_{\QQ} \frac{\QQ[x,y,z]_{\langle x,y,z \rangle}}
{I \QQ[x,y,z]_{\langle x,y,z \rangle}} \, .
\]
It follows that the multiplicity is the vector space dimension of the
ring $\QQ[x,y,z] / \varphi^{-1}(I \QQ[x,y,z]_{\langle x,y,z \rangle})$
where $\varphi \colon \QQ[x,y,z] \to \QQ[x,y,z]_{\langle x,y,z \rangle}$
is the natural map.  Moreover, we can express this using ideal
quotients:
\[
\varphi^{-1}(I \QQ[x,y,z]_{\langle x,y,z \rangle}) \,\,= \,\, \big(I : (I :
\langle x,y,z \rangle^{\infty})\big) \, .
\]
Carrying out this calculation in {\sc Macaulay2}, we obtain:
{\scriptsize
\begin{verbatim}

    i1 : S = QQ[x,y,z];

    i2 : I = ideal( x^5+y^3+z^3, x^3+y^5+z^3, x^3+y^3+z^5 );

    o2 : Ideal of S

    i3 : multiplicity = degree( I : saturate(I) )

    o3 = 27

\end{verbatim}}
\end{solution}

\subsection*{Flat Families}

Non-reduced schemes arise naturally as the flat limit of a family of
reduced schemes. Exercise~III-68 in
\cite{EH} illustrates how a family of skew lines in $\PP^{3}$
gives a double line with an embedded point.

\begin{question}
Let $L$ and $M $  be the lines in $\PP^{3}_{k[t]}$ given by $x=y=0$
and $x-tz = y+t^{2}w =0$ respectively.  Show that the flat limit as $t
\to 0$ of the union $L \cup M$ is the double line $x^{2} = y = 0$ with
an embedded point of degree $1$ located at the point $(0:0:0:1)$.
\end{question}

\begin{solution}
We find the flat limit by saturating the intersection ideal:
{\scriptsize
\begin{verbatim}

    i1 : PP3 = QQ[x, y, z, w];

    i2 : S = QQ[t, x, y, z, w];

    i3 : phi = map( PP3, S, 0 | vars PP3 );
    o3 : RingMap PP3 <--- S

    i4 : L = ideal( x, y );
    o4 : Ideal of S

    i5 : M = ideal( x-t*z, y-t^2*w );
    o5 : Ideal of S

    i6 : X = intersect( L, M );
    o6 : Ideal of S

    i7 : Xzero = trim phi substitute( saturate(X, t), {t => 0})

                      2        2
    o7 = ideal (y*z, y , x*y, x )
    o7 : Ideal of PP3

\end{verbatim}}
\noindent This  is the union of a double line
and an embedded point of degree $1$.
{\scriptsize
\begin{verbatim}

    i8 : intersect( ideal( x^2, y ), ideal( x, y^2, z ) )

                      2        2
    o8 = ideal (y*z, y , x*y, x )
    o8 : Ideal of PP3

    i9 : degree (  ideal( x^2 , y ) / ideal( x, y^2, z ) )

    o9 = 1

\end{verbatim}}

\end{solution}

\subsection*{B\'{e}zout's Theorem}

B\'{e}zout's Theorem for Cohen-Macaulay schemes  \cite[Theorem III-78]{EH}
may fail without the Cohen-Macaulay
hypothesis.  Following Exercise III-81 in
\cite{EH}, we illustrate this in {\sc Macaulay2}.

\begin{question}
Find irreducible closed subvarieties $X$ and $Y$ in $\PP^{4}$ with
\begin{eqnarray*}
\codim(X \cap Y) & = & \codim(X) +\codim(Y) \text{ and }\\
\deg(X \cap Y) & > & \deg(X) \cdot \deg(Y) \, .
\end{eqnarray*}
\end{question}

\begin{solution}
We show that the assertion holds when $X$ is the cone over the
nonsingular rational quartic curve in $\PP^{3}$ and $Y$ is a two-plane
passing through the vertex of the cone.
The computation is done as follows:
{\scriptsize
\begin{verbatim}

    i1 : S = QQ[a,b,c,d,e];

    i2 : quarticCone = trim minors(2,
                            matrix{{a, b^2, b*d, c}, {b, a*c, c^2, d}})

                            3      2     2    2    3    2
    o2 = ideal (b*c - a*d, c  - b*d , a*c  - b d, b  - a c)
    o2 : Ideal of S

    i3 : plane = ideal(a, d);
    o3 : Ideal of S

    i4 : codim quarticCone + codim plane == codim (quarticCone + plane)
    o4 = true

    i5 : (degree quarticCone) * (degree plane)
    o5 = 4

    i6 : degree (quarticCone + plane)
    o6 = 5

\end{verbatim}}
\end{solution}

\subsection*{Constructing Blow-ups}

The blow-up of a scheme $X$ along a subscheme $Y$ can be constructed
from the Rees algebra associated to the ideal sheaf of $Y$ in $X$;
see \cite[Theorem IV-22]{EH}.  Gr\"{o}bner basis
techniques allow one to express the Rees algebra in terms of
generators and relations.  We demonstrate this
by solving Exercise~IV-43 in \cite{EH}.

\begin{question}
Find the blow-up of the affine plane $\AA^{2} = \Spec\big( k[a,b]
\big)$ along the subscheme defined by $\langle a^{3}, ab, b^{2}
\rangle$.
\end{question}

\begin{solution}
We first provide a general function which returns the ideal of
relations for the Rees algebra.
{\scriptsize
\begin{verbatim}

    i1 : blowUpIdeal = (I) -> (
            r := numgens I;
            S := ring I;
            KK := coefficientRing S;
            n := numgens S;
            tR := KK[t, gens S , y_1 .. y_r, MonomialOrder => Eliminate 1];
            f := map(tR, S, submatrix(vars tR, {1 .. n}));
            F := f(gens I);
            J := ideal apply(1 .. r, j -> y_j - t*F_(0,(j-1)));
            L := ideal selectInSubring(1, gens gb J);
            R := KK[gens S, y_1 .. y_r];
            g := map(R, tR, 0 | vars R);
            g(L)
        );
\end{verbatim}}
\noindent Now, applying the function to our specific case yields:

{\scriptsize
\begin{verbatim}

    i2 : S = QQ[a,b];

    i3 : I = ideal(a^3, a*b, b^2);
    o3 : Ideal of S

    i4 : blowUpIdeal(I)

                                2          2            3      2
    o4 = ideal (b*y  - a*y , a*y  - y y , a y  - b*y , a y  - b y )
                   2      3     2    1 3     2      1     3      1

    o4 : Ideal of QQ [a, b, y , y , y ]
                             1   2   3

\end{verbatim}}
\end{solution}

\subsection*{A Classic Blow-up}

We consider the blow-up of the projective plane $\PP^{2}$ at a point.
Many related examples appear in \cite[Section IV.2.2]{EH}.

\begin{question}
Show that the following varieties are isomorphic.
\begin{enumerate}
\item[(a)] the image of the rational map from $\PP^{2}$ to $\PP^{4}$
given by
\[
(r:s:t) \mapsto (r^{2}:s^{2}:rs:rt:st) \, ;
\]
\item[(b)] the blow-up of the plane $\PP^{2}$ at the point $(0:0:1)$;
\item[(c)] the determinantal variety defined by the $2 \times 2$
minors of the matrix
\[
\begin{bmatrix} a & c & d \\ b & d & e \end{bmatrix}
\]
where $\PP^{4} = \Proj\big( k[a,b,c,d,e] \big)$.
\end{enumerate}
This surface is called the {\em cubic scroll} in $\PP^{4}$.
\end{question}

\begin{solution}
We find the ideal in part~(a) by elimination theory.
{\scriptsize
\begin{verbatim}

    i1 : PP4 = QQ[ a .. e ];

    i2 : S = QQ[r .. t, A .. E, MonomialOrder => Eliminate 3 ];

    i3 : I = ideal( A - r^2, B - s^2, C - r*s, D - r*t, E - s*t );
    o3 : Ideal of S

    i4 : phi = map( PP4, S, matrix{{ 0_PP4, 0_PP4, 0_PP4 }} | vars PP4)

    o4 = map(PP4,S,{0, 0, 0, a, b, c, d, e})

    o4 : RingMap PP4 <--- S

    i5 : surfaceA = phi ideal selectInSubring(1, gens gb I )

                                             2
    o5 = ideal (c*d - a*e, b*d - c*e, a*b - c )
    o5 : Ideal of PP4

\end{verbatim}}
\noindent We determine the surface in part~(b) by constructing the
blow-up of $\PP^{2}$ in $\PP^{2} \times \PP^{1}$ and then projecting
its Segre embedding from $\PP^{5}$ into $\PP^{4}$.  Note that its
image under the Segre map lies on a hyperplane in $\PP^{5}$.
{\scriptsize
\begin{verbatim}

    i6 : R = QQ[t, x, y, z, u, v, MonomialOrder => Eliminate 1];

    i7 : blowUpIdeal = ideal selectInSubring( 1, gens gb
                           ideal( u-t*x, v-t*y ))

    o7 = ideal(y*u - x*v)
    o7 : Ideal of R

    i8 : PP2xPP1 = QQ[x, y, z, u, v];

    i9 : psi = map( PP2xPP1, R, 0 | vars PP2xPP1 );

    o9 : RingMap PP2xPP1 <--- R

    i10 : blowUp = PP2xPP1 / psi(blowUpIdeal);

    i11 : PP5 = QQ[ A .. F ];

    i12 : segre = map( blowUp, PP5,
                      matrix{{ x*u, y*u, z*u, x*v, y*v, z*v }});

    o12 : RingMap blowUp <--- PP5

    i13 : ker segre

                                    2
    o13 = ideal (B - D, C*E - D*F, D  - A*E, C*D - A*F)
    o13 : Ideal of PP5

    i14 : theta = map( PP4, PP5, matrix{{ a, c, d, c, b, e }})

    o14 = map(PP4,PP5,{a, c, d, c, b, e})

    o14 : RingMap PP4 <--- PP5

    i15 : surfaceB = trim theta ker segre

                                              2
    o15 = ideal (c*d - a*e, b*d - c*e, a*b - c )
    o15 : Ideal of PP4

\end{verbatim}}
\noindent Finally, we compute the surface in part~(c) and apply a
permutation of the variables to obtain the desired isomorphisms
{\scriptsize
\begin{verbatim}

    i16 : determinantal = minors(2, matrix{{ a, c, d },{ b, d, e }})

                                              2
    o16 = ideal (- b*c + a*d, - b*d + a*e, - d  + c*e)

    o16 : Ideal of PP4

    i17 : sigma = map( PP4, PP4, matrix{{ d, e, a, c, b }});

    o17 : RingMap PP4 <--- PP4

    i18 : surfaceC = sigma determinantal

                                              2
    o18 = ideal (c*d - a*e, b*d - c*e, a*b - c )

    o18 : Ideal of PP4

    i19 : surfaceA == surfaceB

    o19 = true

    i20 : surfaceB == surfaceC

    o20 = true
\end{verbatim}}

\end{solution}

\subsection*{Fano Schemes}

Our final example concern the family of Fano
schemes associated to a flat family of quadrics.
We solve Exercise~IV-69 in \cite{EH}.

\begin{question}
Consider the one-parameter family of quadrics
\[
Q = V(tx^{2}+ty^{2}+tz^{2}+w^{2}) \subseteq \PP^{3}_{k[t]} =
\Proj\big(k[t][x,y,z,w]\big) \, .
\]
As the fiber $Q_{t}$ tends to the double plane $Q_{0}$, what is the
flat limit of the Fano scheme $F_{1}(Q_{t})$
of lines lying on these quadric surfaces~?
\end{question}

\begin{solution}
We first compute the ideal defining the Fano scheme of $Q$:
{\scriptsize
\begin{verbatim}

    i1 : PP3overBase = QQ[t, x, y, z, w];

    i2 : familyOfQuadrics = ideal( t*x^2+t*y^2+t*z^2+w^2 );
    o2 : Ideal of PP3overBase

    i3 : S = QQ[t, u, v, A .. H ];

    i4 : phi = map( S, PP3overBase, matrix{{ t }} |
                   u*matrix{{ A, B, C, D }}+v*matrix{{ E, F, G, H }} );

    o4 : RingMap S <--- PP3overBase

    i5 : imageFamily = phi familyOfQuadrics;
    o5 : Ideal of S

    i6 : coeffOfFamily = (coefficients ( {1,2}, gens imageFamily ))_1;

                 1       3
    o6 : Matrix S  <--- S

    i7 : Sprime = QQ[t, A .. H ];

    i8 : coeffOfFamily = substitute( coeffOfFamily, Sprime );

                      1            3
    o8 : Matrix Sprime  <--- Sprime

    i9 : Sbar = Sprime / (ideal coeffOfFamily);

    i10 : PP5overBase = QQ[t, a .. f ];

    i11 : psi = matrix{{Sbar_"t"}} | substitute( exteriorPower( 2,
                    matrix{{ A, B, C, D }, { E, F, G, H }}), Sbar);

                     1          7
    o11 : Matrix Sbar  <--- Sbar

    i12 : fanoOfFamily = trim ker map( Sbar, PP5overBase, psi);
    o12 : Ideal of PP5overBase

\end{verbatim}}
Secondly, we determine the limit as $t$ tends to $0$.
{\scriptsize
\begin{verbatim}

    i13 : fanoOfZeroFibre = trim substitute(
                                saturate( fanoOfFamily, t), {t => 0} )

                                            2   2   2
    o13 = ideal (e*f, d*f, d*e, a*e + b*f, d , f , e , c*d - b*e + a*f,

                                         2    2    2
                  b*d + c*e, a*d - c*f, a  + b  + c )

    o13 : Ideal of PP5overBase

    i14 : fanoOfOneFibre = trim substitute(
                               saturate( fanoOfFamily, t), {t => 1} )

                             2    2    2
    o14 = ideal (a*e + b*f, d  + e  + f , c*d - b*e + a*f, b*d + c*e,
                             2    2    2                         2    2
                 a*d - c*f, c  + e  + f , b*c + d*e, a*c - d*f, b  - e ,
                             2    2
                 a*b + e*f, a  - f )

    o14 : Ideal of PP5overBase

    i15 : fanoOfOneFibre == intersect( ideal( c-d, b+e, a-f, d^2+e^2+f^2 ),
                                       ideal( c+d, b-e, a+f, d^2+e^2+f^2 ) )

    o15 = true

\end{verbatim}}
\noindent We see that $F_{1}(Q_{0}) $ is
supported on the plane conic $\langle d, e, f, a^{2}+b^{2}+c^{2}
\rangle$.  However, $F_{1}(Q_{0})$ is not reduced but has multiplicity
two. For $t \neq 0$, $F_{1}(Q_{t})$ is the union of
two conics lying in complementary planes and $F_{1}(Q_{0})$ is the
double conic obtained when the two conics move together.
\end{solution}

\providecommand{\bysame}{\leavevmode\hbox to3em{\hrulefill}\thinspace}
\begin{thebibliography}{CLO}

\bibitem[CLO]{CLO}
David Cox, John Little and Donal O'Shea,
 \emph{Ideals, Varieties and Algorithms},
Undergraduate Texts in Mathematics,
Springer--Verlag,   New York, 1996.

\bibitem[CLO2]{CLO2}
David Cox, John Little and Donal O'Shea,
 \emph{Using Algebraic Geometry},
  Graduate Texts in Mathematics~185, Springer--Verlag,
  New York, 1998.

\bibitem[EH]{EH}
David Eisenbud and Joe Harris, \emph{The Geometry of Schemes},
  Graduate Texts in Mathematics~197, Springer--Verlag,
  New York, 1999.

\bibitem[GS]{GS}
Daniel R.~Grayson and Michael E.~Stillman, \emph{Macaulay~2}
  --- a software system for algebraic geometry and commutative algebra,
  available at {\tt http://www.math.uiuc.edu/Macaulay2}.

\end{thebibliography}

\end{document}