
(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 5 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 81.7%
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.6%
Simplified96.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+43) (* y (/ x z)) (if (<= y 1.4e-28) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+43) {
tmp = y * (x / z);
} else if (y <= 1.4e-28) {
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 <= (-1.95d+43)) then
tmp = y * (x / z)
else if (y <= 1.4d-28) 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 <= -1.95e+43) {
tmp = y * (x / z);
} else if (y <= 1.4e-28) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.95e+43: tmp = y * (x / z) elif y <= 1.4e-28: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+43) tmp = Float64(y * Float64(x / z)); elseif (y <= 1.4e-28) 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 <= -1.95e+43) tmp = y * (x / z); elseif (y <= 1.4e-28) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+43], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-28], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+43}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-28}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -1.95e43Initial program 92.2%
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-identity91.9%
Simplified91.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-/.f6475.2%
Simplified75.2%
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f6481.6%
Applied egg-rr81.6%
if -1.95e43 < y < 1.3999999999999999e-28Initial program 74.7%
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-identity99.9%
Simplified99.9%
Taylor expanded in y around 0
Simplified79.9%
if 1.3999999999999999e-28 < y Initial program 85.3%
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.7%
Simplified94.7%
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-/.f6471.6%
Simplified71.6%
associate-/r/N/A
*-commutativeN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f6474.0%
Applied egg-rr74.0%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (/ x z)))) (if (<= y -3.6e+43) t_0 (if (<= y 4e-26) x t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -3.6e+43) {
tmp = t_0;
} else if (y <= 4e-26) {
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 <= (-3.6d+43)) then
tmp = t_0
else if (y <= 4d-26) 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 <= -3.6e+43) {
tmp = t_0;
} else if (y <= 4e-26) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x / z) tmp = 0 if y <= -3.6e+43: tmp = t_0 elif y <= 4e-26: 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 <= -3.6e+43) tmp = t_0; elseif (y <= 4e-26) 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 <= -3.6e+43) tmp = t_0; elseif (y <= 4e-26) 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, -3.6e+43], t$95$0, If[LessEqual[y, 4e-26], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.6000000000000001e43 or 4.0000000000000002e-26 < y Initial program 88.4%
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-identity93.4%
Simplified93.4%
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-/.f6473.2%
Simplified73.2%
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f6477.4%
Applied egg-rr77.4%
if -3.6000000000000001e43 < y < 4.0000000000000002e-26Initial program 74.7%
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-identity99.9%
Simplified99.9%
Taylor expanded in y around 0
Simplified79.9%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (/ y z)))) (if (<= y -3.5e-33) t_0 (if (<= y 1.05e-26) x t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y / z);
double tmp;
if (y <= -3.5e-33) {
tmp = t_0;
} else if (y <= 1.05e-26) {
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 <= (-3.5d-33)) then
tmp = t_0
else if (y <= 1.05d-26) 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 <= -3.5e-33) {
tmp = t_0;
} else if (y <= 1.05e-26) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y / z) tmp = 0 if y <= -3.5e-33: tmp = t_0 elif y <= 1.05e-26: 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 <= -3.5e-33) tmp = t_0; elseif (y <= 1.05e-26) 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 <= -3.5e-33) tmp = t_0; elseif (y <= 1.05e-26) 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, -3.5e-33], t$95$0, If[LessEqual[y, 1.05e-26], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{-33}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.4999999999999999e-33 or 1.05000000000000004e-26 < y Initial program 88.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-identity93.9%
Simplified93.9%
Taylor expanded in y around inf
/-lowering-/.f6471.4%
Simplified71.4%
if -3.4999999999999999e-33 < y < 1.05000000000000004e-26Initial program 73.7%
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-identity99.9%
Simplified99.9%
Taylor expanded in y around 0
Simplified82.8%
(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 81.7%
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.6%
Simplified96.6%
Taylor expanded in y around 0
Simplified50.2%
(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 2024138
(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))