forward-rot-x

Percentage Accurate: 98.8% → 99.4%
Time: 34.6s
Alternatives: 7
Speedup: 1.1×

Specification

?
\[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (+ (* v cosrot) (* (- u u0) sinrot)))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return (v * cosrot) + ((u - u0) * sinrot);
}
real(8) function code(u, v, cosrot, sinrot, u0)
use fmin_fmax_functions
    real(8), intent (in) :: u
    real(8), intent (in) :: v
    real(8), intent (in) :: cosrot
    real(8), intent (in) :: sinrot
    real(8), intent (in) :: u0
    code = (v * cosrot) + ((u - u0) * sinrot)
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	return (v * cosrot) + ((u - u0) * sinrot);
}
def code(u, v, cosrot, sinrot, u0):
	return (v * cosrot) + ((u - u0) * sinrot)
function code(u, v, cosrot, sinrot, u0)
	return Float64(Float64(v * cosrot) + Float64(Float64(u - u0) * sinrot))
end
function tmp = code(u, v, cosrot, sinrot, u0)
	tmp = (v * cosrot) + ((u - u0) * sinrot);
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(N[(v * cosrot), $MachinePrecision] + N[(N[(u - u0), $MachinePrecision] * sinrot), $MachinePrecision]), $MachinePrecision]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	(v * cosrot) + ((u - u0) * sinrot)
END code
v \cdot cosrot + \left(u - u0\right) \cdot sinrot

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.8% accurate, 1.0× speedup?

\[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (+ (* v cosrot) (* (- u u0) sinrot)))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return (v * cosrot) + ((u - u0) * sinrot);
}
real(8) function code(u, v, cosrot, sinrot, u0)
use fmin_fmax_functions
    real(8), intent (in) :: u
    real(8), intent (in) :: v
    real(8), intent (in) :: cosrot
    real(8), intent (in) :: sinrot
    real(8), intent (in) :: u0
    code = (v * cosrot) + ((u - u0) * sinrot)
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	return (v * cosrot) + ((u - u0) * sinrot);
}
def code(u, v, cosrot, sinrot, u0):
	return (v * cosrot) + ((u - u0) * sinrot)
function code(u, v, cosrot, sinrot, u0)
	return Float64(Float64(v * cosrot) + Float64(Float64(u - u0) * sinrot))
end
function tmp = code(u, v, cosrot, sinrot, u0)
	tmp = (v * cosrot) + ((u - u0) * sinrot);
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(N[(v * cosrot), $MachinePrecision] + N[(N[(u - u0), $MachinePrecision] * sinrot), $MachinePrecision]), $MachinePrecision]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	(v * cosrot) + ((u - u0) * sinrot)
END code
v \cdot cosrot + \left(u - u0\right) \cdot sinrot

Alternative 1: 99.4% accurate, 1.1× speedup?

\[\mathsf{fma}\left(u - u0, sinrot, v \cdot cosrot\right) \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (fma (- u u0) sinrot (* v cosrot)))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return fma((u - u0), sinrot, (v * cosrot));
}
function code(u, v, cosrot, sinrot, u0)
	return fma(Float64(u - u0), sinrot, Float64(v * cosrot))
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(N[(u - u0), $MachinePrecision] * sinrot + N[(v * cosrot), $MachinePrecision]), $MachinePrecision]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	((u - u0) * sinrot) + (v * cosrot)
END code
\mathsf{fma}\left(u - u0, sinrot, v \cdot cosrot\right)
Derivation
  1. Initial program 98.8%

    \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
  2. Applied rewrites99.4%

    \[\leadsto \mathsf{fma}\left(u - u0, sinrot, v \cdot cosrot\right) \]
  3. Add Preprocessing

Alternative 2: 87.0% accurate, 0.7× speedup?

