
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
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
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
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
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (* x (+ 1.0 (/ y z))))
double code(double x, double y, double z) {
return x * (1.0 + (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 = x * (1.0d0 + (y / z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 + (y / z));
}
def code(x, y, z): return x * (1.0 + (y / z))
function code(x, y, z) return Float64(x * Float64(1.0 + Float64(y / z))) end
function tmp = code(x, y, z) tmp = x * (1.0 + (y / z)); end
code[x_, y_, z_] := N[(x * N[(1.0 + N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + \frac{y}{z}\right)
\end{array}
Initial program 83.5%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity97.7%
Simplified97.7%
(FPCore (x y z) :precision binary64 (if (<= y -2e+69) (/ (* x y) z) (if (<= y 1.6e+15) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e+69) {
tmp = (x * y) / z;
} else if (y <= 1.6e+15) {
tmp = x;
} else {
tmp = y / (z / x);
}
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) :: tmp
if (y <= (-2d+69)) then
tmp = (x * y) / z
else if (y <= 1.6d+15) then
tmp = x
else
tmp = y / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2e+69) {
tmp = (x * y) / z;
} else if (y <= 1.6e+15) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e+69: tmp = (x * y) / z elif y <= 1.6e+15: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e+69) tmp = Float64(Float64(x * y) / z); elseif (y <= 1.6e+15) tmp = x; else tmp = Float64(y / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e+69) tmp = (x * y) / z; elseif (y <= 1.6e+15) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e+69], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 1.6e+15], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+69}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -2.0000000000000001e69Initial program 89.2%
Taylor expanded in y around inf
*-lowering-*.f6472.5%
Simplified72.5%
if -2.0000000000000001e69 < y < 1.6e15Initial program 79.1%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified78.2%
if 1.6e15 < y Initial program 88.8%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity96.8%
Simplified96.8%
Taylor expanded in y around inf
*-rgt-identityN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
associate-/r*N/A
associate-/l*N/A
*-rgt-identityN/A
associate-*r/N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
/-lowering-/.f64N/A
/-lowering-/.f6465.7%
Simplified65.7%
associate-/r/N/A
*-commutativeN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f6468.9%
Applied egg-rr68.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ y (/ z x)))) (if (<= y -5.2e+70) t_0 (if (<= y 1.45e+15) x t_0))))
double code(double x, double y, double z) {
double t_0 = y / (z / x);
double tmp;
if (y <= -5.2e+70) {
tmp = t_0;
} else if (y <= 1.45e+15) {
tmp = x;
} 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 = y / (z / x)
if (y <= (-5.2d+70)) then
tmp = t_0
else if (y <= 1.45d+15) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / (z / x);
double tmp;
if (y <= -5.2e+70) {
tmp = t_0;
} else if (y <= 1.45e+15) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y / (z / x) tmp = 0 if y <= -5.2e+70: tmp = t_0 elif y <= 1.45e+15: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y / Float64(z / x)) tmp = 0.0 if (y <= -5.2e+70) tmp = t_0; elseif (y <= 1.45e+15) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (z / x); tmp = 0.0; if (y <= -5.2e+70) tmp = t_0; elseif (y <= 1.45e+15) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.2e+70], t$95$0, If[LessEqual[y, 1.45e+15], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{\frac{z}{x}}\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.2000000000000001e70 or 1.45e15 < y Initial program 89.0%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity94.9%
Simplified94.9%
Taylor expanded in y around inf
*-rgt-identityN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
associate-/r*N/A
associate-/l*N/A
*-rgt-identityN/A
associate-*r/N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
/-lowering-/.f64N/A
/-lowering-/.f6466.9%
Simplified66.9%
associate-/r/N/A
*-commutativeN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f6469.8%
Applied egg-rr69.8%
if -5.2000000000000001e70 < y < 1.45e15Initial program 79.1%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified78.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (/ x z)))) (if (<= y -2e+71) t_0 (if (<= y 2.6e+15) x t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -2e+71) {
tmp = t_0;
} else if (y <= 2.6e+15) {
tmp = x;
} 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 = y * (x / z)
if (y <= (-2d+71)) then
tmp = t_0
else if (y <= 2.6d+15) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -2e+71) {
tmp = t_0;
} else if (y <= 2.6e+15) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x / z) tmp = 0 if y <= -2e+71: tmp = t_0 elif y <= 2.6e+15: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x / z)) tmp = 0.0 if (y <= -2e+71) tmp = t_0; elseif (y <= 2.6e+15) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x / z); tmp = 0.0; if (y <= -2e+71) tmp = t_0; elseif (y <= 2.6e+15) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e+71], t$95$0, If[LessEqual[y, 2.6e+15], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -2 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.0000000000000001e71 or 2.6e15 < y Initial program 89.0%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity94.9%
Simplified94.9%
Taylor expanded in y around inf
*-rgt-identityN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
associate-/r*N/A
associate-/l*N/A
*-rgt-identityN/A
associate-*r/N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
/-lowering-/.f64N/A
/-lowering-/.f6466.9%
Simplified66.9%
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f6469.8%
Applied egg-rr69.8%
if -2.0000000000000001e71 < y < 2.6e15Initial program 79.1%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified78.2%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (/ y z)))) (if (<= y -2.3e+72) t_0 (if (<= y 1.85e+15) x t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y / z);
double tmp;
if (y <= -2.3e+72) {
tmp = t_0;
} else if (y <= 1.85e+15) {
tmp = x;
} 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 (y <= (-2.3d+72)) then
tmp = t_0
else if (y <= 1.85d+15) then
tmp = x
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 (y <= -2.3e+72) {
tmp = t_0;
} else if (y <= 1.85e+15) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y / z) tmp = 0 if y <= -2.3e+72: tmp = t_0 elif y <= 1.85e+15: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y / z)) tmp = 0.0 if (y <= -2.3e+72) tmp = t_0; elseif (y <= 1.85e+15) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y / z); tmp = 0.0; if (y <= -2.3e+72) tmp = t_0; elseif (y <= 1.85e+15) tmp = x; 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[y, -2.3e+72], t$95$0, If[LessEqual[y, 1.85e+15], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -2.3 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.3e72 or 1.85e15 < y Initial program 89.0%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity94.9%
Simplified94.9%
Taylor expanded in y around inf
/-lowering-/.f6467.0%
Simplified67.0%
if -2.3e72 < y < 1.85e15Initial program 79.1%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified78.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 83.5%
associate-/l*N/A
*-lowering-*.f64N/A
*-lft-identityN/A
*-inversesN/A
associate-*l/N/A
distribute-lft-inN/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
*-inversesN/A
lft-mult-inverseN/A
*-inversesN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-inversesN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity97.7%
Simplified97.7%
Taylor expanded in y around 0
Simplified56.1%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (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 = x / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2024140
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (/ x (/ z (+ y z))))
(/ (* x (+ y z)) z))