
(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 99.2%
*-commutative99.2%
sub-neg99.2%
distribute-rgt-in99.2%
metadata-eval99.2%
neg-mul-199.2%
associate-+r+99.2%
unsub-neg99.2%
+-commutative99.2%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.2e+40)
(* x z)
(if (<= x -8.5e-100)
(* x y)
(if (<= x 9e-36)
(- z)
(if (or (<= x 7.8e+40)
(and (not (<= x 1.35e+101))
(or (<= x 3.65e+140)
(and (not (<= x 3.8e+217)) (<= x 5.8e+278)))))
(* x y)
(* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+40) {
tmp = x * z;
} else if (x <= -8.5e-100) {
tmp = x * y;
} else if (x <= 9e-36) {
tmp = -z;
} else if ((x <= 7.8e+40) || (!(x <= 1.35e+101) && ((x <= 3.65e+140) || (!(x <= 3.8e+217) && (x <= 5.8e+278))))) {
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 <= (-1.2d+40)) then
tmp = x * z
else if (x <= (-8.5d-100)) then
tmp = x * y
else if (x <= 9d-36) then
tmp = -z
else if ((x <= 7.8d+40) .or. (.not. (x <= 1.35d+101)) .and. (x <= 3.65d+140) .or. (.not. (x <= 3.8d+217)) .and. (x <= 5.8d+278)) 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 <= -1.2e+40) {
tmp = x * z;
} else if (x <= -8.5e-100) {
tmp = x * y;
} else if (x <= 9e-36) {
tmp = -z;
} else if ((x <= 7.8e+40) || (!(x <= 1.35e+101) && ((x <= 3.65e+140) || (!(x <= 3.8e+217) && (x <= 5.8e+278))))) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2e+40: tmp = x * z elif x <= -8.5e-100: tmp = x * y elif x <= 9e-36: tmp = -z elif (x <= 7.8e+40) or (not (x <= 1.35e+101) and ((x <= 3.65e+140) or (not (x <= 3.8e+217) and (x <= 5.8e+278)))): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2e+40) tmp = Float64(x * z); elseif (x <= -8.5e-100) tmp = Float64(x * y); elseif (x <= 9e-36) tmp = Float64(-z); elseif ((x <= 7.8e+40) || (!(x <= 1.35e+101) && ((x <= 3.65e+140) || (!(x <= 3.8e+217) && (x <= 5.8e+278))))) 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 <= -1.2e+40) tmp = x * z; elseif (x <= -8.5e-100) tmp = x * y; elseif (x <= 9e-36) tmp = -z; elseif ((x <= 7.8e+40) || (~((x <= 1.35e+101)) && ((x <= 3.65e+140) || (~((x <= 3.8e+217)) && (x <= 5.8e+278))))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2e+40], N[(x * z), $MachinePrecision], If[LessEqual[x, -8.5e-100], N[(x * y), $MachinePrecision], If[LessEqual[x, 9e-36], (-z), If[Or[LessEqual[x, 7.8e+40], And[N[Not[LessEqual[x, 1.35e+101]], $MachinePrecision], Or[LessEqual[x, 3.65e+140], And[N[Not[LessEqual[x, 3.8e+217]], $MachinePrecision], LessEqual[x, 5.8e+278]]]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+40}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-100}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-36}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{+40} \lor \neg \left(x \leq 1.35 \cdot 10^{+101}\right) \land \left(x \leq 3.65 \cdot 10^{+140} \lor \neg \left(x \leq 3.8 \cdot 10^{+217}\right) \land x \leq 5.8 \cdot 10^{+278}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.2e40 or 7.8000000000000002e40 < x < 1.35000000000000003e101 or 3.6500000000000002e140 < x < 3.80000000000000002e217 or 5.7999999999999995e278 < x Initial program 98.1%
Taylor expanded in y around 0 65.3%
Taylor expanded in x around inf 65.3%
if -1.2e40 < x < -8.50000000000000017e-100 or 9.00000000000000047e-36 < x < 7.8000000000000002e40 or 1.35000000000000003e101 < x < 3.6500000000000002e140 or 3.80000000000000002e217 < x < 5.7999999999999995e278Initial program 99.9%
Taylor expanded in y around inf 70.2%
if -8.50000000000000017e-100 < x < 9.00000000000000047e-36Initial program 100.0%
Taylor expanded in x around 0 76.7%
neg-mul-176.7%
Simplified76.7%
Final simplification70.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.45e-109) (* x (+ z y)) (if (<= x 245.0) (* z (+ x -1.0)) (+ (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-109) {
tmp = x * (z + y);
} else if (x <= 245.0) {
tmp = z * (x + -1.0);
} else {
tmp = (x * y) + (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 <= (-1.45d-109)) then
tmp = x * (z + y)
else if (x <= 245.0d0) then
tmp = z * (x + (-1.0d0))
else
tmp = (x * y) + (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-109) {
tmp = x * (z + y);
} else if (x <= 245.0) {
tmp = z * (x + -1.0);
} else {
tmp = (x * y) + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.45e-109: tmp = x * (z + y) elif x <= 245.0: tmp = z * (x + -1.0) else: tmp = (x * y) + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.45e-109) tmp = Float64(x * Float64(z + y)); elseif (x <= 245.0) tmp = Float64(z * Float64(x + -1.0)); else tmp = Float64(Float64(x * y) + Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.45e-109) tmp = x * (z + y); elseif (x <= 245.0) tmp = z * (x + -1.0); else tmp = (x * y) + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.45e-109], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 245.0], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-109}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{elif}\;x \leq 245:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + x \cdot z\\
\end{array}
\end{array}
if x < -1.45e-109Initial program 97.8%
Taylor expanded in x around inf 90.9%
+-commutative90.9%
Simplified90.9%
if -1.45e-109 < x < 245Initial program 100.0%
Taylor expanded in y around 0 74.3%
if 245 < x Initial program 100.0%
Taylor expanded in x around inf 99.9%
*-commutative99.9%
Simplified99.9%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e-111) (not (<= x 4.6e-33))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-111) || !(x <= 4.6e-33)) {
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 <= (-4d-111)) .or. (.not. (x <= 4.6d-33))) 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 <= -4e-111) || !(x <= 4.6e-33)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e-111) or not (x <= 4.6e-33): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e-111) || !(x <= 4.6e-33)) 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 <= -4e-111) || ~((x <= 4.6e-33))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e-111], N[Not[LessEqual[x, 4.6e-33]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-111} \lor \neg \left(x \leq 4.6 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.00000000000000035e-111 or 4.59999999999999971e-33 < x Initial program 98.8%
Taylor expanded in x around inf 91.0%
+-commutative91.0%
Simplified91.0%
if -4.00000000000000035e-111 < x < 4.59999999999999971e-33Initial program 100.0%
Taylor expanded in x around 0 77.9%
neg-mul-177.9%
Simplified77.9%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-109) (not (<= x 425.0))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-109) || !(x <= 425.0)) {
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 <= (-3d-109)) .or. (.not. (x <= 425.0d0))) 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 <= -3e-109) || !(x <= 425.0)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-109) or not (x <= 425.0): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-109) || !(x <= 425.0)) 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 <= -3e-109) || ~((x <= 425.0))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-109], N[Not[LessEqual[x, 425.0]], $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 -3 \cdot 10^{-109} \lor \neg \left(x \leq 425\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -3.00000000000000021e-109 or 425 < x Initial program 98.7%
Taylor expanded in x around inf 94.8%
+-commutative94.8%
Simplified94.8%
if -3.00000000000000021e-109 < x < 425Initial program 100.0%
Taylor expanded in y around 0 74.3%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-100) (not (<= x 1.15e-40))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-100) || !(x <= 1.15e-40)) {
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 <= (-8.5d-100)) .or. (.not. (x <= 1.15d-40))) 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 <= -8.5e-100) || !(x <= 1.15e-40)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-100) or not (x <= 1.15e-40): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-100) || !(x <= 1.15e-40)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.5e-100) || ~((x <= 1.15e-40))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-100], N[Not[LessEqual[x, 1.15e-40]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-100} \lor \neg \left(x \leq 1.15 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.50000000000000017e-100 or 1.15e-40 < x Initial program 98.8%
Taylor expanded in y around inf 50.7%
if -8.50000000000000017e-100 < x < 1.15e-40Initial program 100.0%
Taylor expanded in x around 0 76.7%
neg-mul-176.7%
Simplified76.7%
Final simplification59.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 99.2%
Taylor expanded in x around 0 30.9%
neg-mul-130.9%
Simplified30.9%
Final simplification30.9%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))