
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(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(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -4.1e+291) (* x z) (if (or (<= x -1.2e-38) (not (<= x 1.65e-64))) (* x y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.1e+291) {
tmp = x * z;
} else if ((x <= -1.2e-38) || !(x <= 1.65e-64)) {
tmp = x * y;
} else {
tmp = -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 (x <= (-4.1d+291)) then
tmp = x * z
else if ((x <= (-1.2d-38)) .or. (.not. (x <= 1.65d-64))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.1e+291) {
tmp = x * z;
} else if ((x <= -1.2e-38) || !(x <= 1.65e-64)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.1e+291: tmp = x * z elif (x <= -1.2e-38) or not (x <= 1.65e-64): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.1e+291) tmp = Float64(x * z); elseif ((x <= -1.2e-38) || !(x <= 1.65e-64)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.1e+291) tmp = x * z; elseif ((x <= -1.2e-38) || ~((x <= 1.65e-64))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.1e+291], N[(x * z), $MachinePrecision], If[Or[LessEqual[x, -1.2e-38], N[Not[LessEqual[x, 1.65e-64]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+291}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{-38} \lor \neg \left(x \leq 1.65 \cdot 10^{-64}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.09999999999999985e291Initial program 71.2%
Taylor expanded in y around 0 80.4%
Taylor expanded in x around inf 80.4%
*-commutative80.4%
Simplified80.4%
if -4.09999999999999985e291 < x < -1.20000000000000011e-38 or 1.65e-64 < x Initial program 97.9%
Taylor expanded in y around inf 63.6%
if -1.20000000000000011e-38 < x < 1.65e-64Initial program 100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.7e-52) (not (<= x 4.8e-23))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.7e-52) || !(x <= 4.8e-23)) {
tmp = x * (z + y);
} else {
tmp = -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 ((x <= (-4.7d-52)) .or. (.not. (x <= 4.8d-23))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.7e-52) || !(x <= 4.8e-23)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.7e-52) or not (x <= 4.8e-23): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.7e-52) || !(x <= 4.8e-23)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.7e-52) || ~((x <= 4.8e-23))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.7e-52], N[Not[LessEqual[x, 4.8e-23]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{-52} \lor \neg \left(x \leq 4.8 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.6999999999999997e-52 or 4.79999999999999993e-23 < x Initial program 96.5%
Taylor expanded in x around inf 93.5%
+-commutative93.5%
Simplified93.5%
if -4.6999999999999997e-52 < x < 4.79999999999999993e-23Initial program 100.0%
Taylor expanded in x around 0 75.4%
neg-mul-175.4%
Simplified75.4%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.016) (not (<= x 1.4e-7))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.016) || !(x <= 1.4e-7)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-0.016d0)) .or. (.not. (x <= 1.4d-7))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.016) || !(x <= 1.4e-7)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.016) or not (x <= 1.4e-7): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.016) || !(x <= 1.4e-7)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.016) || ~((x <= 1.4e-7))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.016], N[Not[LessEqual[x, 1.4e-7]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.016 \lor \neg \left(x \leq 1.4 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -0.016 or 1.4000000000000001e-7 < x Initial program 96.1%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -0.016 < x < 1.4000000000000001e-7Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e-5) (not (<= x 1.05e-11))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-5) || !(x <= 1.05e-11)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - 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 ((x <= (-2.8d-5)) .or. (.not. (x <= 1.05d-11))) then
tmp = x * (z + y)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-5) || !(x <= 1.05e-11)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e-5) or not (x <= 1.05e-11): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e-5) || !(x <= 1.05e-11)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.8e-5) || ~((x <= 1.05e-11))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e-5], N[Not[LessEqual[x, 1.05e-11]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-5} \lor \neg \left(x \leq 1.05 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -2.79999999999999996e-5 or 1.0499999999999999e-11 < x Initial program 96.1%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -2.79999999999999996e-5 < x < 1.0499999999999999e-11Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 72.9%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-39) (not (<= x 5.4e-66))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-39) || !(x <= 5.4e-66)) {
tmp = x * y;
} else {
tmp = -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 ((x <= (-3d-39)) .or. (.not. (x <= 5.4d-66))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-39) || !(x <= 5.4e-66)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-39) or not (x <= 5.4e-66): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-39) || !(x <= 5.4e-66)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3e-39) || ~((x <= 5.4e-66))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-39], N[Not[LessEqual[x, 5.4e-66]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-39} \lor \neg \left(x \leq 5.4 \cdot 10^{-66}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.00000000000000028e-39 or 5.39999999999999992e-66 < x Initial program 96.6%
Taylor expanded in y around inf 61.4%
if -3.00000000000000028e-39 < x < 5.39999999999999992e-66Initial program 100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 37.4%
neg-mul-137.4%
Simplified37.4%
Final simplification37.4%
herbie shell --seed 2024053
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))