\[\begin{array}{l} t_0 := \mathsf{fma}\left(-u0, sinrot, cosrot \cdot v\right)\\ \mathbf{if}\;u0 \leq -3.6281267418831816 \cdot 10^{+31}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;u0 \leq 5.714373608685782 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(cosrot, v, sinrot \cdot u\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (fma (- u0) sinrot (* cosrot v))))
  (if (<= u0 -3.6281267418831816e+31)
    t_0
    (if (<= u0 5.714373608685782e+32)
      (fma cosrot v (* sinrot u))
      t_0))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = fma(-u0, sinrot, (cosrot * v));
	double tmp;
	if (u0 <= -3.6281267418831816e+31) {
		tmp = t_0;
	} else if (u0 <= 5.714373608685782e+32) {
		tmp = fma(cosrot, v, (sinrot * u));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(u, v, cosrot, sinrot, u0)
	t_0 = fma(Float64(-u0), sinrot, Float64(cosrot * v))
	tmp = 0.0
	if (u0 <= -3.6281267418831816e+31)
		tmp = t_0;
	elseif (u0 <= 5.714373608685782e+32)
		tmp = fma(cosrot, v, Float64(sinrot * u));
	else
		tmp = t_0;
	end
	return tmp
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[((-u0) * sinrot + N[(cosrot * v), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[u0, -3.6281267418831816e+31], t$95$0, If[LessEqual[u0, 5.714373608685782e+32], N[(cosrot * v + N[(sinrot * u), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	LET t_0 = (((- u0) * sinrot) + (cosrot * v)) IN
		LET tmp_1 = IF (u0 <= (571437360868578164535154981208064)) THEN ((cosrot * v) + (sinrot * u)) ELSE t_0 ENDIF IN
		LET tmp = IF (u0 <= (-36281267418831816064245553954816)) THEN t_0 ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := \mathsf{fma}\left(-u0, sinrot, cosrot \cdot v\right)\\
\mathbf{if}\;u0 \leq -3.6281267418831816 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;u0 \leq 5.714373608685782 \cdot 10^{+32}:\\
\;\;\;\;\mathsf{fma}\left(cosrot, v, sinrot \cdot u\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u0 < -3.6281267418831816e31 or 5.7143736086857816e32 < u0

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Applied rewrites98.1%

      \[\leadsto \mathsf{fma}\left(u, sinrot, v \cdot cosrot - sinrot \cdot u0\right) \]
    3. Taylor expanded in u around 0

      \[\leadsto cosrot \cdot v - sinrot \cdot u0 \]
    4. Applied rewrites70.6%

      \[\leadsto cosrot \cdot v - sinrot \cdot u0 \]
    5. Applied rewrites71.0%

      \[\leadsto \mathsf{fma}\left(-u0, sinrot, cosrot \cdot v\right) \]

    if -3.6281267418831816e31 < u0 < 5.7143736086857816e32

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in u0 around 0

      \[\leadsto cosrot \cdot v + sinrot \cdot u \]
    3. Applied rewrites70.8%

      \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 86.6% accurate, 0.7× speedup?

\[\begin{array}{l} t_0 := cosrot \cdot v - sinrot \cdot u0\\ \mathbf{if}\;u0 \leq -3.6281267418831816 \cdot 10^{+31}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;u0 \leq 5.714373608685782 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(cosrot, v, sinrot \cdot u\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (- (* cosrot v) (* sinrot u0))))
  (if (<= u0 -3.6281267418831816e+31)
    t_0
    (if (<= u0 5.714373608685782e+32)
      (fma cosrot v (* sinrot u))
      t_0))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (cosrot * v) - (sinrot * u0);
	double tmp;
	if (u0 <= -3.6281267418831816e+31) {
		tmp = t_0;
	} else if (u0 <= 5.714373608685782e+32) {
		tmp = fma(cosrot, v, (sinrot * u));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(u, v, cosrot, sinrot, u0)
	t_0 = Float64(Float64(cosrot * v) - Float64(sinrot * u0))
	tmp = 0.0
	if (u0 <= -3.6281267418831816e+31)
		tmp = t_0;
	elseif (u0 <= 5.714373608685782e+32)
		tmp = fma(cosrot, v, Float64(sinrot * u));
	else
		tmp = t_0;
	end
	return tmp
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[(N[(cosrot * v), $MachinePrecision] - N[(sinrot * u0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[u0, -3.6281267418831816e+31], t$95$0, If[LessEqual[u0, 5.714373608685782e+32], N[(cosrot * v + N[(sinrot * u), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	LET t_0 = ((cosrot * v) - (sinrot * u0)) IN
		LET tmp_1 = IF (u0 <= (571437360868578164535154981208064)) THEN ((cosrot * v) + (sinrot * u)) ELSE t_0 ENDIF IN
		LET tmp = IF (u0 <= (-36281267418831816064245553954816)) THEN t_0 ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := cosrot \cdot v - sinrot \cdot u0\\
\mathbf{if}\;u0 \leq -3.6281267418831816 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;u0 \leq 5.714373608685782 \cdot 10^{+32}:\\
\;\;\;\;\mathsf{fma}\left(cosrot, v, sinrot \cdot u\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u0 < -3.6281267418831816e31 or 5.7143736086857816e32 < u0

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Applied rewrites98.1%

      \[\leadsto \mathsf{fma}\left(u, sinrot, v \cdot cosrot - sinrot \cdot u0\right) \]
    3. Taylor expanded in u around 0

      \[\leadsto cosrot \cdot v - sinrot \cdot u0 \]
    4. Applied rewrites70.6%

      \[\leadsto cosrot \cdot v - sinrot \cdot u0 \]

    if -3.6281267418831816e31 < u0 < 5.7143736086857816e32

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in u0 around 0

      \[\leadsto cosrot \cdot v + sinrot \cdot u \]
    3. Applied rewrites70.8%

      \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 82.3% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := \left(u - u0\right) \cdot sinrot\\ t_1 := sinrot \cdot \left(u - u0\right)\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+142}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+46}:\\ \;\;\;\;\mathsf{fma}\left(cosrot, v, sinrot \cdot u\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (* (- u u0) sinrot)) (t_1 (* sinrot (- u u0))))
  (if (<= t_0 -1e+142)
    t_1
    (if (<= t_0 5e+46) (fma cosrot v (* sinrot u)) t_1))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * sinrot;
	double t_1 = sinrot * (u - u0);
	double tmp;
	if (t_0 <= -1e+142) {
		tmp = t_1;
	} else if (t_0 <= 5e+46) {
		tmp = fma(cosrot, v, (sinrot * u));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(u, v, cosrot, sinrot, u0)
	t_0 = Float64(Float64(u - u0) * sinrot)
	t_1 = Float64(sinrot * Float64(u - u0))
	tmp = 0.0
	if (t_0 <= -1e+142)
		tmp = t_1;
	elseif (t_0 <= 5e+46)
		tmp = fma(cosrot, v, Float64(sinrot * u));
	else
		tmp = t_1;
	end
	return tmp
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[(N[(u - u0), $MachinePrecision] * sinrot), $MachinePrecision]}, Block[{t$95$1 = N[(sinrot * N[(u - u0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+142], t$95$1, If[LessEqual[t$95$0, 5e+46], N[(cosrot * v + N[(sinrot * u), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	LET t_0 = ((u - u0) * sinrot) IN
		LET t_1 = (sinrot * (u - u0)) IN
			LET tmp_1 = IF (t_0 <= (50000000000000002192292152253809867731702382592)) THEN ((cosrot * v) + (sinrot * u)) ELSE t_1 ENDIF IN
			LET tmp = IF (t_0 <= (-10000000000000000508222848402996879704791089448509839788449208028871961714412352270078388372553960191290960287445781834331294577148468377157632)) THEN t_1 ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := \left(u - u0\right) \cdot sinrot\\
t_1 := sinrot \cdot \left(u - u0\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+142}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(cosrot, v, sinrot \cdot u\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 u u0) sinrot) < -1.0000000000000001e142 or 5.0000000000000002e46 < (*.f64 (-.f64 u u0) sinrot)

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in v around 0

      \[\leadsto sinrot \cdot \left(u - u0\right) \]
    3. Applied rewrites62.1%

      \[\leadsto sinrot \cdot \left(u - u0\right) \]

    if -1.0000000000000001e142 < (*.f64 (-.f64 u u0) sinrot) < 5.0000000000000002e46

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in u0 around 0

      \[\leadsto cosrot \cdot v + sinrot \cdot u \]
    3. Applied rewrites70.8%

      \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 76.4% accurate, 0.6× speedup?

\[\begin{array}{l} \mathbf{if}\;v \cdot cosrot \leq -5000000:\\ \;\;\;\;cosrot \cdot v\\ \mathbf{elif}\;v \cdot cosrot \leq 2 \cdot 10^{+131}:\\ \;\;\;\;sinrot \cdot \left(u - u0\right)\\ \mathbf{else}:\\ \;\;\;\;cosrot \cdot v\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (if (<= (* v cosrot) -5000000.0)
  (* cosrot v)
  (if (<= (* v cosrot) 2e+131) (* sinrot (- u u0)) (* cosrot v))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double tmp;
	if ((v * cosrot) <= -5000000.0) {
		tmp = cosrot * v;
	} else if ((v * cosrot) <= 2e+131) {
		tmp = sinrot * (u - u0);
	} else {
		tmp = cosrot * v;
	}
	return tmp;
}
real(8) function code(u, v, cosrot, sinrot, u0)
use fmin_fmax_functions
    real(8), intent (in) :: u
    real(8), intent (in) :: v
    real(8), intent (in) :: cosrot
    real(8), intent (in) :: sinrot
    real(8), intent (in) :: u0
    real(8) :: tmp
    if ((v * cosrot) <= (-5000000.0d0)) then
        tmp = cosrot * v
    else if ((v * cosrot) <= 2d+131) then
        tmp = sinrot * (u - u0)
    else
        tmp = cosrot * v
    end if
    code = tmp
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	double tmp;
	if ((v * cosrot) <= -5000000.0) {
		tmp = cosrot * v;
	} else if ((v * cosrot) <= 2e+131) {
		tmp = sinrot * (u - u0);
	} else {
		tmp = cosrot * v;
	}
	return tmp;
}
def code(u, v, cosrot, sinrot, u0):
	tmp = 0
	if (v * cosrot) <= -5000000.0:
		tmp = cosrot * v
	elif (v * cosrot) <= 2e+131:
		tmp = sinrot * (u - u0)
	else:
		tmp = cosrot * v
	return tmp
function code(u, v, cosrot, sinrot, u0)
	tmp = 0.0
	if (Float64(v * cosrot) <= -5000000.0)
		tmp = Float64(cosrot * v);
	elseif (Float64(v * cosrot) <= 2e+131)
		tmp = Float64(sinrot * Float64(u - u0));
	else
		tmp = Float64(cosrot * v);
	end
	return tmp
end
function tmp_2 = code(u, v, cosrot, sinrot, u0)
	tmp = 0.0;
	if ((v * cosrot) <= -5000000.0)
		tmp = cosrot * v;
	elseif ((v * cosrot) <= 2e+131)
		tmp = sinrot * (u - u0);
	else
		tmp = cosrot * v;
	end
	tmp_2 = tmp;
end
code[u_, v_, cosrot_, sinrot_, u0_] := If[LessEqual[N[(v * cosrot), $MachinePrecision], -5000000.0], N[(cosrot * v), $MachinePrecision], If[LessEqual[N[(v * cosrot), $MachinePrecision], 2e+131], N[(sinrot * N[(u - u0), $MachinePrecision]), $MachinePrecision], N[(cosrot * v), $MachinePrecision]]]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	LET tmp_1 = IF ((v * cosrot) <= (199999999999999982405111001914463627825705729939051460364922737117355163153802565541919878198424069508213948681199740222346696327168)) THEN (sinrot * (u - u0)) ELSE (cosrot * v) ENDIF IN
	LET tmp = IF ((v * cosrot) <= (-5e6)) THEN (cosrot * v) ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;v \cdot cosrot \leq -5000000:\\
\;\;\;\;cosrot \cdot v\\

\mathbf{elif}\;v \cdot cosrot \leq 2 \cdot 10^{+131}:\\
\;\;\;\;sinrot \cdot \left(u - u0\right)\\

\mathbf{else}:\\
\;\;\;\;cosrot \cdot v\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 v cosrot) < -5e6 or 1.9999999999999998e131 < (*.f64 v cosrot)

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in u0 around 0

      \[\leadsto cosrot \cdot v + sinrot \cdot u \]
    3. Applied rewrites70.8%

      \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
    4. Taylor expanded in u around 0

      \[\leadsto cosrot \cdot v \]
    5. Applied rewrites41.4%

      \[\leadsto cosrot \cdot v \]

    if -5e6 < (*.f64 v cosrot) < 1.9999999999999998e131

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in v around 0

      \[\leadsto sinrot \cdot \left(u - u0\right) \]
    3. Applied rewrites62.1%

      \[\leadsto sinrot \cdot \left(u - u0\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 54.1% accurate, 0.7× speedup?

\[\begin{array}{l} \mathbf{if}\;v \cdot cosrot \leq -5000000:\\ \;\;\;\;cosrot \cdot v\\ \mathbf{elif}\;v \cdot cosrot \leq 10^{+106}:\\ \;\;\;\;sinrot \cdot u\\ \mathbf{else}:\\ \;\;\;\;cosrot \cdot v\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (if (<= (* v cosrot) -5000000.0)
  (* cosrot v)
  (if (<= (* v cosrot) 1e+106) (* sinrot u) (* cosrot v))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double tmp;
	if ((v * cosrot) <= -5000000.0) {
		tmp = cosrot * v;
	} else if ((v * cosrot) <= 1e+106) {
		tmp = sinrot * u;
	} else {
		tmp = cosrot * v;
	}
	return tmp;
}
real(8) function code(u, v, cosrot, sinrot, u0)
use fmin_fmax_functions
    real(8), intent (in) :: u
    real(8), intent (in) :: v
    real(8), intent (in) :: cosrot
    real(8), intent (in) :: sinrot
    real(8), intent (in) :: u0
    real(8) :: tmp
    if ((v * cosrot) <= (-5000000.0d0)) then
        tmp = cosrot * v
    else if ((v * cosrot) <= 1d+106) then
        tmp = sinrot * u
    else
        tmp = cosrot * v
    end if
    code = tmp
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	double tmp;
	if ((v * cosrot) <= -5000000.0) {
		tmp = cosrot * v;
	} else if ((v * cosrot) <= 1e+106) {
		tmp = sinrot * u;
	} else {
		tmp = cosrot * v;
	}
	return tmp;
}
def code(u, v, cosrot, sinrot, u0):
	tmp = 0
	if (v * cosrot) <= -5000000.0:
		tmp = cosrot * v
	elif (v * cosrot) <= 1e+106:
		tmp = sinrot * u
	else:
		tmp = cosrot * v
	return tmp
function code(u, v, cosrot, sinrot, u0)
	tmp = 0.0
	if (Float64(v * cosrot) <= -5000000.0)
		tmp = Float64(cosrot * v);
	elseif (Float64(v * cosrot) <= 1e+106)
		tmp = Float64(sinrot * u);
	else
		tmp = Float64(cosrot * v);
	end
	return tmp
end
function tmp_2 = code(u, v, cosrot, sinrot, u0)
	tmp = 0.0;
	if ((v * cosrot) <= -5000000.0)
		tmp = cosrot * v;
	elseif ((v * cosrot) <= 1e+106)
		tmp = sinrot * u;
	else
		tmp = cosrot * v;
	end
	tmp_2 = tmp;
end
code[u_, v_, cosrot_, sinrot_, u0_] := If[LessEqual[N[(v * cosrot), $MachinePrecision], -5000000.0], N[(cosrot * v), $MachinePrecision], If[LessEqual[N[(v * cosrot), $MachinePrecision], 1e+106], N[(sinrot * u), $MachinePrecision], N[(cosrot * v), $MachinePrecision]]]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	LET tmp_1 = IF ((v * cosrot) <= (10000000000000000910359990503684350104604539951754865571545457374840902895351334152154180097541612190564352)) THEN (sinrot * u) ELSE (cosrot * v) ENDIF IN
	LET tmp = IF ((v * cosrot) <= (-5e6)) THEN (cosrot * v) ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;v \cdot cosrot \leq -5000000:\\
\;\;\;\;cosrot \cdot v\\

\mathbf{elif}\;v \cdot cosrot \leq 10^{+106}:\\
\;\;\;\;sinrot \cdot u\\

\mathbf{else}:\\
\;\;\;\;cosrot \cdot v\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 v cosrot) < -5e6 or 1.0000000000000001e106 < (*.f64 v cosrot)

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in u0 around 0

      \[\leadsto cosrot \cdot v + sinrot \cdot u \]
    3. Applied rewrites70.8%

      \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
    4. Taylor expanded in u around 0

      \[\leadsto cosrot \cdot v \]
    5. Applied rewrites41.4%

      \[\leadsto cosrot \cdot v \]

    if -5e6 < (*.f64 v cosrot) < 1.0000000000000001e106

    1. Initial program 98.8%

      \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
    2. Taylor expanded in u0 around 0

      \[\leadsto cosrot \cdot v + sinrot \cdot u \]
    3. Applied rewrites70.8%

      \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
    4. Taylor expanded in u around 0

      \[\leadsto cosrot \cdot v \]
    5. Applied rewrites41.4%

      \[\leadsto cosrot \cdot v \]
    6. Taylor expanded in undef-var around zero

      \[\leadsto cosrot \cdot 0 \]
    7. Applied rewrites3.0%

      \[\leadsto cosrot \cdot 0 \]
    8. Taylor expanded in u around inf

      \[\leadsto sinrot \cdot u \]
    9. Applied rewrites33.1%

      \[\leadsto sinrot \cdot u \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 41.4% accurate, 3.0× speedup?

\[cosrot \cdot v \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (* cosrot v))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return cosrot * v;
}
real(8) function code(u, v, cosrot, sinrot, u0)
use fmin_fmax_functions
    real(8), intent (in) :: u
    real(8), intent (in) :: v
    real(8), intent (in) :: cosrot
    real(8), intent (in) :: sinrot
    real(8), intent (in) :: u0
    code = cosrot * v
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	return cosrot * v;
}
def code(u, v, cosrot, sinrot, u0):
	return cosrot * v
function code(u, v, cosrot, sinrot, u0)
	return Float64(cosrot * v)
end
function tmp = code(u, v, cosrot, sinrot, u0)
	tmp = cosrot * v;
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(cosrot * v), $MachinePrecision]
f(u, v, cosrot, sinrot, u0):
	u in [-inf, +inf],
	v in [-inf, +inf],
	cosrot in [-inf, +inf],
	sinrot in [-inf, +inf],
	u0 in [-inf, +inf]
code: THEORY
BEGIN
f(u, v, cosrot, sinrot, u0: real): real =
	cosrot * v
END code
cosrot \cdot v
Derivation
  1. Initial program 98.8%

    \[v \cdot cosrot + \left(u - u0\right) \cdot sinrot \]
  2. Taylor expanded in u0 around 0

    \[\leadsto cosrot \cdot v + sinrot \cdot u \]
  3. Applied rewrites70.8%

    \[\leadsto \mathsf{fma}\left(cosrot, v, sinrot \cdot u\right) \]
  4. Taylor expanded in u around 0

    \[\leadsto cosrot \cdot v \]
  5. Applied rewrites41.4%

    \[\leadsto cosrot \cdot v \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2026050 +o generate:egglog
(FPCore (u v cosrot sinrot u0)
  :name "forward-rot-x"
  :precision binary64
  (+ (* v cosrot) (* (- u u0) sinrot)))