
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
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
public static double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
def code(x, y, z, t): return x * (((y / z) * t) / t)
function code(x, y, z, t) return Float64(x * Float64(Float64(Float64(y / z) * t) / t)) end
function tmp = code(x, y, z, t) tmp = x * (((y / z) * t) / t); end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
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
public static double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
def code(x, y, z, t): return x * (((y / z) * t) / t)
function code(x, y, z, t) return Float64(x * Float64(Float64(Float64(y / z) * t) / t)) end
function tmp = code(x, y, z, t) tmp = x * (((y / z) * t) / t); end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (/ y z) -5e-133) (* (/ y z) x) (if (<= (/ y z) 5e-266) (/ (* y x) z) (/ x (/ z y)))))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -5e-133) {
tmp = (y / z) * x;
} else if ((y / z) <= 5e-266) {
tmp = (y * x) / z;
} else {
tmp = x / (z / y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this 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) :: tmp
if ((y / z) <= (-5d-133)) then
tmp = (y / z) * x
else if ((y / z) <= 5d-266) then
tmp = (y * x) / z
else
tmp = x / (z / y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -5e-133) {
tmp = (y / z) * x;
} else if ((y / z) <= 5e-266) {
tmp = (y * x) / z;
} else {
tmp = x / (z / y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if (y / z) <= -5e-133: tmp = (y / z) * x elif (y / z) <= 5e-266: tmp = (y * x) / z else: tmp = x / (z / y) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (Float64(y / z) <= -5e-133) tmp = Float64(Float64(y / z) * x); elseif (Float64(y / z) <= 5e-266) tmp = Float64(Float64(y * x) / z); else tmp = Float64(x / Float64(z / y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((y / z) <= -5e-133)
tmp = (y / z) * x;
elseif ((y / z) <= 5e-266)
tmp = (y * x) / z;
else
tmp = x / (z / y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(y / z), $MachinePrecision], -5e-133], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 5e-266], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} \leq -5 \cdot 10^{-133}:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{-266}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if (/.f64 y z) < -4.9999999999999999e-133Initial program 90.6%
associate-/l*96.8%
*-inverses96.8%
/-rgt-identity96.8%
Simplified96.8%
if -4.9999999999999999e-133 < (/.f64 y z) < 4.99999999999999992e-266Initial program 80.9%
associate-/l*88.4%
*-inverses88.4%
/-rgt-identity88.4%
Simplified88.4%
Taylor expanded in x around 0 99.8%
if 4.99999999999999992e-266 < (/.f64 y z) Initial program 85.3%
associate-/l*94.7%
*-inverses94.7%
/-rgt-identity94.7%
Simplified94.7%
clear-num94.7%
un-div-inv95.4%
Applied egg-rr95.4%
Final simplification96.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (/ y z) -5e-135) (* (/ y z) x) (if (<= (/ y z) 5e-242) (* y (/ x z)) (/ x (/ z y)))))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -5e-135) {
tmp = (y / z) * x;
} else if ((y / z) <= 5e-242) {
tmp = y * (x / z);
} else {
tmp = x / (z / y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this 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) :: tmp
if ((y / z) <= (-5d-135)) then
tmp = (y / z) * x
else if ((y / z) <= 5d-242) then
tmp = y * (x / z)
else
tmp = x / (z / y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -5e-135) {
tmp = (y / z) * x;
} else if ((y / z) <= 5e-242) {
tmp = y * (x / z);
} else {
tmp = x / (z / y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if (y / z) <= -5e-135: tmp = (y / z) * x elif (y / z) <= 5e-242: tmp = y * (x / z) else: tmp = x / (z / y) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (Float64(y / z) <= -5e-135) tmp = Float64(Float64(y / z) * x); elseif (Float64(y / z) <= 5e-242) tmp = Float64(y * Float64(x / z)); else tmp = Float64(x / Float64(z / y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((y / z) <= -5e-135)
tmp = (y / z) * x;
elseif ((y / z) <= 5e-242)
tmp = y * (x / z);
else
tmp = x / (z / y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(y / z), $MachinePrecision], -5e-135], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 5e-242], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} \leq -5 \cdot 10^{-135}:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{-242}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if (/.f64 y z) < -5.0000000000000002e-135Initial program 90.8%
associate-/l*96.8%
*-inverses96.8%
/-rgt-identity96.8%
Simplified96.8%
if -5.0000000000000002e-135 < (/.f64 y z) < 4.9999999999999998e-242Initial program 81.6%
*-commutative81.6%
associate-/l*88.9%
*-inverses88.9%
/-rgt-identity88.9%
associate-*l/99.8%
associate-*r/97.9%
Simplified97.9%
if 4.9999999999999998e-242 < (/.f64 y z) Initial program 84.8%
associate-/l*94.5%
*-inverses94.5%
/-rgt-identity94.5%
Simplified94.5%
clear-num94.5%
un-div-inv95.3%
Applied egg-rr95.3%
Final simplification96.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (/ y z) -2e-233) (* (/ y z) x) (if (<= (/ y z) 5e-250) (/ y (/ z x)) (/ x (/ z y)))))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -2e-233) {
tmp = (y / z) * x;
} else if ((y / z) <= 5e-250) {
tmp = y / (z / x);
} else {
tmp = x / (z / y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this 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) :: tmp
if ((y / z) <= (-2d-233)) then
tmp = (y / z) * x
else if ((y / z) <= 5d-250) then
tmp = y / (z / x)
else
tmp = x / (z / y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -2e-233) {
tmp = (y / z) * x;
} else if ((y / z) <= 5e-250) {
tmp = y / (z / x);
} else {
tmp = x / (z / y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if (y / z) <= -2e-233: tmp = (y / z) * x elif (y / z) <= 5e-250: tmp = y / (z / x) else: tmp = x / (z / y) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (Float64(y / z) <= -2e-233) tmp = Float64(Float64(y / z) * x); elseif (Float64(y / z) <= 5e-250) tmp = Float64(y / Float64(z / x)); else tmp = Float64(x / Float64(z / y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((y / z) <= -2e-233)
tmp = (y / z) * x;
elseif ((y / z) <= 5e-250)
tmp = y / (z / x);
else
tmp = x / (z / y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(y / z), $MachinePrecision], -2e-233], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 5e-250], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} \leq -2 \cdot 10^{-233}:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{-250}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if (/.f64 y z) < -1.99999999999999992e-233Initial program 91.1%
associate-/l*97.2%
*-inverses97.2%
/-rgt-identity97.2%
Simplified97.2%
if -1.99999999999999992e-233 < (/.f64 y z) < 5.00000000000000027e-250Initial program 76.8%
associate-/l*84.4%
*-inverses84.4%
/-rgt-identity84.4%
Simplified84.4%
*-commutative84.4%
associate-*l/99.7%
associate-/l*99.8%
Applied egg-rr99.8%
if 5.00000000000000027e-250 < (/.f64 y z) Initial program 85.0%
associate-/l*94.6%
*-inverses94.6%
/-rgt-identity94.6%
Simplified94.6%
clear-num94.5%
un-div-inv95.3%
Applied egg-rr95.3%
Final simplification96.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= t 7.6e-119) (* (/ y z) x) (* y (/ x z))))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 7.6e-119) {
tmp = (y / z) * x;
} else {
tmp = y * (x / z);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this 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) :: tmp
if (t <= 7.6d-119) then
tmp = (y / z) * x
else
tmp = y * (x / z)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 7.6e-119) {
tmp = (y / z) * x;
} else {
tmp = y * (x / z);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if t <= 7.6e-119: tmp = (y / z) * x else: tmp = y * (x / z) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (t <= 7.6e-119) tmp = Float64(Float64(y / z) * x); else tmp = Float64(y * Float64(x / z)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (t <= 7.6e-119)
tmp = (y / z) * x;
else
tmp = y * (x / z);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[t, 7.6e-119], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq 7.6 \cdot 10^{-119}:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if t < 7.59999999999999949e-119Initial program 84.8%
associate-/l*94.6%
*-inverses94.6%
/-rgt-identity94.6%
Simplified94.6%
if 7.59999999999999949e-119 < t Initial program 89.8%
*-commutative89.8%
associate-/l*93.2%
*-inverses93.2%
/-rgt-identity93.2%
associate-*l/93.9%
associate-*r/92.2%
Simplified92.2%
Final simplification93.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* (/ y z) x))
assert(x < y);
double code(double x, double y, double z, double t) {
return (y / z) * x;
}
NOTE: x and y should be sorted in increasing order before calling this 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
code = (y / z) * x
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
return (y / z) * x;
}
[x, y] = sort([x, y]) def code(x, y, z, t): return (y / z) * x
x, y = sort([x, y]) function code(x, y, z, t) return Float64(Float64(y / z) * x) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z, t)
tmp = (y / z) * x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{y}{z} \cdot x
\end{array}
Initial program 86.3%
associate-/l*94.2%
*-inverses94.2%
/-rgt-identity94.2%
Simplified94.2%
Final simplification94.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (/ y z))) (t_2 (/ (* (/ y z) t) t)) (t_3 (/ y (/ z x))))
(if (< t_2 -1.20672205123045e+245)
t_3
(if (< t_2 -5.907522236933906e-275)
t_1
(if (< t_2 5.658954423153415e-65)
t_3
(if (< t_2 2.0087180502407133e+217) t_1 (/ (* y x) z)))))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y / z);
double t_2 = ((y / z) * t) / t;
double t_3 = y / (z / x);
double tmp;
if (t_2 < -1.20672205123045e+245) {
tmp = t_3;
} else if (t_2 < -5.907522236933906e-275) {
tmp = t_1;
} else if (t_2 < 5.658954423153415e-65) {
tmp = t_3;
} else if (t_2 < 2.0087180502407133e+217) {
tmp = t_1;
} 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
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = x * (y / z)
t_2 = ((y / z) * t) / t
t_3 = y / (z / x)
if (t_2 < (-1.20672205123045d+245)) then
tmp = t_3
else if (t_2 < (-5.907522236933906d-275)) then
tmp = t_1
else if (t_2 < 5.658954423153415d-65) then
tmp = t_3
else if (t_2 < 2.0087180502407133d+217) then
tmp = t_1
else
tmp = (y * x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x * (y / z);
double t_2 = ((y / z) * t) / t;
double t_3 = y / (z / x);
double tmp;
if (t_2 < -1.20672205123045e+245) {
tmp = t_3;
} else if (t_2 < -5.907522236933906e-275) {
tmp = t_1;
} else if (t_2 < 5.658954423153415e-65) {
tmp = t_3;
} else if (t_2 < 2.0087180502407133e+217) {
tmp = t_1;
} else {
tmp = (y * x) / z;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y / z) t_2 = ((y / z) * t) / t t_3 = y / (z / x) tmp = 0 if t_2 < -1.20672205123045e+245: tmp = t_3 elif t_2 < -5.907522236933906e-275: tmp = t_1 elif t_2 < 5.658954423153415e-65: tmp = t_3 elif t_2 < 2.0087180502407133e+217: tmp = t_1 else: tmp = (y * x) / z return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y / z)) t_2 = Float64(Float64(Float64(y / z) * t) / t) t_3 = Float64(y / Float64(z / x)) tmp = 0.0 if (t_2 < -1.20672205123045e+245) tmp = t_3; elseif (t_2 < -5.907522236933906e-275) tmp = t_1; elseif (t_2 < 5.658954423153415e-65) tmp = t_3; elseif (t_2 < 2.0087180502407133e+217) tmp = t_1; else tmp = Float64(Float64(y * x) / z); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y / z); t_2 = ((y / z) * t) / t; t_3 = y / (z / x); tmp = 0.0; if (t_2 < -1.20672205123045e+245) tmp = t_3; elseif (t_2 < -5.907522236933906e-275) tmp = t_1; elseif (t_2 < 5.658954423153415e-65) tmp = t_3; elseif (t_2 < 2.0087180502407133e+217) tmp = t_1; else tmp = (y * x) / z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$3 = N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$2, -1.20672205123045e+245], t$95$3, If[Less[t$95$2, -5.907522236933906e-275], t$95$1, If[Less[t$95$2, 5.658954423153415e-65], t$95$3, If[Less[t$95$2, 2.0087180502407133e+217], t$95$1, N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \frac{y}{z}\\
t_2 := \frac{\frac{y}{z} \cdot t}{t}\\
t_3 := \frac{y}{\frac{z}{x}}\\
\mathbf{if}\;t_2 < -1.20672205123045 \cdot 10^{+245}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 < -5.907522236933906 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 < 5.658954423153415 \cdot 10^{-65}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 < 2.0087180502407133 \cdot 10^{+217}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\end{array}
\end{array}
herbie shell --seed 2023185
(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)))