Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1

Percentage Accurate: 67.5% → 98.7%
Time: 5.9s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
	return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x * x) / (y * y)) + ((z * z) / (t * t))
end function
public static double code(double x, double y, double z, double t) {
	return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t):
	return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t)
	return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t)))
end
function tmp = code(x, y, z, t)
	tmp = ((x * x) / (y * y)) + ((z * z) / (t * t));
end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\end{array}

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 5 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: 67.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
	return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x * x) / (y * y)) + ((z * z) / (t * t))
end function
public static double code(double x, double y, double z, double t) {
	return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t):
	return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t)
	return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t)))
end
function tmp = code(x, y, z, t)
	tmp = ((x * x) / (y * y)) + ((z * z) / (t * t));
end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\end{array}

Alternative 1: 98.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{z \cdot z}{t \cdot t} \leq 2 \cdot 10^{+234}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{x}{y} \cdot \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\frac{x}{y}}{y} \cdot x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (/ (* z z) (* t t)) 2e+234)
   (fma (/ (/ z t) t) z (* (/ x y) (/ x y)))
   (fma (/ z t) (/ z t) (* (/ (/ x y) y) x))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (((z * z) / (t * t)) <= 2e+234) {
		tmp = fma(((z / t) / t), z, ((x / y) * (x / y)));
	} else {
		tmp = fma((z / t), (z / t), (((x / y) / y) * x));
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(Float64(z * z) / Float64(t * t)) <= 2e+234)
		tmp = fma(Float64(Float64(z / t) / t), z, Float64(Float64(x / y) * Float64(x / y)));
	else
		tmp = fma(Float64(z / t), Float64(z / t), Float64(Float64(Float64(x / y) / y) * x));
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision], 2e+234], N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision] + N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{z \cdot z}{t \cdot t} \leq 2 \cdot 10^{+234}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{x}{y} \cdot \frac{x}{y}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\frac{x}{y}}{y} \cdot x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 z z) (*.f64 t t)) < 2.00000000000000004e234

    1. Initial program 67.5%

      \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \frac{x \cdot x}{y \cdot y}} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      4. mult-flipN/A

        \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{y \cdot y}} \]
      5. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} - \left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}} \]
      6. sub-flip-reverseN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right)} \]
      7. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      8. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{z \cdot z}}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      9. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{z}{t \cdot t} \cdot z} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      10. distribute-lft-neg-outN/A

        \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right)\right)\right) \cdot \frac{1}{y \cdot y}} \]
      11. remove-double-negN/A

        \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{y \cdot y} \]
      12. mult-flipN/A

        \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      13. lift-/.f64N/A

        \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      14. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x \cdot x}{y \cdot y}\right)} \]
      15. lower-/.f6474.3

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t \cdot t}}, z, \frac{x \cdot x}{y \cdot y}\right) \]
      16. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x \cdot x}{y \cdot y}}\right) \]
      17. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{\color{blue}{x \cdot x}}{y \cdot y}\right) \]
      18. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      19. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      20. lower-/.f6481.1

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
    3. Applied rewrites81.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right)} \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
      3. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x \cdot x}{y \cdot y}}\right) \]
      4. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x \cdot x}{\color{blue}{y \cdot y}}\right) \]
      5. times-fracN/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}\right) \]
      7. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y}} \cdot \frac{x}{y}\right) \]
      8. lower-/.f6490.1

        \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y} \cdot \color{blue}{\frac{x}{y}}\right) \]
    5. Applied rewrites90.1%

      \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}\right) \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t \cdot t}}, z, \frac{x}{y} \cdot \frac{x}{y}\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{\color{blue}{t \cdot t}}, z, \frac{x}{y} \cdot \frac{x}{y}\right) \]
      3. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\frac{z}{t}}{t}}, z, \frac{x}{y} \cdot \frac{x}{y}\right) \]
      4. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{z}{t}}}{t}, z, \frac{x}{y} \cdot \frac{x}{y}\right) \]
      5. lower-/.f6496.8

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\frac{z}{t}}{t}}, z, \frac{x}{y} \cdot \frac{x}{y}\right) \]
    7. Applied rewrites96.8%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\frac{z}{t}}{t}}, z, \frac{x}{y} \cdot \frac{x}{y}\right) \]

    if 2.00000000000000004e234 < (/.f64 (*.f64 z z) (*.f64 t t))

    1. Initial program 67.5%

      \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \frac{x \cdot x}{y \cdot y}} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      4. mult-flipN/A

        \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{y \cdot y}} \]
      5. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} - \left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}} \]
      6. sub-flip-reverseN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right)} \]
      7. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      8. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{z \cdot z}}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      9. lift-*.f64N/A

        \[\leadsto \frac{z \cdot z}{\color{blue}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      10. times-fracN/A

        \[\leadsto \color{blue}{\frac{z}{t} \cdot \frac{z}{t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      11. distribute-lft-neg-outN/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right)\right)\right) \cdot \frac{1}{y \cdot y}} \]
      12. remove-double-negN/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{y \cdot y} \]
      13. mult-flipN/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      14. lift-/.f64N/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      15. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x \cdot x}{y \cdot y}\right)} \]
      16. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, \frac{z}{t}, \frac{x \cdot x}{y \cdot y}\right) \]
      17. lower-/.f6481.9

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \color{blue}{\frac{z}{t}}, \frac{x \cdot x}{y \cdot y}\right) \]
      18. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x \cdot x}{y \cdot y}}\right) \]
      19. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\color{blue}{x \cdot x}}{y \cdot y}\right) \]
      20. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      21. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      22. lower-/.f6489.4

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
    3. Applied rewrites89.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{y \cdot y} \cdot x\right)} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{\color{blue}{y \cdot y}} \cdot x\right) \]
      3. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{\frac{x}{y}}{y}} \cdot x\right) \]
      4. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{\frac{x}{y}}{y}} \cdot x\right) \]
      5. lower-/.f6496.7

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\color{blue}{\frac{x}{y}}}{y} \cdot x\right) \]
    5. Applied rewrites96.7%

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{\frac{x}{y}}{y}} \cdot x\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 96.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 5 \cdot 10^{+298}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{y \cdot y} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (/ (* x x) (* y y)) 5e+298)
   (fma (/ z t) (/ z t) (* (/ x (* y y)) x))
   (fma (/ x y) (/ x y) (* (/ z (* t t)) z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (((x * x) / (y * y)) <= 5e+298) {
		tmp = fma((z / t), (z / t), ((x / (y * y)) * x));
	} else {
		tmp = fma((x / y), (x / y), ((z / (t * t)) * z));
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(Float64(x * x) / Float64(y * y)) <= 5e+298)
		tmp = fma(Float64(z / t), Float64(z / t), Float64(Float64(x / Float64(y * y)) * x));
	else
		tmp = fma(Float64(x / y), Float64(x / y), Float64(Float64(z / Float64(t * t)) * z));
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision], 5e+298], N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision] + N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 5 \cdot 10^{+298}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{y \cdot y} \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x x) (*.f64 y y)) < 5.0000000000000003e298

    1. Initial program 67.5%

      \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \frac{x \cdot x}{y \cdot y}} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      4. mult-flipN/A

        \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{y \cdot y}} \]
      5. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} - \left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}} \]
      6. sub-flip-reverseN/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right)} \]
      7. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      8. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{z \cdot z}}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      9. lift-*.f64N/A

        \[\leadsto \frac{z \cdot z}{\color{blue}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      10. times-fracN/A

        \[\leadsto \color{blue}{\frac{z}{t} \cdot \frac{z}{t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
      11. distribute-lft-neg-outN/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right)\right)\right) \cdot \frac{1}{y \cdot y}} \]
      12. remove-double-negN/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{y \cdot y} \]
      13. mult-flipN/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      14. lift-/.f64N/A

        \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
      15. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x \cdot x}{y \cdot y}\right)} \]
      16. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, \frac{z}{t}, \frac{x \cdot x}{y \cdot y}\right) \]
      17. lower-/.f6481.9

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \color{blue}{\frac{z}{t}}, \frac{x \cdot x}{y \cdot y}\right) \]
      18. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x \cdot x}{y \cdot y}}\right) \]
      19. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\color{blue}{x \cdot x}}{y \cdot y}\right) \]
      20. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      21. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
      22. lower-/.f6489.4

        \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
    3. Applied rewrites89.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{y \cdot y} \cdot x\right)} \]

    if 5.0000000000000003e298 < (/.f64 (*.f64 x x) (*.f64 y y))

    1. Initial program 67.5%

      \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{\frac{z \cdot z}{t \cdot t}} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{x \cdot x}{y \cdot y} + \frac{\color{blue}{z \cdot z}}{t \cdot t} \]
      4. associate-/l*N/A

        \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{z \cdot \frac{z}{t \cdot t}} \]
      5. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} - \left(\mathsf{neg}\left(z\right)\right) \cdot \frac{z}{t \cdot t}} \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \frac{x \cdot x}{y \cdot y} - \color{blue}{\left(\mathsf{neg}\left(z \cdot \frac{z}{t \cdot t}\right)\right)} \]
      7. distribute-rgt-neg-inN/A

        \[\leadsto \frac{x \cdot x}{y \cdot y} - \color{blue}{z \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right)} \]
      8. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right)} \]
      9. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
      10. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot y} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
      11. lift-*.f64N/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
      12. times-fracN/A

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
      13. distribute-rgt-neg-inN/A

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \frac{z}{t \cdot t}\right)\right)} \]
      14. distribute-lft-neg-inN/A

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z \cdot \frac{z}{t \cdot t}\right)\right)}\right)\right) \]
      15. associate-/l*N/A

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\frac{z \cdot z}{t \cdot t}}\right)\right)\right)\right) \]
      16. lift-*.f64N/A

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\color{blue}{z \cdot z}}{t \cdot t}\right)\right)\right)\right) \]
      17. lift-/.f64N/A

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\frac{z \cdot z}{t \cdot t}}\right)\right)\right)\right) \]
      18. remove-double-negN/A

        \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{\frac{z \cdot z}{t \cdot t}} \]
      19. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z \cdot z}{t \cdot t}\right)} \]
    3. Applied rewrites90.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 96.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\frac{x}{y}}{y} \cdot x\right) \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (fma (/ z t) (/ z t) (* (/ (/ x y) y) x)))
