Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B

?

Percentage Accurate: 81.9% → 95.7%
Time: 4.2s
Precision: binary64
Cost: 1353

?

\[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\frac{y}{z} \cdot t}{t}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-216} \lor \neg \left(t_1 \leq 4 \cdot 10^{-323}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \end{array} \]
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (* (/ y z) t) t)))
   (if (or (<= t_1 -5e-216) (not (<= t_1 4e-323)))
     (/ x (/ z y))
     (* y (/ x z)))))
double code(double x, double y, double z, double t) {
	return x * (((y / z) * t) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = ((y / z) * t) / t;
	double tmp;
	if ((t_1 <= -5e-216) || !(t_1 <= 4e-323)) {
		tmp = x / (z / y);
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x * (((y / z) * t) / t)
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = ((y / z) * t) / t
    if ((t_1 <= (-5d-216)) .or. (.not. (t_1 <= 4d-323))) then
        tmp = x / (z / y)
    else
        tmp = y * (x / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x * (((y / z) * t) / t);
}
public static double code(double x, double y, double z, double t) {
	double t_1 = ((y / z) * t) / t;
	double tmp;
	if ((t_1 <= -5e-216) || !(t_1 <= 4e-323)) {
		tmp = x / (z / y);
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
def code(x, y, z, t):
	return x * (((y / z) * t) / t)
def code(x, y, z, t):
	t_1 = ((y / z) * t) / t
	tmp = 0
	if (t_1 <= -5e-216) or not (t_1 <= 4e-323):
		tmp = x / (z / y)
	else:
		tmp = y * (x / z)
	return tmp
function code(x, y, z, t)
	return Float64(x * Float64(Float64(Float64(y / z) * t) / t))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(y / z) * t) / t)
	tmp = 0.0
	if ((t_1 <= -5e-216) || !(t_1 <= 4e-323))
		tmp = Float64(x / Float64(z / y));
	else
		tmp = Float64(y * Float64(x / z));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x * (((y / z) * t) / t);
end
function tmp_2 = code(x, y, z, t)
	t_1 = ((y / z) * t) / t;
	tmp = 0.0;
	if ((t_1 <= -5e-216) || ~((t_1 <= 4e-323)))
		tmp = x / (z / y);
	else
		tmp = y * (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e-216], N[Not[LessEqual[t$95$1, 4e-323]], $MachinePrecision]], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\frac{y}{z} \cdot t}{t}\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{-216} \lor \neg \left(t_1 \leq 4 \cdot 10^{-323}\right):\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\

\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\


\end{array}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 3 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original81.9%
Target98.0%
Herbie95.7%
\[\begin{array}{l} \mathbf{if}\;\frac{\frac{y}{z} \cdot t}{t} < -1.20672205123045 \cdot 10^{+245}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < -5.907522236933906 \cdot 10^{-275}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 5.658954423153415 \cdot 10^{-65}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 2.0087180502407133 \cdot 10^{+217}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (/.f64 y z) t) t) < -5.00000000000000021e-216 or 3.95253e-323 < (/.f64 (*.f64 (/.f64 y z) t) t)

    1. Initial program 93.5%

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified97.9%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
      Step-by-step derivation

      [Start]93.5%

      \[ x \cdot \frac{\frac{y}{z} \cdot t}{t} \]

      associate-/l* [=>]97.9%

      \[ x \cdot \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}} \]

      *-inverses [=>]97.9%

      \[ x \cdot \frac{\frac{y}{z}}{\color{blue}{1}} \]

      /-rgt-identity [=>]97.9%

      \[ x \cdot \color{blue}{\frac{y}{z}} \]
    3. Applied egg-rr98.3%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Step-by-step derivation

      [Start]97.9%

      \[ x \cdot \frac{y}{z} \]

      clear-num [=>]97.8%

      \[ x \cdot \color{blue}{\frac{1}{\frac{z}{y}}} \]

      un-div-inv [=>]98.3%

      \[ \color{blue}{\frac{x}{\frac{z}{y}}} \]

    if -5.00000000000000021e-216 < (/.f64 (*.f64 (/.f64 y z) t) t) < 3.95253e-323

    1. Initial program 52.2%

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified97.6%

      \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
      Step-by-step derivation

      [Start]52.2%

      \[ x \cdot \frac{\frac{y}{z} \cdot t}{t} \]

      *-commutative [=>]52.2%

      \[ \color{blue}{\frac{\frac{y}{z} \cdot t}{t} \cdot x} \]

      associate-/l* [=>]73.6%

      \[ \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}} \cdot x \]

      *-inverses [=>]73.6%

      \[ \frac{\frac{y}{z}}{\color{blue}{1}} \cdot x \]

      /-rgt-identity [=>]73.6%

      \[ \color{blue}{\frac{y}{z}} \cdot x \]

      associate-*l/ [=>]98.2%

      \[ \color{blue}{\frac{y \cdot x}{z}} \]

      associate-*r/ [<=]97.6%

      \[ \color{blue}{y \cdot \frac{x}{z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\frac{y}{z} \cdot t}{t} \leq -5 \cdot 10^{-216} \lor \neg \left(\frac{\frac{y}{z} \cdot t}{t} \leq 4 \cdot 10^{-323}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy95.7%
Cost1353
\[\begin{array}{l} t_1 := \frac{\frac{y}{z} \cdot t}{t}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-216} \lor \neg \left(t_1 \leq 4 \cdot 10^{-323}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 2
Accuracy92.3%
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{-143}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \end{array} \]
Alternative 3
Accuracy92.1%
Cost320
\[\frac{y}{z} \cdot x \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (x y z t)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
  :precision binary64

  :herbie-target
  (if (< (/ (* (/ y z) t) t) -1.20672205123045e+245) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) -5.907522236933906e-275) (* x (/ y z)) (if (< (/ (* (/ y z) t) t) 5.658954423153415e-65) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) 2.0087180502407133e+217) (* x (/ y z)) (/ (* y x) z)))))

  (* x (/ (* (/ y z) t) t)))