
(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 4 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
(let* ((t_1 (pow (cbrt z) 2.0)))
(if (<= z 2.45e-231)
(/ (/ (/ x (/ t_1 y)) (cbrt t_1)) (cbrt (cbrt z)))
(* x (/ y z)))))assert(x < y);
double code(double x, double y, double z, double t) {
double t_1 = pow(cbrt(z), 2.0);
double tmp;
if (z <= 2.45e-231) {
tmp = ((x / (t_1 / y)) / cbrt(t_1)) / cbrt(cbrt(z));
} else {
tmp = x * (y / z);
}
return tmp;
}
assert x < y;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.pow(Math.cbrt(z), 2.0);
double tmp;
if (z <= 2.45e-231) {
tmp = ((x / (t_1 / y)) / Math.cbrt(t_1)) / Math.cbrt(Math.cbrt(z));
} else {
tmp = x * (y / z);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y, z, t) t_1 = cbrt(z) ^ 2.0 tmp = 0.0 if (z <= 2.45e-231) tmp = Float64(Float64(Float64(x / Float64(t_1 / y)) / cbrt(t_1)) / cbrt(cbrt(z))); else tmp = Float64(x * Float64(y / z)); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Power[N[Power[z, 1/3], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[z, 2.45e-231], N[(N[(N[(x / N[(t$95$1 / y), $MachinePrecision]), $MachinePrecision] / N[Power[t$95$1, 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[N[Power[z, 1/3], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_1 := {\left(\sqrt[3]{z}\right)}^{2}\\
\mathbf{if}\;z \leq 2.45 \cdot 10^{-231}:\\
\;\;\;\;\frac{\frac{\frac{x}{\frac{t_1}{y}}}{\sqrt[3]{t_1}}}{\sqrt[3]{\sqrt[3]{z}}}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if z < 2.45000000000000002e-231Initial program 84.2%
associate-/l*92.6%
associate-*r/92.6%
*-commutative92.6%
*-inverses92.6%
/-rgt-identity92.6%
*-commutative92.6%
Simplified92.6%
associate-*r/92.8%
add-cube-cbrt91.7%
associate-/r*91.7%
add-cube-cbrt91.6%
cbrt-prod91.5%
associate-/r*91.6%
associate-/l*94.8%
pow294.8%
pow294.8%
Applied egg-rr94.8%
if 2.45000000000000002e-231 < z Initial program 83.0%
associate-/l*96.2%
associate-*r/96.2%
*-commutative96.2%
*-inverses96.2%
/-rgt-identity96.2%
*-commutative96.2%
Simplified96.2%
Final simplification95.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y 6e-246) (* x (/ y z)) (/ (sqrt y) (* (/ 1.0 x) (/ z (sqrt y))))))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6e-246) {
tmp = x * (y / z);
} else {
tmp = sqrt(y) / ((1.0 / x) * (z / sqrt(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 <= 6d-246) then
tmp = x * (y / z)
else
tmp = sqrt(y) / ((1.0d0 / x) * (z / sqrt(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 <= 6e-246) {
tmp = x * (y / z);
} else {
tmp = Math.sqrt(y) / ((1.0 / x) * (z / Math.sqrt(y)));
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if y <= 6e-246: tmp = x * (y / z) else: tmp = math.sqrt(y) / ((1.0 / x) * (z / math.sqrt(y))) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (y <= 6e-246) tmp = Float64(x * Float64(y / z)); else tmp = Float64(sqrt(y) / Float64(Float64(1.0 / x) * Float64(z / sqrt(y)))); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= 6e-246)
tmp = x * (y / z);
else
tmp = sqrt(y) / ((1.0 / x) * (z / sqrt(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[y, 6e-246], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[y], $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] * N[(z / N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-246}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{y}}{\frac{1}{x} \cdot \frac{z}{\sqrt{y}}}\\
\end{array}
\end{array}
if y < 6e-246Initial program 82.4%
associate-/l*94.1%
associate-*r/94.1%
*-commutative94.1%
*-inverses94.1%
/-rgt-identity94.1%
*-commutative94.1%
Simplified94.1%
if 6e-246 < y Initial program 85.2%
associate-/l*94.1%
associate-*r/94.1%
*-commutative94.1%
*-inverses94.1%
/-rgt-identity94.1%
*-commutative94.1%
Simplified94.1%
clear-num94.0%
un-div-inv94.2%
Applied egg-rr94.2%
associate-/l*94.2%
div-inv94.1%
*-commutative94.1%
Applied egg-rr94.1%
associate-*l/94.2%
*-un-lft-identity94.2%
*-commutative94.2%
associate-/l*94.3%
div-inv94.2%
associate-/r*94.1%
add-sqr-sqrt93.7%
associate-/l*93.8%
associate-/l/95.3%
Applied egg-rr95.3%
Final simplification94.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y 1.65e-250) (* x (/ y z)) (/ (sqrt y) (/ (/ z (sqrt y)) x))))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.65e-250) {
tmp = x * (y / z);
} else {
tmp = sqrt(y) / ((z / sqrt(y)) / x);
}
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 <= 1.65d-250) then
tmp = x * (y / z)
else
tmp = sqrt(y) / ((z / sqrt(y)) / x)
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 <= 1.65e-250) {
tmp = x * (y / z);
} else {
tmp = Math.sqrt(y) / ((z / Math.sqrt(y)) / x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if y <= 1.65e-250: tmp = x * (y / z) else: tmp = math.sqrt(y) / ((z / math.sqrt(y)) / x) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (y <= 1.65e-250) tmp = Float64(x * Float64(y / z)); else tmp = Float64(sqrt(y) / Float64(Float64(z / sqrt(y)) / x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= 1.65e-250)
tmp = x * (y / z);
else
tmp = sqrt(y) / ((z / sqrt(y)) / x);
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[y, 1.65e-250], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[y], $MachinePrecision] / N[(N[(z / N[Sqrt[y], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-250}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{y}}{\frac{\frac{z}{\sqrt{y}}}{x}}\\
\end{array}
\end{array}
if y < 1.65e-250Initial program 82.3%
associate-/l*94.1%
associate-*r/94.1%
*-commutative94.1%
*-inverses94.1%
/-rgt-identity94.1%
*-commutative94.1%
Simplified94.1%
if 1.65e-250 < y Initial program 85.3%
associate-/l*94.1%
associate-*r/94.1%
*-commutative94.1%
*-inverses94.1%
/-rgt-identity94.1%
*-commutative94.1%
Simplified94.1%
clear-num94.0%
un-div-inv94.2%
Applied egg-rr94.2%
associate-/l*94.3%
div-inv94.1%
*-commutative94.1%
Applied egg-rr94.1%
associate-*l/94.3%
*-un-lft-identity94.3%
*-commutative94.3%
associate-/l*94.3%
div-inv94.2%
associate-/r*94.1%
add-sqr-sqrt93.8%
associate-/l*93.8%
associate-/l/95.3%
Applied egg-rr95.3%
associate-*l/95.4%
*-un-lft-identity95.4%
Applied egg-rr95.4%
Final simplification94.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* x (/ y z)))
assert(x < y);
double code(double x, double y, double z, double t) {
return x * (y / z);
}
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 = x * (y / z)
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
return x * (y / z);
}
[x, y] = sort([x, y]) def code(x, y, z, t): return x * (y / z)
x, y = sort([x, y]) function code(x, y, z, t) return Float64(x * Float64(y / z)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z, t)
tmp = x * (y / z);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot \frac{y}{z}
\end{array}
Initial program 83.7%
associate-/l*94.1%
associate-*r/94.1%
*-commutative94.1%
*-inverses94.1%
/-rgt-identity94.1%
*-commutative94.1%
Simplified94.1%
Final simplification94.1%
(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 2023301
(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)))