double code(double x, double y, double z, double t) {
	return fma((z / t), (z / t), (((x / y) / y) * x));
}
function code(x, y, z, t)
	return fma(Float64(z / t), Float64(z / t), Float64(Float64(Float64(x / y) / y) * x))
end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision] + N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\frac{x}{y}}{y} \cdot x\right)
\end{array}
Derivation
  1. Initial program 67.5%

    \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \frac{x \cdot x}{y \cdot y}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
    4. mult-flipN/A

      \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{y \cdot y}} \]
    5. fp-cancel-sign-sub-invN/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} - \left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}} \]
    6. sub-flip-reverseN/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right)} \]
    7. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    8. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{z \cdot z}}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    9. lift-*.f64N/A

      \[\leadsto \frac{z \cdot z}{\color{blue}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    10. times-fracN/A

      \[\leadsto \color{blue}{\frac{z}{t} \cdot \frac{z}{t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    11. distribute-lft-neg-outN/A

      \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right)\right)\right) \cdot \frac{1}{y \cdot y}} \]
    12. remove-double-negN/A

      \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{y \cdot y} \]
    13. mult-flipN/A

      \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
    14. lift-/.f64N/A

      \[\leadsto \frac{z}{t} \cdot \frac{z}{t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
    15. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x \cdot x}{y \cdot y}\right)} \]
    16. lower-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, \frac{z}{t}, \frac{x \cdot x}{y \cdot y}\right) \]
    17. lower-/.f6481.9

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \color{blue}{\frac{z}{t}}, \frac{x \cdot x}{y \cdot y}\right) \]
    18. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x \cdot x}{y \cdot y}}\right) \]
    19. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\color{blue}{x \cdot x}}{y \cdot y}\right) \]
    20. associate-*l/N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
    21. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
    22. lower-/.f6489.4

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
  3. Applied rewrites89.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{y \cdot y} \cdot x\right)} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
    2. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{\color{blue}{y \cdot y}} \cdot x\right) \]
    3. associate-/r*N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{\frac{x}{y}}{y}} \cdot x\right) \]
    4. lower-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{\frac{x}{y}}{y}} \cdot x\right) \]
    5. lower-/.f6496.7

      \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{\color{blue}{\frac{x}{y}}}{y} \cdot x\right) \]
  5. Applied rewrites96.7%

    \[\leadsto \mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \color{blue}{\frac{\frac{x}{y}}{y}} \cdot x\right) \]
  6. Add Preprocessing

