Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C

Percentage Accurate: 99.9% → 99.9%
Time: 970.0ms
Alternatives: 4
Speedup: 1.0×

Specification

?
\[\mathsf{TRUE}\left(\right)\]
\[\begin{array}{l} \\ x \cdot \left(y + z\right) + z \cdot 5 \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
	return (x * (y + z)) + (z * 5.0);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
	return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z):
	return (x * (y + z)) + (z * 5.0)
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0))
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) + (z * 5.0);
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}

Sampling outcomes in binary64 precision:

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 4 alternatives:

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

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \left(y + z\right) + z \cdot 5 \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
	return (x * (y + z)) + (z * 5.0);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
	return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z):
	return (x * (y + z)) + (z * 5.0)
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0))
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) + (z * 5.0);
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \left(y + z\right) + z \cdot 5 \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
	return (x * (y + z)) + (z * 5.0);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * (y + z)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
	return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z):
	return (x * (y + z)) + (z * 5.0)
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0))
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) + (z * 5.0);
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 83.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{-96}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{-49}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ y z))))
   (if (<= x -8.5e-96) t_0 (if (<= x 5.1e-49) (* z 5.0) t_0))))
double code(double x, double y, double z) {
	double t_0 = x * (y + z);
	double tmp;
	if (x <= -8.5e-96) {
		tmp = t_0;
	} else if (x <= 5.1e-49) {
		tmp = z * 5.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x * (y + z)
    if (x <= (-8.5d-96)) then
        tmp = t_0
    else if (x <= 5.1d-49) then
        tmp = z * 5.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (y + z);
	double tmp;
	if (x <= -8.5e-96) {
		tmp = t_0;
	} else if (x <= 5.1e-49) {
		tmp = z * 5.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (y + z)
	tmp = 0
	if x <= -8.5e-96:
		tmp = t_0
	elif x <= 5.1e-49:
		tmp = z * 5.0
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(y + z))
	tmp = 0.0
	if (x <= -8.5e-96)
		tmp = t_0;
	elseif (x <= 5.1e-49)
		tmp = Float64(z * 5.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (y + z);
	tmp = 0.0;
	if (x <= -8.5e-96)
		tmp = t_0;
	elseif (x <= 5.1e-49)
		tmp = z * 5.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.5e-96], t$95$0, If[LessEqual[x, 5.1e-49], N[(z * 5.0), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{-96}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 5.1 \cdot 10^{-49}:\\
\;\;\;\;z \cdot 5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -8.49999999999999983e-96 or 5.10000000000000026e-49 < x

    1. Initial program 99.9%

      \[x \cdot \left(y + z\right) + z \cdot 5 \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{5 \cdot z + x \cdot \left(y + z\right)} \]
    4. Applied rewrites91.9%

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]

    if -8.49999999999999983e-96 < x < 5.10000000000000026e-49

    1. Initial program 99.8%

      \[x \cdot \left(y + z\right) + z \cdot 5 \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(y + \left(z + 5 \cdot \frac{z}{x}\right)\right)} \]
    4. Applied rewrites83.3%

      \[\leadsto \color{blue}{z \cdot 5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 36.8% accurate, 2.8× speedup?

\[\begin{array}{l} \\ z \cdot 5 \end{array} \]
(FPCore (x y z) :precision binary64 (* z 5.0))
double code(double x, double y, double z) {
	return z * 5.0;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = z * 5.0d0
end function
public static double code(double x, double y, double z) {
	return z * 5.0;
}
def code(x, y, z):
	return z * 5.0
function code(x, y, z)
	return Float64(z * 5.0)
end
function tmp = code(x, y, z)
	tmp = z * 5.0;
end
code[x_, y_, z_] := N[(z * 5.0), $MachinePrecision]
\begin{array}{l}

\\
z \cdot 5
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf

    \[\leadsto \color{blue}{x \cdot \left(y + \left(z + 5 \cdot \frac{z}{x}\right)\right)} \]
  4. Applied rewrites35.6%

    \[\leadsto \color{blue}{z \cdot 5} \]
  5. Add Preprocessing

Alternative 4: 7.1% accurate, 4.3× speedup?

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

\\
y + z
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{5 \cdot z + x \cdot \left(y + z\right)} \]
  4. Applied rewrites65.7%

    \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
  5. Taylor expanded in x around 0

    \[\leadsto x \cdot \color{blue}{\left(y + z\right)} \]
  6. Applied rewrites6.7%

    \[\leadsto y + \color{blue}{z} \]
  7. Add Preprocessing

Developer Target 1: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + 5\right) \cdot z + x \cdot y \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* (+ x 5.0) z) (* x y)))
double code(double x, double y, double z) {
	return ((x + 5.0) * z) + (x * y);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x + 5.0d0) * z) + (x * y)
end function
public static double code(double x, double y, double z) {
	return ((x + 5.0) * z) + (x * y);
}
def code(x, y, z):
	return ((x + 5.0) * z) + (x * y)
function code(x, y, z)
	return Float64(Float64(Float64(x + 5.0) * z) + Float64(x * y))
end
function tmp = code(x, y, z)
	tmp = ((x + 5.0) * z) + (x * y);
end
code[x_, y_, z_] := N[(N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + 5\right) \cdot z + x \cdot y
\end{array}

Reproduce

?
herbie shell --seed 2024321 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
  :precision binary64
  :pre (TRUE)

  :alt
  (! :herbie-platform default (+ (* (+ x 5) z) (* x y)))

  (+ (* x (+ y z)) (* z 5.0)))