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

Percentage Accurate: 66.3% → 98.5%
Time: 3.9s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
(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]
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}

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

\[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
(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]
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}

Alternative 1: 98.5% accurate, 0.6× speedup?

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

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


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

    1. Initial program 66.3%

      \[\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 \color{blue}{\frac{z \cdot z}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
      4. lift-*.f64N/A

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

        \[\leadsto \frac{z \cdot z}{\color{blue}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
      6. times-fracN/A

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

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

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

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

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

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

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

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

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

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

      \[\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}, \color{blue}{\frac{x}{y \cdot y}} \cdot x\right) \]
      3. associate-*l/N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000002e220 < (/.f64 (*.f64 x x) (*.f64 y y))

    1. Initial program 66.3%

      \[\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. add-flipN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{z \cdot z}{t \cdot t}\right)\right)\right)\right) \]
      8. 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) \]
      9. distribute-neg-fracN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 97.9% accurate, 0.6× speedup?

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x x) (*.f64 y y)) < 5e-31

    1. Initial program 66.3%

      \[\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 \color{blue}{\frac{z \cdot z}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
      4. lift-*.f64N/A

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

        \[\leadsto \frac{z \cdot z}{\color{blue}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
      6. times-fracN/A

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

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

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

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

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

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

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

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

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

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

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

    if 5e-31 < (/.f64 (*.f64 x x) (*.f64 y y))

    1. Initial program 66.3%

      \[\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. add-flipN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{z \cdot z}{t \cdot t}\right)\right)\right)\right) \]
      8. 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) \]
      9. distribute-neg-fracN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 97.8% accurate, 0.6× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 10^{+84}:\\ \;\;\;\;\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} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (/ (* x x) (* y y)) 1e+84)
   (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)) <= 1e+84) {
		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)) <= 1e+84)
		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], 1e+84], 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}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 10^{+84}:\\
\;\;\;\;\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}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x x) (*.f64 y y)) < 1.00000000000000006e84

    1. Initial program 66.3%

      \[\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 \color{blue}{\frac{z \cdot z}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
      4. lift-*.f64N/A

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

        \[\leadsto \frac{z \cdot z}{\color{blue}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
      6. times-fracN/A

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000006e84 < (/.f64 (*.f64 x x) (*.f64 y y))

    1. Initial program 66.3%

      \[\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. add-flipN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{z \cdot z}{t \cdot t}\right)\right)\right)\right) \]
      8. 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) \]
      9. distribute-neg-fracN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 4: 96.1% accurate, 0.6× speedup?

\[\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, e^{\log \left(\frac{\left|z\right|}{\left|t\right|}\right) \cdot 2}\right) \]
(FPCore (x y z t)
 :precision binary64
 (fma (/ x y) (/ x y) (exp (* (log (/ (fabs z) (fabs t))) 2.0))))
double code(double x, double y, double z, double t) {
	return fma((x / y), (x / y), exp((log((fabs(z) / fabs(t))) * 2.0)));
}
function code(x, y, z, t)
	return fma(Float64(x / y), Float64(x / y), exp(Float64(log(Float64(abs(z) / abs(t))) * 2.0)))
end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[Exp[N[(N[Log[N[(N[Abs[z], $MachinePrecision] / N[Abs[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, e^{\log \left(\frac{\left|z\right|}{\left|t\right|}\right) \cdot 2}\right)
Derivation
  1. Initial program 66.3%

    \[\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. add-flipN/A

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{z \cdot z}{t \cdot t}\right)\right)\right)\right) \]
    8. 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) \]
    9. distribute-neg-fracN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \color{blue}{{\left(\frac{z}{t}\right)}^{2}}\right) \]
    9. pow-to-expN/A

      \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \color{blue}{e^{\log \left(\frac{z}{t}\right) \cdot 2}}\right) \]
    10. lower-unsound-exp.f64N/A

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

      \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, e^{\color{blue}{\log \left(\frac{z}{t}\right) \cdot 2}}\right) \]
    12. lower-unsound-log.f6453.9

      \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, e^{\color{blue}{\log \left(\frac{z}{t}\right)} \cdot 2}\right) \]
  5. Applied rewrites53.9%

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

Alternative 5: 89.7% accurate, 1.0× speedup?

\[\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right) \]
(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]
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t \cdot t} \cdot z\right)
Derivation
  1. Initial program 66.3%

    \[\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. add-flipN/A

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{z \cdot z}{t \cdot t}\right)\right)\right)\right) \]
    8. 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) \]
    9. distribute-neg-fracN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 80.5% accurate, 1.0× speedup?

\[\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right) \]
(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]
\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right)
Derivation
  1. Initial program 66.3%

    \[\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 \color{blue}{\frac{z \cdot z}{t \cdot t}} + \frac{x \cdot x}{y \cdot y} \]
    4. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

    \[\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 2025175 
(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))))