Alternative 4: 90.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right) \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (fma (/ x y) (/ x y) (* (/ z (* t t)) z)))
double code(double x, double y, double z, double t) {
	return fma((x / y), (x / y), ((z / (t * t)) * z));
}
function code(x, y, z, t)
	return fma(Float64(x / y), Float64(x / y), Float64(Float64(z / Float64(t * t)) * z))
end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right)
\end{array}
Derivation
  1. Initial program 67.5%

    \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
    2. lift-/.f64N/A

      \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{\frac{z \cdot z}{t \cdot t}} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{x \cdot x}{y \cdot y} + \frac{\color{blue}{z \cdot z}}{t \cdot t} \]
    4. associate-/l*N/A

      \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{z \cdot \frac{z}{t \cdot t}} \]
    5. fp-cancel-sign-sub-invN/A

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} - \left(\mathsf{neg}\left(z\right)\right) \cdot \frac{z}{t \cdot t}} \]
    6. distribute-lft-neg-inN/A

      \[\leadsto \frac{x \cdot x}{y \cdot y} - \color{blue}{\left(\mathsf{neg}\left(z \cdot \frac{z}{t \cdot t}\right)\right)} \]
    7. distribute-rgt-neg-inN/A

      \[\leadsto \frac{x \cdot x}{y \cdot y} - \color{blue}{z \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right)} \]
    8. fp-cancel-sub-sign-invN/A

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right)} \]
    9. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
    10. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot y} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
    11. lift-*.f64N/A

      \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
    12. times-fracN/A

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(\frac{z}{t \cdot t}\right)\right) \]
    13. distribute-rgt-neg-inN/A

      \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \frac{z}{t \cdot t}\right)\right)} \]
    14. distribute-lft-neg-inN/A

      \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z \cdot \frac{z}{t \cdot t}\right)\right)}\right)\right) \]
    15. associate-/l*N/A

      \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\frac{z \cdot z}{t \cdot t}}\right)\right)\right)\right) \]
    16. lift-*.f64N/A

      \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\color{blue}{z \cdot z}}{t \cdot t}\right)\right)\right)\right) \]
    17. lift-/.f64N/A

      \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\frac{z \cdot z}{t \cdot t}}\right)\right)\right)\right) \]
    18. remove-double-negN/A

      \[\leadsto \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{\frac{z \cdot z}{t \cdot t}} \]
    19. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z \cdot z}{t \cdot t}\right)} \]
  3. Applied rewrites90.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right)} \]
  4. Add Preprocessing

