
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
(FPCore (x y z) :precision binary64 (fma (/ y 2.0) x (* -0.125 z)))
double code(double x, double y, double z) {
return fma((y / 2.0), x, (-0.125 * z));
}
function code(x, y, z) return fma(Float64(y / 2.0), x, Float64(-0.125 * z)) end
code[x_, y_, z_] := N[(N[(y / 2.0), $MachinePrecision] * x + N[(-0.125 * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{2}, x, -0.125 \cdot z\right)
\end{array}
Initial program 99.7%
*-commutative99.7%
associate-*l/100.0%
fma-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= (* y x) -1.65e+43)
(and (not (<= (* y x) 3e-45))
(or (<= (* y x) 8600000.0) (not (<= (* y x) 5e+75)))))
(* (* y x) 0.5)
(* -0.125 z)))
double code(double x, double y, double z) {
double tmp;
if (((y * x) <= -1.65e+43) || (!((y * x) <= 3e-45) && (((y * x) <= 8600000.0) || !((y * x) <= 5e+75)))) {
tmp = (y * x) * 0.5;
} else {
tmp = -0.125 * z;
}
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 * x) <= (-1.65d+43)) .or. (.not. ((y * x) <= 3d-45)) .and. ((y * x) <= 8600000.0d0) .or. (.not. ((y * x) <= 5d+75))) then
tmp = (y * x) * 0.5d0
else
tmp = (-0.125d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * x) <= -1.65e+43) || (!((y * x) <= 3e-45) && (((y * x) <= 8600000.0) || !((y * x) <= 5e+75)))) {
tmp = (y * x) * 0.5;
} else {
tmp = -0.125 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * x) <= -1.65e+43) or (not ((y * x) <= 3e-45) and (((y * x) <= 8600000.0) or not ((y * x) <= 5e+75))): tmp = (y * x) * 0.5 else: tmp = -0.125 * z return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * x) <= -1.65e+43) || (!(Float64(y * x) <= 3e-45) && ((Float64(y * x) <= 8600000.0) || !(Float64(y * x) <= 5e+75)))) tmp = Float64(Float64(y * x) * 0.5); else tmp = Float64(-0.125 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * x) <= -1.65e+43) || (~(((y * x) <= 3e-45)) && (((y * x) <= 8600000.0) || ~(((y * x) <= 5e+75))))) tmp = (y * x) * 0.5; else tmp = -0.125 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * x), $MachinePrecision], -1.65e+43], And[N[Not[LessEqual[N[(y * x), $MachinePrecision], 3e-45]], $MachinePrecision], Or[LessEqual[N[(y * x), $MachinePrecision], 8600000.0], N[Not[LessEqual[N[(y * x), $MachinePrecision], 5e+75]], $MachinePrecision]]]], N[(N[(y * x), $MachinePrecision] * 0.5), $MachinePrecision], N[(-0.125 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -1.65 \cdot 10^{+43} \lor \neg \left(y \cdot x \leq 3 \cdot 10^{-45}\right) \land \left(y \cdot x \leq 8600000 \lor \neg \left(y \cdot x \leq 5 \cdot 10^{+75}\right)\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;-0.125 \cdot z\\
\end{array}
\end{array}
if (*.f64 x y) < -1.6500000000000001e43 or 3.00000000000000011e-45 < (*.f64 x y) < 8.6e6 or 5.0000000000000002e75 < (*.f64 x y) Initial program 99.3%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 83.2%
if -1.6500000000000001e43 < (*.f64 x y) < 3.00000000000000011e-45 or 8.6e6 < (*.f64 x y) < 5.0000000000000002e75Initial program 100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 77.6%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* y x) 0.5)))
(if (<= (* y x) -2e+48)
t_0
(if (<= (* y x) 2e-45)
(* -0.125 z)
(if (<= (* y x) 1.0)
t_0
(if (<= (* y x) 5e+75) (* -0.125 z) (* x (* y 0.5))))))))
double code(double x, double y, double z) {
double t_0 = (y * x) * 0.5;
double tmp;
if ((y * x) <= -2e+48) {
tmp = t_0;
} else if ((y * x) <= 2e-45) {
tmp = -0.125 * z;
} else if ((y * x) <= 1.0) {
tmp = t_0;
} else if ((y * x) <= 5e+75) {
tmp = -0.125 * z;
} else {
tmp = x * (y * 0.5);
}
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) * 0.5d0
if ((y * x) <= (-2d+48)) then
tmp = t_0
else if ((y * x) <= 2d-45) then
tmp = (-0.125d0) * z
else if ((y * x) <= 1.0d0) then
tmp = t_0
else if ((y * x) <= 5d+75) then
tmp = (-0.125d0) * z
else
tmp = x * (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * x) * 0.5;
double tmp;
if ((y * x) <= -2e+48) {
tmp = t_0;
} else if ((y * x) <= 2e-45) {
tmp = -0.125 * z;
} else if ((y * x) <= 1.0) {
tmp = t_0;
} else if ((y * x) <= 5e+75) {
tmp = -0.125 * z;
} else {
tmp = x * (y * 0.5);
}
return tmp;
}
def code(x, y, z): t_0 = (y * x) * 0.5 tmp = 0 if (y * x) <= -2e+48: tmp = t_0 elif (y * x) <= 2e-45: tmp = -0.125 * z elif (y * x) <= 1.0: tmp = t_0 elif (y * x) <= 5e+75: tmp = -0.125 * z else: tmp = x * (y * 0.5) return tmp
function code(x, y, z) t_0 = Float64(Float64(y * x) * 0.5) tmp = 0.0 if (Float64(y * x) <= -2e+48) tmp = t_0; elseif (Float64(y * x) <= 2e-45) tmp = Float64(-0.125 * z); elseif (Float64(y * x) <= 1.0) tmp = t_0; elseif (Float64(y * x) <= 5e+75) tmp = Float64(-0.125 * z); else tmp = Float64(x * Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * x) * 0.5; tmp = 0.0; if ((y * x) <= -2e+48) tmp = t_0; elseif ((y * x) <= 2e-45) tmp = -0.125 * z; elseif ((y * x) <= 1.0) tmp = t_0; elseif ((y * x) <= 5e+75) tmp = -0.125 * z; else tmp = x * (y * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[N[(y * x), $MachinePrecision], -2e+48], t$95$0, If[LessEqual[N[(y * x), $MachinePrecision], 2e-45], N[(-0.125 * z), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 1.0], t$95$0, If[LessEqual[N[(y * x), $MachinePrecision], 5e+75], N[(-0.125 * z), $MachinePrecision], N[(x * N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot x\right) \cdot 0.5\\
\mathbf{if}\;y \cdot x \leq -2 \cdot 10^{+48}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \cdot x \leq 2 \cdot 10^{-45}:\\
\;\;\;\;-0.125 \cdot z\\
\mathbf{elif}\;y \cdot x \leq 1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \cdot x \leq 5 \cdot 10^{+75}:\\
\;\;\;\;-0.125 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot 0.5\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -2.00000000000000009e48 or 1.99999999999999997e-45 < (*.f64 x y) < 1Initial program 100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 82.5%
if -2.00000000000000009e48 < (*.f64 x y) < 1.99999999999999997e-45 or 1 < (*.f64 x y) < 5.0000000000000002e75Initial program 100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 77.6%
if 5.0000000000000002e75 < (*.f64 x y) Initial program 98.3%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 84.2%
expm1-log1p-u79.0%
expm1-udef79.0%
log1p-udef79.0%
add-exp-log84.2%
Applied egg-rr84.2%
+-commutative84.2%
associate--l+84.2%
metadata-eval84.2%
*-commutative84.2%
associate-*r*85.8%
Simplified85.8%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (- (* y (/ x 2.0)) (/ z 8.0)))
double code(double x, double y, double z) {
return (y * (x / 2.0)) - (z / 8.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * (x / 2.0d0)) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return (y * (x / 2.0)) - (z / 8.0);
}
def code(x, y, z): return (y * (x / 2.0)) - (z / 8.0)
function code(x, y, z) return Float64(Float64(y * Float64(x / 2.0)) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = (y * (x / 2.0)) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(y * N[(x / 2.0), $MachinePrecision]), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{x}{2} - \frac{z}{8}
\end{array}
Initial program 99.7%
associate-*l/100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (* -0.125 z))
double code(double x, double y, double z) {
return -0.125 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-0.125d0) * z
end function
public static double code(double x, double y, double z) {
return -0.125 * z;
}
def code(x, y, z): return -0.125 * z
function code(x, y, z) return Float64(-0.125 * z) end
function tmp = code(x, y, z) tmp = -0.125 * z; end
code[x_, y_, z_] := N[(-0.125 * z), $MachinePrecision]
\begin{array}{l}
\\
-0.125 \cdot z
\end{array}
Initial program 99.7%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 50.2%
Final simplification50.2%
herbie shell --seed 2023293
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))