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

Percentage Accurate: 66.7% → 99.7%
Time: 4.1s
Alternatives: 5
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 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: 66.7% 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: 99.7% accurate, 0.9× speedup?

\[\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{\frac{z}{t}}{\frac{t}{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 / t) / Float64(t / z)))
end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z / t), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{\frac{z}{t}}{\frac{t}{z}}\right)
Derivation
  1. Initial program 66.7%

    \[\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-/.f6480.8%

      \[\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.2%

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

    \[\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. lower-*.f6499.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{1}{\color{blue}{\frac{\frac{t}{\frac{z}{t}}}{z}}}\right) \]
    10. div-flip-revN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.6% accurate, 1.0× speedup?

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

    \[\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-/.f6480.8%

      \[\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.2%

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

    \[\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. lower-*.f6499.6%

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

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

Alternative 3: 96.5% accurate, 0.6× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 5 \cdot 10^{+269}:\\ \;\;\;\;\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)) 5e+269)
   (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+269) {
		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+269)
		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+269], 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 5 \cdot 10^{+269}:\\
\;\;\;\;\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)) < 5.0000000000000002e269

    1. Initial program 66.7%

      \[\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-/.f6480.8%

        \[\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.2%

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

      \[\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. lower-*.f6499.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{z}{t} \cdot \color{blue}{\frac{z}{t}} + \frac{x \cdot x}{y \cdot y} \]
      18. lower-fma.f6482.0%

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

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

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

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

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

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

    1. Initial program 66.7%

      \[\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-/.f6480.8%

        \[\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.2%

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

      \[\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: 89.2% 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.7%

    \[\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-/.f6480.8%

      \[\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.2%

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

    \[\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: 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.7%

    \[\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-/.f6473.6%

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