Alternative 5: 81.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right) \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (fma (/ z (* t t)) z (* (/ x (* y y)) x)))
double code(double x, double y, double z, double t) {
	return fma((z / (t * t)), z, ((x / (y * y)) * x));
}
function code(x, y, z, t)
	return fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / Float64(y * y)) * x))
end
code[x_, y_, z_, t_] := N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right)
\end{array}
Derivation
  1. Initial program 67.5%

    \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \frac{x \cdot x}{y \cdot y}} \]
    3. lift-/.f64N/A

      \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
    4. mult-flipN/A

      \[\leadsto \frac{z \cdot z}{t \cdot t} + \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{y \cdot y}} \]
    5. fp-cancel-sign-sub-invN/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} - \left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}} \]
    6. sub-flip-reverseN/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right)} \]
    7. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{z \cdot z}{t \cdot t}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    8. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{z \cdot z}}{t \cdot t} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    9. associate-*l/N/A

      \[\leadsto \color{blue}{\frac{z}{t \cdot t} \cdot z} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right) \cdot \frac{1}{y \cdot y}\right)\right) \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot x\right)\right)\right)\right) \cdot \frac{1}{y \cdot y}} \]
    11. remove-double-negN/A

      \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{y \cdot y} \]
    12. mult-flipN/A

      \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
    13. lift-/.f64N/A

      \[\leadsto \frac{z}{t \cdot t} \cdot z + \color{blue}{\frac{x \cdot x}{y \cdot y}} \]
    14. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x \cdot x}{y \cdot y}\right)} \]
    15. lower-/.f6474.3

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t \cdot t}}, z, \frac{x \cdot x}{y \cdot y}\right) \]
    16. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x \cdot x}{y \cdot y}}\right) \]
    17. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{\color{blue}{x \cdot x}}{y \cdot y}\right) \]
    18. associate-*l/N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
    19. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y} \cdot x}\right) \]
    20. lower-/.f6481.1

      \[\leadsto \mathsf{fma}\left(\frac{z}{t \cdot t}, z, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
  3. Applied rewrites81.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right)} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025149 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1"
  :precision binary64
  (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))