
(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 (* y (/ x z))))
(if (<= (/ y z) -2e+190)
t_1
(if (<= (/ y z) -1e-271)
(/ x (/ z y))
(if (<= (/ y z) 1e-171) t_1 (* x (/ y z)))))))assert(x < y);
double code(double x, double y, double z, double t) {
double t_1 = y * (x / z);
double tmp;
if ((y / z) <= -2e+190) {
tmp = t_1;
} else if ((y / z) <= -1e-271) {
tmp = x / (z / y);
} else if ((y / z) <= 1e-171) {
tmp = t_1;
} else {
tmp = x * (y / 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) :: t_1
real(8) :: tmp
t_1 = y * (x / z)
if ((y / z) <= (-2d+190)) then
tmp = t_1
else if ((y / z) <= (-1d-271)) then
tmp = x / (z / y)
else if ((y / z) <= 1d-171) then
tmp = t_1
else
tmp = x * (y / z)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z, double t) {
double t_1 = y * (x / z);
double tmp;
if ((y / z) <= -2e+190) {
tmp = t_1;
} else if ((y / z) <= -1e-271) {
tmp = x / (z / y);
} else if ((y / z) <= 1e-171) {
tmp = t_1;
} else {
tmp = x * (y / z);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): t_1 = y * (x / z) tmp = 0 if (y / z) <= -2e+190: tmp = t_1 elif (y / z) <= -1e-271: tmp = x / (z / y) elif (y / z) <= 1e-171: tmp = t_1 else: tmp = x * (y / z) return tmp
x, y = sort([x, y]) function code(x, y, z, t) t_1 = Float64(y * Float64(x / z)) tmp = 0.0 if (Float64(y / z) <= -2e+190) tmp = t_1; elseif (Float64(y / z) <= -1e-271) tmp = Float64(x / Float64(z / y)); elseif (Float64(y / z) <= 1e-171) tmp = t_1; else tmp = Float64(x * Float64(y / z)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
t_1 = y * (x / z);
tmp = 0.0;
if ((y / z) <= -2e+190)
tmp = t_1;
elseif ((y / z) <= -1e-271)
tmp = x / (z / y);
elseif ((y / z) <= 1e-171)
tmp = t_1;
else
tmp = x * (y / 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_] := Block[{t$95$1 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y / z), $MachinePrecision], -2e+190], t$95$1, If[LessEqual[N[(y / z), $MachinePrecision], -1e-271], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 1e-171], t$95$1, N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_1 := y \cdot \frac{x}{z}\\
\mathbf{if}\;\frac{y}{z} \leq -2 \cdot 10^{+190}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\frac{y}{z} \leq -1 \cdot 10^{-271}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{elif}\;\frac{y}{z} \leq 10^{-171}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if (/.f64 y z) < -2.0000000000000001e190 or -9.99999999999999963e-272 < (/.f64 y z) < 9.9999999999999998e-172Initial program 75.5%
*-commutative75.5%
associate-/l*82.1%
*-inverses82.1%
/-rgt-identity82.1%
associate-*l/98.8%
associate-*r/99.9%
Simplified99.9%
if -2.0000000000000001e190 < (/.f64 y z) < -9.99999999999999963e-272Initial program 87.4%
associate-/l*99.8%
*-inverses99.8%
/-rgt-identity99.8%
Simplified99.8%
clear-num99.7%
un-div-inv99.8%
Applied egg-rr99.8%
if 9.9999999999999998e-172 < (/.f64 y z) Initial program 85.7%
associate-/l*95.0%
*-inverses95.0%
/-rgt-identity95.0%
Simplified95.0%
Final simplification98.0%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(if (or (<= (/ y z) -2e+190)
(and (not (<= (/ y z) -4e-98)) (<= (/ y z) 1e-171)))
(* y (/ x z))
(* x (/ y z))))assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if (((y / z) <= -2e+190) || (!((y / z) <= -4e-98) && ((y / z) <= 1e-171))) {
tmp = y * (x / z);
} else {
tmp = x * (y / 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 (((y / z) <= (-2d+190)) .or. (.not. ((y / z) <= (-4d-98))) .and. ((y / z) <= 1d-171)) then
tmp = y * (x / z)
else
tmp = x * (y / 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 (((y / z) <= -2e+190) || (!((y / z) <= -4e-98) && ((y / z) <= 1e-171))) {
tmp = y * (x / z);
} else {
tmp = x * (y / z);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if ((y / z) <= -2e+190) or (not ((y / z) <= -4e-98) and ((y / z) <= 1e-171)): tmp = y * (x / z) else: tmp = x * (y / z) return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if ((Float64(y / z) <= -2e+190) || (!(Float64(y / z) <= -4e-98) && (Float64(y / z) <= 1e-171))) tmp = Float64(y * Float64(x / z)); else tmp = Float64(x * Float64(y / z)); 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+190) || (~(((y / z) <= -4e-98)) && ((y / z) <= 1e-171)))
tmp = y * (x / z);
else
tmp = x * (y / 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[Or[LessEqual[N[(y / z), $MachinePrecision], -2e+190], And[N[Not[LessEqual[N[(y / z), $MachinePrecision], -4e-98]], $MachinePrecision], LessEqual[N[(y / z), $MachinePrecision], 1e-171]]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} \leq -2 \cdot 10^{+190} \lor \neg \left(\frac{y}{z} \leq -4 \cdot 10^{-98}\right) \land \frac{y}{z} \leq 10^{-171}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if (/.f64 y z) < -2.0000000000000001e190 or -3.99999999999999976e-98 < (/.f64 y z) < 9.9999999999999998e-172Initial program 75.8%
*-commutative75.8%
associate-/l*86.4%
*-inverses86.4%
/-rgt-identity86.4%
associate-*l/96.7%
associate-*r/99.0%
Simplified99.0%
if -2.0000000000000001e190 < (/.f64 y z) < -3.99999999999999976e-98 or 9.9999999999999998e-172 < (/.f64 y z) Initial program 88.4%
associate-/l*96.4%
*-inverses96.4%
/-rgt-identity96.4%
Simplified96.4%
Final simplification97.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y 3.2e-104) (* x (/ y z)) (/ (* y x) z)))
assert(x < y);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3.2e-104) {
tmp = x * (y / z);
} 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 (y <= 3.2d-104) then
tmp = x * (y / z)
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 (y <= 3.2e-104) {
tmp = x * (y / z);
} else {
tmp = (y * x) / z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z, t): tmp = 0 if y <= 3.2e-104: tmp = x * (y / z) else: tmp = (y * x) / z return tmp
x, y = sort([x, y]) function code(x, y, z, t) tmp = 0.0 if (y <= 3.2e-104) tmp = Float64(x * Float64(y / z)); else tmp = Float64(Float64(y * x) / z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= 3.2e-104)
tmp = x * (y / z);
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[y, 3.2e-104], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{-104}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\end{array}
\end{array}
if y < 3.19999999999999989e-104Initial program 81.3%
associate-/l*92.0%
*-inverses92.0%
/-rgt-identity92.0%
Simplified92.0%
if 3.19999999999999989e-104 < y Initial program 85.0%
associate-/l*91.4%
*-inverses91.4%
/-rgt-identity91.4%
Simplified91.4%
Taylor expanded in x around 0 95.5%
Final simplification93.2%
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 82.6%
associate-/l*91.8%
*-inverses91.8%
/-rgt-identity91.8%
Simplified91.8%
Final simplification91.8%
(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 2023252
(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)))