forward-rot-y

Percentage Accurate: 99.0% → 99.5%
Time: 1.0min
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (- (* (- u u0) cosrot) (* v sinrot)))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return ((u - u0) * cosrot) - (v * 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 = ((u - u0) * cosrot) - (v * sinrot)
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	return ((u - u0) * cosrot) - (v * sinrot);
}
def code(u, v, cosrot, sinrot, u0):
	return ((u - u0) * cosrot) - (v * sinrot)
function code(u, v, cosrot, sinrot, u0)
	return Float64(Float64(Float64(u - u0) * cosrot) - Float64(v * sinrot))
end
function tmp = code(u, v, cosrot, sinrot, u0)
	tmp = ((u - u0) * cosrot) - (v * sinrot);
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(N[(N[(u - u0), $MachinePrecision] * cosrot), $MachinePrecision] - N[(v * 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 =
	((u - u0) * cosrot) - (v * sinrot)
END code
\left(u - u0\right) \cdot cosrot - v \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 8 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: 99.0% accurate, 1.0× speedup?

\[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (- (* (- u u0) cosrot) (* v sinrot)))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return ((u - u0) * cosrot) - (v * 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 = ((u - u0) * cosrot) - (v * sinrot)
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	return ((u - u0) * cosrot) - (v * sinrot);
}
def code(u, v, cosrot, sinrot, u0):
	return ((u - u0) * cosrot) - (v * sinrot)
function code(u, v, cosrot, sinrot, u0)
	return Float64(Float64(Float64(u - u0) * cosrot) - Float64(v * sinrot))
end
function tmp = code(u, v, cosrot, sinrot, u0)
	tmp = ((u - u0) * cosrot) - (v * sinrot);
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(N[(N[(u - u0), $MachinePrecision] * cosrot), $MachinePrecision] - N[(v * 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 =
	((u - u0) * cosrot) - (v * sinrot)
END code
\left(u - u0\right) \cdot cosrot - v \cdot sinrot

Alternative 1: 99.5% accurate, 1.0× speedup?

\[\mathsf{fma}\left(-v, sinrot, \left(u - u0\right) \cdot cosrot\right) \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (fma (- v) sinrot (* (- u u0) cosrot)))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return fma(-v, sinrot, ((u - u0) * cosrot));
}
function code(u, v, cosrot, sinrot, u0)
	return fma(Float64(-v), sinrot, Float64(Float64(u - u0) * cosrot))
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[((-v) * sinrot + N[(N[(u - u0), $MachinePrecision] * 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 =
	((- v) * sinrot) + ((u - u0) * cosrot)
END code
\mathsf{fma}\left(-v, sinrot, \left(u - u0\right) \cdot cosrot\right)
Derivation
  1. Initial program 99.0%

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

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

Alternative 2: 86.2% accurate, 0.7× speedup?

\[\begin{array}{l} t_0 := cosrot \cdot u - v \cdot sinrot\\ \mathbf{if}\;u \leq -3.6237116819841634 \cdot 10^{-6}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;u \leq 4.8790624046209624 \cdot 10^{+58}:\\ \;\;\;\;-\mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (- (* cosrot u) (* v sinrot))))
  (if (<= u -3.6237116819841634e-6)
    t_0
    (if (<= u 4.8790624046209624e+58)
      (- (fma cosrot u0 (* sinrot v)))
      t_0))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (cosrot * u) - (v * sinrot);
	double tmp;
	if (u <= -3.6237116819841634e-6) {
		tmp = t_0;
	} else if (u <= 4.8790624046209624e+58) {
		tmp = -fma(cosrot, u0, (sinrot * v));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(u, v, cosrot, sinrot, u0)
	t_0 = Float64(Float64(cosrot * u) - Float64(v * sinrot))
	tmp = 0.0
	if (u <= -3.6237116819841634e-6)
		tmp = t_0;
	elseif (u <= 4.8790624046209624e+58)
		tmp = Float64(-fma(cosrot, u0, Float64(sinrot * v)));
	else
		tmp = t_0;
	end
	return tmp
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[(N[(cosrot * u), $MachinePrecision] - N[(v * sinrot), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[u, -3.6237116819841634e-6], t$95$0, If[LessEqual[u, 4.8790624046209624e+58], (-N[(cosrot * u0 + N[(sinrot * v), $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 * u) - (v * sinrot)) IN
		LET tmp_1 = IF (u <= (48790624046209624241241801881757209186572933609305466208256)) THEN (- ((cosrot * u0) + (sinrot * v))) ELSE t_0 ENDIF IN
		LET tmp = IF (u <= (-362371168198416339681876274791960668153478763997554779052734375e-68)) THEN t_0 ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := cosrot \cdot u - v \cdot sinrot\\
\mathbf{if}\;u \leq -3.6237116819841634 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u < -3.6237116819841634e-6 or 4.8790624046209624e58 < u

    1. Initial program 99.0%

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

      \[\leadsto cosrot \cdot u - v \cdot sinrot \]
    3. Applied rewrites69.9%

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

    if -3.6237116819841634e-6 < u < 4.8790624046209624e58

    1. Initial program 99.0%

      \[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
    2. Applied rewrites97.3%

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

      \[\leadsto -1 \cdot \left(cosrot \cdot u0 + sinrot \cdot v\right) \]
    4. Applied rewrites70.3%

      \[\leadsto -1 \cdot \mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right) \]
    5. Applied rewrites70.3%

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

Alternative 3: 82.1% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := \left(u - u0\right) \cdot cosrot\\ t_1 := cosrot \cdot \left(u - u0\right)\\ \mathbf{if}\;t\_0 \leq -4 \cdot 10^{+107}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+42}:\\ \;\;\;\;cosrot \cdot u - v \cdot sinrot\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (* (- u u0) cosrot)) (t_1 (* cosrot (- u u0))))
  (if (<= t_0 -4e+107)
    t_1
    (if (<= t_0 2e+42) (- (* cosrot u) (* v sinrot)) t_1))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * cosrot;
	double t_1 = cosrot * (u - u0);
	double tmp;
	if (t_0 <= -4e+107) {
		tmp = t_1;
	} else if (t_0 <= 2e+42) {
		tmp = (cosrot * u) - (v * sinrot);
	} else {
		tmp = t_1;
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (u - u0) * cosrot
    t_1 = cosrot * (u - u0)
    if (t_0 <= (-4d+107)) then
        tmp = t_1
    else if (t_0 <= 2d+42) then
        tmp = (cosrot * u) - (v * sinrot)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * cosrot;
	double t_1 = cosrot * (u - u0);
	double tmp;
	if (t_0 <= -4e+107) {
		tmp = t_1;
	} else if (t_0 <= 2e+42) {
		tmp = (cosrot * u) - (v * sinrot);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(u, v, cosrot, sinrot, u0):
	t_0 = (u - u0) * cosrot
	t_1 = cosrot * (u - u0)
	tmp = 0
	if t_0 <= -4e+107:
		tmp = t_1
	elif t_0 <= 2e+42:
		tmp = (cosrot * u) - (v * sinrot)
	else:
		tmp = t_1
	return tmp
function code(u, v, cosrot, sinrot, u0)
	t_0 = Float64(Float64(u - u0) * cosrot)
	t_1 = Float64(cosrot * Float64(u - u0))
	tmp = 0.0
	if (t_0 <= -4e+107)
		tmp = t_1;
	elseif (t_0 <= 2e+42)
		tmp = Float64(Float64(cosrot * u) - Float64(v * sinrot));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(u, v, cosrot, sinrot, u0)
	t_0 = (u - u0) * cosrot;
	t_1 = cosrot * (u - u0);
	tmp = 0.0;
	if (t_0 <= -4e+107)
		tmp = t_1;
	elseif (t_0 <= 2e+42)
		tmp = (cosrot * u) - (v * sinrot);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[(N[(u - u0), $MachinePrecision] * cosrot), $MachinePrecision]}, Block[{t$95$1 = N[(cosrot * N[(u - u0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+107], t$95$1, If[LessEqual[t$95$0, 2e+42], N[(N[(cosrot * u), $MachinePrecision] - N[(v * sinrot), $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) * cosrot) IN
		LET t_1 = (cosrot * (u - u0)) IN
			LET tmp_1 = IF (t_0 <= (2000000000000000089771425356151833571098624)) THEN ((cosrot * u) - (v * sinrot)) ELSE t_1 ENDIF IN
			LET tmp = IF (t_0 <= (-399999999999999987525536188119707933741485076245118757626576847011166100546682581581016009581583539221037056)) THEN t_1 ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := \left(u - u0\right) \cdot cosrot\\
t_1 := cosrot \cdot \left(u - u0\right)\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+107}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+42}:\\
\;\;\;\;cosrot \cdot u - v \cdot sinrot\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 u u0) cosrot) < -3.9999999999999999e107 or 2.0000000000000001e42 < (*.f64 (-.f64 u u0) cosrot)

    1. Initial program 99.0%

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

      \[\leadsto cosrot \cdot \left(u - u0\right) \]
    3. Applied rewrites63.8%

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

    if -3.9999999999999999e107 < (*.f64 (-.f64 u u0) cosrot) < 2.0000000000000001e42

    1. Initial program 99.0%

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

      \[\leadsto cosrot \cdot u - v \cdot sinrot \]
    3. Applied rewrites69.9%

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

Alternative 4: 74.7% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \left(u - u0\right) \cdot cosrot\\ t_1 := cosrot \cdot \left(u - u0\right)\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+72}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+42}:\\ \;\;\;\;\left(-v\right) \cdot sinrot\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (* (- u u0) cosrot)) (t_1 (* cosrot (- u u0))))
  (if (<= t_0 -5e+72) t_1 (if (<= t_0 2e+42) (* (- v) sinrot) t_1))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * cosrot;
	double t_1 = cosrot * (u - u0);
	double tmp;
	if (t_0 <= -5e+72) {
		tmp = t_1;
	} else if (t_0 <= 2e+42) {
		tmp = -v * sinrot;
	} else {
		tmp = t_1;
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (u - u0) * cosrot
    t_1 = cosrot * (u - u0)
    if (t_0 <= (-5d+72)) then
        tmp = t_1
    else if (t_0 <= 2d+42) then
        tmp = -v * sinrot
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * cosrot;
	double t_1 = cosrot * (u - u0);
	double tmp;
	if (t_0 <= -5e+72) {
		tmp = t_1;
	} else if (t_0 <= 2e+42) {
		tmp = -v * sinrot;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(u, v, cosrot, sinrot, u0):
	t_0 = (u - u0) * cosrot
	t_1 = cosrot * (u - u0)
	tmp = 0
	if t_0 <= -5e+72:
		tmp = t_1
	elif t_0 <= 2e+42:
		tmp = -v * sinrot
	else:
		tmp = t_1
	return tmp
function code(u, v, cosrot, sinrot, u0)
	t_0 = Float64(Float64(u - u0) * cosrot)
	t_1 = Float64(cosrot * Float64(u - u0))
	tmp = 0.0
	if (t_0 <= -5e+72)
		tmp = t_1;
	elseif (t_0 <= 2e+42)
		tmp = Float64(Float64(-v) * sinrot);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(u, v, cosrot, sinrot, u0)
	t_0 = (u - u0) * cosrot;
	t_1 = cosrot * (u - u0);
	tmp = 0.0;
	if (t_0 <= -5e+72)
		tmp = t_1;
	elseif (t_0 <= 2e+42)
		tmp = -v * sinrot;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[(N[(u - u0), $MachinePrecision] * cosrot), $MachinePrecision]}, Block[{t$95$1 = N[(cosrot * N[(u - u0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+72], t$95$1, If[LessEqual[t$95$0, 2e+42], N[((-v) * sinrot), $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) * cosrot) IN
		LET t_1 = (cosrot * (u - u0)) IN
			LET tmp_1 = IF (t_0 <= (2000000000000000089771425356151833571098624)) THEN ((- v) * sinrot) ELSE t_1 ENDIF IN
			LET tmp = IF (t_0 <= (-4999999999999999915168483974806628990154540120342328160919227099783364608)) THEN t_1 ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := \left(u - u0\right) \cdot cosrot\\
t_1 := cosrot \cdot \left(u - u0\right)\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+72}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+42}:\\
\;\;\;\;\left(-v\right) \cdot sinrot\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 u u0) cosrot) < -4.9999999999999999e72 or 2.0000000000000001e42 < (*.f64 (-.f64 u u0) cosrot)

    1. Initial program 99.0%

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

      \[\leadsto cosrot \cdot \left(u - u0\right) \]
    3. Applied rewrites63.8%

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

    if -4.9999999999999999e72 < (*.f64 (-.f64 u u0) cosrot) < 2.0000000000000001e42

    1. Initial program 99.0%

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

      \[\leadsto -1 \cdot \left(sinrot \cdot v\right) \]
    3. Applied rewrites39.8%

      \[\leadsto -1 \cdot \left(sinrot \cdot v\right) \]
    4. Applied rewrites39.8%

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

Alternative 5: 52.5% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \left(u - u0\right) \cdot cosrot\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+72}:\\ \;\;\;\;cosrot \cdot u\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+42}:\\ \;\;\;\;\left(-v\right) \cdot sinrot\\ \mathbf{else}:\\ \;\;\;\;-cosrot \cdot u0\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (* (- u u0) cosrot)))
  (if (<= t_0 -5e+72)
    (* cosrot u)
    (if (<= t_0 2e+42) (* (- v) sinrot) (- (* cosrot u0))))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * cosrot;
	double tmp;
	if (t_0 <= -5e+72) {
		tmp = cosrot * u;
	} else if (t_0 <= 2e+42) {
		tmp = -v * sinrot;
	} else {
		tmp = -(cosrot * u0);
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (u - u0) * cosrot
    if (t_0 <= (-5d+72)) then
        tmp = cosrot * u
    else if (t_0 <= 2d+42) then
        tmp = -v * sinrot
    else
        tmp = -(cosrot * u0)
    end if
    code = tmp
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	double t_0 = (u - u0) * cosrot;
	double tmp;
	if (t_0 <= -5e+72) {
		tmp = cosrot * u;
	} else if (t_0 <= 2e+42) {
		tmp = -v * sinrot;
	} else {
		tmp = -(cosrot * u0);
	}
	return tmp;
}
def code(u, v, cosrot, sinrot, u0):
	t_0 = (u - u0) * cosrot
	tmp = 0
	if t_0 <= -5e+72:
		tmp = cosrot * u
	elif t_0 <= 2e+42:
		tmp = -v * sinrot
	else:
		tmp = -(cosrot * u0)
	return tmp
function code(u, v, cosrot, sinrot, u0)
	t_0 = Float64(Float64(u - u0) * cosrot)
	tmp = 0.0
	if (t_0 <= -5e+72)
		tmp = Float64(cosrot * u);
	elseif (t_0 <= 2e+42)
		tmp = Float64(Float64(-v) * sinrot);
	else
		tmp = Float64(-Float64(cosrot * u0));
	end
	return tmp
end
function tmp_2 = code(u, v, cosrot, sinrot, u0)
	t_0 = (u - u0) * cosrot;
	tmp = 0.0;
	if (t_0 <= -5e+72)
		tmp = cosrot * u;
	elseif (t_0 <= 2e+42)
		tmp = -v * sinrot;
	else
		tmp = -(cosrot * u0);
	end
	tmp_2 = tmp;
end
code[u_, v_, cosrot_, sinrot_, u0_] := Block[{t$95$0 = N[(N[(u - u0), $MachinePrecision] * cosrot), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+72], N[(cosrot * u), $MachinePrecision], If[LessEqual[t$95$0, 2e+42], N[((-v) * sinrot), $MachinePrecision], (-N[(cosrot * u0), $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 t_0 = ((u - u0) * cosrot) IN
		LET tmp_1 = IF (t_0 <= (2000000000000000089771425356151833571098624)) THEN ((- v) * sinrot) ELSE (- (cosrot * u0)) ENDIF IN
		LET tmp = IF (t_0 <= (-4999999999999999915168483974806628990154540120342328160919227099783364608)) THEN (cosrot * u) ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
t_0 := \left(u - u0\right) \cdot cosrot\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+72}:\\
\;\;\;\;cosrot \cdot u\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+42}:\\
\;\;\;\;\left(-v\right) \cdot sinrot\\

\mathbf{else}:\\
\;\;\;\;-cosrot \cdot u0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (-.f64 u u0) cosrot) < -4.9999999999999999e72

    1. Initial program 99.0%

      \[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
    2. Applied rewrites97.3%

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

      \[\leadsto -1 \cdot \left(cosrot \cdot u0 + sinrot \cdot v\right) \]
    4. Applied rewrites70.3%

      \[\leadsto -1 \cdot \mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right) \]
    5. Applied rewrites70.3%

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

      \[\leadsto cosrot \cdot u \]
    7. Applied rewrites33.9%

      \[\leadsto cosrot \cdot u \]

    if -4.9999999999999999e72 < (*.f64 (-.f64 u u0) cosrot) < 2.0000000000000001e42

    1. Initial program 99.0%

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

      \[\leadsto -1 \cdot \left(sinrot \cdot v\right) \]
    3. Applied rewrites39.8%

      \[\leadsto -1 \cdot \left(sinrot \cdot v\right) \]
    4. Applied rewrites39.8%

      \[\leadsto \left(-v\right) \cdot sinrot \]

    if 2.0000000000000001e42 < (*.f64 (-.f64 u u0) cosrot)

    1. Initial program 99.0%

      \[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
    2. Applied rewrites97.3%

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

      \[\leadsto -1 \cdot \left(cosrot \cdot u0 + sinrot \cdot v\right) \]
    4. Applied rewrites70.3%

      \[\leadsto -1 \cdot \mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right) \]
    5. Applied rewrites70.3%

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

      \[\leadsto -cosrot \cdot u0 \]
    7. Applied rewrites34.4%

      \[\leadsto -cosrot \cdot u0 \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 50.6% accurate, 1.0× speedup?

\[\begin{array}{l} \mathbf{if}\;u \leq -3.7678384404308334 \cdot 10^{+93}:\\ \;\;\;\;cosrot \cdot u\\ \mathbf{elif}\;u \leq 4.2456546135261716 \cdot 10^{+60}:\\ \;\;\;\;-cosrot \cdot u0\\ \mathbf{else}:\\ \;\;\;\;cosrot \cdot u\\ \end{array} \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (if (<= u -3.7678384404308334e+93)
  (* cosrot u)
  (if (<= u 4.2456546135261716e+60) (- (* cosrot u0)) (* cosrot u))))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	double tmp;
	if (u <= -3.7678384404308334e+93) {
		tmp = cosrot * u;
	} else if (u <= 4.2456546135261716e+60) {
		tmp = -(cosrot * u0);
	} else {
		tmp = cosrot * u;
	}
	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 (u <= (-3.7678384404308334d+93)) then
        tmp = cosrot * u
    else if (u <= 4.2456546135261716d+60) then
        tmp = -(cosrot * u0)
    else
        tmp = cosrot * u
    end if
    code = tmp
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	double tmp;
	if (u <= -3.7678384404308334e+93) {
		tmp = cosrot * u;
	} else if (u <= 4.2456546135261716e+60) {
		tmp = -(cosrot * u0);
	} else {
		tmp = cosrot * u;
	}
	return tmp;
}
def code(u, v, cosrot, sinrot, u0):
	tmp = 0
	if u <= -3.7678384404308334e+93:
		tmp = cosrot * u
	elif u <= 4.2456546135261716e+60:
		tmp = -(cosrot * u0)
	else:
		tmp = cosrot * u
	return tmp
function code(u, v, cosrot, sinrot, u0)
	tmp = 0.0
	if (u <= -3.7678384404308334e+93)
		tmp = Float64(cosrot * u);
	elseif (u <= 4.2456546135261716e+60)
		tmp = Float64(-Float64(cosrot * u0));
	else
		tmp = Float64(cosrot * u);
	end
	return tmp
end
function tmp_2 = code(u, v, cosrot, sinrot, u0)
	tmp = 0.0;
	if (u <= -3.7678384404308334e+93)
		tmp = cosrot * u;
	elseif (u <= 4.2456546135261716e+60)
		tmp = -(cosrot * u0);
	else
		tmp = cosrot * u;
	end
	tmp_2 = tmp;
end
code[u_, v_, cosrot_, sinrot_, u0_] := If[LessEqual[u, -3.7678384404308334e+93], N[(cosrot * u), $MachinePrecision], If[LessEqual[u, 4.2456546135261716e+60], (-N[(cosrot * u0), $MachinePrecision]), N[(cosrot * u), $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 (u <= (4245654613526171612417188663665039696497402062657605534220288)) THEN (- (cosrot * u0)) ELSE (cosrot * u) ENDIF IN
	LET tmp = IF (u <= (-3767838440430833382452111450546535091604355137179204301070575612783040007786541006163296649216)) THEN (cosrot * u) ELSE tmp_1 ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;u \leq -3.7678384404308334 \cdot 10^{+93}:\\
\;\;\;\;cosrot \cdot u\\

\mathbf{elif}\;u \leq 4.2456546135261716 \cdot 10^{+60}:\\
\;\;\;\;-cosrot \cdot u0\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u < -3.7678384404308334e93 or 4.2456546135261716e60 < u

    1. Initial program 99.0%

      \[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
    2. Applied rewrites97.3%

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

      \[\leadsto -1 \cdot \left(cosrot \cdot u0 + sinrot \cdot v\right) \]
    4. Applied rewrites70.3%

      \[\leadsto -1 \cdot \mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right) \]
    5. Applied rewrites70.3%

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

      \[\leadsto cosrot \cdot u \]
    7. Applied rewrites33.9%

      \[\leadsto cosrot \cdot u \]

    if -3.7678384404308334e93 < u < 4.2456546135261716e60

    1. Initial program 99.0%

      \[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
    2. Applied rewrites97.3%

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

      \[\leadsto -1 \cdot \left(cosrot \cdot u0 + sinrot \cdot v\right) \]
    4. Applied rewrites70.3%

      \[\leadsto -1 \cdot \mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right) \]
    5. Applied rewrites70.3%

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

      \[\leadsto -cosrot \cdot u0 \]
    7. Applied rewrites34.4%

      \[\leadsto -cosrot \cdot u0 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 33.9% accurate, 3.0× speedup?

\[cosrot \cdot u \]
(FPCore (u v cosrot sinrot u0)
  :precision binary64
  :pre TRUE
  (* cosrot u))
double code(double u, double v, double cosrot, double sinrot, double u0) {
	return cosrot * u;
}
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 * u
end function
public static double code(double u, double v, double cosrot, double sinrot, double u0) {
	return cosrot * u;
}
def code(u, v, cosrot, sinrot, u0):
	return cosrot * u
function code(u, v, cosrot, sinrot, u0)
	return Float64(cosrot * u)
end
function tmp = code(u, v, cosrot, sinrot, u0)
	tmp = cosrot * u;
end
code[u_, v_, cosrot_, sinrot_, u0_] := N[(cosrot * u), $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 * u
END code
cosrot \cdot u
Derivation
  1. Initial program 99.0%

    \[\left(u - u0\right) \cdot cosrot - v \cdot sinrot \]
  2. Applied rewrites97.3%

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

    \[\leadsto -1 \cdot \left(cosrot \cdot u0 + sinrot \cdot v\right) \]
  4. Applied rewrites70.3%

    \[\leadsto -1 \cdot \mathsf{fma}\left(cosrot, u0, sinrot \cdot v\right) \]
  5. Applied rewrites70.3%

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

    \[\leadsto cosrot \cdot u \]
  7. Applied rewrites33.9%

    \[\leadsto cosrot \cdot u \]
  8. Add Preprocessing

Reproduce

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