
(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 96.4%
*-commutative96.4%
sub-neg96.4%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
+-commutative96.5%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -5.8e+190)
(* x z)
(if (<= x -1.5e+128)
(* x y)
(if (<= x -3.2e+96)
(* x z)
(if (<= x -3.1e-25)
(* x y)
(if (<= x 4.15e-38)
(- z)
(if (or (<= x 3e+35) (not (<= x 3.7e+122))) (* x y) (* x z))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.8e+190) {
tmp = x * z;
} else if (x <= -1.5e+128) {
tmp = x * y;
} else if (x <= -3.2e+96) {
tmp = x * z;
} else if (x <= -3.1e-25) {
tmp = x * y;
} else if (x <= 4.15e-38) {
tmp = -z;
} else if ((x <= 3e+35) || !(x <= 3.7e+122)) {
tmp = x * y;
} else {
tmp = x * 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 <= (-5.8d+190)) then
tmp = x * z
else if (x <= (-1.5d+128)) then
tmp = x * y
else if (x <= (-3.2d+96)) then
tmp = x * z
else if (x <= (-3.1d-25)) then
tmp = x * y
else if (x <= 4.15d-38) then
tmp = -z
else if ((x <= 3d+35) .or. (.not. (x <= 3.7d+122))) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.8e+190) {
tmp = x * z;
} else if (x <= -1.5e+128) {
tmp = x * y;
} else if (x <= -3.2e+96) {
tmp = x * z;
} else if (x <= -3.1e-25) {
tmp = x * y;
} else if (x <= 4.15e-38) {
tmp = -z;
} else if ((x <= 3e+35) || !(x <= 3.7e+122)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.8e+190: tmp = x * z elif x <= -1.5e+128: tmp = x * y elif x <= -3.2e+96: tmp = x * z elif x <= -3.1e-25: tmp = x * y elif x <= 4.15e-38: tmp = -z elif (x <= 3e+35) or not (x <= 3.7e+122): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.8e+190) tmp = Float64(x * z); elseif (x <= -1.5e+128) tmp = Float64(x * y); elseif (x <= -3.2e+96) tmp = Float64(x * z); elseif (x <= -3.1e-25) tmp = Float64(x * y); elseif (x <= 4.15e-38) tmp = Float64(-z); elseif ((x <= 3e+35) || !(x <= 3.7e+122)) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.8e+190) tmp = x * z; elseif (x <= -1.5e+128) tmp = x * y; elseif (x <= -3.2e+96) tmp = x * z; elseif (x <= -3.1e-25) tmp = x * y; elseif (x <= 4.15e-38) tmp = -z; elseif ((x <= 3e+35) || ~((x <= 3.7e+122))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.8e+190], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.5e+128], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.2e+96], N[(x * z), $MachinePrecision], If[LessEqual[x, -3.1e-25], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.15e-38], (-z), If[Or[LessEqual[x, 3e+35], N[Not[LessEqual[x, 3.7e+122]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+190}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.5 \cdot 10^{+128}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{+96}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3.1 \cdot 10^{-25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.15 \cdot 10^{-38}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+35} \lor \neg \left(x \leq 3.7 \cdot 10^{+122}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -5.79999999999999979e190 or -1.4999999999999999e128 < x < -3.20000000000000006e96 or 2.99999999999999991e35 < x < 3.6999999999999997e122Initial program 94.0%
Taylor expanded in y around 0 76.6%
Taylor expanded in x around inf 76.6%
*-commutative76.6%
Simplified76.6%
if -5.79999999999999979e190 < x < -1.4999999999999999e128 or -3.20000000000000006e96 < x < -3.09999999999999995e-25 or 4.1499999999999998e-38 < x < 2.99999999999999991e35 or 3.6999999999999997e122 < x Initial program 93.9%
Taylor expanded in y around inf 67.6%
if -3.09999999999999995e-25 < x < 4.1499999999999998e-38Initial program 100.0%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e-25) (not (<= x 4.2e-38))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-25) || !(x <= 4.2e-38)) {
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 <= (-2.1d-25)) .or. (.not. (x <= 4.2d-38))) 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 <= -2.1e-25) || !(x <= 4.2e-38)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e-25) or not (x <= 4.2e-38): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e-25) || !(x <= 4.2e-38)) 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 <= -2.1e-25) || ~((x <= 4.2e-38))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e-25], N[Not[LessEqual[x, 4.2e-38]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-25} \lor \neg \left(x \leq 4.2 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.10000000000000002e-25 or 4.20000000000000026e-38 < x Initial program 93.9%
Taylor expanded in x around inf 93.6%
+-commutative93.6%
Simplified93.6%
if -2.10000000000000002e-25 < x < 4.20000000000000026e-38Initial program 100.0%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0004) (not (<= x 1.5e-38))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0004) || !(x <= 1.5e-38)) {
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.0004d0)) .or. (.not. (x <= 1.5d-38))) 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.0004) || !(x <= 1.5e-38)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0004) or not (x <= 1.5e-38): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0004) || !(x <= 1.5e-38)) 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.0004) || ~((x <= 1.5e-38))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0004], N[Not[LessEqual[x, 1.5e-38]], $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.0004 \lor \neg \left(x \leq 1.5 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -4.00000000000000019e-4 or 1.49999999999999994e-38 < x Initial program 93.6%
Taylor expanded in x around inf 96.7%
+-commutative96.7%
Simplified96.7%
if -4.00000000000000019e-4 < x < 1.49999999999999994e-38Initial program 99.9%
Taylor expanded in y around 0 73.8%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0011) (not (<= x 3.6e-38))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0011) || !(x <= 3.6e-38)) {
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 <= (-0.0011d0)) .or. (.not. (x <= 3.6d-38))) 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 <= -0.0011) || !(x <= 3.6e-38)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0011) or not (x <= 3.6e-38): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0011) || !(x <= 3.6e-38)) 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 <= -0.0011) || ~((x <= 3.6e-38))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0011], N[Not[LessEqual[x, 3.6e-38]], $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 -0.0011 \lor \neg \left(x \leq 3.6 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -0.00110000000000000007 or 3.6000000000000001e-38 < x Initial program 93.6%
Taylor expanded in x around inf 96.7%
+-commutative96.7%
Simplified96.7%
if -0.00110000000000000007 < x < 3.6000000000000001e-38Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
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 73.9%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e-25) (not (<= x 3.8e-38))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e-25) || !(x <= 3.8e-38)) {
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 <= (-1.75d-25)) .or. (.not. (x <= 3.8d-38))) 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 <= -1.75e-25) || !(x <= 3.8e-38)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.75e-25) or not (x <= 3.8e-38): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e-25) || !(x <= 3.8e-38)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.75e-25) || ~((x <= 3.8e-38))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e-25], N[Not[LessEqual[x, 3.8e-38]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-25} \lor \neg \left(x \leq 3.8 \cdot 10^{-38}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.7500000000000001e-25 or 3.8e-38 < x Initial program 93.9%
Taylor expanded in y around inf 54.8%
if -1.7500000000000001e-25 < x < 3.8e-38Initial program 100.0%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification63.5%
(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 96.4%
Taylor expanded in x around 0 34.7%
neg-mul-134.7%
Simplified34.7%
Final simplification34.7%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))